OpenGL camera errors..can't find 'em!?

This is a discussion on OpenGL camera errors..can't find 'em!? within the Game Programming forums, part of the General Programming Boards category; ok...i'm putting togeather my camera code, with the first OpenGL camera tutorial from gametutorials.com as a guide...anyway...i'm using DevC++, and ...

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070

    OpenGL camera errors..can't find 'em!?

    ok...i'm putting togeather my camera code, with the first OpenGL camera tutorial from gametutorials.com as a guide...anyway...i'm using DevC++, and it's putting out errors, but i can't find them (well i kno where they should be but i dont see 'em )

    anyway...here's my camera.cpp:
    Code:
    #include <windows.h>
    #include <gl/gl.h>
    #include "camera.h"
    
    //camera constructor
    CCamera :: CCamera()
    {
    CVector3 vZero = {0.0, 0.0, 0.0};
    CVector3 vView = {0.0, 1.0, 0.5);
    CVector3 vUp = {0.0, 0.0, 1.0};
    
    C_vPosition = vZero;
    C_vView = vView;
    C_vUpVector = vUp;
    }
    
    //position camera
    CCamera :: PositionCamera(int positionX, int positionY, int positionZ,
    int viewX,     int viewY,     int viewZ,
    int upVectorX, int upVectorY, int upVectorZ)
    {
    CVector3 vPosition	= {positionX, positionY, positionZ};
    CVector3 vView		= {viewX, viewY, viewZ};
    CVector3 vUpVector	= {upVectorX, upVectorY, upVectorZ};
    
    C_vPosition = vPosition;
    C_vView = vView;
    C_vUpVector = C_vUpVector;
    }
    errors:
    -end of file read inside definition ~ line7
    -'CCamera :: CCamera()' has already been declared in 'CCamera' ~ line7
    -parse error at end of input ~ line30

    the camera.h code:
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <gl\gl.h>
    
    //vector class
    class CVector3
    {
    public:
    int x, y, z;
    };
    
    //camera class
    class CCamera
    {
    public:
    CVector C_vPosition; //camera position
    CVector C_vView;     //camera view
    CVector C_vUpVector; //camera 'up' vector
    
    CCamera(); //camera constructor
    
    //values for camera positioning
    int PositionX, PositionY, PositionZ;
    int ViewX, ViewY, ViewZ;
    int UpVectorX, UpVectorY, UpVectorZ;
    
    void PositionCamera(int positionX, int positionY, int positionZ,
    			 		    int viewX,     int viewY,     int viewZ,
    						int upVectorX, int upVectorY, int upVectorZ);
    
    //camera movement
    int speed;
    MoveCamera(speed);
    
    //extern values so they can be accessed globally
    extern CCamera gl_Camera;
    errors:
    -syntax error befor ';' ~ line 19
    -syntax error before ';' ~ line20
    -invalid use of member 'CCamera::speed' ~ line35
    -ANSI C++ forbids declaration 'MoveCamera' with no type ~ line35
    -storage class specified for feild 'gl_Camera' ~ line38
    -field 'gl_Camera' has incomplete type ~ line38


    anyway....if anyone can help i'll be very grateful

    -psychopath

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    How bout adding a }; to the end of your camera.h

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    ok...same .h errors...and new .cpp errors:
    -return type specification for constructor invalid
    -warning: initilization to 'int' from 'double' (that happend 9 times, 3 on line 9, 10, and eleven)
    -C_vPosition undeclared
    -C_vView undeclared
    -C-vUpVector undeclared
    -ANSI c++ forbids declaration of 'Position Camera' with no type
    -new declaration 'int CCamera :: PositionCamera(int, int, int, int, int, int, int, int, int)'
    ambiguates old declaration 'void CCamera :: PositionCamera(int, int, int, int, int, int, int, int, int)' <-(in the .h file)


    -psychopath

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >CVector3 vView = {0.0, 1.0, 0.5);
    That should be a brace at the end.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    did that...still dosn't work

  6. #6
    Registered User
    Join Date
    Apr 2004
    Posts
    2
    Well first of all, you called your vector class CVector3, but in your CCamera class you called it CVector.

    The whole 'int to double' thing happens because you put '0.0' instead of just 0. Your vector class as it is handles integers, which cannot have decimal points. If you need decimal points you need to change your CVector3 class to have float x, y, z or double x, y, z.

    In camera.cpp you should put void CCamera :: PositionCamera()

    In camera.h you should have void MoveCamera()

    Inside of MoveCamera in camera.h you need to have a variable type, not just a variable name, like int speed, float speed, or double speed.


    Hope that helps.

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    ok heres my code now:

    camera.cpp
    Code:
    #include <windows.h>
    #include <gl/gl.h>
    #include "camera.h"
    
    //camera constructor
    CCamera :: CCamera()
    {
    CVector3 vZero = {0.0, 0.0, 0.0};
    CVector3 vView = {0.0, 1.0, 0.5};
    CVector3 vUp = {0.0, 0.0, 1.0};
    
    C_vPosition = vZero;
    C_vView = vView;
    C_vUpVector = vUp;
    };
    
    
    //position camera
    void CCamera :: PositionCamera(float positionX, float positionY, float positionZ,
    float viewX,     float viewY,     float viewZ,
    float upVectorX, float upVectorY, float upVectorZ)
    {
    CVector3 vPosition = {positionX, positionY, positionZ};
    CVector3 vView = {viewX, viewY, viewZ};
    CVector3 vUpVector = {upVectorX, upVectorY, upVectorZ};
    
    C_vPosition = vPosition;
    C_vView = vView;
    C_vUpVector = C_vUpVector;
    };
    camera.h
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <gl\gl.h>
    
    //vector class
    class CVector3
    {
    public:
    float x, y, z;
    };
    
    //camera class
    class CCamera
    {
    public:
    CVector3 C_vPosition; //camera position
    CVector3 C_vView;     //camera view
    CVector3 C_vUpVector; //camera 'up' vector
    
    CCamera(); //camera constructor
    
    //values for camera positioning
    float PositionX, PositionY, PositionZ;
    float ViewX, ViewY, ViewZ;
    float UpVectorX, UpVectorY, UpVectorZ;
    
    //camera movement
    float speed;
    void MoveCamera(float speed);
    
    //extern values so they can be accessed globally
    extern CCamera gl_Camera;
    };
    first of all:
    >>you need to have a variable type, not just a variable name<<
    can i have an example (not really sure of what you mean)

    and now the only errors are:

    camera.h:
    feild 'gl_Camera' has incomplete type (you told me about that one but i'm not sure how to fix it (as stated above :P ))

    camera.cpp:
    no void CCamera :: PositionCamera(float, float, float,
    float, float, float, float, float, float) member function declared in class 'CCamera'

    anyway what you told me really helped...i like it when the error output gets chopped down to almost working :P

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    //vector class
    class CVector3
    {
    public:
    int x, y, z;
    };

    //camera class
    class CCamera
    {
    public:
    CVector C_vPosition; //camera position
    CVector C_vView; //camera view
    CVector C_vUpVector; //camera 'up' vector

    CCamera(); //camera constructor

    //values for camera positioning
    int PositionX, PositionY, PositionZ;
    int ViewX, ViewY, ViewZ;
    int UpVectorX, UpVectorY, UpVectorZ;
    ...
    };

    This only handles integers. If there are no vector classes already defined for you then here is a possible solution to handle any data type.

    Code:
    //vector class
    template <class Class_Type> CVector3
    {
      public:
        CVector3() {}
        CVector3(Class_Type x,Class_Type y,Class_Type z):x(x),y(y),z(z) {}
        Class_Type x, y, z;
    };
    
    //camera class
    class CCamera
    {
    public:
      CVector3<float> C_vPosition; //camera position
      CVector3<float> C_vView;     //camera view
      CVector3<float> C_vUpVector; //camera 'up' vector
    
      CCamera(); //camera constructor
    
      //values for camera positioning
      CVector3<float> Position;
      CVector3<float> View;
      CVector3<float> UpVector;
    
    ...
    };
    But shouldn't those variables relative to camera be at least declared as protected instead of public??
    Last edited by VirtualAce; 04-20-2004 at 08:23 PM.

  9. #9
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    hmm.....ok after much work to the code, i got it to work....then I added the movement code.....in my 'mainprog.cpp'...it says 'unidentified reference to 'gl_Camera' ...sorry theres no code posted..i'm in school right now....if there are no replies before i get home, then i'll post the code...if not.......but otherwise, does anyone know why i would be getting this error?

  10. #10
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    ok...here it is.....in the camera.h i did:

    extern CCamera gl_Camera;

    in the mainprog.cpp:

    Code:
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    glClear( GL_COLOR_BUFFER_BIT );
    
    gluLookAt(gl_Camera.C_vPosition.x, gl_Camera.C_vPosition.y, gl_Camera.C_vPosition.z,
    			  gl_Camera.C_vView.x,	  gl_Camera.C_vView.y,	  gl_Camera.C_vView.z,
    			  gl_Camera.C_vUpVector.x, gl_Camera.C_vUpVector.y, gl_Camera.C_vUpVector.z);
    
    glPushMatrix();
    glBegin( GL_POLYGON );
    glColor3f( 1.0f, 1.0f, 0.0f ); glVertex3f( 1.0f, 1.0f, -1.0f );
    glColor3f( 0.0f, 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, -1.0f );
    glColor3f( 0.0f, 0.0f, 1.0f ); glVertex3f( -1.0f, -1.0f, -1.0f );
    glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( -1.0f, 1.0f, -1.0f );
    glEnd();
    glPopMatrix();
    
    SwapBuffers( hdc );
    
    theta += 1.0f;
    and:
    Code:
    case WM_KEYDOWN:
    float speed;
    
    switch ( wparam ) {
    
    case VK_ESCAPE:
    PostQuitMessage( 0 );
    break;
    
    case VK_UP:
    gl_Camera.MoveCamera(speed); //move camera forward
    void RenderScene();  //render the scene after movement
    break;
    
    case VK_DOWN:
    gl_Camera.MoveCamera(-speed); //move camera backward
    void RenderScene();  //render the scene after movement
    break;
    return 0;
    }
    those are the areas i get 'unidentified reference to gl_Camera...below is the camera.cpp and camera.h incase it might be important:

    camera.cpp
    Code:
    #include <windows.h>
    #include <gl/gl.h>
    #include "include.h"
    
    //camera constructor
    CCamera :: CCamera()
    {
    CVector3 vZero = {0.0, 0.0, 0.0};
    CVector3 vView = {0.0, 1.0, 0.5};
    CVector3 vUp = {0.0, 0.0, 1.0};
    
    C_vPosition = vZero;
    C_vView = vView;
    C_vUpVector = vUp;
    };
    
    //position camera
    void CCamera :: PositionCamera(float positionX, float positionY, float positionZ,
    float viewX,     float viewY,     float viewZ,
    float upVectorX, float upVectorY, float upVectorZ)
    {
    CVector3 vPosition = {positionX, positionY, positionZ};
    CVector3 vView = {viewX, viewY, viewZ};
    CVector3 vUpVector = {upVectorX, upVectorY, upVectorZ};
    
    C_vPosition = vPosition;
    C_vView = vView;
    C_vUpVector = C_vUpVector;
    };
    
    //move camera
    void CCamera::MoveCamera(float speed)
    {
    CVector3 vVector = {0};
    
    vVector.x = C_vView.x - C_vPosition.x;
    vVector.y = C_vView.y - C_vPosition.y;
    vVector.z = C_vView.z - C_vPosition.z;
    
    C_vPosition.x += vVector.x * speed;
    C_vPosition.z += vVector.z * speed;
    C_vView.x += vVector.x * speed;
    C_vView.z += vVector.z * speed;
    };
    camera.h
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <gl\gl.h>
    
    //vector class
    class CVector3
    {
    public:
    float x, y, z;
    };
    
    //camera class
    class CCamera
    {
    public:
    CVector3 C_vPosition; //camera position
    CVector3 C_vView;     //camera view
    CVector3 C_vUpVector; //camera 'up' vector
    
    CCamera(); //camera constructor
    
    //values for camera positioning
    void PositionCamera(float PositionX, float PositionY, float PositionZ,
                        float ViewX, float ViewY, float ViewZ,
                        float UpVectorX, float UpVectorY, float UpVectorZ);
    
    //camera movement
    float speed;
    void MoveCamera(float speed);
    
    };
    
    //extern values so they can be accessed globally
    extern CCamera gl_Camera;
    -psychopath

  11. #11
    Registered User
    Join Date
    Apr 2004
    Posts
    2
    You extern gl_Camera in camera.h. extern doesn't actually create an object, but rather tells that file "this object exists somewhere else, but act like it is declared here." You need to add a line in mainprog.cpp to make a global CCamera object, like:

    CCamera gl_Camera;

    Unless you use the gl_Camera object in camera.h, you don't need to include that extern line. Remove that, and you should be fine.

  12. #12
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    hmmm.....now it says:

    multiple definition of 'gl_Camera'
    first defined here:
    Code:
    gl_Camera.MoveCamera(speed);
    -psychopath

  13. #13
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    hmm....it seems to do this even when i comment out all the references to gl_Camera!?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OPENGL noo--bee, fullscreen problems
    By Shadow12345 in forum Game Programming
    Replies: 2
    Last Post: 08-13-2002, 01:53 PM
  2. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  3. 4 errors I can't find
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-13-2002, 09:35 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM
  5. cant find the errors.
    By sscook69 in forum C++ Programming
    Replies: 2
    Last Post: 09-10-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21