Camera rotation (I'm lost...) [Solved again]

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
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Camera rotation (I'm lost...) [Solved again]

Post by FriendlyWarlord »

Hi, I'm trying to do something seemingly simple: rotate the camera. I don't know how matrix4's work, but I completely understand vectors, and Irrlicht's input. Is there a simple tutorial or something to help with first person(ish) camera rotation? I don't even know which methods I should use (though I know some NOT to use *cough*setRotation.) I'd be perfect if there's a routine already written (in code snippets, maybe?) that does what I naively thought setRotation would do (i.e. given a vector, the camera looks in that vector's angle).

I'm planning on controlling camera movement by having the camera attached to a Newton body (and/or another Irrlicht node), but I still need to know how to rotate its view... Any help or pointers to info at all would be great =] I did search the site, and I'm definately not using the default cameraSceneNodeFPS (and I'm willing to learn all about matrix4, but I'd rather avoid it if possible :wink: )
Last edited by FriendlyWarlord on Fri Feb 02, 2007 6:15 am, edited 5 times in total.
=D
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post by stef_ »

The simplest way (you must use setInputReceiverEnabled (false) in this case):

Code: Select all

ICameraSceneNode *camera;
camera = smgr->addCameraSceneNodeFPS (0, 100, 500);
camera->setInputReceiverEnabled (false);

then:
camera->setPosition (irr::core::vector3df (posx, posy, posz));
camera->setRotation (irr::core::vector3df (rotx, roty,rotz)); 
Bye
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Post by FriendlyWarlord »

Wow, that was fast and easy, thanks! =)
=D
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, you must use setTarget. setRotation will only turn the children of the camera, but still look into the same direction.
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Post by FriendlyWarlord »

setRotation() will rotate the view if I use addCameraSceneNodeFPS, but when I use a plain ol' addCameraSceneNode, setRotation() doesn't rotate the view. Mystery solved, it would seem...?
=D
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Post by FriendlyWarlord »

Arg, I had a feeling this would come back to haunt me...


So now I'm focusing on moving the camera (and the player). The player moves fine, but the FPS camera has the classic "lagging behind one frame" problem. If I try calling camera->updateAbsolutePosition() (either before each frame is rendered or after the camera is moved or rotated), the camera rotation goes INSANE (appearing in different directions suddenly each frame whenever you're moving or rotating the camera).

If I try using the non-FPS camera, updateAbsolutePosition() does indeed solve the 1 frame camera lag. But, setRotation() with the non-FPS camera still does absolutely nothing (the camera can still move around, but it's always looking at point (0,0,0)).

So, what should I do? Find some other way to get the regular camera to rotate? Calculate the camera's target every frame (shudder)? Report a bug in the FPS camera?

Also interesting to note: if I try using the FPS camera as a child node of the player node, camera->setRotation() stops working (and the "insane" rotation is gone), exactly like using the non-FPS camera. I feel so utterly screwed =P


[Edit]

Hah! I always seem to find the solution 5 minutes after I type a long post about it. So camera->setTarget() works, but only if I use updateAbsolutePosition() on the camera AND the player, and use the non FPS camera. And there I was worried that setTarget's fancy vector would screw up my FOV :oops:


[Edit]

I spoke too soon.... it's mostly fixed (using the solution from the post in the previous edit), BUT there's still one problem left: the camera's rotation lags behind one frame. Looks like that was actually happening all along. Any ideas?
=D
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

well here it is a code i use u dont need to know matrix or to do it just understand it:

Code: Select all


core::vector3df c = car->getPosition();
         core::vector3df d= car->getRotation();
float diry = ((d.Y+90)*3.14)/180;
        if (up)
         {

            c.X += speed * cos((d.Y) * 3.14 / 180);
  c.Z -= speed * sin((d.Y) * 3.14 / 180);

         }
         if (down)
         {
                     c.X -= speed * cos((d.Y) * 3.14 / 180);
  c.Z += speed * sin((d.Y) * 3.14 / 180);
         }
         if (left)
         {
            d.Y -= 0.1;
         }
         if (right)
         {
            d.Y += 0.1;
         }
car->setRotation(d);
core::stringw cy = d.Y;
cy+="xpos";
cy+=c.X;
cy+="zpos";
cy+=c.Z;
device->setWindowCaption(cy.c_str());




car->setPosition(c);





int xf = (c.X-sin(diry)*125);
int zf =(c.Z-cos(diry)*125);
int yf =c.Y;
         camera->setPosition(vector3df(xf,yf,zf));
       camera->setTarget(c);
that's all folks :wink:
FriendlyWarlord
Posts: 58
Joined: Thu Apr 06, 2006 11:54 pm

Post by FriendlyWarlord »

I looked at your code, but not long enough to understand it very well =P

Turns out I was using getAbsoluteTransformation() instead of getRelatveTransformation(), and fixing that solved the problem. I think it's relatively safe to say my rotation problem is solved =D
=D
Post Reply