#### Archived

This topic is now archived and is closed to further replies.

# Wolfenstein MDS models

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

## Recommended Posts

I am writing a program to display the Return to Castle Wolfenstein .MDS models (using OpenGL). The file-format I have taken from http://www.quake.cz/winclan/mdsexporter/MDSFormat.html My code seems to more or less work, the bones appear to be in the correct place since the animations are recognisable, but the orientation of the bones is wrong. This is the [current] code for getting the bone position/rotation:

{	// Get the offsetAngles from the .MDS file and convert to radians

float offsetPitch = pBoneFrame[f].offsetAngles[0] * (2*3.1415927f) / 65536.0f;
float offsetYaw = pBoneFrame[f].offsetAngles[1] * (2*3.1415927f) / 65536.0f;

Matrix4D mat1,mat2,mat3;
float vec[3];
// Create a vector with parentDist as X

vec[0] = pBones[f].parentDist;
vec[1] = vec[2] = 0;
mat1.createRotation(-offsetPitch,0,-1,0);	// Pitch rotation (Y Axis)

mat2.createRotation(offsetYaw,0,0,1);		// Yaw rotation (Z Axis)

mat2.multiply(mat1.m);
mat2.multiplyVector3(vec);	// Rotate vector

if ( bone has a parent )
{
vec[0] += m_boneTree[f].parent->origin[0];
vec[1] += m_boneTree[f].parent->origin[1];
vec[2] += m_boneTree[f].parent->origin[2];
}
else
{
vec[0] += pFrames->parentOffset[0];
vec[1] += pFrames->parentOffset[1];
vec[2] += pFrames->parentOffset[2];
}
// Set the bones origin to this vector - This part appears to be correct

m_boneTree[f].origin[0] = vec[0];
m_boneTree[f].origin[1] = vec[1];
m_boneTree[f].origin[2] = vec[2];

// Get the angles from the .MDS file (in radians)

float angles[3];
angles[0] = pBoneFrame[f].angles[0] * (2*3.1415927f) / 65536.0f;
angles[1] = pBoneFrame[f].angles[1] * (2*3.1415927f) / 65536.0f;
angles[2] = pBoneFrame[f].angles[2] * (2*3.1415927f) / 65536.0f;

mat1.createRotation(angles[2], 1,0,0);		// Roll (around X axis)

mat2.createRotation(-angles[0], 0,-1,0);	// Pitch (around Y axis)

mat3.createRotation(angles[1], 0,0,1);		// Yaw (around Z axis)

// Multiply rotations together, roll,pitch,yaw

// This will be the rotation matrix for this bone

// This matrix does not seem to orient the bone correctly

m_boneTree[f].matrix.createIdentity();
m_boneTree[f].matrix.multiply(mat1.m);	// mult Roll

m_boneTree[f].matrix.multiply(mat2.m);	// mult Pitch

m_boneTree[f].matrix.multiply(mat3.m);	// mult Yaw

}

Each bone is drawn using this, to draw a line representing the bone glPushMatrix(); glTranslatef(m_boneTree[f].origin[0],m_boneTree[f].origin[1],m_boneTree[f].origin[2]); glMultMatrixf(m_boneTree[f].matrix); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(2,0,0); glEnd(); glPopMatrix(); Now can anyone help me get my bones pointing in the correct direction?

##### Share on other sites
If you could convert from degrees to radians correctly:

Or

##### Share on other sites
My last post wasn''t meant to seem brash in anyway, sorry.

##### Share on other sites
No, that didn''t seem brash - just wrong. The angles are fine, but I''ve solved that problem - the order of rotations was the wrong way round and I needed to invert the matrix before using it.

But now I have another issue:

I''m not particularly experienced with OpenGL so can anyone give me some pointers on the best way to display the character.
The sequence of operations I have is as follows:

1. Tween the bone angles together for the current frame time

2. Construct a position/rotation matrix for each bone

3. Transform each vertex by the bones that affect it.

4. Render the triangles

My best guess would be to store the polygons for each bone in seperate display lists, and call these with the appropriate bone matrix set up. This would put steps 3&4 into the hardware.
The problem here is the triangles which are affected by more than one bone. I can only think of transforming them in software and then rendering them with lots of seperate glVertex3f(....) calls.
90% of the triangles could be included in lists but this method seems messy.

Is there some way I can get OpenGL (and hopefully the graphics hardware) to take over more of the processing?

##### Share on other sites
*bump* to 29th pm

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633329
• Total Posts
3011382
• ### Who's Online (See full list)

There are no registered users currently online

×