## General Physics Engine Questions

Moderator
Posts: 373
Joined: 2006.08
Post: #1
Hello again everyone
I've been working on my physics engine and I've run into some problems, so I'd like to ask some specific and general questions.
My engine only needs to work with convex, static 3D triangle meshes.
I was thinking that I'd compute axis-aligned rectangular prisms (aligned along the world coordinates) for each object and all of its sub-objects. By 'rectangular prisms', I just mean that I'm storing the length of lines from the center of the object to the maximum X, Y, and Z coordinates. I came up with my own penetration depth formula, like so (this one's for the Y penetration depth):
Code:
`penetrationY = fabs(movingAnims[i]->getCenterY() - staticAnims[x]->getCenterY()) - (movingAnims[i]->getMaxY() - movingAnims[i]->getCenterY())+(staticAnims[x]->getMaxY() - staticAnims[x]->getCenterY()) - (movingAnims[i]->lastOffsetY - movingAnims[i]->offsetY);`
This code is meant to find the penetration depth between a moving object and a non-moving object. It always returns a negative number, which I figured was fine; for moving it back out of the object I just find the time it takes to do so based on the new y-velocity of the object, like so:
Code:
`timeRequired = -1 * penetrationY / fabs(movingAnims[i]->vectorY);`
Then we just move the object by multiplying the timeRequired by vectorY.
This seems to work fine, as long as vectorY isn't zero, and I think I can getting it working even if vectorY is zero.....but is this a good approach? Am I missing something critical here, or doing something that makes life harder than it should be?

I also need to have friction in the engine so that objects slow down and eventually stop when moving against another object. To find this, I figured I'd also compute axis-aligned bounding rectangular prisms with the axis being aligned relative to the object. To calculate if friction should be applied instead of having the object bounce (which is what I'm doing with the penetration depth at the moment), I figured I would calculate the slopes of the two colliding lines of the colliding bounding prisms. If the slopes were close to being perpendicular, I would make the object bounce off of the other object, otherwise friction would be applied.
Is this a decent strategy?
When rotation is applied, I'm not quite sure how to find the new bounding coordinates relative to the world; is this what quaternions are for? How would I go about calculating when the bounding X coordinates have become the bounding Y coordinates (like when a 90 degree rotation about the z axis occurs)? Is this why people using bounding cubes instead of prisms?

Thank you,
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Moderator
Posts: 373
Joined: 2006.08
Post: #2
Ok, sorry for the previous post.....it was written late at night and is clearly not easy to read >.> Let me simplify and re-phrase my question a bit:

I have a line, and the line has separate X, Y, and Z velocities. That line then hits a plane. This plane can be titled any which way in 3D space. How do I determine how the X, Y, and Z velocities of my line change when it hits the plane?
Thank you
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/