Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: how move 2d polygon across screen ?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    5

    how move 2d polygon across screen ?

    can anyone please point me to a tut or explain how to move a 2d coloured polygon across the screen and stop at a given point


  2. #2
    Intern Contributor
    Join Date
    Mar 2004
    Location
    springfield, va [usa]
    Posts
    61

    Re: how move 2d polygon across screen ?

    try http://nehe.gamedev.net/ - plenty of useful tutorials.

    :regards:

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    5

    Re: how move 2d polygon across screen ?

    Had a look at nehe's site but none of the examples deal specificly with what i want to do. All beginners tutorials seem to deal with movement by using glRotatef(). Is glTranslatef() able to move objects across the screen if so how does it work? If not then how is it done?

    A basic explanation would be helpfull.


  4. #4
    Junior Member Regular Contributor
    Join Date
    Aug 2004
    Location
    Angers, France
    Posts
    248

    Re: how move 2d polygon across screen ?

    Hm, hope a very basic explanation helps you...

    Ok so, you can use 3 modelisation transformations:

    _glRotate[ type ]( angle , x, y, z);

    where type is d (for double), i(for int), f(for float), and angle is your angle of rotation, because this function is used for rotating objects. x, y and z are your coords in 3D space (x axis, y axis, z axis...)
    in theory: This function multiply the active matrix by a rotation about an object.

    _glTranslate[ type ](x, y, z);

    where type is d (for double), i(for int), f(for float), this function is used for translate objects in 3D space (left or right, up or down, far or near).
    in theory: This function multiply the active matrix by a matrix that move an object (moving the local coords system).

    _glScale[ type ](x, y, z);

    where type is d (for double), i(for int), f(for float), this function is used to modify how your object look like, at every coords (x, y or z) if you specify a value < 1, the object appear more little, if the value is > 1, the object appear bigger.
    in theory: This function multiply the active matrix by a matrix that modify the appearence (more little, more big, more deep...)

    Tricks and counter traps:
    _Don't forget that if you want to translate and rotate an object, the result is not the same if you translate before rotate or rotate before translate !
    There is no "good" order, because you can use this little trap such as a bonus to facilitate your transformations

    _Don't forget, angle is in degree (:

    _You must use glLoadIdentity() function very often, i.e. between 2 transformations, because if you don't, the current transformation willbe affected by the older transformation, note: such as rotate and translate, this traps can be used like a bonus...

    _all transformation are multiplications of matrix by other matrix in reality, so check your math out !
    Code :
      (note that your transformations may look like
    ( 1 0 0 )   
    ( 0 1 0 )  <-- erks ! (i.e. an identity matrix)
    ( 0 0 1 )
    If you want to move an object from a point to another point you can try something like that:

    Code :
    // globals 
    GLfloat myXmove;
    ....
    // renderer
    glTranslatef( myXmove, y, z);
    glBegin();
       glVertex....
       ...
    glEnd();
    if(myXmove < 10.0f)
    {
       myxmove += 0.001f;
    }
    else
    {
       another_transformations...
    }
    (don't hurt, this is an example (: )

    Hope that helps, don't forget to check the OpenGL RedBook out (this is the official bible)

    Gollum
    The .Product will make you .Believe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •