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
Camera rotation (I'm lost...) [Solved again]
-
FriendlyWarlord
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm
Camera rotation (I'm lost...) [Solved again]
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
)
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
Last edited by FriendlyWarlord on Fri Feb 02, 2007 6:15 am, edited 5 times in total.
=D
The simplest way (you must use setInputReceiverEnabled (false) in this case):
Bye
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));
-
FriendlyWarlord
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm
-
FriendlyWarlord
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm
-
FriendlyWarlord
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm
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
[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?
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
[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:
well here it is a code i use u dont need to know matrix or to do it just understand it:
that's all folks 
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);
-
FriendlyWarlord
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm