Position offset

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Position offset

Post by Seven »

assuming that i have a physics obj and a scenenode (in this case, a PhysX cube and a IMeshSceneNode)
and all works fine with positioning and rotating the node to match the physx cube.

the trouble is when the mesh needs to be positioned differently than the physx cube.
i try to use something like

vector3df positionOffset(0,-60,0);
node->setPosition(physXCube->getPosition() + positionOffset);

which works fine as long as the item is not rotated since a direct -60 is applied to the Y axis of the node.
if the item is rotated however, then the positionOffset wont work properly because the -60 is applied to the Y axis and the node is rendered 60 units down from the physx cube.

not sure that makes sense. but the end result is that I am looking for help.

how do you position a node relative to a physx cube when you dont want the node at the 0,0,0 of the cube?
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: Position offset

Post by Seven »

answer.........

Code: Select all

 
        virtual vector3df getIn(ISceneNode* node)
        {
            if (node)
            {
                matrix4 mat = node->getRelativeTransformation();
                vector3df in(mat[8], mat[9], mat[10]);
                in.normalize();
                return in;
            }
            else return vector3df(0, 0, 0);
        }
 
        virtual vector3df getLeft(ISceneNode* node)
        {
            if (node)
            {
                matrix4 mat = node->getRelativeTransformation();
                vector3df left(mat[0], mat[1], mat[2]);
                left.normalize();
                return left;
            }
            else return vector3df(0, 0, 0);
        }
 
        virtual vector3df getUp(ISceneNode* node)
        {
            if (node)
            {
                matrix4 mat = node->getRelativeTransformation();
                vector3df up(mat[4], mat[5], mat[6]);
                up.normalize();
                return up;
            }
            else return vector3df(0, 0, 0);
        }
 

Code: Select all

 
            m_Rotation = getPhysXObject()->getRotation();
            m_Position = getPhysXObject()->getPosition();
            vector3df up = getUp(getPrimarySceneNode()) * getPositionOffset().Y;
            vector3df left  = getLeft(getPrimarySceneNode()) * getPositionOffset().X;
            vector3df in    = getIn(getPrimarySceneNode()) * getPositionOffset().Z;
            vector3df posoffset = (up+in+left);
 
            setPrimarySceneNodePositionAndRotation(getPosition() + posoffset, getRotation() + getRotationOffset());
 
CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Position offset

Post by CuteAlien »

Nice if you got it. I'm not sure if I really understood your problem. But if it was that you want to rotate an offset the same way as a node then you can use matrices. The irrlicht matrix has transformVect and rotateVect functions which do that job for you. So you get the matrix of your node and then call one of the transformation functions on your vector and it will for example rotate the same way as your node did.
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
Post Reply