Page 1 of 1

How to move an object based on a transformation matrix

Posted: Fri Aug 03, 2018 12:26 am
by Burton
Hi everyone,

My current object requires me to transform one object with a given transformation matrix (4 by 4). Looks like there is no API for this function. Be more specific, what I want is given a transformation matrix A, I somehow get the current modelview matrix B, and set B = A*B to change its location, rotation and scale. If you know OpenGL, what I ask is very similar to the function glMultMatrix to change the location of the model.

Any suggestions about how should I do this? Thanks very much.

Re: How to move an object based on a transformation matrix

Posted: Fri Aug 03, 2018 8:57 am
by CuteAlien
It's not the fastest solution as it adds additional transformations for the nodes, but you can use a addDummyTransformationSceneNode as parent of your node. And then set getRelativeTransformationMatrix () (which returns a reference) to your matrix.

Re: How to move an object based on a transformation matrix

Posted: Sat Aug 04, 2018 9:57 am
by Burton
CuteAlien wrote:It's not the fastest solution as it adds additional transformations for the nodes, but you can use a addDummyTransformationSceneNode as parent of your node. And then set getRelativeTransformationMatrix () (which returns a reference) to your matrix.
thanks, I think this would work for me.

Re: How to move an object based on a transformation matrix

Posted: Sat Aug 04, 2018 12:10 pm
by devsh
Irrlicht splits matrices into world view and proj, so modelview is actually a concatenation of two matrices in the engine. All you really need to do is get the relative transformation matrix and multiply it by the matrix A, then get the position, scale and rotation and set it on the object again.

If you know plain GL and matrices, and need instancing with LoD.. you should check out my fork.

I changed ISceneNode (it actually inherits from IDummyTransformationSceneNode) to support setting rotation, position and scale directly from a 4x3 matrix (works like a 4x4 with assumed 0 0 0 1 on the bottom row)
You can get the relative transformation matrix (there's a call for that) concatenate it with the matrix A, then use setRelativeTransform to set it immediately.

I removed the operator* on matrices, but provided `concatenate` functions which allow more control over the associativity of the operation, precision and ordering.