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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:59:21+00:00 2026-05-26T05:59:21+00:00

More a maths question then a programming one, but I need to code camera

  • 0

More a maths question then a programming one, but I need to code camera rotation and I have no idea how. The maths are a bit to abstract for me to do out of the blue.
The camera’s rotation is done with quaternions, all I really want is a sample to study or just an article about the subject but I can’t find anything.

  • 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-26T05:59:21+00:00Added an answer on May 26, 2026 at 5:59 am

    here is something i wrote in opengl. the basic algorithm should be the same in any language. the things you need are:

    the up vector of unit length (where up is defined if you are looking at the center): (upx, upy, upz)

    origin (the place you are looking at): (ox,oy,oz)

    camera position (where your camera is): (cx, cy, cz)

    assume “del” is the amount you want to move, and that

    norma() = (ox-cx, oy-cy, oz-cz)/sqrt( (ox-cx) * (ox-cx) + (oy-cy) * (oy-cy) + (oz-cz) * (oz-cz) )
    

    after that, you can calculate the “forward” vector. that is, the vector which is unit length and points from you to the center via:

    (fox, foy, foz) = (ox-cx, oy-cy, oz-cz)/norma();
    

    you can then calculate the unit “left” vector, that is, the vector pointing to the left of unit length if you are looking at the center:

    lx = foz*upy-foy*upz;
    ly = fox*upz-foz*upx;
    lz = foy*upx-fox*upy;
    

    you can then write the following routines (each original ‘//’ justified left signifies a new routine)

    // move camera forward
            cx = cx + del*fox;
            cy = cy + del*foy;
            cz = cz + del*foz;
    
    // move camera backward
            cx = cx - del*fox;
            cy = cy - del*foy;
            cz = cz - del*foz;
    
    // rotate figure right
            cx0 = cx; // initial position
            cy0 = cy;
            cz0 = cz;
    
            R1 = norma(); // initial distance
            cx = cx + del*lx;
            cy = cy + del*ly;
            cz = cz + del*lz;
            R2 = norma(); // new distance after moving in up direction
            cx = cx + (R2-R1)*fox;
            cy = cy + (R2-R1)*foy;
            cz = cz + (R2-R1)*foz; // move towards center so the original distance is the same
    
            // new "left" vector should be (cx-cx0, cy-cy0, cz-cz0) but normalized
            lx = (cx-cx0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            ly = (cy-cy0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            lz = (cz-cz0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
    
    
    // rotate left
            cx0 = cx; // initial position
            cy0 = cy;
            cz0 = cz;
    
            R1 = norma(); // initial distance
            cx = cx - del*lx;
            cy = cy - del*ly;
            cz = cz - del*lz;
            R2 = norma(); // new distance after moving in up direction
            cx = cx + (R2-R1)*fox;
            cy = cy + (R2-R1)*foy;
            cz = cz + (R2-R1)*foz; // move towards center so the original distance is the same
    
            // new "left" vector should be (cx-cx0, cy-cy0, cz-cz0) but normalized
            lx = (cx-cx0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            ly = (cy-cy0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            lz = (cz-cz0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
    
    // rotate figure up
            cx0 = cx; // initial position
            cy0 = cy;
            cz0 = cz;
    
            R1 = norma(); // initial distance
            cx = cx + del*upx;
            cy = cy + del*upy;
            cz = cz + del*upz;
            R2 = norma(); // new distance after moving in up direction
            cx = cx + (R2-R1)*fox;
            cy = cy + (R2-R1)*foy;
            cz = cz + (R2-R1)*foz; // move towards center so the original distance is the same
    
            // new "up" vector should be (cx-cx0, cy-cy0, cz-cz0) but normalized
            upx = (cx-cx0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            upy = (cy-cy0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            upz = (cz-cz0)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
    
    
    
    // rotate figure down
            cx0 = cx; // initial position
            cy0 = cy;
            cz0 = cz;
    
            R1 = norma(); // initial distance
            cx = cx - del*upx;
            cy = cy - del*upy;
            cz = cz - del*upz;
            R2 = norma(); // new distance after moving in up direction
            cx = cx + (R2-R1)*fox;
            cy = cy + (R2-R1)*foy;
            cz = cz + (R2-R1)*foz; // move towards center so the original distance is the same
    
            // new "up" vector should be (cx-cx0, cy-cy0, cz-cz0) but normalized
            upx = (cx0-cx)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            upy = (cy0-cy)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
            upz = (cz0-cz)/sqrt( (cx-cx0)*(cx-cx0) + (cy-cy0)*(cy-cy0) + (cz-cz0)*(cz-cz0) );
    
    
    
    // move fig down
            cx = cx + del*upx;
            cy = cy + del*upy;
            cz = cz + del*upz;
    
            ox = ox + del*upx;
            oy = oy + del*upy;
            oz = oz + del*upz;
    
    // move fig up
            cx = cx - del*upx;
            cy = cy - del*upy;
            cz = cz - del*upz;
    
            ox = ox - del*upx;
            oy = oy - del*upy;
            oz = oz - del*upz;
    
    // move fig left
            cx = cx + del*rx;
            cy = cy + del*ry;
            cz = cz + del*rz;
    
            ox = ox + del*rx;
            oy = oy + del*ry;
            oz = oz + del*rz;
    
    // move fig right
            cx = cx - del*rx;
            cy = cy - del*ry;
            cz = cz - del*rz;
    
            ox = ox - del*rx;
            oy = oy - del*ry;
            oz = oz - del*rz;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more of a maths question than programming but I figure a lot
This is more of a maths/general programming question, but I am programming with PHP
OK. This might be more of a math question but here goes. I have
This may be a math question more than a programming question, but we'll see.
More detail to my question: HTML and JavaScript are called client-side code. C# and
This is more of a challenge question than something I urgently need, so don't
This may be a more math focused question, but wanted to ask here because
Its a very tiny bit of math and more a question of the most
I apologize as I don't know whether this is more of a math question
More out of interest than anything else, but can you compile a DirectX app

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.