getting global point position from object pos/orientation
-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
getting global point position from object pos/orientation
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
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
-
- Posts: 225
- Joined: Wed Jan 07, 2009 11:43 am
- Location: London
Re: getting global point position from object pos/orientatio
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?
-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
Re: getting global point position from object pos/orientatio
well if the transform is only in position then this is simple,but I don't know how to apply the rotation transform
-
- Posts: 109
- Joined: Tue May 01, 2012 10:42 am
Re: getting global point position from object pos/orientatio
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.
-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
Re: getting global point position from object pos/orientatio
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
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
-
- Posts: 225
- Joined: Wed Jan 07, 2009 11:43 am
- Location: London
Re: getting global point position from object pos/orientatio
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.
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.
-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
Re: getting global point position from object pos/orientatio
oh is it that simple ? 
so multiplying btTransform by btVector3 will result in btVector3 that I want? as I didn't know that btTransform can be worked like that
if so,then this will be the best reply I heared so far, thanks 

so multiplying btTransform by btVector3 will result in btVector3 that I want? as I didn't know that btTransform can be worked like that


-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
Re: getting global point position from object pos/orientatio
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 !!
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 !!
-
- Posts: 109
- Joined: Tue May 01, 2012 10:42 am
Re: getting global point position from object pos/orientatio
Code: Select all
pointPositionWorld = pointPositionLocal * rigidBody->getWorldTransform();
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.
-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
Re: getting global point position from object pos/orientatio
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
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
-
- Posts: 109
- Joined: Tue May 01, 2012 10:42 am
Re: getting global point position from object pos/orientatio
btVector3 btTransform::operator* ( const btVector3 & x ) const
inline
Return the transform of the vector.
Definition at line 100 of file btTransform.h.
try
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:
(you are allowed to look into the reference guide or classes yourself too btw
)
inline
Return the transform of the vector.
Definition at line 100 of file btTransform.h.
try
Code: Select all
rigidBody->getWorldTransform() * vector
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;

-
- Posts: 15
- Joined: Sun Jun 23, 2013 3:41 am
Re: getting global point position from object pos/orientatio
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
)
btVector3 global_position = local_position * rigidBody->getWorldTransform().getBasis() + rigidBody->getWorldTransform().getOrigin();
is the same as:
btVector3 global_position = rigidBody->getWorldTransform() * local_position;

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

btVector3 global_position = local_position * rigidBody->getWorldTransform().getBasis() + rigidBody->getWorldTransform().getOrigin();
is the same as:
btVector3 global_position = rigidBody->getWorldTransform() * local_position;
-
- Posts: 109
- Joined: Tue May 01, 2012 10:42 am
Re: getting global point position from object pos/orientatio
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!
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!