Hi,
I want to apply a force that is pointing forward from the perspective of the capsule body.
So how could I transform a force in capsule's local coordinates to global coordinates. Currently, I am using CapsuleX.
For example, suppose that I want to apply a force of 2 units that pointing forward.
Vector3f localforce= new Vector3f(0,0,2); //Is this local force's direction correct?
Transform t=new Transform();
t=body.getMotionState().getWorldTransform(t);
//transform the force from local coordinates to global coordinates.
Vector3f globalForce=new Vector3f(0,0,0);
globalForce.x=localforce.dot(new Vector3f(t.basis.m00, t.basis.m10, t.basis.m20));
globalForce.y=localforce.dot(new Vector3f(t.basis.m01, t.basis.m11, t.basis.m21));
globalForce.z=localforce.dot(new Vector3f(t.basis.m02, t.basis.m12, t.basis.m22));
body3.setCentralForce(globalForce);
What's wrong with the above code? It seems that sometimes the force is perpendicular to the capsule body instead of pointing forward.
Thank you very much.
Capsules orientation
-
- Posts: 109
- Joined: Tue May 01, 2012 10:42 am
Re: Capsules orientation
not sure what is wrong with your code, but maybe it's easier to do something like
Code: Select all
btTransform t;
body.getMotionState().getWorldTransform(t);
t.setOrigin(new btVector3(0,0,0));
btVector3 localForce=new btVector3 (0,1,0);
body.applyCentralForce(t * localForce);
-
- Posts: 3
- Joined: Thu Jun 27, 2013 6:04 pm
Re: Capsules orientation
Thanks! The problem is that I could multiply a transform with vector3f in java.STTrife wrote:not sure what is wrong with your code, but maybe it's easier to do something like
Code: Select all
btTransform t; body.getMotionState().getWorldTransform(t); t.setOrigin(new btVector3(0,0,0)); btVector3 localForce=new btVector3 (0,1,0); body.applyCentralForce(t * localForce);