int a=(int)(ship.rotation/90);
float temp;
float x=0,y=0;
switch(a)
{
case 0:
x-=ship.rotation/90;
y+=(90-ship.rotation)/90;
break;
case 1:
temp=180-ship.rotation;
x-=temp/90;
y-=(90-temp)/90;
break;
case 2:
temp=270-ship.rotation;
x+=(90-temp)/90;
y-=temp/90;
break;
case 3:
temp=360-ship.rotation;
x+=temp/90;
y+=(90-temp)/90;
break;
case 4:
y++;
break;
}
gluLookAt(ship.pos.x-x*30, ship.pos.y-y*30, 0,
ship.pos.x, ship.pos.y, zoom,
x, y, 0
);
trying to get the camera to rotate.....
ok, I''ve got a dillemma here, I''m trying to get it so that in my game, the camera is exactly behind the ship at all times, by rotating it''s position in relation to the ship''s rotation, this is what i have:
And when I turn, the camera goes out and in over and over, I know why, it''s because the x and y positions end up making a box and when it reaches the corners, it bounces off and goes back down the middle again. What I would like to know is how i can manipulate the LookAt function to make it rotate around the ship in a CIRCLE, lol, not a box
-thanks, jverkoey
I am not going to read through your code, but let me venture a possible solution.
You say your camera is confined to a box, when you want it confined to a sphere. Now consider that anywher on the surface of a sphere, the length from the center must be the same.
What you must do is normalize your vector. I assume you have the camera''s position from the ship in the form of a vector (xyz co-ords)? If not, you will need to represent it as one.
If you don''t know how to normalize, then here we go:
vectorlen = sqrt( x^2 + y^2 + z^2 );
x = x / vectorlen;
y = y / vectorlen;
z = z / vectorlen;
Your vector will be one unit long. If you want ot be furthur out from the ship, simply multiply x, y and z by the same number (the distance out, in units)
ANDREW RUSSELL STUDIOS
Cool Links :: [ GD | TG | MS | NeHe | PA | SA | M&S | TA | LiT | H*R ]
Got Clue? :: [ Start Here! | Google | MSDN | GameDev.net Reference | OGL v D3D | File Formats | Asking Questions | Go FAQ yourself ]
You say your camera is confined to a box, when you want it confined to a sphere. Now consider that anywher on the surface of a sphere, the length from the center must be the same.
What you must do is normalize your vector. I assume you have the camera''s position from the ship in the form of a vector (xyz co-ords)? If not, you will need to represent it as one.
If you don''t know how to normalize, then here we go:
vectorlen = sqrt( x^2 + y^2 + z^2 );
x = x / vectorlen;
y = y / vectorlen;
z = z / vectorlen;
Your vector will be one unit long. If you want ot be furthur out from the ship, simply multiply x, y and z by the same number (the distance out, in units)
Do not meddle in the affairs of moderators, for they are subtle and quick to anger.
ANDREW RUSSELL STUDIOS
Cool Links :: [ GD | TG | MS | NeHe | PA | SA | M&S | TA | LiT | H*R ]
Got Clue? :: [ Start Here! | Google | MSDN | GameDev.net Reference | OGL v D3D | File Formats | Asking Questions | Go FAQ yourself ]
quote:
Original post by Andrew Russell
vectorlen = sqrt( x^2 + y^2 + z^2 );
x = x / vectorlen;
y = y / vectorlen;
z = z / vectorlen;
what do you mean for the x,y,z''s? which xyz do i want in there? the ship''s coordinates or the camera''s coordinates?
The camera''s co-ordinates in relation to the ship.
Say we were in just one dimention
camera at 12 and ship at 14.
Then the vector would be 2.
For 3D
Camera (12, 13, 9)
Ship (14, 10, 10)
Vector (2, -3, 1)
So what you normalise is the last one. Once it is normalised, and then (if you wish) multiplied to make it longer, you add it to the vector position of the ship.
So say our normalised and multiplied vector was still (2, -3, 1), then you add it to Ship to get Camera. Simple vector addition.
ANDREW RUSSELL STUDIOS
Cool Links :: [ GD | TG | MS | NeHe | PA | SA | M&S | TA | LiT | H*R ]
Got Clue? :: [ Start Here! | Google | MSDN | GameDev.net Reference | OGL v D3D | File Formats | Asking Questions | Go FAQ yourself ]
Say we were in just one dimention
camera at 12 and ship at 14.
Then the vector would be 2.
For 3D
Camera (12, 13, 9)
Ship (14, 10, 10)
Vector (2, -3, 1)
So what you normalise is the last one. Once it is normalised, and then (if you wish) multiplied to make it longer, you add it to the vector position of the ship.
So say our normalised and multiplied vector was still (2, -3, 1), then you add it to Ship to get Camera. Simple vector addition.
Do not meddle in the affairs of moderators, for they are subtle and quick to anger.
ANDREW RUSSELL STUDIOS
Cool Links :: [ GD | TG | MS | NeHe | PA | SA | M&S | TA | LiT | H*R ]
Got Clue? :: [ Start Here! | Google | MSDN | GameDev.net Reference | OGL v D3D | File Formats | Asking Questions | Go FAQ yourself ]
quote:
Original post by Andrew Russell
The camera''s co-ordinates in relation to the ship.
Say we were in just one dimention
camera at 12 and ship at 14.
Then the vector would be 2.
For 3D
Camera (12, 13, 9)
Ship (14, 10, 10)
Vector (2, -3, 1)
So what you normalise is the last one. Once it is normalised, and then (if you wish) multiplied to make it longer, you add it to the vector position of the ship.
So say our normalised and multiplied vector was still (2, -3, 1), then you add it to Ship to get Camera. Simple vector addition.
Sorry for asking 1 stupid vector question. I don''t know how to define "camera''s co-ordinates in relation to the ship" is Vector(2, -3, 1) or Vector(-2, 3, -1). Can u teach me?
Thank you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement