View Full Version : How to place md2 models ???

02-24-2000, 02:04 PM

I have md2 loading in my engine, but I can't place standard q2 weapon model.
When I just load the model and display it, it is somehow rotated around the Z axis
and it's not translated right. Can someone tell my the matrix that quake2 uses to
place the model correct in front of the player ?


mike j
02-24-2000, 07:34 PM
I'm pretty sure that all the quake engine
games have a world coordinate system
where Y goes into the screen and Z is up and
down.. so I think somewhere in your q2model loading code you may need to swap your Y and Z values - I once had to do the same for a bit of code which parsed .ASC files

you can find out more about the quake world coords in this article http://www.planetquake.com/code3arena/articles/article2.shtml

02-24-2000, 11:53 PM
Just remember, if you swap the y and z values then y' = z, but z' = -y (due to the fact that the negative z axis goes away from the camera in OpenGL).

02-25-2000, 09:42 AM
No, this doen't work. The model isn't just mirrored, it is somehow translated, and is rotated in non-90 angles...
I think the q2 engine uses a single matrix that is simply applied with glmultmatrix before the model is drawn...

Any ideas ???

mike j
02-25-2000, 10:29 AM
try loading the model with its own identity matrix - glLoadIdentity()

02-25-2000, 12:33 PM
Hmm... can't image that this works, but I'll try it. What about official information on this topic ? Are there any information from id software ???

mike j
02-25-2000, 05:40 PM
let me get some more clarification.. are you trying to position a weapon model in reference to a player model (get the player
to hold weapon and not have it floating above
the player models head or something)


are you trying to get a weapon model to extend out down the -z axis in a first person perspective

[This message has been edited by mike j (edited 02-25-2000).]

[This message has been edited by mike j (edited 02-25-2000).]

02-27-2000, 03:04 AM
I'm trying to place the md2 like in any q2 engine 3d shooter from the players point of view:

I've pasted some code of my main rendering loop here:

// Draw the full scene

// Draw skybox (Draw without Z-buffer, so everything that
// comes after it will overdraw)
cSkyBox.DrawSkyBox(cMotion.GetUpDownRotation(), cMotion.GetYRotation(),
cSettings.m_FOV, cSettings.m_SunAmbient + cSettings.m_SunDiffuse, cGL.GetAspect());

// Save matrix
// Transform the viewport
// Set sunlight position relative to transform
// Draw landscape
// Draw trees (trees are not affected by the sunlight)
cTreeCollection.DrawAllTrees(cMotion.GetYRotation( ), cMotion.GetXPos(),
cMotion.GetYPos(), cMotion.GetZPos());
// Reset matrix

// Clear depth buffer

// Everything that comes now isn't clipped with the previous objects

// Draw Weapon
if (cSettings.m_WeaponEnabled == 1)

I'm pretty sure this is right. But when I start my engine, the model is somehow rotated to the right. Simply rotating it back doesn't work. I think there must be as simply transformation matrix for all the different model types like enemys, entities, weapons thta lie on the ground, weapons that are hold by players....

Any ideas ?

mike j
02-27-2000, 10:33 AM
ok... I don't know how much this is going
to help but have you looked at the Quake1
source..? If you do have the source.. open
up and look at glr_main. There maybe a hint
about the single matrix your looking for - in fact r_base_world_matrix[16] and r_world_matrix[16] are defined. They also load r_base_world_matrix[16] with glLoadMatrixf()

if you don't have the source.. http://www.netcomuk.co.uk/~sio2/glquake.htm

sorry can't be of anymore help... but when you do sort it out post your fix in this thread

02-28-2000, 10:34 AM
thank you anyway.
Does anyone know a good newsgroup with md2 as topic ? Or a mailing list for the q2 engine ? this is suge a huge topic, there must be a forum somewhere....