Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - jmachete

#1
Support / Re: How to do 2D click to 3D object picking?
December 21, 2010, 02:58:26 PM
But from where I can get the X and Y values from:

SimpleVector dir=Interact2D.reproject2D3DWS(cam, fb, x, y);


??

#2
Support / Re: How to do 2D click to 3D object picking?
December 20, 2010, 03:15:09 PM
I guys,

I'm following the wiki but I still haven't make this work yet. I'm doing this inside the method "onDrawFrame", so I'm a bit confusing in terms of how I can get the picked object in the end.

When I reproject what is going to be my X and Y, the position of my camera?

SimpleVector dir=Interact2D.reproject2D3DWS(cam, fb, (int)cam.getXAxis().x, (int)cam.getXAxis().y);

and who I pickup the object?

Object3D picked=res[1] ????

this is the code I'm using:


public void onDrawFrame(GL10 gl) {

try {
if (!stop) {
Camera cam = world.getCamera();

SimpleVector dir=Interact2D.reproject2D3DWS(cam, fb, (int)cam.getXAxis().x, (int)cam.getXAxis().y);
dir.matMul(world.getCamera().getBack().invert3x3());
dir.add(world.getCamera().getPosition());  

if (turn != 0) {
world.getCamera().rotateY(-turn);
}

if (touchTurn != 0) {
world.getCamera().rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
world.getCamera().rotateX(touchTurnUp);
touchTurnUp = 0;
}

if (move != 0) {
world.getCamera().moveCamera(cam.getDirection(), move);
}

Object[] res=world.calcMinDistanceAndObject3D(cam.getPosition(), dir, 10000 /*or whatever*/);
if(res[1]!=null)
Object3D picked=res[1]; //??????????????? I'm confuse

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
blitNumber(lfps, 5, 5);

fb.display();

if (box != null) {
box.rotateX(0.01f);
}

if (sun != null) {
sun.rotate(sunRot, plane.getTransformedCenter());
}

if (System.currentTimeMillis() - time >= 1000) {
lfps = fps;
fps = 0;
time = System.currentTimeMillis();
}
fps++;
} else {
if (fb != null) {
fb.dispose();
fb = null;
}
}
} catch (Exception e) {
e.printStackTrace();
Logger.log("Drawing thread terminated!", Logger.MESSAGE);
}


Hope anyone can give me some light.

Cheers
Joao