Author Topic: Interact2D  (Read 4085 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Interact2D
« on: October 15, 2008, 02:52:53 am »
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:

Code: [Select]
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Interact2D
« Reply #1 on: October 15, 2008, 07:22:51 am »
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

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Interact2D
« Reply #2 on: October 15, 2008, 10:40:56 am »
Thanks, looks like the matMul() method is what I need.

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Interact2D
« Reply #3 on: October 15, 2008, 11:30:38 am »
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...

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Interact2D
« Reply #4 on: October 15, 2008, 01:32:59 pm »
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).