jPCT-AE - a 3d engine for Android > Support
Translating an Object3D to the touch point
Babu:
Hi Raft,
I am back ;D
I am just trying a simple thing to make an Object3D follow my touch points i.e. the Object3D moves to whatever point that I touch on the screen. But I am unsuccessful :(
I used the basic cube example of the Hello World AE. I changed the onTouchEvent() as below:
--- Code: ---public boolean onTouchEvent(MotionEvent me)
{
if (me.getAction() == MotionEvent.ACTION_DOWN)
{
xpos = me.getX();
ypos = me.getY();
mTouchVector = Interact2D.reproject2D3DWS(world.getCamera(), fb,
(int)xpos, (int)ypos);
return true;
}
try
{
Thread.sleep(15);
}
catch (Exception e)
{
// No need for this...
}
return super.onTouchEvent(me);
}
--- End code ---
Then I changed the onDrawFrame as below:
--- Code: ---public void onDrawFrame(GL10 gl)
{
try
{
fb.clear(back);
if(mTouchVector != null)
{
cube.clearTranslation();
cube.translate(mTouchVector);
}
world.renderScene(fb);
world.draw(fb);
fb.display();
}
catch (Exception e)
{
Logger.log(e, Logger.MESSAGE);
}
}
--- End code ---
I see that the cube is moving, but very little!! Can you please let me know if I am missing something :-[
raft:
I'm not quite sure (quite a time passed last I used this stuff). it seemed ok to me.
maybe it's a sampling issue? what is your screen resolution? what does FrameBuffer.getHeight() and getWidth() return?
Note: Moved topic as this is not Bones related
Babu:
Following are values
11-23 22:33:42.735: D/HelloJPCT(679): frame-buffer-width = 320 frame-buffer-height = 480
11-23 22:33:42.735: D/HelloJPCT(679): TouchEvent-xpos = 98.30721 TouchEvent-ypos = 362.75574
11-23 22:33:42.735: D/HelloJPCT(679): mTouchVector.x = -0.2421875 mTouchVector.y = 0.4765625 mTouchVector.z = 1.0
raft:
these results seemed as they are in camera space to me. are you sure you are actually using Interact2D.reproject2D3DWS instead of Interact2D.reproject2D3D? former returns result in world space, later in camera space.
if so, there may be a bug. Egon will clarify either way
Babu:
The code snippet I provided was a copy-paste from my source file...
"mTouchVector = Interact2D.reproject2D3DWS(world.getCamera(), fb,
(int)xpos, (int)ypos);"
Navigation
[0] Message Index
[#] Next page
Go to full version