Jump to content
  • Advertisement

Jonathan2006

Member
  • Content count

    11
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Jonathan2006

  • Rank
    Member

Personal Information

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Jonathan2006

    Transforming Angular Velocity

    The red wire sphere code is the “mat4 rotateMatrix” that I posted further above. Thank you JoeJ for your time. I just don’t know enough to figure this out. Below are some things I have learned. After skimming through some game developer physics books, euclideanspace.com, and your posts here’s what I think I have learned so far... 1) Axis Angle can be used to represent the length and direction of angular velocity/rotations in quaternions and matrices. 2) Multiplying two quaternions is just like multiplying two matrices. 3) Angular velocity can be represented in a 3x3 skew matrix. What went wrong 1) I could never get any of my axis angle functions to work with more than one integrator. 2) Not sure about multiplying quaternions since I could never get the correct output after multiplying. 3) I tried multiplying several skew matrices together and the final matrix had all zero values. I used the GLM library for most of my quaternion and matrix code but I was never really able to debug the axis angle quaternions. I tried axis angle matrices from euclideanspace.com and I did find a bug in the GLM code that I fixed in my code. The output of angular velocity in the matrices never came out correctly after I added more than one integrator. Since nothing worked I will have to use my old unreliable code below: vec3 angleRadians = GEEulerAngleFromMat4(matrix); vec3 angularVelocity = (angleRadians - oldAngleRadians) / globalTimeStep; vec3 oldAngleRadians = angleRadians; Hope this helps anyone else with this problem. Thanks again, Jonathan
  2. Jonathan2006

    Transforming Angular Velocity

    Thank you again for all the help! I am still trying to wrap my head around quaternions. I just thought of something. Even if I use something like quatCur - quatOld should the angular oscillating stop if I normalize the quaternion like you did in your code? I think I understand your last post on quaternions but I am getting weird acceleration. I also added the time step back into the last integrator (hope that's the name). The reason I use the last angleEulerRadians and angularVelocityVector (integrator?) is to only test the final angular velocity. I created a gif of the rotations below. Also Here's the code I am using: void integrateAngularVelocity(const quat curOrn, const vec3 angvel, const float timeStep, quat *predictedOrn) { vec3 axis; float fAngle = GEMagnitudeVector(angvel); if (fAngle < 0.00001) { *predictedOrn = curOrn; return; } else { axis = GEMultiplyVectorAndScalar(angvel, sinf(fAngle * timeStep * 0.5) / fAngle); } quat dorn = GESetQuaternion(axis.x, axis.y, axis.z, cosf(fAngle * timeStep * 0.5)); *predictedOrn = GEMultiplyQuaternions(dorn, curOrn); *predictedOrn = GENormalizeQuaternion(*predictedOrn); } void Shape(void) { vec3 angularVelocityVector1 = GERadiansFromDegreesVector(GESetVector(20.0, 0.0, 0.0)); vec3 angularVelocityVector2 = GERadiansFromDegreesVector(GESetVector(0.0, 0.0, 20.0)); vec3 angularVelocityVector3 = GERadiansFromDegreesVector(GESetVector(20.0, 0.0, 0.0)); static quat quaternion; integrateAngularVelocity(quaternion, angularVelocityVector1, globalTimeStep, &quaternion); integrateAngularVelocity(quaternion, angularVelocityVector2, globalTimeStep, &quaternion); integrateAngularVelocity(quaternion, angularVelocityVector3, globalTimeStep, &quaternion); vec3 angularVelocityVector = GEMultiplyVectorAndScalar(GEAxisFromQuaternion(quaternion), GEAngleFromQuaternion(quaternion)); angularVelocityVector = GEAddVectors(angularVelocityVector, GEMultiplyVectorAndScalar(angularAccelerationVector, globalTimeStep)); angleEulerRadians = GEAddVectors(angleEulerRadians, GEMultiplyVectorAndScalar(angularVelocityVector, globalTimeStep)); glColor3f(0.0, 1.0, 1.0); glPushMatrix(); glTranslatef( 2.0, 0.0, 0.0); // This spins really fast glMultMatrixf(GEMat4FromEulerAngle(angleEulerRadians).array); glutWireSphere(2.0, 7.0, 7.0); glPopMatrix(); } It's not the best quality but the red sphere is the correct rotation and the cyan is the quaternion code above.
  3. Jonathan2006

    Transforming Angular Velocity

    Thanks for the posts and ideas. I already know how to get the final values for position, linear velocity, linear acceleration, and Euler angle. I have been researching quaternions some more. if it’s even possible I would like to know the instant angular velocity and angular acceleration which I tried to find in the code below. If it’s not possible to find the instant value I am confused as to what should be a vector and what should be a quaternion in your post above. If it matters I am trying to use instant quaternions. I had problems with oscillating after a perfect collision using just the original and resulting vectors (I have not tried it with quaternions though). The C code below is as close as I can get to the real motion engine: void rotateShapeX(mat4 *m, quat *q, vec3 *angleRadians, vec3 *angularVelocity, vec3 *angularAcceleration) { *angularVelocity = GEAddVectors(*angularVelocity, GEMultiplyVectorAndScalar(*angularAcceleration, globalTimeStep)); *angleRadians = GEAddVectors(*angleRadians, GEMultiplyVectorAndScalar(*angularVelocity, globalTimeStep)); *q = GEQuaternionFromAxisAndAngle(*angularVelocity, angleRadians->x); *m = GEMultiplyMat4(GEMat4FromRotate(angleRadians->x, 1.0, 0.0, 0.0), *m); } void rotateShapeZ(mat4 *m, quat *q, vec3 *angleRadians, vec3 *angularVelocity, vec3 *angularAcceleration) { *angularVelocity = GEAddVectors(*angularVelocity, GEMultiplyVectorAndScalar(*angularAcceleration, globalTimeStep)); *angleRadians = GEAddVectors(*angleRadians, GEMultiplyVectorAndScalar(*angularVelocity, globalTimeStep)); *q = GEQuaternionFromAxisAndAngle(*angularVelocity, angleRadians->z); *m = GEMultiplyMat4(GEMat4FromRotate(angleRadians->z, 0.0, 0.0, 1.0), *m); } void shape(void) { mat4 rotateMatrix, rotateMatrix1, rotateMatrix2, rotateMatrix3; rotateMatrix = rotateMatrix1 = rotateMatrix2 = rotateMatrix3 = GEIdentityMat4(); // These will be static once it works vec3 angularVelocityVector1 = GERadiansFromDegreesVector(GESetVector(20.0, 0.0, 0.0)); vec3 angularVelocityVector2 = GERadiansFromDegreesVector(GESetVector(0.0, 0.0, 20.0)); vec3 angularVelocityVector3 = GERadiansFromDegreesVector(GESetVector(20.0, 0.0, 0.0)); // This is here so I can test only the angular velocity vec3 angularAccelerationVector = GESetVector(0.0, 0.0, 0.0); static vec3 angleEulerRadians, angleEulerRadians1, angleEulerRadians2, angleEulerRadians3; static quat quaternion, quaternion1, quaternion2, quaternion3; static char initialze = 0; if (initialze == 0) { angleEulerRadians = angleEulerRadians1 = angleEulerRadians2 = angleEulerRadians3 = GESetVector(0.0, 0.0, 0.0); quaternion = GESetQuaternion(0.0, 0.0, 0.0, 1.0); initialze = 1; } // Rotate rotateShapeX(&rotateMatrix1, &quaternion1, &angleEulerRadians1, &angularVelocityVector1, &angularAccelerationVector); rotateShapeZ(&rotateMatrix2, &quaternion2, &angleEulerRadians2, &angularVelocityVector2, &angularAccelerationVector); rotateShapeX(&rotateMatrix3, &quaternion3, &angleEulerRadians3, &angularVelocityVector3, &angularAccelerationVector); // Multiply matrices (works) rotateMatrix = GEMultiplyMat4(rotateMatrix1, rotateMatrix); rotateMatrix = GEMultiplyMat4(rotateMatrix2, rotateMatrix); rotateMatrix = GEMultiplyMat4(rotateMatrix3, rotateMatrix); // Multiply Quaternions? (does not work) quaternion = GETransformQuaternions(quaternion, quaternion1); quaternion = GETransformQuaternions(quaternion, quaternion2); quaternion = GETransformQuaternions(quaternion, quaternion3); vec3 angularVelocityVector = GEAxisFromQuaternion(quaternion); // Not sure if this is correct but I took out multipling globalTimeStep since it is already used in rotateShape*(); angularVelocityVector = GEAddVectors(angularVelocityVector, angularAccelerationVector); angleEulerRadians = GEAddVectors(angleEulerRadians, angularVelocityVector); glColor3f(0.0, 1.0, 1.0); glPushMatrix(); glTranslatef( 2.0, 0.0, 0.0); // This spins really fast glMultMatrixf(GEMat4FromEulerAngle(angleEulerRadians).array); glutWireSphere(2.0, 7.0, 7.0); glPopMatrix(); glColor3f(1.0, 0.0, 0.0); glPushMatrix(); glTranslatef(-2.0, 0.0, 0.0); glMultMatrixf(rotateMatrix.array); // (Works) glutWireSphere(2.0, 7.0, 7.0); glPopMatrix(); }
  4. Jonathan2006

    Transforming Angular Velocity

    That was one I didn't think of. Thanks for the averaging idea. I still cannot get it working. I am trying to mimic OpenGL's glRotate(); except I need to know the final angular velocity and acceleration vectors. The physics engine I am working on only accepts one angular velocity and angular acceleration vector. Below I am posting more of the code: // The Angle Radians Test (code used both by the matrix and quaternions) angularVelocity1 = GEAddVectors(angularVelocity1, GEMultiplyVectorAndScalar(angularAcceleration1, timeStep)); angleRadiansVector1 = GEAddVectors(angleRadiansVector1, GEMultiplyVectorAndScalar(angularVelocity1, timeStep)); angularVelocity2 = GEAddVectors(angularVelocity2, GEMultiplyVectorAndScalar(angularAcceleration2, timeStep)); angleRadiansVector2 = GEAddVectors(angleRadiansVector2, GEMultiplyVectorAndScalar(angularVelocity2, timeStep)); angularVelocity3 = GEAddVectors(angularVelocity3, GEMultiplyVectorAndScalar(angularAcceleration3, timeStep)); angleRadiansVector3 = GEAddVectors(angleRadiansVector3, GEMultiplyVectorAndScalar(angularVelocity3, timeStep)); // Matrix (This works and is used to test the accuracy of the quaternions) mat4 rotateMatrix = GEMultiplyMat4(GEMat4FromRotate(angleRadiansVector1.x, 1.0, 0.0, 0.0), GEIdentityMat4()); rotateMatrix = GEMultiplyMat4(GEMat4FromRotate(angleRadiansVector2.z, 0.0, 0.0, 1.0), rotateMatrix); rotateMatrix = GEMultiplyMat4(GEMat4FromRotate(angleRadiansVector3.x, 1.0, 0.0, 0.0), rotateMatrix); glMultMatrixf(rotateMatrix.array); glutWireSphere(2.0, 7.0, 7.0); The first few lines are extra code that I was hoping I could leave out in the first post. The rotateMatrix works just like OpenGL's glRotate(); and is the desired output. I am trying to transform the angular vectors the same way OpenGL does when multipling two matrices.
  5. Jonathan2006

    Transforming Angular Velocity

    My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below: // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
  • 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!