3D depth not using 3D functions

K

Kevin_Hahn

Guest
Hello,

I'm making a 3D platform game. I am not using 3D functions, as I am unfamiliar with them. Instead, I'm using some draw functions to project sprites into 3D with my own functions. As of now, I'm calculating the depth of a block (and all other objects) by the distance from the center of the view:
Code:
var xd,yd;

xd=abs(x-global.view_x);
yd=abs(y-global.view_y);

depth=(xd+yd);
The problem that arises from this method is depicted in these two pictures:


In both of these examples, the depth overlap is caused by one of the blocks being off the regular grid.
However, if I build a level to a block-sized grid, the depth performs just fine:

I could just build my level to a grid, but I really want to add lifts and other things.

Any help would be great!
 

Attachments

K

Kevin_Hahn

Guest
If you mean making the front and sides a separate object to control depth, and making the front object above the side object, I've already tried that. I've even attempted making all sides separate objects (very inefficient) with no success.

Here's an example (the right picture) of what happens when the front is drawn over everything.


Thanks for the reply! I hope I'm not misunderstanding you!

Keep in mind that I have other objects (not 3D) that use the same depth code which work great when all objects use the same depth code.
 

Attachments

Last edited by a moderator:

obscene

Member
No not separate objects. What I would think you could do (and I don't know that this would work as you're pulling off a pretty sweet trick there that I'm sure a has a lot of complicated parts I don't understand) is create a controller object that creates this effect. The object's depth would be something higher than your 3D blocks so it's draw event runs first.

It would do something like ...

with (obj_3d_block)
{
scr_cool_3d_effect();
}

And then when it comes time for the blocks to execute their normal draw events they all get drawn on top of the effect.
 
K

Kevin_Hahn

Guest
Thanks again for sticking with me!

I'm still not exactly sure what you mean... What do you mean by "execute their normal draw events"? The 3D draw effect is the draw event, which makes it flat (so I can't protrude it over other objects, obviously).

I don't wanna waste your time, but could you give a graphical example? I bet I'm misunderstanding.
 

obscene

Member
OK so as you probably understand, everything is drawn in order by depth from high to low. When GM is internally drawing stuff to screen everything is being layered on top of the previously drawn stuff. First backgrounds are drawn, then objects are drawn overtop of them, etc. Objects at lower depths are then drawn on top of those objects and on and on until there are no more objects to draw. Then the foregrounds are drawn, right on top of the existing image, until finally there's nothing left to draw and GM puts it out to the screen. The important thing in all this is everythign is drawn back to front, ontop of itself.

Now, even when objects are all the same depth like your blocks, GM still draws them individually one at a time in some order you can't control.

So, let's say you have two block side by side like in your screenshot where the bug appears. First you are probably drawing your 3D effect on the block. Then you draw the front. Looks great...

EDIT: Stupid editor messing up my ascii drawings...

Next block. Uh, oh,... problem. We need to draw the 3D effect but we've already drawn the front of the previous block. If we draw the sides of this block, they will be drawn on top of the previous block. Oh well... GM does what GM wants.

So despite the fact these two blocks are on the same depth, the second block and it's sides were drawn on top of the first and now it looks all screwed up.

The solution is to draw all the 3D geometry FIRST. Before you draw blocks. You can't do it block-by-block. First draw all sides, then draw all blocks.
 

BLang

Member
You're calculating your depth wrong. Try this instead:
Code:
depth = point_distance(x,y,view_xview[0]+view_wview[0]/2,view_yview[0]+view_yview[0]/2);
 

obscene

Member
Because my ASCII characters were messed up I made this.

The left side shows how you are doing it.

The right side shows how you need to do it.
 

Attachments

Last edited:
K

Kevin_Hahn

Guest
You're calculating your depth wrong. Try this instead:
Code:
depth = point_distance(x,y,view_xview[0]+view_wview[0]/2,view_yview[0]+view_yview[0]/2);
That was the first thing I tried when making this. Apparently this does some weird glitchy stuff for me. Manually finding the distance worked perfect, except for when the block isn't aligned (the whole point of this thread).

Because my ASCII characters were messed up I made this.

The left side shows how you are doing it.

The right side shows how you need to do it.
I'll spend the next few weeks trying to get this to work. That looks promising, although I have to admit, I'm still a little lost on the point you're trying to make. But I assume you want me to draw all the blocks with no depth at first, than each block draws the 3D effect thingy on top? I can't see how that would work, but I'll try!

Also about your other post, there is no situation in my game where the blocks have the same depth as another one, so that's not my problem (I can successfully build a level without any problems unless one of the blocks, like a lift, goes up a pixel).
 
Last edited by a moderator:

BLang

Member
Oh, that's weird. Okay then.

I think obscene is saying you should do it the other way around, first the 3d effect, then the tiles on top.
 
K

Kevin_Hahn

Guest
Oh, that's weird. Okay then.

I think obscene is saying you should do it the other way around, first the 3d effect, then the tiles on top.
But what should the depth be? Same as I had it? In my second post in this thread, the picture on the right shows what happens when I put the front on top.

Also, the numbers on the pictures in my first post show the depth of each block, if that's any help.
 

obscene

Member
Ah I missed your second post. With my solution you would get the same result but if you made the sides all the same color it would be concealed. This might be a concession you have to make unless you want to actually generate 3d geometry.

Draw the sides at depth n. (Anything) Draw the fronts at depth n-1.
 
Last edited:
K

Kevin_Hahn

Guest
It's actually not that complicated. All I did was create 8 virtual points, all which calculated their distance from the center of the screen, then I connected the dots with draw_sprite_pos()

Things I've also tried (very similar concept):
untitled.JPG
believe it or not, doing depth on the above project was easier than this one, and it worked perfect!
 

BLang

Member
Alright, so, I think the fix could be to calculate the depth of each side of the square, then draw the sides in order of depth.
 
I

icuurd12b42

Guest
depth = point_distance(x,y,view_xview+view_wview/2,view_yview+view_hview/2);

your box should have its origins centered.
 
K

Kevin_Hahn

Guest
depth = point_distance(x,y,view_xview+view_wview/2,view_yview+view_hview/2);

your box should have its origins centered.
This was already suggested, and, as I said, it was the first thing I tried. And yes, my box's origin is already centered.
 
Top