|
-
June 21st, 2009, 08:02 AM
#1
Mathematical concept behind 3D-Trackball
the following code comes from a file named trackball.c (http://scv.bu.edu/documentation/pres...gl/trackball.c)
What I'd like to know is the mathematical concept behind this function. Why are this two constants being used here and what does it mean "inside sphere" and "on hyperbola". I was not able to find any website explaining why this works. I can use this function and the trackball in my OpenGL app works but I don't know why and it drives me crazy ;]
Code:
/*
* Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
* if we are away from the center of the sphere.
*/
inline float
tb_project_to_sphere(float r, float x, float y)
{
float d, t, z;
d = sqrt(x*x + y*y);
if (d < r * 0.70710678118654752440)
{
/* Inside sphere */
z = sqrt(r*r - d*d);
}
else
{
/* On hyperbola */
t = r / 1.41421356237309504880;
z = t*t / d;
}
return z;
}
(this function is used to find the z-coordinate on an imagined sphere from mouse coordinates to further calculate a quaternion rotation for the camera/scene)
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback  you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|