Archived

This topic is now archived and is closed to further replies.

trying to get the camera to rotate.....

This topic is 5646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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:

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
);

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

Share on other sites
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)

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 ]

Share on other sites
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?

Share on other sites
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.

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 ]

Share on other sites
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.

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 15
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631724
• Total Posts
3001903
×