Gamestudio Links
Zorro Links
Newest Posts
M1 Oversampling
by 11honza11. 04/26/24 08:32
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (Quad, EternallyCurious, RealSerious3D, 1 invisible), 839 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Rotating the camera toward a target #355122
01/24/11 19:31
01/24/11 19:31
Joined: Jan 2011
Posts: 120
United States
Logan Offline OP
Member
Logan  Offline OP
Member

Joined: Jan 2011
Posts: 120
United States
Hi, this is a completely n00b question--one I've solved before, but I just can't figure it out right now. I want to rotate the camera smoothly toward a target. I know how to compute the angles to the target, but I am having trouble figuring out how to then rotate the camera smoothly toward those angles. The camera will likely change both its pan AND tilt (ideally simultaneously)... and it is not guaranteed what direction. That is to say, the object to be rotated toward may be up and to the left of the camera, or down and to the right, or whatever. So I want the camera to figure out what direction it needs to go, and then rotate there, ideally getting there in about 10 frames.

Here is what I have so far:
Code:
vec_set(turnvector,focus_ent.x); 
vec_sub(turnvector,camera.x);
vec_to_angle(turnangle,turnvector);
// now I need to smoothly rotate the camera to turnangle



I would be really appreciative of any help, even if it's just a nudge in the right direction.

Thanks in advance.

Logan

Re: Rotating the camera toward a target [Re: Logan] #355128
01/24/11 20:12
01/24/11 20:12
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
var smoothing_factor = 0.1;
...

camera.pan += ang(turnangle-camera.pan)*smoothing_factor*time_step;
camera.tilt += ang(turnangle-camera.tilt)*smoothing_factor*time_step;

EDIT: You can limit the speed with clamp, too:

var smoothing_factor = 0.1;
var smoothing_limit = 10;
...

camera.pan += clamp(ang(turnangle-camera.pan)*smoothing_factor,-smoothing_limit,smoothing_limit)*time_step;
camera.tilt += clamp(ang(turnangle-camera.tilt)*smoothing_factor,-smoothing_limit,smoothing_limit)*time_step;

Last edited by Superku; 01/24/11 20:14.

"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Rotating the camera toward a target [Re: Superku] #355156
01/24/11 23:05
01/24/11 23:05
Joined: Jan 2011
Posts: 120
United States
Logan Offline OP
Member
Logan  Offline OP
Member

Joined: Jan 2011
Posts: 120
United States
Thanks a ton Superku. It looks great. And it's so sleek! 2 lines!


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