Jump to content


Photo

Off center rotation


  • Please log in to reply
8 replies to this topic

#1 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 11 February 2012 - 04:36 PM

Im trying to make a ball roll without any projections of 3d, so its a 2.5D view so im making it rotate on the z axis. This is my code:
d3d_transform_set_scaling(1,1,1) //Set the translation to the scaling (_set_ removes all previous transformations)
d3d_transform_add_rotation_z(radtodeg(rot)) //rot is in radians, but the function takes degrees
d3d_transform_add_translation(x,y,z) //Add the translation after rotation
d3d_draw_ellipsoid(-0,-0,-0,32,32,32,texture,1,1,16) //Draw an ellipsoid with radius 1 at (0,0,0)
d3d_transform_set_identity()
Now, this works for rotating but it rotates as if the object were a sprite and its origin of rotation or anchor point or whatever you would call it is not at 16,16 but instead 0,0. Help.
  • 0

#2 zehevi

zehevi

    GMC Member

  • GMC Member
  • 637 posts
  • Version:GM8

Posted 11 February 2012 - 05:42 PM

Change the draw and translation functions to
d3d_transform_add_translation(x,y,z+16)
d3d_draw_ellipsoid(-16,-16,-16,16,16,16,texture,1,1,16)

  • 0

#3 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2435 posts
  • Version:GM:Studio

Posted 11 February 2012 - 05:55 PM

Oh, you made a new topic? If you had answered my question in the old one I could've answered you there.
You need to draw the ellipsoid centered at (0,0,0), which will be the center of rotation. Right now you're drawing it at (16,16,16). Also, the d3d_transform_set_scaling is there for a reason:
d3d_transform_set_scaling(32,32,32) //Set the transformation to the scaling (_set_ removes all previous transformations)
d3d_transform_add_rotation_z(radtodeg(rot)) //rot is in radians, but the function takes degrees
d3d_transform_add_translation(x,y,z) //Add the translation after rotation
d3d_draw_ellipsoid(-1,-1,-1,1,1,1,texture,1,1,16) //Draw an ellipsoid with radius 1 at (0,0,0)
d3d_transform_set_identity()
Please don't be afraid to ask, I'd rather not run around looking for new topics with the same question

Edited by TheSnidr, 11 February 2012 - 05:57 PM.

  • 0

#4 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 11 February 2012 - 06:10 PM

Oh, you made a new topic? If you had answered my question in the old one I could've answered you there.
You need to draw the ellipsoid centered at (0,0,0), which will be the center of rotation. Right now you're drawing it at (16,16,16). Also, the d3d_transform_set_scaling is there for a reason:

d3d_transform_set_scaling(32,32,32) //Set the transformation to the scaling (_set_ removes all previous transformations)
d3d_transform_add_rotation_z(radtodeg(rot)) //rot is in radians, but the function takes degrees
d3d_transform_add_translation(x,y,z) //Add the translation after rotation
d3d_draw_ellipsoid(-1,-1,-1,1,1,1,texture,1,1,16) //Draw an ellipsoid with radius 1 at (0,0,0)
d3d_transform_set_identity()
Please don't be afraid to ask, I'd rather not run around looking for new topics with the same question

Sorry! I edited my post because I didnt want to make a new post because it would be redundant to have the same information in the same topic twice.
  • 0

#5 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 11 February 2012 - 06:13 PM


Oh, you made a new topic? If you had answered my question in the old one I could've answered you there.
You need to draw the ellipsoid centered at (0,0,0), which will be the center of rotation. Right now you're drawing it at (16,16,16). Also, the d3d_transform_set_scaling is there for a reason:

d3d_transform_set_scaling(32,32,32) //Set the transformation to the scaling (_set_ removes all previous transformations)
d3d_transform_add_rotation_z(radtodeg(rot)) //rot is in radians, but the function takes degrees
d3d_transform_add_translation(x,y,z) //Add the translation after rotation
d3d_draw_ellipsoid(-1,-1,-1,1,1,1,texture,1,1,16) //Draw an ellipsoid with radius 1 at (0,0,0)
d3d_transform_set_identity()
Please don't be afraid to ask, I'd rather not run around looking for new topics with the same question

Sorry! I edited my post because I didnt want to make a new post because it would be redundant to have the same information in the same topic twice.

And also, SORRY FOR THE DOUBLE POST but i dont want to just edit it, Now, its too big. And also when i roll to the left it stays rolling right instead of rolling left...
  • 0

#6 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2435 posts
  • Version:GM:Studio

Posted 11 February 2012 - 06:35 PM

Oops, my fault. Replace the rotation code with this:
//step event
rotspd=hspeed/radius
rot+=rotspd

Edited by TheSnidr, 11 February 2012 - 06:35 PM.

  • 0

#7 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 11 February 2012 - 06:40 PM

Oops, my fault. Replace the rotation code with this:

//step event
rotspd=hspeed/radius
rot+=rotspd

THANK YOU! Thanks for all of your help! i got it working just fine~ If i wanted the spin to be double the speed its spinning now would i change the code to:
rotspd=hspeed/radius*2
rot+=rotspd
?
Well thanks for all of your help!
  • 0

#8 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2435 posts
  • Version:GM:Studio

Posted 11 February 2012 - 06:53 PM

That's how you'd increase the angular speed, yeah, but then it'd be rotating too fast compared to its speed. As it is now, it's rotating mathematically correct. That's up to you though

Edited by TheSnidr, 11 February 2012 - 06:53 PM.

  • 0

#9 howabout

howabout

    GMC Member

  • GMC Member
  • 99 posts

Posted 11 February 2012 - 06:59 PM

I have another question. Without a projection, It is upside down. So in the step event I kinda fixed that by putting the code
view_angle[0]=180
But that mirrors everything. This makes it hard to properly design levels. How do I fix this?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users