[SOLVED] Reset nodes absolute position to zero

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
PioBeat
Posts: 4
Joined: Wed Aug 22, 2012 6:48 am

[SOLVED] Reset nodes absolute position to zero

Post by PioBeat »

Hello!

This is my first post in this forum after a long while (still being active with Irrlicht) and this is a question that is around in my head for a long time.
I want to "reset" the absolute position of a node to vector3df(0,0,0) and then manually set the local position with the old absolute value.
Example: A Node has the initial absolute position of (11,14-2). That means after resetting the position this should give me

Code: Select all

node->getAbsolutePosition()
(0,0,0) so that I can manually set the position with

Code: Select all

node->setPosition(vector3df(11,14,-2))
Everything is fine when you load a model directly in Irrlicht

Code: Select all

smgr->getMesh("./media/models/TreeA.3ds")
or create a simple shape

Code: Select all

smgr->addCubeSceneNode(1.0f);
the initial absolute position is always 0 (unless otherwise specified).

But when I load a COLLADA Scene into Irrlicht (modelled with Blender) the object is initialized with the position which is specified in Blender in the transform panel:
http://postimg.org/image/z8l3a1k2b/
In this example (11,14,-2).

This gives me a huge problem in my whole application because I have to do different kinds of checks, re-positioning, re-calculating etc. Especially when it comes to using the Bullet Physics Engine. The bounding boxes and position are getting messed up.

That is how I load the collada file:

Code: Select all

 
smgr->getParameters()->setAttribute(irr::scene::COLLADA_CREATE_SCENE_INSTANCES, true);
scene::IAnimatedMesh* meshmodel = smgr->getMesh(name);
core::array<scene::ISceneNode *> nodes;
smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes);
 
I tried something like in the following snippet but the absolute position stays the same:

Code: Select all

 
matrix4 m;
m.setTranslation(-node->getAbsolutePosition());
smgr->getMeshManipulator()->transform(ams->getMesh(), m);
I really hope you can help me with this kind of problem.
Thank you very much...
Last edited by PioBeat on Wed Dec 09, 2015 6:06 pm, edited 1 time in total.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Reset nodes absolute position to zero

Post by Mel »

I think you're having problems with the position your exporter sets your mesh on. As a rule of thumb, unless you're using an exporter which allows some special pivotting options, like setting the center of the object to a null/dummy/empty primitive, export your objects centered on the origin, that is, the point you want your object to pivot on, placed on the origin, its transformation in blender should be 0,0,0 and then, translate them inside the engine, That saves a lot of problems, as it is what most engines, both graphics and physics, expect things to be
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
PioBeat
Posts: 4
Joined: Wed Aug 22, 2012 6:48 am

Re: Reset nodes absolute position to zero

Post by PioBeat »

Thanks for your answer. This is exactly what I had expected.
Blender hasn't that option for exporting. It's also very important that you only transform the objects in Blender in "object mode" (and don't do Apply->Location/Rotation/Scale, CTRL+A)

The previous approach obviously didn't work. I stumbled upon this enlightening forum post:
http://irrlicht.sourceforge.net/forum/v ... =1&t=29035
and finally solved it.

The solution was merely setting a new parent:

Code: Select all

 
matrix4 oldTransform = node->getAbsoluteTransformation(); //save old transformation matrix
node->setParent(smgr->getRootSceneNode()); //set root node as new parent
node->updateAbsolutePosition();
//now locally set the old transformations (this is in object space)
node->setPosition(oldTransform.getTranslation());
node->setScale(oldTransform.getScale());
node->setRotation(oldTransform.getRotationDegrees());
node->updateAbsolutePosition();
 
After this the absolute position of the node is (0,0,0).

Hopes this helps someone! And thanks Mel for this valuable information.
Post Reply