Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:50:09+00:00 2026-06-18T08:50:09+00:00

I’m currently working on a game which renders a textured sphere (representing Earth) and

  • 0

I’m currently working on a game which renders a textured sphere (representing Earth) and cubes representing player models (which will be implemented later).

When a user clicks a point on the sphere, the cube is translated from the origin (0,0,0) (which is also the center of the sphere) to the point on the surface of the sphere.

The problem is that I want the cube to rotate so as to sit with it’s base flat on the sphere’s surface (as opposed to just translating the cube).

What the best way is to calculate the rotation matrices about each axis in order to achieve this effect?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:50:10+00:00Added an answer on June 18, 2026 at 8:50 am

    This is the same calculation as you’d perform to make a “lookat” matrix.

    In this form, you would use the normalised point on the sphere as one axis (often used as the ‘Z’ axis), and then make the other two as perpendicular vectors to that. Typically to do that you choose some arbitrary ‘up’ axis, which needs to not be parallel to your first axis, and then use two cross-products. First you cross ‘Z’ and ‘Up’ to make an ‘X’ axis, and then you cross the ‘X’ and ‘Z’ axes to make a ‘Y’ axis.

    The X, Y, and Z axes (normalised) form a rotation matrix which will orient the cube to the surface normal of the sphere. Then just translate it to the surface point.

    The basic idea in GL is this:

    float x_axis[3];
    float y_axis[3];
    float z_axis[3]; // This is the point on sphere, normalised
    
    x_axis = cross(z_axis, up);
    normalise(x_axis);
    y_axis = cross(z_axis, x_axis);
    
    DrawSphere();
    
    float mat[16] = {
        x_axis[0],x_axis[1],x_axis[2],0,
        y_axis[0],y_axis[1],y_axis[2],0,
        z_axis[0],z_axis[1],z_axis[2],0,
        (sphereRad + cubeSize) * z_axis[0], (sphereRad + cubeSize) * z_axis[1], (sphereRad + cubeSize) * z_axis[2], 1 };
    
    glMultMatrixf(mat);
    
    DrawCube();
    

    Where z_axis[] is the normalised point on the sphere, x_axis[] is the normalised cross-product of that vector with the arbitrary ‘up’ vector, and y_axis[] is the normalised cross-product of the other two axes. sphereRad and cubeSize are the sizes of the sphere and cube – I’m assuming both shapes are centred on their local coordinate origin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.