Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Movement along the surface of a sphere
#1
So I'm working on something in 3D, and need some help with my math...

I'm having a hard time with something, and I think if I get this right it'll work-- essentially I need to find the coords of the point directly under the mouse. Since the camera itself a point on a sphere with a center at its target, whenever I move the mouse around the screen, I should be moving it along the surface of that sphere.

All 3D stuff aside, it's a math question: given the radius of a sphere, the (x, y, z) of the starting point, and the direction and distance of the movement, how do I find the new coordinates?
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#2
This should give you any point on a sphere. It just uses the 3D version of the distance formula to determine the angle, then plots it according to the radius of the sphere. This version only works with perfect circles though...

X1, Y1 and Z1 should be the location of the mouse cursor.
X2, Y2 and Z2 should be the center of the sphere.
Radius is the radius of the sphere... :lol:


Code:
Distance% = SQR((X2% - X1%) ^ 2 + (Y2% - Y1%) ^ 2 + (Z2% - Z1%) ^ 2)

angx! = (X1% - X2%) / Distance%
angy! = (Y1% - Y2%) / Distance%
angz! = (Z1% - Z2%) / Distance%

PointX! = X2% + Radius% * angx!
PointY! = Y2% + Radius% * angy!
PointZ! = Z2% + Radius% * angz!
Reply
#3
You already know how to convert spherical coords. Work from that. :*)

BTW, use a matrix lookat transform to set your viewangle to the center of the sphere.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#4
*wonders why he didn't think of that before--*

so I'd just convert it to spherical coordinate, move it as if it were in two dimensions, and change it back to xyz...
size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Reply
#5
In a sense yes, but spherical coord system is 3d so you have two angles.

Theta: Azimuth
Phi: Elevation
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)