CameraSceneNode problems!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
DoritoX
Posts: 16
Joined: Fri Mar 11, 2011 2:16 pm
Location: 144

CameraSceneNode problems!

Post by DoritoX »

Hi there,
I'm working on a project for the Playstation Portable(with LTE Irrlicht Port)
and it does not support any CameraSceneNodeFPS camera...

So i'm looking for a way to "recreate" that camera with a normal camerascenenode, or i atleast want to know how to manipulate the movement and targetting correctly,
so i can atleast focus it on certain models.

for the movement (not rotation)
i tried this: (well this is just an example of what i did)

Code: Select all

if(key.IsKeyDown(W)) {modelmovez -= 5;}
if(key.IsKeyDown(A)) {modelmovex -= 5;}
if(key.IsKeyDown(S)) {modelmovez += 5;}
if(key.IsKeyDown(D)) {modelmovex += 5;}

targetx = modelmovex;
targety = modelmovey;
targetz = modelmovez += 50;

model->setPosition(vector3df(modelmovez,modelmovey,modelmovex));
camera->setTarget(vector3df(targetz,targety,targetx));
But the screen just kinda flickers, and it doesn't look very good, i'm sure this isn't the correct way to do this but i can't figure it out,

i was hoping you guys could help me out...

thanks alot!
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

First I assume your "model" pointer refers to your camera node, and you move it via the keys, and it always looks towards positive Z. Otherwise I cannot get what you wanna do adding some z-positive (0,0,50) vector to it.

This is probably your biggest problem:

Code: Select all

targetz = modelmovez += 50.f; 
It first increases the modelmovez value with 50, then sets the result to targetZ. You end up with targetz equal to modelmovez, where both are wrong- the modelmovez is wrong because its unintentionally modified, and the target is the same as the origin, hence it`s invalid target position too.

Code should probably be like:

Code: Select all

targetz = modelmovez + 50.f; 

Maybe just a little bit better version could be:

Code: Select all

// declare globals (header or in somewhere in global scope)
core::vector3df moveVec;
core::vector3df targetVec;

// set their values (init time)
moveVec.set( 0, 0, 0 ); // some values
targetVec = moveVec + core::vector3df(0,0,1);

// loop
if (key.IsKeyDown(W)) {moveVec.Z -= 5;}
if (key.IsKeyDown(A)) {moveVec.X -= 5;}
if (key.IsKeyDown(S)) {moveVec.Z += 5;}
if (key.IsKeyDown(D)) {moveVec.X += 5;}

targetVec.set(moveVec.X, moveVec.Y, moveVec.Z + 50.f);

camera->setPosition(moveVec);
camera->setTarget(targetVec);
If you wanna your camera to look at the model, which is the camera target,( this is not exactly the default FPS camera behaviour) you may try sth like:

Code: Select all

core::vector3df camPos(camera->getAbsolutePosition());
core::vector3df targetDir(model->getPosition() - camPos);
targetDir.normalize();

camera->setTarget(camPos + targetDir);
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
DoritoX
Posts: 16
Joined: Fri Mar 11, 2011 2:16 pm
Location: 144

Post by DoritoX »

It worked, that's great....Thanks alot for your fast and useful reply!
Post Reply