views:

38

answers:

1

Hi, im currently trying to figure out how to develop a method in my program that takes care of the forces and updates the positions of the rectangle after collision with a wall. At the moment, i just have it moving inside the walls. i know the equations of motion in terms of acceleration and understand they need to be integrated in the RK4 method and respective positions x1,y1,theta1, and x2,y2,theta2 can be then calculated, and these positions updated....the thing i really need to know is what other equations do i need? and how do i apply the angular position to the x,y positions? im not sure about the inertia/torque either.....for drawing the rectangle im using (x1,y1) (x2,y2) positions as opposed to (x,y,w,h)...here are the equations i know i need for the RK4 method for (x1,y1) of the rectangle:

vx1' = (− k vx1) ⁄ m

vy1' = (− m g − k vy1) ⁄ m

ω' = − k ω ⁄ I

x1' = vx1

y1' = vy1

θ' = ω

k=damping const, I=inertia, omega=angular velocity

Any help would be greatly appreciated as this has been bugging me for a while....Thanks

+3  A: 

If you just want to get the job done, then consider using a ready-made and debugged physics engine. I highly recommend FarseerPhysics, which is free and open-source.

If you're interested in how to calculate the physics then http://math.stackexchange.com might be more appropriate.

If you're interested in how to implement the physics then your best bet would be to look around for various tutorials because it's a fairly large and complex topic. Or ask here, but only if you have a specific question. Perhaps GameDev is a good starting point.

If you do go down the route of implementing this yourself, take a look at this tutorial on collision detection to get an idea of what you're getting yourself into.

By the way, you don't have to use the RK4 integrator for this - it's just that RK4 strikes a good balance between accuracy and complexity. Simple integration (x += V * dt style) may provide sufficiently acceptable results, and is a lot less work than RK4.

romkyns