Main Menu

Interact2D

Started by paulscode, October 15, 2008, 02:52:53 AM

Previous topic - Next topic

paulscode

Another question related to rotations.  I am planning to use Interact2D.reproject2D3D(Camera camera, FrameBuffer buffer, int x, int y, float z) for interacting with the world via the mouse.  I assume the returned SimpleVector is in Camera space, so I would need to apply the camera's rotations (inverted I assume) and translations to it to get a SimpleVector in world space.  Translations are a simple matter of addition, but what methods do I use for rotations?  I'm guessing I would start with this:

Matrix m = myCamera.getBack().cloneMatrix().invert3x3();

Then what method do I use to apply this matrix to the SimpleVector?

Thanks for the help, BTW.  I know I am asking questions that have been asked before.  I just have trouble finding things in the forums occasionally.

EgonOlsen

Yes, you have to tranform it back into world space in that case. Somehow like so: http://www.jpct.net/forum2/index.php/topic,1133.0.html

paulscode

Thanks, looks like the matMul() method is what I need.

    SimpleVector v = new SimpleVector( Interact2D.reproject2D3D(
                         myWorld.getCamera(), myFrameBuffer, x, y ) );
    v.matMul( myWorld.getCamera().getBack().invert3x3() );
    v.add( myWorld.getCamera().getPosition() );


EgonOlsen

You'll most likely need the add too. I think i should that this to camera, because the problem pops up from time to time...

paulscode

At least the solution is simple.  My problem is that I sort of jumped feet-first into 3D programming without first having a good understanding of the basics (in this case matrices and how they fit in to the big picture).  I suppose there are many ways to learn something, and I have always been the kind who prefers trial and error.  I really should go online and read up a little more on the subject, I suppose.  I just seem to have trouble wrapping my head around theory without something real to relate it to (probably why I did so poorly in trigonometry ;D).