- #1
adamjmacky
- 2
- 0
Hey,
I am making a simple game engine for a university computer graphics course, and I'm running into a (simple?) problem with rotations of boxes. I am using bounding box collisions, where a vertex of the box which enters another box receives a force to push it away.
At the end of each frame, I have 8 force vectors for each box (one for each vertex) to apply to the velocity and position of the box. I could simply apply all forces to the center of the box, and this works fine. But, the boxes wouldn't rotate. I would like them to rotate depending on the location of the forces (which will always be in the 8 corners).
To achieve this, I am trying to get a torque from the force, and use that as the angular acceleration. Then, the angular acceleration is used to increment the angular velocity, which is then used to increment the rotation of the box.
force[8] = force vectors for each corner of the box
vertex[8] = vector from the center of the box to each corner
alpha = angular acceleration (i-component = angle about i-axis)
omega = angular velocity
rot = rotation of the box
pos = position of the box
vel = linear velocity of the box
dt = 0.01 timestep
// find torque and set alpha
for each vertex (i)
torque = force X vertex
alpha -= torque <-- why negative? positive doesn't work at all
vel += force[all] * dt / mass
pos += vel * dt
omega += alpha * dt / (mass*10)
rot += omega * dt
I don't want to have to worry about moment of inertia, since its constant for a box. When I run this, it seems that sometimes the box will rotate properly, while other times the box will spin out of control. I think the problem might be that some of the torques are too strong - am I forgetting something?
Is there a problem with my method? Remember, I'm just trying to get something simple that will run stable for collisions, not a perfectly accurate physics simulation.
I am making a simple game engine for a university computer graphics course, and I'm running into a (simple?) problem with rotations of boxes. I am using bounding box collisions, where a vertex of the box which enters another box receives a force to push it away.
At the end of each frame, I have 8 force vectors for each box (one for each vertex) to apply to the velocity and position of the box. I could simply apply all forces to the center of the box, and this works fine. But, the boxes wouldn't rotate. I would like them to rotate depending on the location of the forces (which will always be in the 8 corners).
To achieve this, I am trying to get a torque from the force, and use that as the angular acceleration. Then, the angular acceleration is used to increment the angular velocity, which is then used to increment the rotation of the box.
force[8] = force vectors for each corner of the box
vertex[8] = vector from the center of the box to each corner
alpha = angular acceleration (i-component = angle about i-axis)
omega = angular velocity
rot = rotation of the box
pos = position of the box
vel = linear velocity of the box
dt = 0.01 timestep
// find torque and set alpha
for each vertex (i)
torque = force X vertex
alpha -= torque <-- why negative? positive doesn't work at all
vel += force[all] * dt / mass
pos += vel * dt
omega += alpha * dt / (mass*10)
rot += omega * dt
I don't want to have to worry about moment of inertia, since its constant for a box. When I run this, it seems that sometimes the box will rotate properly, while other times the box will spin out of control. I think the problem might be that some of the torques are too strong - am I forgetting something?
Is there a problem with my method? Remember, I'm just trying to get something simple that will run stable for collisions, not a perfectly accurate physics simulation.