How to move an object based on a transformation matrix

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Burton
Posts: 5
Joined: Fri Aug 03, 2018 12:08 am

How to move an object based on a transformation matrix

Post 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.
CuteAlien
Admin
Posts: 9645
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

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

Post 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.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Burton
Posts: 5
Joined: Fri Aug 03, 2018 12:08 am

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

Post 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.
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

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

Post 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.
Post Reply