Camera Movement
Camera Movement
When the camera moves, how come it doesn't move relative to the camera's Y angle?
Re: Camera Movement
can you be more specific about your problem? and maybe show some code?tomtetlaw wrote:When the camera moves, how come it doesn't move relative to the camera's Y angle?
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
Well, I'm trying to get my FPS controls properly working, I've got movement worked out, but when I'm not looking straight, but side to side, then I press the W key, he still just moves forward instead of the way the camera is looking.
Here's the relevant code:
Here's the relevant code:
Code: Select all
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
const f32 MOVEMENT_SPEED = 5.f;
u32 then = device->getTimer()->getTime();
while(device->run())
{
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
then = now;
core::vector3df nodePosition = camera->getPosition();
if(receiver.IsKeyDown(irr::KEY_KEY_W))
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
camera->setPosition(nodePosition);
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
Ok now we do a simple test.
First take a breath. Now take a look at your code.
Now take a look at your code again.
Do you see anything that tells the camera to move to the direction it is looking at? Well I don't. And your compiler probably neither.
So we have cleared this question. There is no code that does what you want. So here comes the next question: Why do you think that this code will do something it can't ?
And finally the one million dollar question: Why are you trying to implement your own FPS camera? There is a built-in FPS camera that does all the things for you.
First take a breath. Now take a look at your code.
Now take a look at your code again.
Do you see anything that tells the camera to move to the direction it is looking at? Well I don't. And your compiler probably neither.
So we have cleared this question. There is no code that does what you want. So here comes the next question: Why do you think that this code will do something it can't ?
And finally the one million dollar question: Why are you trying to implement your own FPS camera? There is a built-in FPS camera that does all the things for you.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Here you go:
Code: Select all
ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
const f32 MOVEMENT_SPEED = 5.f;
u32 then = device->getTimer()->getTime();
while(device->run())
{
const u32 now = device->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f;
then = now;
core::vector3df nodePosition = camera->getPosition();
core::vector3df vel(0,0,0);
if(receiver.IsKeyDown(irr::KEY_KEY_W))
vel.Z += MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
vel.Z -= MOVEMENT_SPEED * frameDeltaTime;
if(receiver.IsKeyDown(irr::KEY_KEY_A))
vel.X -= MOVEMENT_SPEED * frameDeltaTime;
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
vel.X += MOVEMENT_SPEED * frameDeltaTime;
matrix4 mat = camera->getAbsoluteTransformation();
mat.rotateVect(vel);
camera->setPosition(nodePosition+vel);
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
I didn't even copy that answer, I used
Code: Select all
scene::ICameraSceneNode* camera=smgr>smgr>addCameraSceneNodeFPS()
#1 Most Common Error:
Reality Error: Object behind keyboard cannot program.
Reality Error: Object behind keyboard cannot program.