Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AemStones, AndrewAMD, gamers, Kingware), 1,679 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Manage angles smoothy #232790
10/23/08 22:41
10/23/08 22:41
Joined: Sep 2004
Posts: 130
Italy
Alessandro Offline OP
Member
Alessandro  Offline OP
Member

Joined: Sep 2004
Posts: 130
Italy
Hello,
I need to adjust camera PAN to a car PAN...
Code:
camera.pan = myCar.pan;


But the problem I wish to do that smoothly, slowly.
If I use the previous code, the camera takes the same angle immediately.

How can I do that?

Thank you!

Re: Manage angles smoothy [Re: Alessandro] #232802
10/24/08 04:07
10/24/08 04:07
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Very simple approach:
Code:
camera->pan = myCar->pan * 0.05 + camera->pan * 0.95;


For better results have a look in the manual under "accelerate".


Always learn from history, to be sure you make the same mistakes again...
Re: Manage angles smoothy [Re: Uhrwerk] #232896
10/24/08 19:45
10/24/08 19:45
Joined: Sep 2004
Posts: 130
Italy
Alessandro Offline OP
Member
Alessandro  Offline OP
Member

Joined: Sep 2004
Posts: 130
Italy
Thank you! I will do it!

Re: Manage angles smoothy [Re: Alessandro] #232943
10/25/08 09:56
10/25/08 09:56
Joined: Sep 2004
Posts: 130
Italy
Alessandro Offline OP
Member
Alessandro  Offline OP
Member

Joined: Sep 2004
Posts: 130
Italy
Hello,
I tried it and it works.

But the problem is PAN property in A7 7.50 goes from -180 to +180, and when the object rotates, for example, from -179 to +179 (clockwise), of 2 degrees, the sign changes, and the object make a 360 degree rotation!

I cannot find a good algorithm to manage this exception.

Can you help me?

Thank you!

Re: Manage angles smoothy [Re: Alessandro] #232946
10/25/08 11:09
10/25/08 11:09
Joined: Sep 2004
Posts: 130
Italy
Alessandro Offline OP
Member
Alessandro  Offline OP
Member

Joined: Sep 2004
Posts: 130
Italy
Solved! I finally solved!
In this way there is no problem related to -180 -> 180 barrier!

The function below "smooth_movement()" makes the dirty job.
I even included a brief example (inside forever loop) to show how I used to move camera to follow smoothly my car.

I hope this will help you.

Thank you

Code:
function smooth_movement(float argNewValue, float argOldValue, float increments)
{
	float slip;
	float calc1;
	
	calc1 = argOldValue - argNewValue;
	if( abs(calc1) > 180 ) {
		calc1 = 360 + calc1;
	}
	
	slip = calc1 / increments;

	argOldValue -= slip;
	
	return(argOldValue);	
}

var relativeCamera_angle = 0;

while(1) {
  relativeCamera_angle = smooth_movement(pMyCar.pan, relativeCamera_angle, 300);
  camera.x = pMyCar.x - relativeCamera_offset * cos(-relativeCamera_angle);
  camera.y = pMyCar.y - relativeCamera_offset * sin(relativeCamera_angle);
	
  vec_set(temp, pFocus.x); 
  vec_sub(temp, camera.x);
  vec_to_angle(camera.pan, temp);

}


Re: Manage angles smoothy [Re: Alessandro] #233051
10/26/08 10:38
10/26/08 10:38
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
instead of using
Code:
	if( abs(calc1) > 180 ) {
		calc1 = 360 + calc1;
	}
	
	slip = calc1 / increments;


use
Code:
slip = ang(calc1) / increments;


hope this helps

Re: Manage angles smoothy [Re: MrGuest] #233132
10/26/08 22:52
10/26/08 22:52
Joined: Sep 2004
Posts: 130
Italy
Alessandro Offline OP
Member
Alessandro  Offline OP
Member

Joined: Sep 2004
Posts: 130
Italy
Thank you for this tip!
I didn't know "ang" function!

Thank you!


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