Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Seven
Posts: 1030 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Sun Mar 03, 2013 9:08 pm
scenenode movement code.
forward, left and up are relative to the 'facing;' of the scenenode
Code: Select all
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);
}
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);
}
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);
}
// use
Code: Select all
ISceneNode* node = (create a scenenode)
// move the scenenode forward
node->setPosition( node->getPosition() + getIn(node) * speed);
// move the scenenode backward
node->setPosition( node->getPosition() - getIn(node) * speed);
// move the scenenode left
node->setPosition( node->getPosition() + getLeft(node) * speed);
// move the scenenode right
node->setPosition( node->getPosition() - getLeft(node) * speed);
// move the scenenode up
node->setPosition( node->getPosition() + getUp(node) * speed);
// move the scenenode down
node->setPosition( node->getPosition() - getUp(node) * speed);
Last edited by
Seven on Tue Mar 05, 2013 4:24 pm, edited 1 time in total.
chronologicaldot
Competition winner
Posts: 685 Joined: Mon Sep 10, 2012 8:51 am
Post
by chronologicaldot » Tue Mar 05, 2013 1:54 am
That's nice
I'd rename the function getIn() to getFwd() for less confusion.
EDIT:
setPosition is missing it's closing paranthesis on all three examples. That's just a notice for those considering copying the code verbatum.
Seven
Posts: 1030 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Tue Mar 05, 2013 4:25 pm
I modified the setPosition() calls.
also, I should have noted that this is not my code, it is from this forum in multiple places. I simply put it together in a single location for future reference.
Seven
Posts: 1030 Joined: Mon Nov 14, 2005 2:03 pm
Post
by Seven » Tue Apr 16, 2013 7:48 pm
as used in my wrapper - shows getpointinffront() and getpointabove() etc........
Code: Select all
// simple functions for AI useage
virtual vector3df getPointInFront(float distance) { vector3df p = getPosition(); p += distance * getIn(); return p; }
virtual vector3df getPointInBack(float distance) { vector3df p = getPosition(); p -= distance * getIn(); return p; }
virtual vector3df getPointAbove(float distance) { vector3df p = getPosition(); p += distance * getUp(); return p; }
virtual vector3df getPointBelow(float distance) { vector3df p = getPosition(); p -= distance * getUp(); return p; }
vector3df CSObject::getPointInFrontAndAbove(float d, float u)
{
vector3df p = getPointInFront(d);
p.Y = getPointAbove(u).Y;
return p;
};
vector3df CSObject::getPointLeftAndAbove(float d, float u)
{
vector3df p = getPosition();
p -= d * getLeft();
p.Y = getPointAbove(u).Y;
return p;
};
vector3df CSObject::getPointInBackAndAbove(float d, float u)
{
vector3df p = getPointInBack(d);
p.Y = getPointAbove(u).Y;
return p;
};
vector3df CSObject::getIn()
{
if (getPhysicsObject()) return getPhysicsObject()->getIn();
else
if (getPrimarySceneNode())
{
matrix4 mat = getPrimarySceneNode()->getRelativeTransformation();
vector3df in(mat[8],mat[9],mat[10]);
in.normalize();
return in;
} else return vector3df(0,0,0);
}
vector3df CSObject::getUp()
{
if (getPhysicsObject()) return getPhysicsObject()->getUp();
else
if (getPrimarySceneNode())
{
matrix4 mat = getPrimarySceneNode()->getRelativeTransformation();
vector3df up(mat[4],mat[5],mat[6]);
up.normalize();
return up;
}
else return vector3df(0,0,0);
}
vector3df CSObject::getLeft()
{
if (getPhysicsObject()) return getPhysicsObject()->getLeft();
else
if (getPrimarySceneNode())
{
matrix4 mat = getPrimarySceneNode()->getRelativeTransformation();
vector3df left(mat[0],mat[1],mat[2]);
left.normalize();
return left;
}
else return vector3df(0,0,0);
}