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 10 of 10

Thread: Coordinate transformation

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Bremen
    Posts
    12

    Coordinate transformation

    Hi there !!

    First, hello to all the OpenGL-Coders !
    Next, my problem: I wrote a small particle animation using 2D Textures. So, when I set my Viewpoint in front of the particles, I see them clearly. As I set the Viewpoint on Top, I can't see anything becouse these particles are only 2-dimensional. Has anybody an idea for rotating each particle to the coordinates of my eye-point like doing a coordinate transformation ? Please help me!!!

  2. #2
    Intern Contributor nemesis's Avatar
    Join Date
    Nov 2001
    Posts
    92

    Re: Coordinate transformation

    Hi!

    Setting your viewpoint on top means you are rotatting your camera 90º. You should try to glRotate all the particles the opposite angle, -90º. Remember to put this rotation matrix at the end of your transformations.

    - nemesis -

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Bremen
    Posts
    12

    Re: Coordinate transformation

    Well, thanks.
    But how is the Rotation of the PArticles done ? As I used glRotate, all the Scene was rotated, but not every single Particle. So, where is it to be done every single Particle is rotated ? For Info: I got a loop to draw the Particles by using Triangle Strips.

  4. #4
    Intern Contributor nemesis's Avatar
    Join Date
    Nov 2001
    Posts
    92

    Re: Coordinate transformation

    Ok,

    you should do something like this:

    for each particle
    glPushMatrix();
    glTranslate the particle
    glRotate the particle 90º
    draw the particle
    glPopMatrix();
    end for

    I think it should work.

    - nemesis -

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Bremen
    Posts
    12

    Re: Coordinate transformation

    Wow, it works. Its a little slow, but it works.

    Thanks a lot !!

  6. #6
    Intern Contributor
    Join Date
    Aug 2001
    Location
    doesnt matter
    Posts
    62

    Re: Coordinate transformation

    hi, there is some calculation stuff for this problem in the internet too... here is it:

    void buildRot(float theta, float x, float y, float z, float m[16]) {
    float d = x*x + y*y + z*z;
    float ct = cosf(theta * 3.141592654f / 180), st = sinf(theta * 3.141592654f / 180);


    /* normalize */
    if (d > 0)
    {
    d = 1/d;
    x *= d;
    y *= d;
    z *= d;
    }


    m[ 0] = 1; m[ 1] = 0; m[ 2] = 0; m[ 3] = 0;
    m[ 4] = 0; m[ 5] = 1; m[ 6] = 0; m[ 7] = 0;
    m[ 8] = 0; m[ 9] = 0; m[10] = 1; m[11] = 0;
    m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;


    /* R = uu' + cos(theta)*(I-uu') + sin(theta)*S
    *
    * S = 0 -z y u' = (x, y, z)
    * z 0 -x
    * -y x 0
    */


    m[0] = x*x + ct*(1-x*x) + st*0;
    m[4] = x*y + ct*(0-x*y) + st*-z;
    m[8] = x*z + ct*(0-x*z) + st*y;


    m[1] = y*x + ct*(0-y*x) + st*z;
    m[5] = y*y + ct*(1-y*y) + st*0;
    m[9] = y*z + ct*(0-y*z) + st*-x;


    m[2] = z*x + ct*(0-z*x) + st*-y;
    m[6] = z*y + ct*(0-z*y) + st*x;
    m[10]= z*z + ct*(1-z*z) + st*0;
    }

    /*2d object dreht sich in immer in eine richtung*/

    static void CalcMatrix(void) {
    float mat[16];

    glGetFloatv(GL_MODELVIEW_MATRIX, mat);
    buildRot(-180*atan2f(mat[8], mat[10])/3.141592654f, 0, 1, 0, mat);
    glMultMatrixf(mat);
    }

    dont know if it's faster... but i use it *ggg*
    Beginners First [img]/forum/images/%%GRAEMLIN_URL%%/wink.gif[/img]
    OpenGL tuts soon at www.mofux.de.vu

  7. #7
    Junior Member Regular Contributor
    Join Date
    Aug 2001
    Location
    England
    Posts
    174

    Re: Coordinate transformation

    If you get the current modelview matrix by calling
    glGetFloatv(GL_MODELVIEW_MATRIX, your_array_to_hold_matrix_info);

    and then build right and up vectors from this matrix, then render your particles as triangle strips using the point they exist at and then adding/subtracting (depending on the vertex) the right and up vectors you will obtain a tri strip that faces the camera (under all circumstances).

    I think Nate Miller's programming page is where I found this technique, you could try looking there for more info.

    -Mezz

  8. #8
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Bremen
    Posts
    12

    Re: Coordinate transformation

    Thanks Mezz for your Posting ,
    but sorry Im a raw newbie on OpenGL. COuld you please explain me how to do this by posting Code or something like that ?

  9. #9
    Intern Contributor nemesis's Avatar
    Join Date
    Nov 2001
    Posts
    92

    Re: Coordinate transformation

    Hi again!

    about how to speed up your program...
    If you don't usually move the camera, I mean, if you are not moving around all the time, it might be better to really rotate your particle geometry (I supose you only have one particle model, do you?) every time you move the camera before start rendering. This way, you can avoid the glRotate command in the loop.
    I think you could use the code posted by Mofux, or something similar, to build your own rotation matrix.
    I don't know if it will be useful in your case.

    - nemesis -


    [This message has been edited by nemesis (edited 11-29-2001).]

  10. #10
    Junior Member Newbie
    Join Date
    Nov 2001
    Location
    Bremen
    Posts
    12

    Re: Coordinate transformation

    Thanks Mezz for your Posting ,
    but sorry Im a raw newbie on OpenGL. COuld you please explain me how to do this by posting Code or something like that ?

Posting Permissions

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