Results 1 to 2 of 2

Thread: Need help w/navigating within a scene

  1. #1
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Huntsville, AL. USA
    Posts
    302

    Need help w/navigating within a scene

    Any ideas why this doesn't work? I am drawing a scene just fine and I want to be able to attach to any object in it.

    First I clear the scene and apply the viewport transformation. Second I setup the projection transformation. Then I setup the viewing transformation and render my scene graph.

    Problem is that it doesnt matter what the attach point coordinates are, I am always looking at the origin.

    Any clues?

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Render this scene

    void MScene::render()
    {
    glPushAttrib(GL_TRANSFORM_BIT);

    // Clear the scene and apply the viewport transformation.

    glClearColor(
    m_BkgColor.red(),
    m_BkgColor.green(),
    m_BkgColor.blue(),
    m_BkgColor.alpha()
    );
    clear();

    MCamera* camera = m_CameraPtr.get(); // Get pointer to camera

    camera->applyViewportTransformation(); // Viewport transformation

    // Setup the projection transformation

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    camera->applyProjectionTransformation();

    // Setup the viewing transformation and render the scene

    MAttachedNavigator* navigator = m_NavigatorPtr.get(); // Get pointer to the navigator

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    navigator->setupViewingTransform(); // Viewing transformation
    ActionTree(p_SceneGraph); // Render the scene
    glPopMatrix();

    // Done

    glPopAttrib();
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Apply the viewport transformation for this camera.

    void MCamera::applyViewportTransformation() const
    {
    glViewport(
    viewPortXOrigin(),viewPortYOrigin(),viewPortWidth( ),viewPortHeight()
    );
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Apply the viewport transformation for this camera.

    void MCamera::applyProjectionTransformation() const
    {
    gluPerspective(fovY(),viewPort()->aspectRatio(),nearPlane(),farPlane());
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Setup the viewing transform.

    void MAttachedNavigator::setupViewingTransform()
    {
    MDoubleVector3D cameraPos(attachment().attachPoint());
    cameraPos += m_CameraOffset;

    glTranslated(0,0,-cameraPos.magnitude());
    glRotated(-m_CameraRotation.x(),0,0,1);
    glRotated(-m_CameraRotation.y(),1,0,0);
    glRotated(-m_CameraRotation.z(),0,0,1);
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Retrieve the current attachment

    const MAttachable& MAttachedNavigator::attachment() const
    {
    return m_CurrentAttachment;
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Retrieve the coordinates of this attachment

    const MDoubleVector3D& MAttachable::attachPoint() const
    {
    return m_AttachPointCoordinates;
    }
    Obsessive - A word used by the lazy to describe the motivated.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Huntsville, AL. USA
    Posts
    302

    Re: Need help w/navigating within a scene

    .
    Obsessive - A word used by the lazy to describe the motivated.

Similar Threads

  1. 3d scene
    By joker40 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-19-2011, 07:02 AM
  2. Pan on a scene
    By luisillo in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-04-2006, 07:43 AM
  3. Slow navigating large scenes?
    By imported_Budric in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-19-2004, 06:05 AM
  4. Navigating using Viewing Transformations
    By rangers99 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-12-2002, 09:24 PM
  5. how to display 2d scene on top of 3d scene???
    By immy in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 03-26-2002, 04:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean