Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

gluLookat() for more than one object

Options
  • 07-12-2003 4:21pm
    #1
    Closed Accounts Posts: 222 ✭✭


    I have created a openGL scene with a few objects ... I'm trying to look at my beautiful 3D scene ... *to make sure its all there!* ... but I'm only getting to look at the first object created ... everything else is staying still as it was before ... leaving me with this UFO type thing flying across the screen!!! is there a way to include all the objects together ? ... here is the code if helps explain my question:

    int DrawGLScene(GLvoid)
    {
    gluLookAt(g_Camera.m_Position.x, g_Camera.m_Position.y, g_Camera.m_Position.z,g_Camera.m_View.x, g_Camera.m_View.y, g_Camera.m_View.z,g_Camera.m_upVector.x, g_Camera.m_upVector.y, g_Camera.m_upVector.z);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    count=0;

    // glPushMatrix();
    for (yloop=1;yloop<4;yloop++)
    {
    for (xloop=0;xloop<3;xloop++) {

    for (zloop=0;zloop<3;zloop++)
    {
    //glPopMatrix();
    rubiks[count].draw_cuboid(texture);
    //glPushMatrix();
    count++;
    }
    }
    }
    return TRUE;
    }

    I was advised that a glPopMatrix() and glPushMatrix() would do the trick... but with that I'm just left with what a had before .. a stationary scene .... the ufo disapears.

    *btw .. the ufo is the first cuboid created*


