PDA

View Full Version : Quack3 BSP and MD3 character



Kicsit
02-03-2005, 11:19 AM
I am creating a 3rd person view game as my final project of BS.
I am loading a Quack 3 BSP and also loading a MD3 character.

First....................
I created simple MD3 character movement file with respect to camera using this code
(i.e character moving on a grid and not on BSP)

///////////////////////////////// RENDER SCENE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This function renders the entire scene.
/////
///////////////////////////////// RENDER SCENE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The matrix

Direction += (model.direction-Direction)/15;
// some little math :)

Heading.x = cos(90-Direction);
Heading.z = sin(90-Direction);

model.heading.x = cos(90-model.direction);
model.heading.z = sin(90-model.direction);

Camera.x += ((View.x + Heading.x * -6) - Camera.x) / 3;
Camera.y += ((View.y + Heading.y * -6 + 1) - Camera.y) / 3;
Camera.z += ((View.z + Heading.z * -6) - Camera.z) / 3;

// some more math :)
model.position.x += model.speed.x;
model.position.y += model.speed.y;
model.position.z += model.speed.z;
View.x = model.position.x;
View.y = model.position.y + 1;
View.z = model.position.z;



// here we put the airdrag force in action :) and affect our model's speed

model.speed.x /= airdrag;
model .speed.y /= airdrag;
model .speed.z /= airdrag;

gluLookAt(Camera.x, Camera.y, Camera.z, // the position
View.x, View.y, View.z, //the View
0.0f,1.0f,0.0f); //the Up-Vector

glPushMatrix();
glEnable(GL_TEXTURE_2D);
glEnable(GL_CULL_FACE); // Turn back face culling on
glCullFace(GL_FRONT);
glTranslatef(model.position.x, model.position.y, model.position.z);
glScalef(0.04f,0.04f,0.04f);
glRotatef(model.direction*180/PI -110,0.0,1.0,0.0);

g_Model.DrawModel();
glDisable(GL_CULL_FACE);

glDisable(GL_TEXTURE_2D);

glPopMatrix();

// Draw a grid so we can get a good idea of movement around the world
Draw3DSGrid();


// Swap the backbuffers to the foreground
SwapBuffers(g_hDC);
}

//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

This code works really well when we use it on a file where i haven't wrote any code for BSP loading

BUT........................

when I integrated that code with the BSP loader a strange thing happened
Camera was working correct and moving through the Q3 BSP but the character was not drawing at its location instead I have to change the actuall above code line

View.z = model.position.z; //(thats where it should be drawn)
TO
View.z = model.position.z-5; //(but we have to minus atleast five in the equation )

i.e character never draws at model.position.z instead we have to minus 5 or more out of it
But by doing that camera is totally disrupt, character goes far away from camera aslo if we move the camera around; character goes to the backside of the camera and camera comes ahead of the chaaracter

/************************************************** ********8

Please help me out solving this problem
also If u have any implementation of 3rd person view in Q3 BSP then plz let me know
I'll be gr8full.