Really Need Help With My Opengl Camera!!!!

This is a discussion on Really Need Help With My Opengl Camera!!!! within the Game Programming forums, part of the General Programming Boards category; I'm currently working on a open-source game engine/application, and am having trouble with the camera movment here is a link ...

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

    Really Need Help With My Opengl Camera!!!!

    I'm currently working on a open-source game engine/application, and am having trouble with the camera movment

    here is a link to the download the current code: http://www.freewebs.com/psychopathpr...ychoEngine.zip

    basicly, the triangle moves slow while on the grid (which for some reason wont display properly)...when moving backward, the triangle moves up like in 2d while on the grid, until it's off the top blue line....thats when it moves fast, and it shrinks (as if to move into the distance, in 3d)...for moving forward, when the triangle leaves the bottom blue line, it simply dissapears....dosn't get bigger (like you would expect it to do since backwards it works)
    so....the questions:

    -why dosn't it work properly while on the grid??
    -why does it go so fast when off the grid?
    -why does it dissapear, when it leaves the grid when moving forward?
    -why does it seem to work when moving backwards (when it leaves the grid)?

    i just can't get it to work!? so if anyone can help it would be REALLY great!!!!!!

    --EDIT--
    the link dosn't seem to work or display properly so..after:
    www.freewebs.com/

    its then:
    psychopathproductions/PsychoEngine.zip

    -psychopath
    Last edited by psychopath; 05-18-2004 at 06:32 PM.

  2. #2
    Shadow12345
    Guest
    not found, even if i remove the ] at the end

    EDIT:
    Code:
    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);
    the second vector you give is actually the normalized view plus position, not just the view. That is, in all likelihood, your problem.

    Your code does not work, I downloaded an older version, it just crashes on mscv (after I tried including all libs and stuff).
    Last edited by Shadow12345; 05-18-2004 at 06:36 PM.

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    heh...you posted while i was editing so i'll just quote it again here :P

    the link dosn't seem to work or display properly so..after:
    www.freewebs.com/

    its then:
    psychopathproductions/PsychoEngine.zip

  4. #4
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    hmm....grr...i still can't get it to work!?

    --EDIT--
    ok...i'll just post the most recent code:

    mainprog.cpp
    Code:
    /*
       Name: PsychoEngine
       Author: Daniel Cook
       Description: Game Creation Studio
       Date: NULL
       Copyright: 2004
       License: This software is provided 'as-is' without warranty of any kind.
       This software is provided with an 'Open-Source' license, to be used and
       distributed freely, but under NO circumstances is this software to be sold
       by persons other than members/representitves of PsychopathProductions with the
       permission of their superior(s).
    
    */
    
    // Include files
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glut.h>
    #include <math.h>
    #include "include.h"
    //end include files
    
    //set-up camera vectors
    float PositionX = 0;
    float PositionY = 0;
    float PositionZ = 0;
    float ViewX = 0;
    float ViewY = 1;
    float ViewZ = 8;
    float UpX = 0;
    float UpY = 0;
    float UpZ = 1;
    
    float VectorX;
    float VectorY;
    float VectorZ;
    //end camera vector set-up
    
    //CCamera gl_Camera;
    HWND edit_box = NULL; //edit window handle
    
    
    // Function Declarations
    LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );  //'define' the winproc call
    VOID EnableOpenGL( HWND edit_box, HDC * hDC, HGLRC * hRC );  //'define' the OpenGL enable function call
    VOID DisableOpenGL( HWND edit_box, HDC hDC, HGLRC hRC );    //'define' the OpenGL disable function call
    
    // WinMain
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow )
    {
    WNDCLASS wc;  //main window class
    WNDCLASS ed;  //edit window class
    WNDCLASS mp;  //model preview class
    HWND hwnd;   //main window handle
    HDC hdc;     //windows device context
    HGLRC gl_hrc;//OGL device context
    MSG msg;     //message handle
    BOOL bQuit = FALSE;
    float theta = 0.0f;
    
    //gl_Camera.PositionCamera(0, 0.0f, 0,   0, 1.0f, 0.5,   0, 0, 1);
    
    // register window class
    wc.style = NULL;  //define window style
    wc.lpfnWndProc = WndProc;  //define the winproc
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;  //define the HINSTANCE
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); //set the icon
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );  //set the cursor
    wc.hbrBackground = (HBRUSH)GetStockObject( GRAY_BRUSH ); //set the main window color
    wc.lpszMenuName = "MAINMENU"; //menu name
    wc.lpszClassName = "PsychoEngine"; //window class name
    RegisterClass( &wc ); //regester the class
    
    //regester edit class (same format as above :)
    ed.style = CS_OWNDC;
    ed.lpfnWndProc = WndProc;
    ed.cbClsExtra = 0;
    ed.cbWndExtra = 0;
    ed.hInstance = hInstance;
    ed.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    ed.hCursor = LoadCursor( NULL, IDC_ARROW );
    ed.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
    ed.lpszMenuName = NULL;
    ed.lpszClassName = "EDIT";
    RegisterClass( &ed );
    
    //regester model preview class (same format as above :
    mp.style = CS_OWNDC;
    mp.lpfnWndProc = WndProc;
    mp.cbClsExtra = 0;
    mp.cbWndExtra = 0;
    mp.hInstance = hInstance;
    mp.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    mp.hCursor = LoadCursor( NULL, IDC_ARROW );
    mp.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
    mp.lpszMenuName = NULL;
    mp.lpszClassName = "MODEL";
    RegisterClass( &mp );
    
    // create main window
    hwnd = CreateWindow(
    "PsychoEngine", "PsychoEngine | PsychopathProductions", //class, caption text
    WS_TILEDWINDOW | WS_POPUPWINDOW | WS_VISIBLE,  //style
    0, 0, 800, 570,   //x,y,width,height
    NULL, NULL, hInstance, NULL );
    
    HWND edit_box = NULL;  //define edit_box handle
    HWND model_box = NULL; //define model preview handle
    LPARAM lParam;
    
    RECT rect;
    GetClientRect(hwnd,&rect);
    //set up and create editbox
    edit_box = CreateWindow("EDIT", "Edit Window",WS_CHILD | WS_CAPTION | WS_VISIBLE,
    0, 0, 600, 516, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
    
    //setup and create model preview box
    model_box = CreateWindow("MODEL", "Model Preview",WS_CHILD | WS_CAPTION | WS_VISIBLE,
    600, 338, 192, 178, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
    
    //draw buttons
    HWND button;
    button = CreateWindow("BUTTON", "NPC's", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 30, 64, 24, hwnd,(HMENU) 10, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Player", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 30, 64, 24, hwnd, (HMENU) 20, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "World Options", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 646, 58, 98, 24, hwnd, (HMENU) 30, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Lighting", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 86, 64, 24, hwnd, (HMENU) 40, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Textures", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 86, 64, 24, hwnd, (HMENU) 50, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Weapons/Projectiles", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 620, 114, 148, 24, hwnd, (HMENU) 60, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Attributes", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 616, 142, 64, 24, hwnd, (HMENU) 70, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Camera", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 708, 142, 64, 24, hwnd, (HMENU) 80, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Insert Brush", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 606, 184, 80, 24, hwnd, (HMENU) 90, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    button = CreateWindow("BUTTON", "Insert Entity", WS_VISIBLE |WS_CHILD | BS_PUSHBUTTON, 708, 184, 80, 24, hwnd, (HMENU) 100, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    
    // enable OpenGL for the edit window
    EnableOpenGL( edit_box, &hdc, &gl_hrc );
    
    // program main loop
    while ( !bQuit ) {
    
    // check for messages
    if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
    
    // handle or dispatch messages
    if ( msg.message == WM_QUIT ) {
    bQuit = TRUE;
    }
    else
    {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
    }
    
    } else {
    
    void RenderScene();
    {
    int i=0;	
    
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    	glLoadIdentity();									// Reset The matrix
    
    // OpenGL animation code
    
    gluLookAt(PositionX, PositionY, PositionZ,
              ViewX, ViewY, ViewZ,
              UpX, UpY, UpZ);
    
    glBegin (GL_TRIANGLES);								// This is our BEGIN to draw
    
    		glColor3ub(255, 0, 0);							// Make the top vertex RED
    		glVertex3f(0, -0.5, 0);							// Here is the top point of the triangle
    
    		glColor3ub(0, 255, 0);							// Make the left vertex GREEN
    		glVertex3f(-0.5, 0, 0);							// Here is the left point of the triangle
    
    		glColor3ub(0, 0, 255);							// Make the right vertex BLUE
    		glVertex3f(0.5, 0, 0);							// Here is the right point of the triangle
    	glEnd();
    
    for(float i = -50; i <= 50; i += 1)
    	{
    		// Start drawing some lines
    		glBegin(GL_LINES);
    
    			// Do the horizontal lines (along the X)
    			glVertex3f(-50, 0, i);
    			glVertex3f(50, 0, i);
    
    			// Do the vertical lines (along the Z)
    			glVertex3f(i, 0, -50);
    			glVertex3f(i, 0, 50);
    
    		// Stop drawing lines
    		glEnd();
    	}
    
    SwapBuffers( hdc );
    
    }
    }
    }
    // shutdown OpenGL
    DisableOpenGL( hwnd, hdc, gl_hrc );
    
    // destroy the window explicitly
    DestroyWindow( hwnd );
    
    return msg.wParam;
    
    }
    
    // Window Procedure
    
    LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
    {
    HDC hdc;  //define the hDC
    static TEXTMETRIC textInfo; //define the textmetric
    char szSTRING1[]="Menu"; //string 1
    char szSTRING2[]="____________________"; //string2
    PAINTSTRUCT paintStruct; //define the PAINTSTRUCT
    hdc=NULL;
    
    switch ( message )
    {
    case WM_CREATE:
    break;
    
    case WM_PAINT:
    hdc = BeginPaint(hwnd, &paintStruct);  //begin paint
    SetTextColor(hdc, RGB(0, 0, 0)); //set text color
    SetBkColor(hdc , RGB(128, 128, 128)); //set background color OF THE TEXT
    TextOut(hdc, 676, 8, (szSTRING1), strlen(szSTRING1));  //put out string1
    TextOut(hdc, 616, 156, (szSTRING2), strlen(szSTRING2)); //put out string2
    EndPaint(hwnd, &paintStruct); //end paint
    break;
    
    case WM_CLOSE:
    if(MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)==IDYES)
    {
    PostQuitMessage( 0 );
    }
    break;
    return 0;
    
    case WM_DESTROY:
    break;
    return 0;
    
    case WM_KEYDOWN:
    switch ( wparam )
    {
    case VK_UP:
    VectorX = ViewX - PositionX;
    VectorY = ViewY - PositionY;
    VectorZ = ViewZ - PositionZ;
    
    PositionX += VectorX * speed;
    PositionZ += VectorZ * speed;
    ViewX += VectorX * speed;
    ViewZ += VectorZ * speed;
    void RenderScene();  //render the scene after movement
    break;
    
    case VK_DOWN:
    VectorX = ViewX - PositionX;
    VectorY = ViewY - PositionY;
    VectorZ = ViewZ - PositionZ;
    
    PositionX += VectorX * -speed;
    PositionZ += VectorZ * -speed;
    ViewX += VectorX * -speed;
    ViewZ += VectorZ * -speed;
    void RenderScene();  //render the scene after movement
    break;
    }
    break;
    
    case WM_COMMAND:
    //buttons
    WORD wID,wNotify;
    
      wID=LOWORD(wparam);
      wNotify=HIWORD(wparam);
      if (lparam)
        {
        //if a button was clicked
        if (wNotify==BN_CLICKED)
          {
           //if a buttons id was clicked
          if (wID==10)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==20)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==30)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==40)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==50)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==60)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==70)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==80)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==90)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
          if (wID==100)
          {
          MessageBox (NULL, "it works" , ":)", 0);
          }
       }
    }
    //end buttons
    return 0;
    
    default:
    return DefWindowProc( hwnd, message, wparam, lparam );
    
    }
    
    }
    
    // Enable OpenGL
    
    VOID EnableOpenGL( HWND edit_box, HDC * hdc, HGLRC * gl_hrc )
    {
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;
    
    // get the device context (DC)
    *hdc = GetDC( edit_box );
    
    // set the pixel format for the DC
    ZeroMemory( &pfd, sizeof( pfd ) );
    pfd.nSize = sizeof( pfd );
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | 
    PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; //GL flags
    pfd.iPixelType = PFD_TYPE_RGBA; //pixel type
    pfd.cColorBits = COLOR_DEPTH;  //color depth
    pfd.cDepthBits = SCREEN_DEPTH;  //screen depth
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ChoosePixelFormat( *hdc, &pfd );  //choose the best pixel format
    SetPixelFormat( *hdc, iFormat, &pfd ); //set the pixel format
    
    // create and enable the render context (RC)
    glViewport(0,0,0,1);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,0/1, 1.0f, 150.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    *gl_hrc = wglCreateContext( *hdc );
    wglMakeCurrent( *hdc, *gl_hrc );
    }
    
    // Disable OpenGL
    
    VOID DisableOpenGL( HWND edit_box, HDC hdc, HGLRC gl_hrc )
    {
    wglMakeCurrent( NULL, NULL );
    wglDeleteContext( gl_hrc );
    ReleaseDC( edit_box, hdc ); //release from the drive context
    }
    defs.h
    Code:
    #define SCREEN_DEPTH 32 //define the screen depth
    #define COLOR_DEPTH 32   //define the color depth
    #define speed 0.0013f  //define the camera 'walk' speed
    include.h
    Code:
    #include <gl/glut.h>
    #include "camera.h"
    #include "defs.h"
    #include "menu.h"
    menu.h
    Code:
    #define ID_OPEN 100
    #define ID_SAVE 200
    
    #define ID_16DEPTH 300
    #define ID_32DEPTH 400
    #define ID_16COLOR 500
    #define ID_32COLOR 600
    
    #define ID_ABOUT 700
    iv'e taken out the camera and vector class all togeather, since it really isn't that necessary, and because it seems to work better (for me) with out it.

    -psychopath
    Last edited by psychopath; 05-19-2004 at 08:34 AM.

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

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    why dont you pack up the current source in a .zip along with an .exe so we can see your problem. (or is your link updated with current source and exe?)

  7. #7
    Shadow12345
    Guest
    i am going to get kicked off of the site again, here's my contact info:

    AIM: OpenGLProgrammer

    email: letsallthrowrocks@yahoo.com

    I'm confident I can help you with this, just re-send the current exe and source

  8. #8
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    not sure why you are/did get kicked off (theres a reason i'm sure, that I don't know about ;]).....anyway iv'e sent an e-mail with the code attached.

  9. #9
    Banned
    Join Date
    May 2004
    Posts
    129
    I downloaded the zip and i ran it but it crashes, I also updated the code, and it does not compile, so I added some compiler directives to make sure that the thing wasn't redefining some things, sure enough there are various errors...this is exactly what you posted, I am under visual studio 6

    it could honestly be so many things and i have so many possible suggestions but it needs to be narrowed down or i need something to play with. sorry .

  10. #10
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    it works perfectly for me....just dosn't do what it's supposed to.......i'll try re-uploading the zip momentarily

  11. #11
    Banned
    Join Date
    May 2004
    Posts
    129
    I don't think it will do any good, I think it's because I'm using a different compiler.

  12. #12
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    hmmm....i'll try anyway:

    http://www.freewebs.com/psychopathpr...ychoEngine.zip

    sigh....link is still messed, so just right-click and click 'copy url location' and paste it in the address bar ;]

  13. #13
    Banned
    Join Date
    May 2004
    Posts
    129
    This is too weird...I can build that, but when I run it, it just plain crashes!

  14. #14
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    i dunno.......works for me!?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  2. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. OpenGL camera errors..can't find 'em!?
    By psychopath in forum Game Programming
    Replies: 12
    Last Post: 04-22-2004, 06:17 PM
  5. Camera rotation/movement in 3D world
    By tegwin in forum Game Programming
    Replies: 11
    Last Post: 01-24-2003, 12:43 PM

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