reproject question

Started by Disastorm, July 12, 2011, 04:45:52 AM

Previous topic - Next topic

Disastorm

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? 

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();

EgonOlsen

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:


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

Disastorm

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.

Disastorm

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?

EgonOlsen

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.

Disastorm

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.