3D Model rotation not working.

J

jtmx

Guest
Hello, I am making a 3D game and I have a model loaded in but it isn't rotating the model with d3d_transform_* functions, I have set the model to rotate with the camera's yaw and pitch variables however it just isn't working. Any help would be greatly appreciated :)

EDIT: I got it working thanks to @Juju

You must rotate the model before setting the translation and drawing it.

Project File: https://www.dropbox.com/s/473mj4yt2ne3v9q/3d Model Rotation.gmx.rar?dl=0
 
Last edited by a moderator:
J

jtmx

Guest
Would you please post the problematic code as well?
obj_camera Draw End event:
Code:
d3d_transform_set_identity()
d3d_transform_add_translation(x,y,- 1)
d3d_transform_set_rotation_x(pitch)
d3d_transform_set_translation(x,y,z)
d3d_model_draw(gun,lengthdir_x(2,yaw - 90),lengthdir_y(2,yaw - 90),- 1,- 1)
d3d_transform_set_identity()
This is where I am having trouble, the gun variable is set to d3d_model_create() in the Create event of the camera.
 

Juju

Member
You've got set and add the wrong way round.

Code:
d3d_transform_set_translation(x,y,- 1)
d3d_transform_add_rotation_x(pitch)
d3d_transform_add_translation(x,y,z)
d3d_model_draw(gun,lengthdir_x(2,yaw - 90),lengthdir_y(2,yaw - 90),- 1,- 1)
d3d_transform_set_identity()
 
J

jtmx

Guest
You've got set and add the wrong way round.

Code:
d3d_transform_set_translation(x,y,- 1)
d3d_transform_add_rotation_x(pitch)
d3d_transform_add_translation(x,y,z)
d3d_model_draw(gun,lengthdir_x(2,yaw - 90),lengthdir_y(2,yaw - 90),- 1,- 1)
d3d_transform_set_identity()
Thank you! :) I have changed it to:

Code:
d3d_transform_set_translation(x,y,z)
d3d_transform_add_rotation_x(pitch)
d3d_transform_add_rotation_z(yaw)
d3d_transform_add_translation(x,y,z)
d3d_model_draw(gun,lengthdir_x(2,yaw - 90),lengthdir_y(2,yaw - 90),32,- 1)
d3d_transform_set_identity()
But it is drawing weirdly way off from the camera? :-(
 

Juju

Member
Order of operation is crucial for 3D transformations. Draw it out (in 2D) on a piece of paper, remembering that rotations always happen around the origin (the point 0,0,0).
 
J

jtmx

Guest
Order of operation is crucial for 3D transformations. Draw it out (in 2D) on a piece of paper, remembering that rotations always happen around the origin (the point 0,0,0).
Okay I shall do that, thank you for your help!

FIXED IT:

Code:
d3d_transform_add_rotation_x(pitch)
d3d_transform_add_rotation_z(yaw - 90)
d3d_transform_add_translation(x,y,z)
d3d_model_draw(model,lengthdir_x(2,60),lengthdir_y(2,90),- 1,- 1) 
d3d_transform_set_identity()
 
Last edited by a moderator:
Top