2D interface - Object Picking

Started by RhoX, August 09, 2011, 11:37:02 PM

Previous topic - Next topic

RhoX

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:


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


RhoX

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:


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

EgonOlsen

I'm not sure if picking will work on a bill boarded object... ???

EgonOlsen

...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?

RhoX

Okay. I'll do it later.

Thanks for everything!

I'll be back soon XD!

RhoX

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  :-\

Thomas.

If you need buttons on screen, will be better use FrameBuffer.blit(...); and check it by touchevent  ;)

EgonOlsen

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.

RhoX

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

Edak

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.

RhoX

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