Original Post
hey guys i have been working on a small, simple physics engine for my upcoming game. right now i am having a problem with my update code. i have 3 objects floating above my scene at the beginning. all 3 are supposed to drop (with updating gravity) at the same time. what happens is the first 2 initialized boxes start dropping. the first travels at the normal acceleration. the second box appears to moving at a tenth of the speed that the first is. (here is where it gets really weird) the third box does not start moving until the first two have collided and stopped on the floor. i have spent a long time checking my update function and cant find a thing. maybe someone can help me out. here is the code for the update function:
void Object::Update()
{
static int Last_time = GetTickCount();
int Current_time = GetTickCount();
float GravDivTime = (Current_time - Last_time)/(1000*GRAVITY);
bool vert_check = false;
vel.y = vel.y - GravDivTime;
pos.y = pos.y + vel.y;
rot.x += 10 / GravDivTime;
if((pos.y + vel.y) - radius <= GROUND)
{
pos.y = radius + GROUND;
//Check for Vertex Collision
int i=0;
while(i<vertex.capacity() && vert_check!=false)
{
if(vertex[i] < -30 || vertex[i] > 30)
vert_check = true;
else if(vertex[i+1] < 0 || vertex[i+1] > 60)
vert_check = true;
else if(vertex[i+2] < -30 || vertex[i+2] > 30)
vert_check = true;
if(vert_check == true)
vel.y = -(vel.y + DAMPER);
i+=3;
}
}
if((abs(vel.y) <= 0.001f) && (vel.y > 0))
{
active = false;
}
Last_time = GetTickCount();
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
//glRotatef(rot.x, 1, 0, 0);
//glRotatef(rot.y, 0, 1, 0);
glColor4f(0, 1, 0, 1);
glCallList(obj);
glPopMatrix();
}
the update function is a public function of each object that reacts to the scene''s physics.