Comments

  • Closed Accounts Posts: 222 ✭✭The Second


    my head hurts. here is my code... its all I can offer! Please ..... somebody .. anybody....????

    in init: g_Camera.PositionCamera(-0.62f, -0.42f, -5, 0, 0.5f, 1, 0, 1, 0);

    int DrawGLScene(GLvoid)
    {

    gluLookAt( g_Camera.m_Position.x, g_Camera.m_Position.y, g_Camera.m_Position.z,
    g_Camera.m_View.x, g_Camera.m_View.y, g_Camera.m_View.z,
    g_Camera.m_upVector.x, g_Camera.m_upVector.y, g_Camera.m_upVector.z);

    glPushMatrix();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    count=0;



    for (yloop=1;yloop<4;yloop++)
    {

    for (xloop=0;xloop<3;xloop++)
    {

    for (zloop=0;zloop<3;zloop++)
    {

    rubiks[count].draw_cuboid(texture);
    glPopMatrix();
    glPushMatrix();
    count++;
    }
    }
    }


    return TRUE;
    }

    LRESULT CALLBACK WndProc( HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
    {
    switch (uMsg)
    {
    case WM_ACTIVATE:
    {
    if (!HIWORD(wParam))
    {
    active=TRUE;
    }
    else
    {
    active=FALSE;
    }
    return 0;
    }
    case WM_SYSCOMMAND:
    {
    switch (wParam)
    {
    case SC_SCREENSAVE:
    case SC_MONITORPOWER:
    return 0;
    break;

    }
    break;
    }
    case WM_CLOSE:
    {
    PostQuitMessage(0);
    return 0;
    }
    case WM_KEYDOWN:
    {
    keys[wParam] = TRUE;
    return 0;
    }
    case WM_KEYUP:
    {
    keys[wParam] = FALSE;
    return 0;
    }
    case WM_SIZE:
    {
    ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
    return 0;
    }
    }

    return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
    int WINAPI WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {
    MSG msg;
    BOOL done=FALSE;

    if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
    {
    fullscreen=FALSE;
    }

    if (!CreateGLWindow("cube",640,480,16,fullscreen))
    {
    return 0;
    }
    while(!done)
    {
    if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
    if (msg.message==WM_QUIT)
    {
    done=TRUE;
    }
    else
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    else
    {

    if ((active && !DrawGLScene()) || keys[VK_ESCAPE])
    {
    done=TRUE;
    }
    else
    {
    SwapBuffers(hDC);

    if (keys[VK_F1])
    {
    keys[VK_F1]=FALSE;
    KillGLWindow();
    fullscreen=!fullscreen;

    if (!CreateGLWindow("Rubik's Cube",640,480,16,fullscreen))
    {
    return 0;
    }
    }
    if(GetKeyState(VK_UP) & 0x80) {
    g_Camera.MoveCamera(kSpeed);
    }

    if(GetKeyState(VK_DOWN) & 0x80) {
    g_Camera.MoveCamera(-kSpeed);
    }

    if(GetKeyState(VK_LEFT) & 0x80) {
    g_Camera.RotateView(kSpeed, 0, 1, 0);
    }

    if(GetKeyState(VK_RIGHT) & 0x80) {
    g_Camera.RotateView(-kSpeed, 0, 1, 0);
    }
    }//else

    }//while
    }

    KillGLWindow();
    return (msg.wParam);
    }


    Then the camera itself:

    #include "camera.h"

    camera::camera()
    {
    Vector vZero = {0.0, 0.0, 0.0};
    Vector vView = {0.0, 1.0, 0.5};
    Vector vUp = {0.0, 0.0, 1.0};

    m_Position = vZero;
    m_View = vView;
    m_upVector = vUp;
    }

    GLvoid camera::PositionCamera(float positionX, float positionY, float positionZ,
    float viewX, float viewY, float viewZ,
    float upVectorX, float upVectorY, float upVectorZ)
    {
    Vector vPosition = {positionX, positionY, positionZ};
    Vector vView = {viewX, viewY, viewZ};
    Vector vUpVector = {upVectorX, upVectorY, upVectorZ};

    m_Position = vPosition;
    m_View = vView;
    m_upVector = vUpVector;
    }

    void camera::RotateView(float angle, float x, float y, float z)
    {
    Vector newView;
    Vector vView;

    vView.x = m_View.x - m_Position.x;
    vView.y = m_View.y - m_Position.y;
    vView.z = m_View.z - m_Position.z;

    float cosTheta = (float)cos(angle);
    float sinTheta = (float)sin(angle);

    newView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x;
    newView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;
    newView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;

    newView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;
    newView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y;
    newView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;

    newView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;
    newView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;
    newView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;

    m_View.x = m_Position.x + newView.x;
    m_View.y = m_Position.y + newView.y;
    m_View.z = m_Position.z + newView.z;
    }




    void camera::MoveCamera(float speed)
    {
    Vector vVector = {0};

    vVector.x = m_View.x - m_Position.x;
    vVector.y = m_View.y - m_Position.y;
    vVector.z = m_View.z - m_Position.z;

    m_Position.x += vVector.x * speed;
    m_Position.z += vVector.z * speed;
    m_View.x += vVector.x * speed;
    m_View.z += vVector.z * speed;
    }


  • Closed Accounts Posts: 222 ✭✭The Second


    sorry... I forgot to mention the problem!!

    it doesn't move. Nothing moves. I've gotten ride of the ufo... but I don't think thats a good thing.. I think it may still be lurking in the backround... moving... preventing anything else from moving!


  • Closed Accounts Posts: 392 ✭✭Skyclad


    If you use gluLookAt, it looks at the point specified. Also, glPush/PopMatrix is only useful if you include some of your draw code in between eg

    gluLookat(a,b,c,x,y,z,j,k,l);

    glPushMatrix();
    // Draw an object in 3d space with origin based on the identity matrix
    glPopMatrix();

    glPushMatrix();
    // Draw the next object in 3d space with origin based on the identity matrix
    glPopMatrix();

    etc.

    Theres VC++ code for a rotating rubiks cube at: http://matrix.netsoc.tcd.ie/~skyclad/cube.zip

    It's based on the Nehe basecode, if you havent looked there yet (nehe.gamedev.net), it's really invaluable for learning opengl.

    Dave


  • Closed Accounts Posts: 222 ✭✭The Second


    Thanks Dave ... if Nehe was a shop .. the assistants would know my name by now! ... the lesson 5 is just for rotating 1 object...

    I need a camera to pan around 27 objects ... I see where you are going with the rubik's cube though! :D this is my intention.

    for some reason the only thing the key input moves is the first cuboid created .. push and pop are displaying the rest of the rubik's cube ok now.. but the arrow keys aren't zooming on it.. just the first cuboid. :(


  • Closed Accounts Posts: 392 ✭✭Skyclad


    Are you still having the same problems as before? I've updated the previous link to include a bucket load of cubes all spinning on different axes and a free roaming camera.

    Dave


  • Advertisement
  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    I like that code skyclad - i was wondering what to do over christmas, do the code for my project in college, or go play with opengl, you've just answered that question for me :) Where can i subscribe to your news letter.


Advertisement