CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Spherical coordinates to XYZ?

    I am starting to get grip of my game. But I need to now how to calculate x units away in the viewing direction. I have solved this by taking the coordinates from a "invisible" sphere around me. I am using this forumla:

    float Radius = 5;
    float theta = (xrot/180)*3.141592654f;
    float phi = (yrot/180)*3.141592654f;
    s_x = xpos + (Radius * sin(theta) * cos(phi));
    s_y = ypos + (Radius * sin(theta) * sin(phi));
    s_z = zpos + (Radius * cos(theta));
    The yrot range between 0-360. The yrot is my camera rotation around me vertically.

    And my xrot range between 90 - (-90).

    (-90) while looking up and 90 the opposite.

    What I want to do is to get xyz from yrot and xrot.

    But I just cant get it right.

    Can someone tell me how to do this and maybe link to a site thats explains the formula. Thanks in advance!

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,604

    Re: Spherical coordinates to XYZ?

    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width