Results 1 to 4 of 4

Thread: Problem with translate in z direction

  1. #1
    Member Contributor
    Join Date
    Mar 2002
    Location
    CA,USA
    Posts
    57

    Problem with translate in z direction

    Hi,
    I have a simple draw line code ....
    I am drawing a line in VC++ MFC application.
    void CSim_4_26_02View::draw3dobject()
    {
    glBegin ( GL_LINES);
    glColor3f ( 0.0f, 1.0f, 1.0f ) ;
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(12.5f,0.0f,0.0f);
    glEnd();
    }
    Now I am able to see the line.But the line is going out of the screen.
    So what I want to do is to scale the screen so that I can see the whole line falling within the screen.

    So what I thought that by translating in Z direction I will be able to see the whole line....
    void CSim_4_26_02View::OnLButtonDblClk(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default

    CView::OnLButtonDblClk(nFlags, point);
    glTranslatef(-0.0f,0.0f,+0.9f);
    draw3dobject();
    }
    Now whenever I click on the screen the line diappears...
    It works when i translate only in x direction or y...
    I have also tried changing the Z value of the translate function from + to - but to no avail....
    So when i translate my line in z direction regardless of direction it disappears..
    Can any body help me with it...what am i doing wrong....

    Thanks in advance
    aus

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Fort Collins, Colorado
    Posts
    446

    Re: Problem with translate in z direction

    What are you setting your near clipping plane to? For example, if your near clipping plane is 1.0f, you won't see the line being drawn at 0.9f.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Problem with translate in z direction

    I think part of your problem is structure of your openGL program; I am not a big on object-oriented programming but will try to give you an example of structure for drawing and you my have to translate a little more to OOP.

    Also you must understand that you have to redraw all the objects on the screen every time you move an object. You should not be translating your object on a mouse button press, but changing a variable. Then during the Drawing of the screen, the variable change will then will make the line position updated.

    Letís create a few basic program objects:

    1. opengl initializes screen: Cview::Init_Opengl()
    2. Draw objects: Cview: raw_Screen()
    3. Draw a object: Cview: raw_Object()
    4. opengl object control: Cview::Object_Control()

    Letís create a basic object storage variable:

    struct My_Object
    {
    float x,y,z;
    float r,g,b
    float *data[];
    }

    Draw_Screen()
    {
    // Do all screen processing here.
    for(x=0; x < object_total; x++) // process all the object on our screen.
    {
    Draw_Object( My_Object[x] );
    }
    SwapBuffers();
    }

    Draw_Object( *My_Object )
    {
    glPushMatrix();
    glColor3f(My_Object.r, My_Object.g, My_Object.b );
    glTranslate(My_Object.x, My_Object.y, My_Object.z );

    // Process Object data here.
    My_Object.data

    glPopMatrix();
    }

    Object_Control()
    {

    if ( On_left_button ) Update_Object( My_Object ); Change objects variables here.

    }


    Originally posted by aus79er:
    Hi,
    I have a simple draw line code ....
    I am drawing a line in VC++ MFC application.
    void CSim_4_26_02View::draw3dobject()
    {
    glBegin ( GL_LINES);
    glColor3f ( 0.0f, 1.0f, 1.0f ) ;
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(12.5f,0.0f,0.0f);
    glEnd();
    }
    Now I am able to see the line.But the line is going out of the screen.
    So what I want to do is to scale the screen so that I can see the whole line falling within the screen.

    So what I thought that by translating in Z direction I will be able to see the whole line....
    void CSim_4_26_02View::OnLButtonDblClk(UINT nFlags, CPoint point)
    {
    // TODO: Add your message handler code here and/or call default

    CView::OnLButtonDblClk(nFlags, point);
    glTranslatef(-0.0f,0.0f,+0.9f);
    draw3dobject();
    }
    Now whenever I click on the screen the line diappears...
    It works when i translate only in x direction or y...
    I have also tried changing the Z value of the translate function from + to - but to no avail....
    So when i translate my line in z direction regardless of direction it disappears..
    Can any body help me with it...what am i doing wrong....

    Thanks in advance
    aus



    [This message has been edited by nexusone (edited 05-15-2002).]

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    London, England
    Posts
    160

    Re: Problem with translate in z direction

    Also, remember that opengl has the z axis running -ve into the screen. So, to translate the line away from you, you need:
    glTranslatef(-0.0f,0.0f,-0.9f);
    not
    glTranslatef(-0.0f,0.0f,+0.9f);

Similar Threads

  1. Scaling Translate Problem
    By Yogurt in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-07-2014, 12:04 AM
  2. Translate + Rotate problem.
    By Tivin in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-21-2009, 01:34 PM
  3. problem with Rotate() and Translate()
    By openujs in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-26-2005, 09:38 AM
  4. gluLookAt translate in y direction
    By ulric in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-15-2004, 12:26 PM
  5. Moving a ship and calculating direction to translate
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-27-2003, 03:10 PM

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