Jump to content
  • Advertisement
Sign in to follow this  
ScottyB

Spheres and a general test utility

This topic is 5082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am a recent to the programming world of DirectX While learning I am having some problem with my geometry knowledge ( or lack of it ;-) I created an object at origin and am purely trying to rotate the camera in a circle around it (view pointing to the origin) I have no problem on a constant plane - by using X = r * cos(theta) y = r * sin(theta) which works a charm However - when I try and move the camera along the circumference of a sphere - I get whacky results (it starts in a spherical arc but then bends back into the same plane) and also my camera flips at the various poles. I tried using the spherical equations x = r * sin(phi) * cos(theta) y = r * sin(phi) * sin(theta) z = r * cos(phi) and also (?) x = r * cos(phi) * cos(theta) y = r * cos(phi) * sin(theta) z = r * sin(phi) which I found on the net in the form of e.g. camrot_x += 000.5f; camrot_y += 000.5f; campos_x = (float)(radius)*(sin(camrot_z))*(cos(camrot_x)); campos_y = (float)(radius)*(sin(camrot_z))*(sin(camrot_x)); campos_z = (float)(radius)*(cos(camrot_z)); Then set the camera view - but to no avail; Can anyone help me ? Am I doing something wrong ? How do I stop the camera flipping ? Also - is there any freeware software app which I can use to test geometric equations so I can watch a point/object easily in order to determine its correctness - rather than re-running my directX and trying to view it in there ? I tried doing excel graphs on calculated (x,y,z) coords but 2D doesn't really show the complete 3D picture.. Sorry if this is a real newbie question but I have tried to search for my answer in vain. Thanks, ScottyB

Share this post


Link to post
Share on other sites
Advertisement
that's called gimbal lock. For example, in first person shooters, the camera can never view straight up and beyond (or straight back). Well, there are ways, but using Euler angles, it's not recommended because of the gimbal lock.

if you want to do a camera that can rotate properly, you have to set it kind of like that


cam_rotation += 0.0005f;
cam_elevation += 0.0005f;

Vector Strafe( sin(cam_rotation), 0.0f, -cos(cam_rotation));
Vector Look(-cos(cam_rotation), -sin(cam_elevation), -sin(cam_rotation));
Vector Up(Look.Cross(Strafe));
Vector Eye(cos(cam_rotation) * dist, sin(cam_elevation) * dist, sin(cam_rotation) * dist);

Camera.SetEyePosition(Eye);
Camera.SetEyeOrientation(Strafe, Up, Look);



something like that, depending on your coordinate system.

Also, for your maths, you want Maple.

Share this post


Link to post
Share on other sites
Brilliant - thanks alot Oliii !
Twas perplexing me

I shall give it a try when back home :-)
Never had heard of a Gimbal lock before - but I am still a newbie atm.

Thanks again
ScottyB

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!