Author Topic: 2D interface - Object Picking  (Read 6157 times)

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
2D interface - Object Picking
« on: August 09, 2011, 11:37:02 pm »
Hey, guys, whats'up?

I am TRYING to develop an simple 2D interface with jPCT-AE: its just a 2D button which, when I press it, the 3D displayed model is changed by another model. For doing this, I'm using object picking, but it just doesnt work! Actually, it works. But it shows that the button was "picked" in screen points outside of the button area (the button is just a plane).
Do you know what I am missing  here?
My code for collision is:

Code: [Select]
public boolean checkCollision(int x, int y)
{
dir = Interact2D.reproject2D3DWS(world.getCamera(), fb, x, y).normalize();

Object[] res = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), dir, 300 );
if (res[1] != null && res[1] == nextBt)
return true;

return false;
}

This method is called by the main activity when the user touches the screen.

Thanks!

RhoX

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2D interface - Object Picking
« Reply #1 on: August 10, 2011, 07:31:14 am »

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
Re: 2D interface - Object Picking
« Reply #2 on: August 10, 2011, 08:35:47 am »
Well, I've tried the idea of using the diferent projection, but it still doesnt work. Maybe it is because my object's center is "bad" positioned.
My 2D button is:

Code: [Select]
Texture tela = new Texture(res.openRawResource(R.raw.icon1));
tm.addTexture("tela", tela);

nextBt = Primitives.getPlane(4, 25f);
nextBt.setTexture("tela");
//nextBt.setCollisionOptimization(true);
nextBt.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
nextBt.setLighting(Object3D.LIGHTING_NO_LIGHTS);
nextBt.translate(65f, 140f, -75f);
nextBt.setBillboarding(Object3D.BILLBOARDING_ENABLED);

Some idea?

Thanks for the reply! :D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2D interface - Object Picking
« Reply #3 on: August 10, 2011, 09:51:23 am »
I'm not sure if picking will work on a bill boarded object... ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2D interface - Object Picking
« Reply #4 on: August 10, 2011, 09:58:14 am »
...just tried it: It works fine will bill boarding.

Anyway, i'm not 100% sure what your actual problem is. Can you make a screen shot, draw a picture or post a test case?

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
Re: 2D interface - Object Picking
« Reply #5 on: August 10, 2011, 10:18:39 am »
Okay. I'll do it later.

Thanks for everything!

I'll be back soon XD!

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
Re: 2D interface - Object Picking
« Reply #6 on: August 10, 2011, 08:40:40 pm »
Here is the screenshot of the application:



The blue button at the right down corner of the screen is suppose to be clickable. And when it gets clicked, the model displayed is changed by other. Actually, with my lines of code, the picking not occurs at the right points (i.e., when I pick some points int the area above the button, my "debugger" says "PICKED!".

That is my problem  :-\

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: 2D interface - Object Picking
« Reply #7 on: August 10, 2011, 09:16:03 pm »
If you need buttons on screen, will be better use FrameBuffer.blit(...); and check it by touchevent  ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2D interface - Object Picking
« Reply #8 on: August 10, 2011, 09:21:30 pm »
Have you checked that your touch coordinates match the framebuffer's? As mentioned in the other thread, the bars on top might introduce an offset.

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
Re: 2D interface - Object Picking
« Reply #9 on: August 13, 2011, 09:39:37 pm »
Well, I kinda solved this problem with the blitting method that you told in another thread. But, how am I supposed to correct ou ajust these coordinates (framebuffer x touch)?

Thank you again!  ;D

Offline Edak

  • byte
  • *
  • Posts: 14
    • View Profile
Re: 2D interface - Object Picking
« Reply #10 on: August 14, 2011, 12:15:01 pm »
Hey RhoX, are you still having issues finding the touched part?

Basically it goes like this,

if(TouchX > ButtonX && TouchX < ButtonX+ButtonWidth && TouchY > ButtonY && TouchY < ButtonY+ButtonHeight){
                return true;
}

Where TouchX and TouchY are the points on the screen touched.
Where ButtonX and ButtonY are the button's positions on the screen.
Where ButtonWidth and ButtonHeight are the Width and Height of the button on the screen.

I'm assuming that was your most recent question, let me know if this helps.

Offline RhoX

  • byte
  • *
  • Posts: 29
    • View Profile
Re: 2D interface - Object Picking
« Reply #11 on: August 17, 2011, 03:45:36 am »
Hey, Edak!

Thats exactly what my question is about. I've tried some days ago some code like similar to the one you showed but it didnt work. But, when I have time, I'm going to try again (with your code) and then I'll post the results.

Thanks for the help!

RhoX