Rolling ball?
#1
Posted 10 February 2012 - 01:15 PM
#2
Posted 10 February 2012 - 02:21 PM
Rule 1: the order you do the transformations matters! You gotta rotate the ball first, THEN translate it.
Rule 2: the origin matters! Make sure the center of the ball is in (0,0,0) (No matter where the ball is in the room! Translate the rotated ball with (x,y,z) to get it to the right position, but draw it at (0,0,0)!), or else the ball won't look like it's rolling properly.
#3
Posted 10 February 2012 - 10:14 PM
#4
Posted 10 February 2012 - 11:10 PM
Assuming the ball doesn't roll at a constant speed, you'll need to use its speed to create the angle it is to be drawn. If you're using hspeed and vspeed (or speed and direction), this will simply be the "speed" variable. Next you'll need to transform it so that the ball rolls at the logical angular speed according to its radius. Now we'll have use of the definition of radians:
radian=arc/radiusOr, in a more relevant format:
rotspd=speed/radiusNotice that this gives us the rotation speed, not the actual rotation. To add it to the current rotation you just need to store a variable that keeps track of the current rotation. So far:
//create event rot=0 rotspd=0 //step event rotspd=speed/radius rot+=rotspdAnd to answer your actual question: assuming the gameplay takes place in the xy-plane, you'll need to use d3d_transform_add_rotation_z:
d3d_transform_set_scaling(radius,radius,radius) //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(-1,-1,-1,1,1,1,texture,1,1,20) //Draw an ellipsoid with radius 1 at (0,0,0) d3d_transform_set_identity()
Edited by TheSnidr, 10 February 2012 - 11:11 PM.
#5
Posted 10 February 2012 - 11:18 PM
EDIT: Radius is not a defined variable... Maybe I should just give up.
DOUBLE EDIT: Okay, I have gotten it to work now. The only problem is that I probably dont have the origin set correctly so the object rolls on the anchor point of the corner of the object instead of the middle, how would I go about setting the origin exactly? And another problem, when I go left it still rotates right. But other then that its working like a charm so far!
Edited by howabout, 10 February 2012 - 11:27 PM.
#6
Posted 10 February 2012 - 11:26 PM
The part where it draws the ellipsoid goes in draw event
Edited by TheSnidr, 10 February 2012 - 11:27 PM.
#7
Posted 13 February 2012 - 08:48 AM
Didn't his first post convey that? He's completely new to it.How much about game maker's 3D do you know?
#8
Posted 15 February 2012 - 01:36 PM
not completely newDidn't his first post convey that? He's completely new to it.How much about game maker's 3D do you know?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











