Jump to content
  • Advertisement
Sign in to follow this  
will874

Moving a joint to an angle problem.

This topic is 4347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I'm currently working on my first open source game (http://ragdollcombat.sourceforge.net) implementing the Newton Game Dynamics library (though this is probably a generic problem and not specific to any library) and I need some help with physics calculations as i'm very new to computer game physics, sorry if this post is a bit long but i'll try and explain my problem as best I can. Note: Child body is the body the joint is attaching and parent body is the body the joint is attached to, for example the parent body of the elbow is the upper arm and the child body is the forearm. The effect i'm trying to achieve is that a joint, in this case a ball joint, can be given the rotation it should be at (the rotation of the child body relative to the parent body) and then will move there by applying the correct torque to the child body on every time step of the physics simulation. So I can animate everything in the game using nothing but physics. The system i'm using right now handles all rotations in euler angles in radians. Here are the Newton physics engine procedures which i'm using: BallJointGetAngle gets the euler angles of rotation of the joint. BallJointGetOmega gets the angular velocity of the rotation of the joint. BodyGetMassMatrix gets the inertia matrix of the mass of the body, specifically ixx, iyy and izz. WorldGetTimestep returns the amount time has been stepped by. BodySetTorque sets the torque vector being applied to the body. The algorithm i'm using is a simple spring formula for each of the euler angles of rotation, this procedure is called at every timestep of the simulation: k = 20 <-- spring constant b = 0.5 <-- damping constant moveTo <-- the angle the joint should move to BallJointGetAngle(joint, angle) BallJointGetOmega(joint, omega) BodyGetMassMatrix(body, mass, ixx, iyy, izz) timestep = WorldGetTimeStep(world) torque.X = (moveTo.X - angle.X) * k - (omega.X * b) * ixx / timestep torque.Y = (moveTo.Y - angle.Y) * k - (omega.Y * b) * iyy / timestep torque.Z = (moveTo.Z - angle.Z) * k - (omega.Z * b) * izz / timestep BodySetTorque(body, torque) My problem is that whenever I set more than one of the moveTo angles to something other than zero the system goes crazy and starts to jerk around and spin faster and faster. The really confusing bit is that if I set just one of the moveTo angles to something other than zero (e.g. Pi/4) it works absolutely perfectly. I think my problem is something to do with the order euler angles are applied in or just me not understanding euler angles properly :(. If anyone has a way of fixing this or a better way of achieving the same effect, like using quaternions (which I don't know about but would be more than willing to learn if it will fix the problem) it would be amazingly appreciated and would save my project. Will

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!