Gamestudio Links
Zorro Links
Newest Posts
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
3 registered members (7th_zorro, AndrewAMD, Ayumi), 750 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Math question #134383
06/06/07 22:30
06/06/07 22:30
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline OP
Developer
LogantheHogan  Offline OP
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
Hey all. I'm trying to program a nice third person camera, and it's causing me a lot of grief to say the least. Right now I'm trying to devise a function that will allow me to calculate the TILT value that my camera needs to have in order to always be pointing at the player. I can't use a fixed value because the camera is elevated above the player and I want it to rotate downward to show him, even when the player's back is right up against a wall (in other words, the value of "a" below can change). I thought that this could be acheived using trig functions, however it's giving me problems.

My basic concept behind my code is as follows.



Based on this idea,

tan(x) = a/b, and atan(a/b) = x. I thought this would allow me to determine the value of x. However my camera is tilting in weird ways and producing undesirable results.

My code is
Code:
 
vec_set(m_cam_pos,camera.x);
vec_set(cam_play_pos,player.x);

m_cam_pos.z = 0; // so that Z isn't figured in to the vec_dist calculation
cam_play_pos.z = 0;

m_cam_dist = vec_dist(m_cam_pos,cam_play_pos); // determining the value of "a"

temp = (m_cam_dist)/(abs(camera.z-player.z));
camera.tilt = -atan(temp); // to determine the angle that the player is at from the camera (negative because the camera points downward)



Does anyone see anything wrong with this code or anything wrong with my math?

Thanks a lot guys. God bless.

Re: Math question [Re: LogantheHogan] #134384
06/07/07 02:09
06/07/07 02:09
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline OP
Developer
LogantheHogan  Offline OP
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
Gag. I figured it out. The line

camera.tilt = -atan(temp);

should have been

camera.tilt = atan(temp)-90;

Or I could have just used vec_to_angle... it does all the math and work for you... and it's probably faster... sheesh. What's the moral of this story kids? READ THE MANUAL. Before you do any tricky script tricks see if there's a command for what you're trying to do.

Thanks anyways guys.

Re: Math question [Re: LogantheHogan] #134385
06/07/07 05:32
06/07/07 05:32
Joined: Mar 2004
Posts: 281
England
frescosteve Offline
Member
frescosteve  Offline
Member

Joined: Mar 2004
Posts: 281
England
I like the way you answered your own question.

Re: Math question [Re: frescosteve] #134386
06/07/07 08:03
06/07/07 08:03
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
tompo Offline
User
tompo  Offline
User

Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
Quote:

I like the way you answered your own question.



Yeah... first search HELP, then search forum... and finaly ask the question... this is the best way


Never say never.
Re: Math question [Re: tompo] #134387
06/07/07 14:24
06/07/07 14:24
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline OP
Developer
LogantheHogan  Offline OP
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
yeah, I know. sorry for cluttering things up, guys.


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