Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Simple Opengl matrix question

  1. #1

    Simple Opengl matrix question

    I'm back with a simple question
    Ok, let's say that i'm currently in a certain matrix, obtained after dozens of glTranslate and glRotate.
    Now i draw something at position x,y,z.
    What's the best way to obtain x,y,z in world coordinate (so inverting the transformation)?
    Maybe if you've some code too it will be appreciated
    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. #2

    Simple Opengl matrix question

    couldn't you just take the inverted matrix?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Simple Opengl matrix question

    Quote Originally Posted by JSoftware
    couldn't you just take the inverted matrix?
    Umm yes.. How do i do that ?
    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>

  4. #4

    Simple Opengl matrix question

    if you head over to www.delphi3d.net the DOT framework has a very good geometry unit which has matrix invert, it should give you some pointers.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  5. #5

    Simple Opengl matrix question

    glGetFloatv(GL_MODELVIEW_MATRIX, @Matrix[0]);
    and invert

  6. #6

    Simple Opengl matrix question

    uhh. getting the inverse of a matrix is very hard! i surfed for several weeks to find out how. here's my vector and matrix code: http://graesdal.dk/mark1.zip

    i just made it simple if you would want to compile it just straight away. you can remove cpu1 and vectors units if you don't need them. the matinverse function should be pretty easy to just cut and paste out of there if you need it..

    happy coding,
    Jeppe :roll: [/url]
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7

    Simple Opengl matrix question

    Thanks guys!
    I've came out with this code:

    [pascal]
    var SAVEDVECT:TVector;

    procedure SavePosition;
    var
    ModM, B : TMatrix;
    begin
    glGetFloatv(GL_MODELVIEW_MATRIX, @ModM[0]);
    B := MatrixInverse(ModM);
    SAVEDVECT := getVector(0,0,0);
    SAVEDVECT := VectorMatrixMult(B, SAVEDVECT);
    end;
    [/pascal]

    After this i draw something in position SAVEDVECT..
    But it doesn't work..
    I was wondering if it was about camera.. Becouse when i draw stuff i draw after the camera setup..
    Maybe i should use not only the inverse of the modelview, but also the camera matrix and do some calculation..
    Am i right? any hint on what calculation do i need ?
    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>

  8. #8

    Simple Opengl matrix question

    I didn't propably quite understand your question, but to get "camera" position in moved position can be simply looked from 4x4 GL_MODELVIEW_MATRIX obtained with glGet.
    [#,#,#,posX]
    [#,#,#,posY]
    [#,#,#,posZ]
    [#,#,#,#]

    If you are rendering something in a world, first camera is moved to the wanted position, then if you call glTranslate or glRotate for single objects, remember glPushMatrix before to store the camera location and glPopMatrix after the object to restore previus position.

  9. #9

    Simple Opengl matrix question

    how do you apply your projection matrix?

    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 :!:
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  10. #10

    Simple Opengl matrix question

    If you multiply projected matrix with its inverse, wouldn't you get the same as glLoadIdentity would give?

Page 1 of 2 12 LastLast

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
  •