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 6830573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:38:02+00:00 2026-05-26T22:38:02+00:00

I’m working on a simple OpenGL world- and so far I’ve got a bunch

  • 0

I’m working on a simple OpenGL world- and so far I’ve got a bunch of cubes randomly placed about and it’s pretty fun to go zooming about. However I’m ready to move on. I would like to drop blocks in front of my camera, but I’m having trouble with the 3d angles. I’m used to 2d stuff where to find an end point we simply do something along the lines of:

endy = y + (sin(theta)*power);
endx = x + (cos(theta)*power);

However when I add the third dimension I’m not sure what to do! It seems to me that the power of the second dimensional plane would be determined by the z axis’s cos(theta)*power, but I’m not positive. If that is correct, it seems to me I’d do something like this:

endz = z + (sin(xtheta)*power);

power2 = cos(xtheta) * power;

endx = x + (cos(ytheta) * power2);
endy = y + (sin(ytheta) * power2);

(where x theta is the up/down theta and y = left/right theta)

Am I even close to the right track here? How do I find an end point given a current point and an two angles?

  • 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-05-26T22:38:03+00:00Added an answer on May 26, 2026 at 10:38 pm

    Working with euler angles doesn’t work so well in 3D environments, there are several issues and corner cases in which they simply don’t work. And you actually don’t even have to use them.

    What you should do, is exploit the fact, that transformation matrixes are nothing else, then coordinate system bases written down in a comprehensible form. So you have your modelview matrix MV. This consists of a model space transformation, followed by a view transformation (column major matrices multiply right to left):

    MV = V * M
    

    So what we want to know is, in which way the “camera” lies within the world. That is given to you by the inverse view matrix V^-1. You can of course invert the view matrix using Gauss Jordan method, but most of the time your view matrix will consist of a 3×3 rotation matrix with a translation vector column P added.

    R P
    0 1
    

    Recall that

    (M * N)^-1 = N^-1 * M^-1
    

    and also

    (M * N)^T = M^T * N^T
    

    so it seems there is some kind of relationship between transposition and inversion. Not all transposed matrices are their inverse, but there are some, where the transpose of a matrix is its inverse. Namely it are the so called orthonormal matrices. Rotations are orthonormal. So

    R^-1 = R^T
    

    neat! This allows us to find the inverse of the view matrix by the following (I suggest you try to proof it as an exersice):

    V = / R P \
        \ 0 1 /
    
    V^-1 = / R^T -P \
           \   0  1 /
    

    So how does this help us to place a new object in the scene at a distance from the camera? Well, V is the transformation from world space into camera space, so V^-1 transforms from camera to world space. So given a point in camera space you can transform it back to world space. Say you wanted to place something at the center of the view in distance d. In camera space that would be the point (0, 0, -d, 1). Multiply that with V^-1:

     V^-1 * (0, 0, -d, 1) = (R^T)_z * d - P
    

    Which is exactly what you want. In your OpenGL program you somewhere have your view matrix V, probably not properly named yet, but anyway it is there. Say you use old OpenGL-1 and GLU’s gluLookAt:

    void display(void)
    {
        /* setup viewport, clear, set projection, etc. */
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(...);
        /* the modelview matrix now holds the View transform */
    

    At this point we can extract the modelview matrix

        GLfloat view[16];
        glGetFloatv(GL_MODELVIEW_MATRIX, view);
    

    Now view is in column major order. If we were to use it directly we could directly address the columns. But remember that transpose is inverse of a rotation, so we actually want the 3rd row vector. So let’s assume you keep view around, so that in your event handler (outside display) you can do the following:

    GLfloat z_row[3];
    z_row[0] = view[2];
    z_row[1] = view[6];
    z_row[2] = view[10];
    

    And we want the position

    GLfloat * const p_column = &view[12];
    

    Now we can calculate the new objects position at distance d:

    GLfloat new_object_pos[3] = {
        z_row[0]*d - p_column[0],
        z_row[1]*d - p_column[1],
        z_row[2]*d - p_column[2],
    };
    

    There you are. As you can see, nowhere you had to work with angles or trigonometry, it’s just straight linear algebra.

    • 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
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string

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.