Archived

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

Odd Physics Problem

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

Recommended Posts

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)
{

//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.

Share on other sites
yes it will definitly be the static variable.

A static variable within a class method acts just like a global variable (just only accessable in that method)...
You will need to make Last_time a member variable of the 'Object' class instead.

the resond is because the value of Last_time is not unique to every instance of Object. So each object is sharing the same value, so the object appears to move at 1/10th the speed because thats the time between the first and second object having Update called, not the time between individual calls of Update to individual instances of Object.

| - My project website - | - email me - |

[edited by - RipTorn on April 22, 2004 8:48:33 PM]

Share on other sites
WOW thanks alot guys! can anyone say DUH!!

all i did was declared Last_time as a global variable and put the Last_time = GetTickCount() in my Init function.

thanks again

quick question....
does anyone out there know of a place where i can find collision reaction dampening coefficeints. in english: i need to know how much to decrease the collision reaction after two objects collide. for example when a box falls on cement how much force should be applied upward to make it bounce?

[edited by - adam17 on April 23, 2004 1:17:24 PM]

Share on other sites
what you can do is use the "constituion of restitution" (e) i think it is, we did it in mechanics. u have one of these set for a surface and the values range from 0 to 1.

e = speed of seperation of coliding objects
---------------------------------------
speed of approach of coliding objects

so to get the objects to leave at half the speed of the approach then you would set the e of that surface to a half

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

• 33
• 13
• 11
• 10
• 12
• Forum Statistics

• Total Topics
632572
• Total Posts
3007128

×