getting global point position from object pos/orientation

mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

getting global point position from object pos/orientation

Post by mohamed »

I got a triangular mesh which I want to read all its updated points position after each timestep

so the points of the object "at the start" are in local space

if the object has a position in space "x,y,z" and a rotation "rx,ry,rz" how to use these data to get the global position of any point
i.e. assume I got a sphere of 200 points,I want to get the global position of these 200 points after each step

in Blender for example I can get the point global position:
vertex_global.co = object_world_matrix * vertex_local.co
so all i need to do is get that object_world_matrix for my object,how to do this please

thanks in advance
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: getting global point position from object pos/orientatio

Post by xexuxjy »

If this is for rigid bodies can you not just get the world tranform of the rigid body and apply that to your local point?
mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

Re: getting global point position from object pos/orientatio

Post by mohamed »

well if the transform is only in position then this is simple,but I don't know how to apply the rotation transform
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: getting global point position from object pos/orientatio

Post by STTrife »

The transform also holds rotation. Could even contain scaling (it's a full 4x4 matrix I think). So if you apply it to local points your get the world coordinates of those points.
mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

Re: getting global point position from object pos/orientatio

Post by mohamed »

well how to use getWorldTransform() with the points? as it contains origin,basis and rotation

I know these data are for the rigid body "so it got a position,rotation and scale"
but for the points they need only the position "which should be get by multiplying something (typically a matrix) with the local position of the point

I need just a simple 2 lines of code if possible to clarify this for me please
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: getting global point position from object pos/orientatio

Post by xexuxjy »

erm, wouldn't it be :

pointPositionWorld = pointPositionLocal * rigidBody->getWorldTransform();

if you just want the position without rotation you can get it from :
rigidBody->getWorldTransform().getOrigin();
or just rotation as :
btMatrix3x3 rot = rigidBody->getWorldTransform().getBasis();

apologies if I've mis-understood.
mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

Re: getting global point position from object pos/orientatio

Post by mohamed »

oh is it that simple ? :D
so multiplying btTransform by btVector3 will result in btVector3 that I want? as I didn't know that btTransform can be worked like that :D if so,then this will be the best reply I heared so far, thanks :)
mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

Re: getting global point position from object pos/orientatio

Post by mohamed »

so please correct me if I'm wrong:
btVector3 local_position(5,6,7);//any value for now

btVector3 global_position = local_position * rigidBody->getWorldTransform().getBasis() + rigidBody->getWorldTransform().getOrigin();

not sure if I understand this correct as you told in the last post :
pointPositionWorld = pointPositionLocal * rigidBody->getWorldTransform();

which is not possible due to data matching !!
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: getting global point position from object pos/orientatio

Post by STTrife »

Code: Select all

pointPositionWorld = pointPositionLocal * rigidBody->getWorldTransform(); 
this is the correct code. The transform is a matrix that is setup to rotate, scale and position vectors in a certain way. The results of a 'vector * matrix' is a vector that has been transformed by that matrix. So that is exactly what you want.
It would be wise to read up on basic 3D calculations. Not that you need to understand everything fully, but this if you don't understand how to transform vertices with matrices you're gonna have a hard time... but just imagine a worldTransform as a container for both rotation and position.
mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

Re: getting global point position from object pos/orientatio

Post by mohamed »

well I know that vector * matrix = vector

but the rigidBody->getWorldTransform() is not a matrix .... (at least here it says "error:no operator matches these operands" as the type is btTransform not matrix 3x3 or 4x4 for example
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: getting global point position from object pos/orientatio

Post by STTrife »

btVector3 btTransform::operator* ( const btVector3 & x ) const
inline
Return the transform of the vector.

Definition at line 100 of file btTransform.h.


try

Code: Select all

rigidBody->getWorldTransform() * vector
then...

But indeed it's not a 4x4 matrix internally as I thought, but it stores a 3x3 matrix for rotation and vector for translation, and this is what it does in the * operand:

Code: Select all

return x.dot3(m_basis[0], m_basis[1], m_basis[2]) + m_origin;
(you are allowed to look into the reference guide or classes yourself too btw :P)
mohamed
Posts: 15
Joined: Sun Jun 23, 2013 3:41 am

Re: getting global point position from object pos/orientatio

Post by mohamed »

oh,thanks a lot for the nice help :)

I see now it returns the dot product of vector * basis + origin (which is what I expected in a previous comment manually :D )

btVector3 global_position = local_position * rigidBody->getWorldTransform().getBasis() + rigidBody->getWorldTransform().getOrigin();

is the same as:

btVector3 global_position = rigidBody->getWorldTransform() * local_position;
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: getting global point position from object pos/orientatio

Post by STTrife »

indeed.

I was kinda surprised that it wasn't a 4x4 matrix cause that would be 'easier' to apply, but probably the dot product + translation method is faster when compiled. I wouldn't dare to question speed related choices in bullet, they are probably well thought out :)
Anyway good luck with it!