• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Rotating a 3D object around its own origin

L

LV154

Guest
I know this topic has been discussed before, and the solution is usually that rotation comes before translation of the model. However other threads seem to focus on imported models.

My problem is a little different. I have created various objects that draw multiple things at once in the draw event.

Eg.

draw_set_color(c_white);

d3d_draw_block(x-16,y-16,z,x+16,y+26,z1,sprite_get_texture(block_spr,0),1,1);

draw_set_color(c_black);}


If I add a rotation command, the object rotates around the room axis. How can I translate it to its origin? If I use the code d3d_transform_add_translation(x,y,0) or the actual coordinates placed in the room, it just isn't there when the game runs. What am I doing wrong?
 
Think of transforming and drawing as this: transformations are the new origin, and the actual block drawing is the offset from that origin. If you transform, don't factor in the coordinates into the drawing line, otherwise you'll be stacking. For example, if you translate to 100,100,100, but also draw the block at 100,100,100, the block will draw at 200,200,200. If you're also rotating, it's then like using lengthdir as it will orbit around that 100,100,100 point from 100 units away due to the offset.

So just add in the transformations again but remove the coordinates from the block drawing.
 
L

LV154

Guest
Thanks for clearing that up.
I apologise for sounding very stupid, but I can't see how this would work for things that have been drawn relative to each other. For example
a wall may be drawn at the front of the block, and a floor may be drawn above the block. How would you go about it? Would I need to rotate and translate each individual drawing function?
 
There is no relativity to each other, only to the origin. Draw everything where they need to be initially, the transformations will handle the rest.
 
Top