|
0 registered members (),
938
guests, and 4
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
3-dimensional camera rotation
#275253
06/30/09 18:40
06/30/09 18:40
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
Hello, I'm trying to make a simple camera that would always stand behind the object, and when I pan or tilt it the camera would still be behind it. Here's the code which I wrote with the help of AUM, though it does not define the camera behavior when tilting the object:
var camera_distance = 50; var camera_height = 40;
action move() { player = my; while (1) { if (key_w)c_move(my, vector(10*time_step,0,0), nullvector, GLIDE); if (key_a)my.pan +=5*time_step; if (key_q)my.roll -=10*time_step; if (key_d)my.pan -=5*time_step; if (key_e)my.roll +=10*time_step; if (key_z)my.tilt +=5*time_step; if (key_x)my.tilt -=5*time_step; camera.x = player.x - camera_distance * cos(player.pan); camera.y = player.y - camera_distance * sin(player.pan); camera.z = player.z + camera_height; camera.pan = player.pan; wait (1); } }
when I press key_a or key_d the camera works fine, but when key_z or key_x it does not react at all. I see that the code is not complete, but any my attempt to make the camera move properly while tilting the object faild. HELP!!
a generator of dull questions
|
|
|
Re: 3-dimensional camera rotation
[Re: Damocles_]
#275261
06/30/09 19:17
06/30/09 19:17
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
I see that the code is not complete, but any my attempt to make the camera move properly while tilting the object faild. HELP!! I mean I tried to write a code to effect the tilt parameter of the camera, but nothing helped. The camera tilted unproperly, I simply can't make it stand always behind the object (only while panning). Maybe I should ask the question this way: can anyone help me complete my code so that the camera keeps standing behind the object while tilting it?
a generator of dull questions
|
|
|
Re: 3-dimensional camera rotation
[Re: BastovBros]
#275266
06/30/09 19:28
06/30/09 19:28
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
heya try something like
action move()
{
player = my;
while (1)
{
//change alignment before moving fowards
if(key_a || key_d){
my.pan += (key_a - key_d) * 5 * time_step;
my.tilt += (key_z - key_x) * 5 * time_step;
my.roll += (key_e - key_q) * 10 * time_step;
}
if (key_w)c_move(my, vector(10*time_step,0,0), nullvector, GLIDE);
camera.x = player.x + (cos(player.pan) * cos(player.tilt) * camera_distance);
camera.y = player.y + (sin(player.pan) * cos(player.tilt) * camera_distance);
camera.z = player.z + sin(player.tilt);
camera.pan = player.pan;
camera.tilt = player.tilt;
wait (1);
}
}
hope this helps *untested*
|
|
|
Re: 3-dimensional camera rotation
[Re: MrGuest]
#275272
06/30/09 19:59
06/30/09 19:59
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
thx, that almost helped  the camera now moves behind the object, however it seams like it moves not around a circle but around an oval, because the distance between the view and the object becomes smaller two times per a full rotation. Like this: camera.tilt = player.tilt = 90; camera_distance = 50; camera.tilt = player.tilt = 180; camera_distance = 10; camera.tilt = player.tilt = 270; camera_distance = 50; camera.tilt = player.tilt = 360; camera_distance = 10; Why?
a generator of dull questions
|
|
|
Re: 3-dimensional camera rotation
[Re: BastovBros]
#275297
06/30/09 22:14
06/30/09 22:14
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Im not precisely sure what you mean, but how is this (untested)...
action move()
{
player = my;
VECTOR tmpV;
while (1)
{
//change alignment before moving fowards
if(key_a || key_d)
{
my.pan += (key_a - key_d) * 5 * time_step;
my.tilt += (key_z - key_x) * 5 * time_step;
my.roll += (key_e - key_q) * 10 * time_step;
}
if (key_w)c_move(my, vector(10*time_step,0,0), nullvector, GLIDE);
//
vec_set(tmpV, vector(-camera_distance,0,0));
vec_rotate(tmpV, my.pan);
vec_add(tmpV, my.x);
vec_set(camera.x,tmpV);
vec_to_angle(camera.pan, vec_diff(NULL, my.x, camera.x));
camera.roll = my.roll; //(?? not sure if you want this line)
wait (1);
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: 3-dimensional camera rotation
[Re: EvilSOB]
#275416
07/01/09 09:55
07/01/09 09:55
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
Here's what I mean, I've finally solved my problem..... maybe my code is a bit clumsy and awkward (I'm a beginner in scripting), but it works fine for me now  Anyway thx for help! action move() { player = my; while (1) { if (key_w) c_move(my, vector(10*time_step,0,0), nullvector, GLIDE); if (key_a) my.pan +=5*time_step; if (key_q) my.roll -=10*time_step; if (key_d) my.pan -=5*time_step; if (key_e) my.roll +=10*time_step; if (key_z) my.tilt +=5*time_step; if (key_x) my.tilt -=5*time_step; camera.x = player.x - (cos(player.pan) * cos(player.tilt) * camera_distance); camera.y = player.y - (sin(player.pan) * cos(player.tilt) * camera_distance); camera.z = player.z - sin(player.tilt) * camera_distance; camera.pan = player.pan; camera.tilt = player.tilt; wait (1); } }
a generator of dull questions
|
|
|
Re: 3-dimensional camera rotation
[Re: Joozey]
#276329
07/04/09 14:39
07/04/09 14:39
|
Joined: Jul 2008
Posts: 128 Ukraine
BastovBros
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 128
Ukraine
|
Can I use it too??????????????????????????Please!!!! yep, ofc, why not... I would recommend to go into vector calculations as soon as possible. your cos and sin stuff are all present in vec_to_angle. You can read the same calculation in the manual. Try to embed your if statements into one algorithm, e.g.: (key_d - key_a) * 5*time_step; I know that, but I'm still a bit confused how to use this vector functions... I should read the manual I guess... thanks, though my primary aim was at least to create a working code and only then to try to optimize it...
a generator of dull questions
|
|
|
|