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

  • Home
  • SEARCH
  • 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 8287249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:59:01+00:00 2026-06-08T11:59:01+00:00

I am having problems setting the camera such that it points at the origin

  • 0

I am having problems setting the camera such that it points at the origin O(0,0,0) with a degree of 45° to all other axes with all coordinates positive (which should have the same value, of course). You can see in the image the closest I’ve got

enter image description here

However, as you can see, the x value is negative here, so the camera is on the wrong side of the YZ plane.

The complete compilable project can be found at this revision in a gist.

The relevant matrix multiplications done are

osg::Matrixd rotate_x(
        1.0, 0.0, 0.0, 0.0,
        0.0, q_cos, -q_sin, 0.0,
        0.0, q_sin, q_cos, 0.0,
        0.0, 0.0, 0.0, 1.0 
);
osg::Matrixd rotate_y(
        q_cos, 0.0, q_sin, 0.0,
        0.0, 1.0, 0.0, 0.0,
        -q_sin, 0.0, q_cos, 0.0,
        0.0, 0.0, 0.0, 1.0 
);
camera_pos = camera_pos * rotate_x;
camera_pos = camera_pos * rotate_y;

in the file Simple.cpp.

I’m trying to figure out how this works (both mathematically and programmatically). I would prefer solutions which rely as little as possible on openscenegraph, and more on the math side, as I’d like to do the maths myself at first, to get a real grasp of how it works. So no quaternions or other advanced stuff yet, which are not taught in a basic linear algebra university course.

  • 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-08T11:59:02+00:00Added an answer on June 8, 2026 at 11:59 am

    Your rotate_y matrix looks flipped to me.

    Starting with rotation matrix from glRotate, I simplified the resulting matrix with xyz = (0,1,0), and I got this (in column major order (standard opengl notation)

     q_cos  0  q_sin   0 
     0      1  0       0 
    -q_sin  0  q_cos   0
     0      0  0       1
    

    However, you’re supplying the same matrix in row major order:

    osg::Matrixd rotate_y(
            q_cos,  0.0, q_sin,  0.0,
            0.0,    1.0, 0.0,    0.0,
            -q_sin, 0.0, q_cos,  0.0,
            0.0,    0.0, 0.0,    1.0
    );
    

    -q_sin should be element [2] of the matrix, and q_sin should be element [8], but it looks like you’ve flipped them.


    EDIT


    OpenGL and OSG typically represent matrices in column major format, when you see a 4×4 matrix, it is laid out like the following

    [0]    [4]     [8]     [12]
    [1]    [5]     [9]     [13]
    [2]    [6]     [10]    [14]
    [3]    [7]     [11]    [15]
    

    Where [0] is the first element of the array, 1 is the second, etc.

    When you create a matrix with OSG, you’re defining 16 sequential memory elements, from [0] to [15]

    osg::Matrixd rotate_y([0], [1], [2]......,[15]);
    

    When you break up the command into 4 rows, it looks like this:

    osg::Matrixd rotate_y(
       [0], [1], [2], [3],
       [4], [5], [6], [7],
       [8], [9], [10],[11],
       [12],[13],[14],[15] 
    )
    

    Do you see how this is transposed from the original column vector representation? You need to flip it because the 4×4 matrix examples you find are the internet are represented by column vectors, while you’re currently uploading them as row vectors. It doesn’t mean that what you’re reading is ‘wrong’, it’s just in a different representation.

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

Sidebar

Related Questions

I am having problems setting up Git with Github. I am following the instruction
I'm having problems setting a BOOL using @property and @synthesize . I'm using @property
i am having problems with an asp.net c# site whereby i am setting a
I'm having problems setting up an Entity Framework 4 model. A Contact object is
I'm having problems setting the path of the zip file, X, in ZipFile zipfile
i am trying to run Nutch with Cygwin. I am having problems setting the
I'm having problems with setting the div and body tags to dynamically expand over
I'm using the Google Maps javascript V3 API and I'm having problems with setting
I'm new to cakephp and I'm having some problems with setting up a local
I am having problems setting the educationflag variable to 1. The problem I am

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.