Re: Vehicle demo
Posted: Mon Mar 07, 2011 11:39 am
Well, GTA4 is probably using joints and even at high speeds the cars are stable and the handling is amazing because the cars can actually drift 
i think provided raycast class can be taken as starting point for own class, for example you can use raycasting code and suspension code and rewrite impulse calculation for movement completely... so you will have all control, may be i shall try it little later... i found one old example (s. code in attachment) :Nice catch
I was thinking of actually setting up friction real-time by the amount of default_friction * dot(normalize(chassis_direction), normalize(chassis_velocity)), it might work.
Code: Select all
//Render Ground Plane-------------------------------
float PLANE_EXTENT = 100.0f;
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-PLANE_EXTENT, 0.0f, -PLANE_EXTENT); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-PLANE_EXTENT, 0.0f, PLANE_EXTENT); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( PLANE_EXTENT, 0.0f, PLANE_EXTENT); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( PLANE_EXTENT, 0.0f, -PLANE_EXTENT); // Top Right Of The Texture and Quad
glEnd();
glColor3f(1.0,0,0);
//Render Chassis-----------------------------------
glPushMatrix();
glMultMatrixf(ptrShapes->m);
glMultMatrixf(ptrShapes->childMat);
drawBox(ptrShapes->halfExtent[0], ptrShapes->halfExtent[1], ptrShapes->halfExtent[2]);
glPopMatrix();
//Render the obstructing green box
glColor3f(0.0,1.0,0.0);
glPushMatrix();
glMultMatrixf(ptrShapes->m_box);
drawBox(ptrShapes->box_halfExtent[0], ptrShapes->box_halfExtent[1], ptrShapes->box_halfExtent[2]);
printf("\n box : %f, %f,%f", ptrShapes->box_halfExtent[0], ptrShapes->box_halfExtent[1], ptrShapes->box_halfExtent[2]);
glPopMatrix();
//Render the 4 wheels
glColor3f(1.0,1.0,0);
for (int i=0; i<4; i++){
glPushMatrix();
switch(i){
case 0 : glMultMatrixf(ptrShapes->m1);break;
case 1 : glMultMatrixf(ptrShapes->m2);break;
case 2 : glMultMatrixf(ptrShapes->m3);break;
case 3 : glMultMatrixf(ptrShapes->m4);break;
}
drawCylinder(ptrShapes->radius, ptrShapes->halfHeight, ptrShapes->upAxis);
printf("\n r : %f ht:%f", ptrShapes->radius, ptrShapes->halfHeight);
glPopMatrix();
}
//---------------Debug code : for pink wheel-----------------------
glColor3f(1.0,0.0,1.0);
glPushMatrix();
glMultMatrixf(ptrShapes->m);
glTranslatef(ptrShapes->m2[12] - ptrShapes->m[12],
ptrShapes->m2[13] - ptrShapes->m[13],
ptrShapes->m2[14] - ptrShapes->m[14]);
drawCylinder(ptrShapes->radius, ptrShapes->halfHeight, ptrShapes->upAxis);
glPopMatrix();
Code: Select all
//---------Debug code------------
glColor3f(1.0,0.0,1.0);
glPushMatrix();
glTranslatef(ptrShapes->m2[12] ,
ptrShapes->m2[13],
ptrShapes->m2[14] );
drawCylinder(ptrShapes->radius, ptrShapes->halfHeight, ptrShapes->upAxis);
glPopMatrix();