Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Simple Opengl matrix question

  1. #11

    Simple Opengl matrix question

    Quote Originally Posted by JSoftware
    the common mistake is just to apply the projection matrix while in modelview mode. if you then query the modelview matrix then you get both that and the projection matrix.
    if that's not the answer then i have no idea(probably a bug in the code). multiplying a transformed vector by the matrix's inverse would untransform it :!:
    Umm maybe this is the problem..
    I usually set up the camera without thinking of matrices..
    [pascal]
    glLoadIdentity;
    glTranslatef(0,6,10);
    gluLookAt(campos.x, campos.y, campos.z, camtarget.x,camtarget.y,camtarget.z,0,1,0);
    [/pascal]

    then i start drawing stuff without switching matrix..
    How should it be done instead?
    Maybe i've some problem with basis
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  2. #12

    Simple Opengl matrix question

    Quote Originally Posted by User137
    If you multiply projected matrix with its inverse, wouldn't you get the same as glLoadIdentity would give?
    That's not what i'm doing.. i'd like to transform a vector instead.
    the question is: if i'm in the middle of some transformation (glTranslate, Rotate etc), and i draw something in position 0,0,0, what's the absolute position of that point?
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  3. #13

    Simple Opengl matrix question

    How do you test that it doesn?¢_~t work?

  4. #14

    Simple Opengl matrix question

    Quote Originally Posted by Paulius
    How do you test that it doesn?¢_~t work?
    I call the saveposition procedure i pasted before, in the middle of my rendering, trying to "unproject" the 0,0,0 vector into SAVEDVECT.
    Then i return to "camera" matrix (that i calculated before), and i try to draw something at the SAVEDVECT position.

    pseudocode:
    Code:
    glLoadIdentity
    applyCamera
    
    for each object&#58;
       glPush
       transform matrix
       drawObject
       if it's the special object, call saveposition
       glPop
    
    translate to SAVEDVECT
    drawsomething
    Now the thing i draw sometimes enters and exits the screen, but it's not in the position i want it to be..
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  5. #15

    Simple Opengl matrix question

    load identity matrix before translating to SAVEDVECT,

  6. #16

    Simple Opengl matrix question

    Quote Originally Posted by Paulius
    load identity matrix before translating to SAVEDVECT,
    Umm.. But that's not what i want.. i'd like the position to be in the same coordinate frame of the rest of the objects..
    Indeed, i need to spawn objects in that position, that should be treated as any other..
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  7. #17

    Simple Opengl matrix question

    For saving, how about getting modelview-matrix with glGet and later recall it with glLoadidentity and glMultMatrix?

    Or maybe there was a way to directly write into modelview-matrix...

  8. #18

    Simple Opengl matrix question

    Quote Originally Posted by User137
    ...Or maybe there was a way to directly write into modelview-matrix...
    You can with glLoadMatrixf.
    Anyway if it?¢_~s only transformed origin you want MSX you might as well just take it from the last row of the modelview matrix.

  9. #19

    Simple Opengl matrix question

    ok, after lots of blind tries, i got it working.. but i don't know how

    here's the working code:

    [pascal]procedure SavePosition;
    var
    ModM, B : TMatrix;
    begin
    glGetFloatv(GL_MODELVIEW_MATRIX, @ModM[0]);
    savedvect.x:=modm[12];
    savedvect.y:=modm[13];
    savedvect.z:=modm[14];
    CAMMATRIX := MatrixInverse(CAMMATRIX);
    SAVEDVECT := VectorMatrixMult(CAMMATRIX, SAVEDVECT);
    end;
    [/pascal]

    Where CAMMATRIX is the modelview matrix saved just after camera setup.
    Now if i spawn an object at SAVEDVECT, it goes to the right position

    Who knows how it works ? :mrgreen:
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  10. #20

    Simple Opengl matrix question

    glGetFloatv(GL_MODELVIEW_MATRIX, @ModM[0]);

    you get the current modelview matrix

    savedvect.x:=modm[12];
    savedvect.y:=modm[13];
    savedvect.z:=modm[14];

    savedvect contains the translation of the current matrix

    CAMMATRIX := MatrixInverse(CAMMATRIX);

    you inverse cammatrix

    SAVEDVECT := VectorMatrixMult(CAMMATRIX, SAVEDVECT);

    you multiply translation with inverse cammatrix... if the current matrix is multiplied with the cammatrix in some way then savedvect would contain translation of current matrix in local space

    heh i took five minutes trying to figure out how to explain that and i'm not really sure it's correct
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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