void Camera::RotateY(float angle)
{
double cs = cos(3.14159265/180 * angle);
double sn = sin(3.14159265/180 * angle);
_look.setx(_look.retx()*cs- _rightVector.retx()*sn);
_look.sety(_look.rety()*cs- _rightVector.rety()*sn);
_look.setz(_look.retz()*cs- _rightVector.retz()*sn);
_look.Normalise();
_rightVector = (_look.CrossProduct(_up));
CallModelViewMatrix();
}
void Camera::CallModelViewMatrix()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
_ViewPoint.setx(_e.retx()+_look.retx());
_ViewPoint.sety(_e.rety()+_look.rety());
_ViewPoint.setz(_e.retz()+_look.retz());
gluLookAt(_e.retx(),_e.rety(),_e.retz(),_ViewPoint.retx(),_ViewPoint.rety(),_ViewPoint.retz(),_up.retx(),_up.rety(),_up.retz());
}
Problems with my camera please help
hi everyone
I have been working on this problem for days and i just can't seem to figure it out. ok first of all when i want to shoot i place the initial position of the bullet as the camera position and the direction that the bullet will travel as the view direction. this works ok when i am facing along the z axis however when i rotate towords the x axis things get messed up. the view plane does not rotate around the camera position instead it just rotates about itself.
situation when facing z axis
Eye
_____
situation when facing the x axis
Eye
|
|
the eye equals the camera positon and line equals the view plane. so as you can see if i shoot when facing along the x axis the bullet appears beside me. Below i have posted my rotation and where i plug the values into glulookat
thanks in advance to anyone who can help me with this problem
[Edited by - Magoo2005 on November 19, 2005 8:41:54 AM]
I don't know whether I interpret it all right, but the snippet you've posted seems strange to me. I want to mention the following things:
By multiplying the entire _look or _rightVector with the cosine and sine, resp., lets the one or other vector disappear with growing _angle. IMHO this is similar but not exactly as a rotation would work.
The overhanded angle is accumulated in the member _angle. So the member _angle denotes an orientation rather than a delta angle. So I assume it would be better to compute the _look from also a fixed standard rather than from the previous one.
Perhaps maybe I'm wrong.
By multiplying the entire _look or _rightVector with the cosine and sine, resp., lets the one or other vector disappear with growing _angle. IMHO this is similar but not exactly as a rotation would work.
The overhanded angle is accumulated in the member _angle. So the member _angle denotes an orientation rather than a delta angle. So I assume it would be better to compute the _look from also a fixed standard rather than from the previous one.
Perhaps maybe I'm wrong.
the _angle is not actually used for anything its just something i forgot to delete from when i was trying something else. The rotation is calculated by the angle value which is just a set value that is passed into the function everytime you press a certain key. i have gotten rid of _angle in order to make things a bit clearer
Ok. Let's have a deeper look.
The standard way of computing a y rotation is this:
where [x y z]^T is either your _look or else _rightVector, and the right sided result is the new _look or else new _rightVector. There is a big difference to what you're computing. Could you please verify your way of computing the new _look vector?
The standard way of computing a y rotation is this:
[ cos 0 sin ] [ x ] [ x*cos + z*sin ][ 0 1 0 ] * [ y ] = [ y ][-sin 0 cos ] [ z ] [-x*sin + z*cos ]
where [x y z]^T is either your _look or else _rightVector, and the right sided result is the new _look or else new _rightVector. There is a big difference to what you're computing. Could you please verify your way of computing the new _look vector?
yea according to what you said i was doing the rotation wrong i have changed it to this
vector3d temp = _look;
_look.x =(temp.x*cs+ temp.z*sn);
_look.z= (temp.z*cs- temp.x*sn);
where sn and cs = to the sine and cosine of the angle
however i still seem to be getting kind of the same problem with the eye position not being exactly center of the screen after i rotate so i am facing the x axis;
vector3d temp = _look;
_look.x =(temp.x*cs+ temp.z*sn);
_look.z= (temp.z*cs- temp.x*sn);
where sn and cs = to the sine and cosine of the angle
however i still seem to be getting kind of the same problem with the eye position not being exactly center of the screen after i rotate so i am facing the x axis;
Sorry, but I don't understand your description of what's happening.
In principal, at first when rendering a frame, you have to guarantee that the MODELVIEW matrix stack is active. You are doing that inside of Camera::CallModelViewMatrix(). Next you have to reset the matrix (also ok), and to multiply that preset with the inverse of the camera co-ordinate frame. This means first to multiply the inverse camera rotation, and then the inverse camera translation. This in fact centers the world at the camera origin (== eye point), and rotates around that point so that the look-at axis is in front. You are using the gluLookAt function for that purpose, and those function works the aforementioned way. So it looks all fine for me.
Maybe the angle has not the value you are expecting? What does it mean when you say that the "view plane does not rotate around the camera position instead it just rotates about itself"? The view plane is in front of the camera, and rotating around a point on the view plane needs at least one (normally two) additional translations that I could not see in the posted code snippets.
In principal, at first when rendering a frame, you have to guarantee that the MODELVIEW matrix stack is active. You are doing that inside of Camera::CallModelViewMatrix(). Next you have to reset the matrix (also ok), and to multiply that preset with the inverse of the camera co-ordinate frame. This means first to multiply the inverse camera rotation, and then the inverse camera translation. This in fact centers the world at the camera origin (== eye point), and rotates around that point so that the look-at axis is in front. You are using the gluLookAt function for that purpose, and those function works the aforementioned way. So it looks all fine for me.
Maybe the angle has not the value you are expecting? What does it mean when you say that the "view plane does not rotate around the camera position instead it just rotates about itself"? The view plane is in front of the camera, and rotating around a point on the view plane needs at least one (normally two) additional translations that I could not see in the posted code snippets.
ok i will try to explane this a bit better.
all bullets are spawned at the _eye point. when i am looking down the -z axis this means that they will spawn right at my cross hair. when i rotate the camera so that i am facing down the x axis the bullets spawn right beside me as oposed to spawning on the cross hair. i am taking this to mean that the eye point is beside the view plane when i fire along the x axis. i will try to do a little diagram 's' = where bullets are spawned. '_' and '|' represent the view plane.
when looking down the -z axis the situation is like this
s
_
as you can see the bullets are spawned in front of the camera.
when look down the x axis the situation is like this
s
|
as you can see the bullets are spawned beside the camea and not in front of it.
hope that this describes the problem i am having a bit better
all bullets are spawned at the _eye point. when i am looking down the -z axis this means that they will spawn right at my cross hair. when i rotate the camera so that i am facing down the x axis the bullets spawn right beside me as oposed to spawning on the cross hair. i am taking this to mean that the eye point is beside the view plane when i fire along the x axis. i will try to do a little diagram 's' = where bullets are spawned. '_' and '|' represent the view plane.
when looking down the -z axis the situation is like this
s
_
as you can see the bullets are spawned in front of the camera.
when look down the x axis the situation is like this
s
|
as you can see the bullets are spawned beside the camea and not in front of it.
hope that this describes the problem i am having a bit better
Ok, I see the problem now. Sorry for the inconvenience.
However, the posted snippets seems to be ok. What happens if you're looking in +z direction? Does the bullet again spawn from the center? And similarly, if looking along -x, does the bullet spawn at the (other) side as if looking in +x?
To check what's happening to the eye point under your control, simply put something like
at the end of Camera::CallModelViewMatrix(). Does the printed values change during rotation? If not, the spawning code is candidate of a bug. You could also get back the current modelview matrix after the gluLookAt, and compare the positioning part with the printed eye point.
If all that does not help, please post also the bullet spawning code.
However, the posted snippets seems to be ok. What happens if you're looking in +z direction? Does the bullet again spawn from the center? And similarly, if looking along -x, does the bullet spawn at the (other) side as if looking in +x?
To check what's happening to the eye point under your control, simply put something like
cout << _ViewPoint.getx() << ',' << _ViewPoint.gety() << ',' << _ViewPoint.getz() << endl;
at the end of Camera::CallModelViewMatrix(). Does the printed values change during rotation? If not, the spawning code is candidate of a bug. You could also get back the current modelview matrix after the gluLookAt, and compare the positioning part with the printed eye point.
If all that does not help, please post also the bullet spawning code.
hmm so you are saying that i should be passing the _ViewPoint as the bullet spawning position currently i am passing the _eye point. when passing the eye point no matter what direction i am facing the bullet always spawns in the same place.
Gnnn, copy-&-paste mistake: No, I meant the eye point. However, it should not make such a difference, since the ViewPoint is located always 1 length unit in front of the eye point, assuming that the eye point is given in world space. But of course the ViewPoint _will_ change during rotation, so please substitute it in my previous post by the _e point.
EDIT: To be precise: Your orig post says that spawning occurs at the eye point. That would be ok since it should always denote the center of the view, independent in what direction you are looking. The ViewPoint is the eye point plus the look-at vector, and hence changes with rotation in its world co-ordinates, but in eye co-ordinates it should always be central in front of the eye point.
EDIT: To be precise: Your orig post says that spawning occurs at the eye point. That would be ok since it should always denote the center of the view, independent in what direction you are looking. The ViewPoint is the eye point plus the look-at vector, and hence changes with rotation in its world co-ordinates, but in eye co-ordinates it should always be central in front of the eye point.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement