MyFPS Camera (mouse rotation with right button)
Posted: Sat Jul 04, 2009 3:01 pm
First i tried to do this by setting only the Y rotation but it sucks. It change target of cam in some strange way (for me ) so I change the method and now i am setting the target and it works ok.. Did any one tried with rotation on Y and it works good ?
Here is my code of rotating with the change of target . maby some one will find this usefull or will help me with upgrading it
Ofcoruse i set :
_view is camera object
MouseMv <- return true if mouse was moved
MouseX <- return X of mouse
It is based on
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11214
Ofcourse it needs adding X rotation
Here is my code of rotating with the change of target . maby some one will find this usefull or will help me with upgrading it
Code: Select all
if ((_receiver.MouseR()!=1)&& (_rot == true))
{
_rot=false;
}
if (_receiver.MouseR()==1)
{
if (_rot==true)
{
if (_receiver.MouseMv())
{
int new_X = _receiver.MouseX();
if (_old_X != new_X)
{
float dyst = (_old_X - new_X);
_rotation+=dyst/100;
vector3df mPos = _view->getPosition();
vector3df mView = _view->getTarget();
vector3df vVector = mView - mPos; // Get the view vector
irr::f32 R = sqrt(vVector.X*vVector.X+vVector.Z*vVector.Z); //Get the R of circle
mView.X = mPos.X+R*cos(_rotation); //calculate absolute X position on circle
mView.Z = mPos.Z+R*sin(_rotation);//calculate absolute Z position on circle
_view->setTarget(mView); // Update Target
_rot = false;
}
}
}
else if (_rot==false)
{
_rot = true;
_old_X = _receiver.MouseX();
}
}
Ofcoruse i set :
Code: Select all
_view->bindTargetAndRotation(true)
MouseMv <- return true if mouse was moved
MouseX <- return X of mouse
It is based on
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11214
Ofcourse it needs adding X rotation