I have a 3D object moving and I need to be able to apply forces to it such as gravity. In 2D, I would simply store its movement in dx and dy, but since this is in 3D, I am using a Vector3D direction and a float speed. How can I determine how much to rotate the direction and change the speed when by using something like applyForce(Vector3D force)?
|
|
||||
|
|
There's a problem with the information you have. Speed (or velocity), is not a force! You need to have an acceleration value and a mass value if you want to apply a force. Remember that You may find that you just want to use the mass of the object in all cases, that's fine, and it simplifies things. Then you can simply set your acceleration appropriately to get the kind of forces you want. Whatever mass*acceleration you use: Take your direction, normalize it, scale it by the acceleration. That will give you an acceleration in the direction of travel. Then multiply it by the mass. Finally apply it as a force to your object. |
|||
|
|
|
Just a simple idea for your reference. The force in 3D space is also a 3D vector, so that's all about 3D vector arithmetic, suppose you have a model with a velocity of V and mass of m, and you want to apply a force F on it, use the second law of Newton, then it is something as below
where a is the acceleration, that's also a 3D vector. V' is the new velocity when applying the force. |
|||
|
|