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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:35:12+00:00 2026-05-21T04:35:12+00:00

I have a very rudimentary camera which generates 3 vectors for use with gluLookAt(…)

  • 0

I have a very rudimentary camera which generates 3 vectors for use with gluLookAt(...) the problem is I’m not sure if this is correct, I adapted code from something my lecturer showed us (I think he got it from somewhere).

This actually works until you spin the mouse round in circles than camera starts to rotate around the z-axis. Which shouldn’t happen as the mouse coords are only attached to the pitch and yaw not the roll.

Camera

// Camera.hpp

#ifndef MOOT_CAMERA_INCLUDE_HPP
#define MOOT_CAMERA_INCLUDE_HPP

#include <GL/gl.h>
#include <GL/glu.h>

#include <boost/utility.hpp>
#include <Moot/Platform.hpp>
#include <Moot/Vector3D.hpp>

namespace Moot
{
    class Camera : public boost::noncopyable
    {
    protected:

        Vec3f m_position, m_up, m_right, m_forward, m_viewPoint;
        uint16_t m_height, m_width;

    public:


        Camera()
        {
            m_forward = Vec3f(0.0f, 0.0f, -1.0f);
            m_right = Vec3f(1.0f, 0.0f, 0.0f);
            m_up = Vec3f(0.0f, 1.0f, 0.0f);
        }

        void setup(uint16_t setHeight, uint16_t setWidth)
        {
            m_height = setHeight;
            m_width = setWidth;
        }

        void move(float distance)
        {
            m_position += (m_forward * distance);
        }


        void addPitch(float setPitch)
        {
            m_forward = (m_forward * cos(setPitch) + (m_up * sin(setPitch)));
            m_forward.setNormal();

                    // Cross Product
            m_up = (m_forward / m_right) * -1;
        }


        void addYaw(float setYaw)
        {
            m_forward = ((m_forward * cos(setYaw)) - (m_right * sin(setYaw)));
            m_forward.setNormal();

                    // Cross Product
            m_right = m_forward / m_up;
        }


        void addRoll(float setRoll)
        {
            m_right = (m_right * cos(setRoll) + (m_up * sin(setRoll)));
            m_right.setNormal();

                    // Cross Product
            m_up = (m_forward / m_right) * -1;
        }

        virtual void apply() = 0;       

    }; // Camera
} // Moot

#endif

Snippet from update cycle

    // Mouse movement
    m_camera.addPitch((float)input().mouseDeltaY() * 0.001);
    m_camera.addYaw((float)input().mouseDeltaX() * 0.001);

apply() in the camera class is defined in an inherited class, which is called from the draw function of the game loop.

void apply()
        {
            glMatrixMode(GL_PROJECTION);  
            glLoadIdentity();
            gluPerspective(40.0,(GLdouble)m_width/(GLdouble)m_height,0.5,20.0);

            m_viewPoint = m_position + m_forward;

            gluLookAt(  m_position.getX(),  m_position.getY(),  m_position.getZ(),
                        m_viewPoint.getX(), m_viewPoint.getY(), m_viewPoint.getZ(),
                        m_up.getX(),        m_up.getY(),        m_up.getZ());
        }
  • 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-21T04:35:13+00:00Added an answer on May 21, 2026 at 4:35 am

    Don’t accumulate the transforms in your vectors, store the angles and generate the vectors on-the-fly.

    EDIT: Floating-point stability. Compare the output of a and b:

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        const float small = 0.00001;
        const unsigned int times = 100000;
    
        float a = 0.0f;
        for( unsigned int i = 0; i < times; ++i )
        {
            a += small;
        }
        cout << a << endl;
    
        float b = 0.0f;
        b = small * times;
        cout << b << endl;
    
        return 0;
    }
    

    Output:

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

Sidebar

Related Questions

I have a very simple problem which requires a very quick and simple solution
We have very strange problem, one of our applications is continually querying server by
i have very simple problem. I need to create model, that represent element of
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very strange problem. Under some elusive circumstances I fail to apply
I have a very simple WPF application in which I am using data binding
I have a very interesting problem on my LinqToSql model. On some of my
I have very simple query. I want to make sure that I don't have
I have very simple iPhone app, which uses just UIButtons , UIlabels , UITableView
I have very little experience building software for Windows, and zero experience using the

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.