Translating an Object3D to the touch point

Started by Babu, November 23, 2011, 04:22:35 PM

Previous topic - Next topic

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:

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


Then I changed the onDrawFrame as below:

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


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

raft

well, i don't know then ??? Egon should hopefully help..

EgonOlsen

The coordinates look as if you've not moved the camera at all, which is why they look like camera space. That method projects the 2D coordinate to a 3D point on the view plane, i.e. on z=1 in camera space. This point will then be transformed into world space. If the camera hasn't moved, both spaces are equal.
However, it's unlikely that you want to move in view plane.
Like i did in the other thread that is currently dealing with this issue, i'll link to a recent thread for desktop jPCT that offers a little example at the bottom of the thread: http://www.jpct.net/forum2/index.php/topic,2413.0.html
The basic idea is to calculate the position in world space on a given plane (in world space, not in camera space) based on the result from reproject2D3DWS. You can do it that way or by doing a collision detection based on this vector. I'm mentioning that in the thread too.
Hope this helps.

Babu

Thanks a lot, Egon.  Your code in that thread works perfect!!  :D

I am attaching the working Android code...

[attachment deleted by admin]

gourabf9systems

Can anyone post , working example of this topic. that solved by anyone.

EgonOlsen

Quote from: gourabf9systems on March 05, 2013, 11:57:33 AM
Can anyone post , working example of this topic. that solved by anyone.
The post right above yours has a working Activity attached.

gourabf9systems

Hi EgonOlsen,

I use example made by Babu. I modify that code for my self. I attach that with this post.Can you peace check it. I just wnat to make the Object3D smaller that present when I move this from +y axis to -y axis.   Can you explain bellow lines


int Z_PLANE  = 0;
float a = (Z_PLANE - camPos.z) / mTouchVector.z;
         float x = camPos.x +  a * mTouchVector.x;
         float y = camPos.y + a * mTouchVector.y;

[attachment deleted by admin]

EgonOlsen

If you want to make an object smaller or bigger, just use Object3D.scale() or Object3D.setScale(). And i don't see how this relates to the lines of code that you've posted... ???

Anyway, these lines are a pretty simple system of linear equations to find the point on a given z-plane. It's basic math.

gourabf9systems

Dear EgonOlsen,

I search lot's in google to get a sample code of game using jpct ae. But I have not get yet. If you post source code of game develop by you using JPCT ae. Then I able to learn some thing from that. If u post a video tutorial for this then I am very happy and become muster to use it.

Thanks
Gourab Singha

EgonOlsen

You might want to look at the Alien Runner sources. There have been written for the G1 class of devices, so there's a lot of micro-optimizing in them that might not be needed on current devices. Keep that in mind just in case you are wondering why some things have been done in the way that they are. Here you go: http://www.jpct.net/forum2/index.php/topic,1629.msg14207.html#msg14207