Jump to content
• ### What is your GameDev Story?

• Advertisement

Public Group

# MD5 swizzle

This topic is 4881 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

I just got a Doom 3 MD5 model to render correctly, but i want to have it in XYZ coordinates rather than XZY coordinates. I tried flipping just the vertex positions, but then (of course) the skeleton won't be flipped. Then i tried flipping the quaternion values directly when i read the joints, and i got some really strange result (the model "marine" looks like some scary hellish alien. It could actually have been a real model [grin]). Is there a simple way to do this, like flipping some values, or do i have to re-calculate all quaternions in some "proper" way?

#### Share this post

##### Share on other sites
Advertisement
I managed to figure it out by myself. The secret is to rotate both the quaternion part and the pos part by a 90 degree axis quaternion. Here's the source if anyone should need it:
/** Quternion functions from http://tfc.duke.free.fr/coding/md5-specs-en.html*/float posVec[3] = { pos_x, pos_y, pos_z };float orientQuat[4] = { orient_x, orient_y, orient_z, 0.0f };Quat_computeW(orientQuat);// create 90 degree rotation quatfloat angle = (-90.0f / 180.0f) * 3.1415f;float axis[3] = { 1.0f, 0.0f, 0.0f };float rotQuat[4] = { axis[0] * sin(angle/2), axis[1] * sin(angle/2), axis[2] * sin(angle/2), cos(angle/2) };// rotate model from z-up to y-upQuat_rotatePoint(rotQuat, posVec, m->skeleton[jointCounter].pos);Quat_multQuat(rotQuat, orientQuat, m->skeleton[jointCounter].quat_orient);void Quat_computeW( quat4_t q ){  float t = 1.0f - (q[0] * q[0]) - (q[1] * q[1]) - (q[2] * q[2]);  if( t < 0.0f ) {	q[3] = 0.0f;  }  else {	q[3] = -sqrt( t );  }}void Quat_multQuat( const quat4_t qa, const quat4_t qb, quat4_t out ){  out[3] = (qa[3] * qb[3]) - (qa[0] * qb[0]) - (qa[1] * qb[1]) - (qa[2] * qb[2]);  out[0] = (qa[3] * qb[0]) + (qa[0] * qb[3]) + (qa[1] * qb[2]) - (qa[2] * qb[1]);  out[1] = (qa[3] * qb[1]) + (qa[1] * qb[3]) + (qa[2] * qb[0]) - (qa[0] * qb[2]);  out[2] = (qa[3] * qb[2]) + (qa[2] * qb[3]) + (qa[0] * qb[1]) - (qa[1] * qb[0]);}void Quat_rotatePoint( const quat4_t q, const vec3_t in, vec3_t out ){  quat4_t tmp, inv, final;  inv[0] = -q[0]; inv[1] = -q[1];  inv[2] = -q[2]; inv[3] =  q[3];  Quat_normalize( inv );  Quat_multVec( q, in, tmp );  Quat_multQuat( tmp, inv, final );  out[0] = final[0];  out[1] = final[1];  out[2] = final[2];}

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 15
• 9
• 11
• 9
• 9
• Advertisement
• ### Forum Statistics

• Total Topics
634135
• Total Posts
3015752
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!