Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 938 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
3-dimensional camera rotation #275253
06/30/09 18:40
06/30/09 18:40
Joined: Jul 2008
Posts: 128
Ukraine
BastovBros Offline OP
Member
BastovBros  Offline 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 smile
Re: 3-dimensional camera rotation [Re: BastovBros] #275256
06/30/09 19:08
06/30/09 19:08
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
The cameras tilt can not change, as you change it nowhere.
You only change the cameras pan.

You need to apply the sinus/cosinus calculation also to the
tilt.

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 Offline OP
Member
BastovBros  Offline OP
Member

Joined: Jul 2008
Posts: 128
Ukraine
Originally Posted By: BastovBros
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 smile
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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
heya

try something like

Code:
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 Offline OP
Member
BastovBros  Offline OP
Member

Joined: Jul 2008
Posts: 128
Ukraine
thx, that almost helped smile 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 smile
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 Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Im not precisely sure what you mean, but how is this (untested)...
Code:
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 Offline OP
Member
BastovBros  Offline 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 smile Anyway thx for help!
Quote:
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 smile
Re: 3-dimensional camera rotation [Re: BastovBros] #276164
07/03/09 16:53
07/03/09 16:53
Joined: Apr 2009
Posts: 274
atari98 Offline
Member
atari98  Offline
Member

Joined: Apr 2009
Posts: 274
Can I use it too??????????????????????????Please!!!!


Meine Fun Websiten
www.free4-fun.de.tl

www.gamer-liga-live.de.tl

Meine Game-Projekt Websiten
www.gamer-projects.de.tl
Re: 3-dimensional camera rotation [Re: atari98] #276173
07/03/09 17:27
07/03/09 17:27
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
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;


Click and join the 3dgs irc community!
Room: #3dgs
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 Offline OP
Member
BastovBros  Offline OP
Member

Joined: Jul 2008
Posts: 128
Ukraine
Originally Posted By: atari98
Can I use it too??????????????????????????Please!!!!

yep, ofc, why not...
Originally Posted By: Joozey
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 smile
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1