How to move the camera along its local axis?
I want to move the camera 1 unit along its local x axis as if it were strafing along to the direction that it's looking.
If I add 1 to the X value of camera->setPosition() it instead moves along what I think is the global axis; it also doesn't account for rotation. How can I take a vector(1, 0, 0) and transform it in such a way that I can simply add it to the camera's position so that it moves along its local axis?
If I understand Irrlicht's camera methods, I think I also need to add this to the target so that it doesn't just strafe and then turn to look back at the target.
Information I'm finding on the internet talks about multiplying vectors with matrices but there doesn't seem to be an overload for multiplying vector3df and matrix4.
How to move the camera along its local axis?
Re: How to move the camera along its local axis?
You can get that vector by computing the cross product of the up and forward vector.
Vector3df side = up.crossProduct(forward).normalize();
You can get the up vector with camera->getUpVector() and the forward vector by subtracting the camera position from the target position.
No need for matrices here
Vector3df side = up.crossProduct(forward).normalize();
You can get the up vector with camera->getUpVector() and the forward vector by subtracting the camera position from the target position.
No need for matrices here
Re: How to move the camera along its local axis?
Glorious, thank you!
One thing I'm uncertain of is when I should call camera->updateAbsolutePosition(). Is it something I should do before calling getPosition() or after setPosition()? When should it be used?
One thing I'm uncertain of is when I should call camera->updateAbsolutePosition(). Is it something I should do before calling getPosition() or after setPosition()? When should it be used?
Re: How to move the camera along its local axis?
As long as it works I wouldn't think to hard about it.
It's also automatically called with drawAll.
You usually need it, when you call setPosition and then getAbsolutePosition, otherwise that will return the position from the previous frame.
You also don't need it if your node does not have a parent. (In that case getPosition() can be used instead of getAbsolutePosition())
It's also automatically called with drawAll.
You usually need it, when you call setPosition and then getAbsolutePosition, otherwise that will return the position from the previous frame.
You also don't need it if your node does not have a parent. (In that case getPosition() can be used instead of getAbsolutePosition())
Re: How to move the camera along its local axis?
here are a few useful code snippets for what you are doing.
Code: Select all
vector3df CSObject::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 CSObject::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);
}
vector3df CSObject::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);
}