Sign in to follow this  

Spheres and a general test utility

This topic is 4737 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

Sorry for the repost from the Maths and Physics forum - but would really appreciate a C++ source example from someone who has done this - Thanks 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
Why dont you use Direct3D capabilities for that? It is much easier to provide this functionality by using matrices. In D3D even presents function that creates view matrix base on it's position and view point ( (0,0,0) in your case? ).

However, if you dont want to use D3D, you would use matrices instead of such geometrical calculations. Also you can learn something about matrix transformations from DXSDK.

there is an example of rotation camera around Y-axis

D3DXMATRIX mat_roty;
D3DXMatrixRotationY(&mat, alpha);
D3DXMATRIX mat_mov;
D3DXMatrixIdentity(&mat);
mat._41 = 0;
mat._42 = 0;
mat._43 = -r;

camera_mat = mat_roty * mat_mov * mat_roty;

maybe I have some mistakes, but idea presents:

0. camera's position (0,0,0)
1. rotate camera around Y-axis
2. move camera back
3. rotate around Y-axis

best regards

Share this post


Link to post
Share on other sites

This topic is 4737 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this