3D Model rotation not working.

Discussion in 'Programming' started by jtmx, Oct 1, 2016.

  1. jtmx

    jtmx Member

    Joined:
    Oct 1, 2016
    Posts:
    20
    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: Oct 2, 2016
  2. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    972
    Would you please post the problematic code as well?
     
  3. jtmx

    jtmx Member

    Joined:
    Oct 1, 2016
    Posts:
    20
    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.
     
  4. Juju

    Juju Member

    Joined:
    Jun 20, 2016
    Posts:
    412
    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()
     
  5. jtmx

    jtmx Member

    Joined:
    Oct 1, 2016
    Posts:
    20
    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? :-(
     
  6. Juju

    Juju Member

    Joined:
    Jun 20, 2016
    Posts:
    412
    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).
     
  7. jtmx

    jtmx Member

    Joined:
    Oct 1, 2016
    Posts:
    20
    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: Oct 2, 2016

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice