Author Topic: Translating an Object3D to the touch point  (Read 4422 times)

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Translating an Object3D to the touch point
« on: November 23, 2011, 04:22:35 pm »
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: [Select]
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:
Code: [Select]
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  :-[

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: Translating an Object3D to the touch point
« Reply #1 on: November 23, 2011, 04:43:44 pm »
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

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Translating an Object3D to the touch point
« Reply #2 on: November 23, 2011, 06:04:48 pm »
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


Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: Translating an Object3D to the touch point
« Reply #3 on: November 23, 2011, 06:22:54 pm »
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

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Translating an Object3D to the touch point
« Reply #4 on: November 23, 2011, 07:06:52 pm »
The code snippet I provided was a copy-paste from my source file...

"mTouchVector = Interact2D.reproject2D3DWS(world.getCamera(), fb,
                  (int)xpos, (int)ypos);"

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: Translating an Object3D to the touch point
« Reply #5 on: November 23, 2011, 07:25:35 pm »
well, i don't know then ??? Egon should hopefully help..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Translating an Object3D to the touch point
« Reply #6 on: November 23, 2011, 08:10:59 pm »
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.

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Translating an Object3D to the touch point - Resolved
« Reply #7 on: November 24, 2011, 02:35:19 pm »
Thanks a lot, Egon.  Your code in that thread works perfect!!  :D

I am attaching the working Android code...

[attachment deleted by admin]

Offline gourabf9systems

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Translating an Object3D to the touch point
« Reply #8 on: March 05, 2013, 11:57:33 am »
Can anyone post , working example of this topic. that solved by anyone.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Translating an Object3D to the touch point
« Reply #9 on: March 05, 2013, 08:01:14 pm »
Can anyone post , working example of this topic. that solved by anyone.
The post right above yours has a working Activity attached.

Offline gourabf9systems

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Translating an Object3D to the touch point
« Reply #10 on: March 06, 2013, 11:17:52 am »
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]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Translating an Object3D to the touch point
« Reply #11 on: March 06, 2013, 08:21:29 pm »
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.

Offline gourabf9systems

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Translating an Object3D to the touch point
« Reply #12 on: March 07, 2013, 08:04:48 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Translating an Object3D to the touch point
« Reply #13 on: March 07, 2013, 08:55:21 am »
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