Results 1 to 5 of 5

Thread: f1 segment

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2002
    Posts
    4

    f1 segment

    im trying with one of the tutorial on the OpenGL book, and trying to modify it, but how come when make the segment of f1, it give me a big cube. and is outsite of the elbow cube

    void display (void)
    {
    glClear (GL_COLOR_BUFFER_BIT);
    glPushMatrix ();
    glTranslatef (-1.0, 0.0, 0.0);
    glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (2.0, 0.4, 1.0);
    glutWireCube (1.0);
    glPopMatrix ();

    glTranslatef (1.0, 0.0, 0.0);
    glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (2.0, 0.4, 1.0);
    glutWireCube (1.0);
    glPopMatrix ();

    glClear (GL_COLOR_BUFFER_BIT);
    glTranslatef (0.0, 1.0, 0.0);
    glRotatef ((GLfloat) f1, 0.0, 1.0, 0.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (1.0, 0.2, 0.5);
    glutWireCube (0.25);
    glPopMatrix ();

    glPopMatrix ();
    glutSwapBuffers ();
    }

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

    Re: f1 segment

    Here a few things I see:

    1. glClear.... only call once at the start of the display routine.

    2. I think your problem is in how you have setup your glPush/pop matrix.

    3. Explain more about what you trying to do and can give you more of an idea of what to do.

    Originally posted by opengluser:
    im trying with one of the tutorial on the OpenGL book, and trying to modify it, but how come when make the segment of f1, it give me a big cube. and is outsite of the elbow cube

    void display (void)
    {
    glClear (GL_COLOR_BUFFER_BIT);
    glPushMatrix ();
    glTranslatef (-1.0, 0.0, 0.0);
    glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (2.0, 0.4, 1.0);
    glutWireCube (1.0);
    glPopMatrix ();

    glTranslatef (1.0, 0.0, 0.0);
    glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (2.0, 0.4, 1.0);
    glutWireCube (1.0);
    glPopMatrix ();

    glClear (GL_COLOR_BUFFER_BIT);
    glTranslatef (0.0, 1.0, 0.0);
    glRotatef ((GLfloat) f1, 0.0, 1.0, 0.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (1.0, 0.2, 0.5);
    glutWireCube (0.25);
    glPopMatrix ();

    glPopMatrix ();
    glutSwapBuffers ();
    }


  3. #3
    Junior Member Newbie
    Join Date
    Oct 2002
    Posts
    4

    Re: f1 segment

    actually im trying to do is a robot arm with fingers, f1 will be the fingers on the wrist, which is end of the elbow point.

    Originally posted by nexusone:
    Here a few things I see:

    1. glClear.... only call once at the start of the display routine.

    2. I think your problem is in how you have setup your glPush/pop matrix.

    3. Explain more about what you trying to do and can give you more of an idea of what to do.


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

    Re: f1 segment

    Should look something like this:


    // hand
    glPushMatrix(); // Save matrix to stack
    glTranslatef(.....); // location of hand
    glRotatef(......); // Rotation of whole hand
    draw_base_of_hand();
    // Draw first finger
    glPushMatrix(); // Save matrix to stack
    glTranslatef(.....); location of finger on hand.
    glRotatef(......); rotation of finger.
    draw_finger_seg1();
    // Draw next finger segment.
    glPushMatrix();
    glTranslatef(.....);
    glRotatef(......);
    draw_finger_seg2();
    glPopMatrix();
    // If you wanted another finger segment would go here..
    glPopMatrix();

    // Draw Second finger would repeat for each finger.
    glPushMatrix(); // Save matrix to stack
    glTranslatef(.....); location of finger on hand.
    glRotatef(......); rotation of finger.
    draw_finger_seg1();
    // Draw next finger segment.
    glPushMatrix();
    glTranslatef(.....);
    glRotatef(......);
    draw_finger_seg2();
    glPopMatrix();
    // If you wanted another finger segment would go here..
    glPopMatrix();

    glPopMatrix();


    Note unless a glRotate/Translate/scale is between a glPush/PopMatrix, it will effect everything after it.

    glTranslatef(.....)
    // 1
    glPushMatrix()
    glTranslatef(.....)
    glPopMatrix()
    // 2
    glPushMatrix()
    glTranslatef(.....)
    glPopMatrix()

    note that both 1 and 2 are both effected by the first translate, but because of the use of push/pop matrix, 1 does not effect 2.

    Originally posted by opengluser:
    actually im trying to do is a robot arm with fingers, f1 will be the fingers on the wrist, which is end of the elbow point.


  5. #5
    Junior Member Newbie
    Join Date
    Oct 2002
    Posts
    4

    Re: f1 segment

    humm..actually im still confuse with it...below is my initial code. so now i need to add the fingers segment ast the end of the elbow cube.

    coding :
    #include <Gl/glut.h>
    #include <stdlib.h>

    static int shoulder = -35, elbow = 30;
    void init (void)
    {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);
    }

    void display (void)
    {
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);


    glPushMatrix ();
    glTranslatef (-1.0, 0.0, 0.0);
    glRotatef ((GLfloat) shoulder, 0.0, 0.0, 0.1);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (2.0, 0.4, 1.0);
    glutWireCube (1.0);
    glPopMatrix ();

    glTranslatef (1.0, 0.0, 0.0);
    glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
    glTranslatef (1.0, 0.0, 0.0);
    glPushMatrix ();
    glScalef (2.0, 0.4, 1.0);
    glutWireCube (1.0);
    glPopMatrix ();
    glPopMatrix ();
    glutSwapBuffers ();
    }

    void reshape (int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective (65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    glTranslatef (0.0, 0.0, -5.0);
    }

    void keyboard (unsigned char key, int x, int y)
    {
    switch (key)
    {
    case 's':
    shoulder = (shoulder + 5) % 360;
    glutPostRedisplay ();
    break;

    case 'S':
    shoulder = (shoulder - 5) % 360;
    glutPostRedisplay ();
    break;

    case 'e':
    elbow = (elbow + 5) % 360;
    glutPostRedisplay ();
    break;

    case 'E':
    elbow = (elbow - 5) % 360;
    glutPostRedisplay ();
    break;
    default:
    break;
    }
    }
    int main (int argc, char** argv)
    {
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init ();
    glutDisplayFunc (display);
    glutReshapeFunc (reshape);
    glutKeyboardFunc (keyboard);
    glutMainLoop ();
    return 0;
    }


    can you plase explain why you use the draw_base_of_hand(); & draw_finger_seg1();
    thanks.

Similar Threads

  1. Segment Fault error - libpng
    By kieranlavelle in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-10-2017, 06:00 PM
  2. Intersect triangle with segment
    By Yandersen in forum OpenGL: General
    Replies: 5
    Last Post: 08-29-2015, 04:36 PM
  3. Intersecting a 3D segment with perspective frustum
    By devdept in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-26-2009, 12:14 AM
  4. Replies: 3
    Last Post: 01-28-2003, 03:27 AM
  5. individual segment
    By opengluser in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-27-2002, 02:33 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