I need to know how to convert a simple matrix rotating camera class into an irrlicht like lookat camera.
i'll could probably work it out on my own, but i don't want to reinvent that again
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
Code: Select all
#ifndef MCAMERA_H
#define MCAMERA_H
#include <irrlicht.h>
using namespace irr;
class MCamera
{
scene::ICameraSceneNode* camera;
f32 rotationX;
f32 rotationY;
core::vector3df direction;
public:
MCamera(scene::ISceneManager* smgr)
{
camera = smgr->addCameraSceneNode();
rotationX = 0.0f;
rotationY = 0.0f;
direction = core::vector3df(0,0,1);
}
~MCamera(){}
void turnRight(f32 i)
{
rotationY += i;
if(rotationY>=360)rotationY-=360;
if(rotationY<0)rotationY+=360;
direction = core::vector3df(0,0,1);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (rotationX,rotationY,0));
matrix.rotateVect(direction);
camera->setTarget(camera->getPosition() + direction);
}
void turnLeft(f32 i)
{
rotationY -= i;
if(rotationY>=360)rotationY-=360;
if(rotationY<0)rotationY+=360;
direction = core::vector3df(0,0,1);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (rotationX,rotationY,0));
matrix.rotateVect(direction);
camera->setTarget(camera->getPosition() + direction);
}
void turnUp(f32 i)
{
rotationX += i;
if(rotationX>=360)rotationX-=360;
if(rotationX<0)rotationX+=360;
direction = core::vector3df(0,0,1);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (rotationX,rotationY,0));
matrix.rotateVect(direction);
camera->setTarget(camera->getPosition() + direction);
}
void turnDown(f32 i)
{
rotationX -= i;
if(rotationX>=360)rotationX-=360;
if(rotationX<0)rotationX+=360;
direction = core::vector3df(0,0,1);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (rotationX,rotationY,0));
matrix.rotateVect(direction);
camera->setTarget(camera->getPosition() + direction);
}
void moveForward(f32 i)
{
core::vector3df step = core::vector3df(0,0,i);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (0,rotationY,0));
matrix.rotateVect(step);
camera->setPosition(camera->getPosition() + step);
camera->setTarget(camera->getPosition() + direction);
}
void moveBack(f32 i)
{
core::vector3df step = core::vector3df(0,0,-i);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (0,rotationY,0));
matrix.rotateVect(step);
camera->setPosition(camera->getPosition() + step);
camera->setTarget(camera->getPosition() + direction);
}
void moveRight(f32 i)
{
core::vector3df step = core::vector3df(i,0,0);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (0,rotationY,0));
matrix.rotateVect(step);
camera->setPosition(camera->getPosition() + step);
camera->setTarget(camera->getPosition() + direction);
}
void moveLeft(f32 i)
{
core::vector3df step = core::vector3df(-i,0,0);
core::matrix4 matrix;
matrix.setRotationDegrees(core::vector3df (0,rotationY,0));
matrix.rotateVect(step);
camera->setPosition(camera->getPosition() + step);
camera->setTarget(camera->getPosition() + direction);
}
void setHeight(f32 i)
{
camera->setPosition(core::vector3df(camera->getPosition().X, i, camera->getPosition().Z));
camera->setTarget(camera->getPosition() + direction);
}
void setPosition(core::vector3df pos)
{
camera->setPosition(pos);
}
core::vector3df getPosition()
{
return camera->getPosition();
}
core::vector3df getDirection()
{
return direction;
}
core::vector3df getTarget()
{
return camera->getTarget();
}
f32 getHeading()
{
return rotationY;
}
f32 getPitch()
{
return rotationX;
}
f32 getFarValue()
{
return camera->getFarValue()
}
f32 setFarValue(f32 f)
{
camera->setFarValue(f);
}
f32 getNearValue()
{
return camera->getNearValue()
}
f32 setNearValue(f32 n)
{
camera->setNearValue(n);
}
f32 getFOV()
{
return camera->getFOV()
}
f32 setFOV(f32 v)
{
camera->setFOV(v);
}
f32 getAspectRatio()
{
return camera->getAspectRatio()
}
f32 setAspectRatio(f32 a)
{
camera->setAspectRatio(a);
}
};
#endif