|
|
How does vec_to_angle work?
#125450
04/21/07 13:59
04/21/07 13:59
|
Joined: Jan 2007
Posts: 1,619 Germany
Scorpion
OP
Serious User
|
OP
Serious User
Joined: Jan 2007
Posts: 1,619
Germany
|
I tried for hours to find out how vec_to_angle could work...but no results, does someone of you know it?
edit: i mean not how to use it... i mean what this function does
Last edited by Scorpion; 04/21/07 14:00.
|
|
|
Re: How does vec_to_angle work?
[Re: Scorpion]
#125455
04/21/07 17:22
04/21/07 17:22
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Not 100% sure, but I'm pretty sure this is how it works...
// get the length of the vector length = vec_length(input);
// get the percentage used of each direction percent.x = input.x / length; percent.y = input.y / length; percent.z = input.z / length;
// use trig to convert to angles (MINE IS PROBABLY WRONG... // BUT ITS SOMETHING LIKE THIS:) output.pan = acos(percent.x) * asin(percent.y); output.tilt = acos(percent.x) * acos(percent.y) * asin(percent.z); output.roll = 0;
This should be correct (looking at the vec_for_angle() description in the manual). Let me know about your results...
xXxGuitar511 - Programmer
|
|
|
Re: How does vec_to_angle work?
[Re: Scorpion]
#125457
04/21/07 21:35
04/21/07 21:35
|
Joined: Oct 2006
Posts: 1,245
AlbertoT
Serious User
|
Serious User
Joined: Oct 2006
Posts: 1,245
|
Quote:
i mean not how to use it... i mean what this function does
This is one of the most popular function in game programming Given a vector the function returns a direction
for example you know the coordinates of a player and of a target player.x ... target.x..etc You might calculates by yourself the angles of the vector having the player and the target as initial and end points well the function makes the job for you
|
|
|
Re: How does vec_to_angle work?
[Re: AlbertoT]
#125458
04/23/07 15:01
04/23/07 15:01
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Mine was just to show the math, not really ready to go into c-script.. this will though Code:
function angle_for_vector(&output, &input) { var length; percent[3];
// get the length of the vector length = vec_length(input); // get the percentage used of each direction percent.x = input.x / length; percent.y = input.y / length; percent.z = input.z / length; // use trig to convert to angles (MINE IS PROBABLY WRONG... // BUT ITS SOMETHING LIKE THIS:) output.pan = acos(percent.x) * asin(percent.y); output.tilt = acos(percent.x) * acos(percent.y) * asin(percent.z); output.roll = 0; }
xXxGuitar511 - Programmer
|
|
|
|