Author Topic: reproject question  (Read 1557 times)

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
reproject question
« on: July 12, 2011, 04:45:52 am »
Hello, this is my first time programming anything in android.
I'm not sure why im having this problem but maybe you can help me.  When I do the below code it seems to keep adding the object at the center of the screen instead of where i click/touch.  Am I using this method incorrectly? 
Code: [Select]
SimpleVector dest = new SimpleVector(0, 0, 0);
dest=Interact2D.reproject2D3DWS(cam, fb, (int)xpos, (int)ypos);

Object3D newObj = Primitives.getBox(5f, 5f);
newObj.setOrigin(dest);
world.addObject(newObj);
newObj.strip();
newObj.build();

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: reproject question
« Reply #1 on: July 12, 2011, 08:06:07 am »
Might be correct because the assumed z-coordinate of 1 is very close to the viewer so that the space that this plane covers is pretty small and it might look like as if it's all located in the center. You might want to print out the actual coordinates to see if something changes. You might as well try the method without ...WS, use a higher z-value than 1 to offset the object and do the tranformation into world space yourself. Something like:

Code: [Select]
SimpleVector p = reproject2D3D(camera, buffer, x, y, 20f);
p.matMul(camera.backMatrix.invert3x3());
obj.setOrigin(p);

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
Re: reproject question
« Reply #2 on: July 12, 2011, 09:20:39 pm »
Ok thanks I got it working although it still seemed like there was some y offset that i had to subtract, but after that, it works now.

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
Re: reproject question
« Reply #3 on: July 13, 2011, 11:30:44 pm »
I have a question about the offsets that I seem to need to add to get the correct positioning.  Will these be the same on all phones/android versions?  I feel like using constant offsets is not good unless it will always be the same on all versions, and also I don't know what causes them.  I saw you mentioned in an older thread that sometimes menubars and things can do that, so I'm thinking maybe its the titlebar (bar that contains the apps name) that messes up the positioning?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: reproject question
« Reply #4 on: July 14, 2011, 12:05:04 am »
No idea what introduces the offsets. The actual math of the operation is pixel perfect, so the positions that you get have to be already off. Try to check which coordinates you are getting on specific positions and which you are actually expecting. Maybe that clarifies where these offsets come from. If they are from the menu bar, i would guess that it has to be possible to get its size somehow. I wouldn't rely on it being the same on all devices.

Offline Disastorm

  • long
  • ***
  • Posts: 161
    • View Profile
Re: reproject question
« Reply #5 on: July 14, 2011, 01:29:11 am »
Ah ok thanks, and yes it turns out it was the menu bar.  I disabled the menu bar and I don't need to do the offset anymore.