Results 1 to 7 of 7

Thread: How to connect objects

  1. #1
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    5

    How to connect objects

    Hi all,
    what is the best approach to "connect" objects??
    Example:

    PushMatrix
    translated1..
    rotated1...
    Block1
    Popmatrix

    Pushmatrix
    translated2..
    rotated2...
    Block2
    Popmatrix

    Now i got two Blocks that i can move independently in the space by changing values of translated and rotated....
    Is that a good way??

    How can i now connect them both that they atre both in one Coordinatesystem and behave like one objekt when rotating /translating??

    Thanks in advance!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: How to connect objects

    Hi !

    Just put another push/pop around it:

    push
    transform
    draw something here
    push
    transform
    draw part of object
    pop
    push
    transform
    draw another part of object
    pop
    pop

    Now you can transform each part of the object, and also the whole object any way you want.

    Mikael

  3. #3
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    5

    Re: How to connect objects

    Thanks Mikael.
    One more question:
    Is that the best way since there is a limit for the Matrix Stack concerning Push and Pop(32)?
    How can i make one Object being moved
    by translation and rotation when it is selected and the others not without defining every object with its own PushMatrix and Popmatrix??
    Like this:
    Pushmatrix()
    obj1
    obj2
    obj3
    .
    .
    .
    Popmatrix

    Now i have selected Obj3
    What to do to rotate just Obj3 now??

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: How to connect objects

    For each object you want to transform without affecting other objects, draw the object inside yet anoter glPush/PopMatirx pair, and make the object specific transformation inside that pair.

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: How to connect objects

    Sorry, didn't see you wanted to do it without push/pop. Well, is there a reason you DON'T want to use them?

    You can of course keep on transforming each object, without pushing them, and when you want to go back one step in the transformation (i.e. pop the stack), you can load the identity matrix, and redo all matrix operations but the last one.

    Yes, there is a limit on the modelview stack. The depth is implementation depdenent, but you are guaranteed to have at least 32 matrices deep stack. That means you can call glPushMatrix at least 32 times, with out popping the stack. That that should be more than enough for any not too advanced application.

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

    Re: How to connect objects

    I don't think the limit of 32 is a problem, since you would have to push 32 times in a row and not pop to go over the 32.
    If you push then pop each object you are still back at zero.


    example

    glPushMartix() // Push matrix by 1
    draw_object1()
    glPopMatrix() // Pop matrix subtract matrix by 1

    glPushMartix() // Push matrix by 1
    draw_object2()
    glPopMatrix() // Pop matrix subtract matrix by 1

    If you do the math your matrix is back at zero.

    A little more advanced:

    glPushMartix() // Push matrix by 1
    glTranslate(.....) Move robot
    glRotate(....) Rotate robot
    draw_robot_body()
    glPushMartix() // Push matrix by 1
    glRotate() // move robot arm
    draw_robot_arm()
    glPopMatrix() // Pop matrix subtract matrix by 1

    glPushMartix() // Push matrix by 1
    glRotate(....) // rotate robot legs
    draw_robot_legs()
    glPopMatrix() // Pop matrix subtract matrix by 1

    glPopMatrix() // Pop matrix subtract matrix by 1

    same results matrix is back at zero.


    Originally posted by Stef:
    Thanks Mikael.
    One more question:
    Is that the best way since there is a limit for the Matrix Stack concerning Push and Pop(32)?
    How can i make one Object being moved
    by translation and rotation when it is selected and the others not without defining every object with its own PushMatrix and Popmatrix??
    Like this:
    Pushmatrix()
    obj1
    obj2
    obj3
    .
    .
    .
    Popmatrix

    Now i have selected Obj3
    What to do to rotate just Obj3 now??

  7. #7
    Junior Member Newbie
    Join Date
    May 2002
    Posts
    5

    Re: How to connect objects

    Thanks all!
    If the push/pop is not a problem then it's ok.
    That would have been the only reason not to do it with Push/pop...

Similar Threads

  1. Replies: 5
    Last Post: 10-21-2016, 05:25 PM
  2. How to smoothly connect a number of points
    By ssyybbyy in forum OpenGL: General
    Replies: 1
    Last Post: 02-20-2014, 06:26 PM
  3. How to connect a variable to an edit field?
    By gyagyus in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-05-2009, 08:15 AM
  4. how to "connect" the grid for curved surface?
    By coda in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-12-2004, 11:58 PM
  5. How to draw more than one quad (connect together) on the screen?
    By beachboy1976 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-27-2002, 01:40 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