I have been trying to rotate a camera around a point in space or an object or node.
I have set the target of the camera to 0,0,0 and then used setRotation.
I have two cameras in my scene and I am trying to rotate camera[0] around a point in space, thus (0,0,0) being that point.
Because I am making a board game, I will require the camera to have the ability to rotate around the board.
You may be wondering why in the setrotation I put (vector3df(1,1, camrot)). This is because when I used (vector3df(0,0, camrot)) nothing moved. However all I get is a gentle bobbing of the cameras like as if you are on the sea, but no rotation. I must remember these settings if I ever do a boat game LOL.
I am guessing this line is wrong
camrot+=50 * frameDeltaTime;
Perhaps it should be using some kind of radian or something, but I am far from being a mathmation.
I think maybe quaterians might be used, if I knew what I was doing doh.
Will paste relavent code.
Code: Select all
ICameraSceneNode *camera[2]={0,0};
camera[0] = smgr->addCameraSceneNode(0,vector3df(100, 70, 150), vector3df(0, 70, 60));
camera[1] = smgr->addCameraSceneNode(0,vector3df(100, 70, 550), vector3df(0, 70, 60));
camera[0]->setTarget(vector3df(0, 0, 0));
camera[0]->bindTargetAndRotation(true);
smgr->setActiveCamera(camera[0]);
//smgr->addCameraSceneNodeFPS();
float rotation=0;
float camrot=0;
// In order to do framerate independent movement, we have to know
// how long it was since the last frame
u32 then = device->getTimer()->getTime();
// This is the movemen speed in units per second.
const f32 MOVEMENT_SPEED = 5.f;
while(device->run())
{
// Work out a frame delta time.
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
receiver.Checkkeys(receiver,frameDeltaTime,&rotation);
if(receiver.ChangeCamera1(receiver)) smgr->setActiveCamera(camera[0]);
if(receiver.ChangeCamera2(receiver)) smgr->setActiveCamera(camera[1]);
spaceinvader.RotateMesh(&rotation,frameDeltaTime);
camera[0]->setRotation(vector3df(1,1, camrot));
camrot+=50 * frameDeltaTime;
driver->beginScene(true,true,video::SColor(100,100,100,255));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return 0;