www.jpct.net
jPCT-AE - a 3d engine for Android => Support => Topic started by: hisong on August 24, 2011, 03:27:52 pm
-
Hi, I am again.
I am doing a test about picking with JPCT-AE , so I consulted the threads(http://www.jpct.net/forum2/index.php?topic=1601.0 (http://www.jpct.net/forum2/index.php?topic=1601.0) and http://www.jpct.net/wiki/index.php/Picking (http://www.jpct.net/wiki/index.php/Picking)) about picking.
I did like the thread discussed, but I always get the null result! I don't know why.
This is the code sample.
I get two objects of Object3D from the 3ds file: cube[0] and cube[1], I want to pick the cube[1] in the world.
so I set the cube[1] to be picked:
try {
cube = Loader.load3DS(
new FileInputStream("/sdcard/jpct/sphere.3ds"), 1);
Loader.clearCache();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cube[0].setTexture("texture");
cube[0].strip();
cube[0].build();
world.addObject(cube[0]);
cube[1].setTexture("mark");
cube[1].strip();
cube[1].build();
world.addObject(cube[1]);
cube[1].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
and then I was doing picking like this as the thread http://www.jpct.net/wiki/index.php/Picking (http://www.jpct.net/wiki/index.php/Picking) did.
SimpleVector dir=Interact2D.reproject2D3DWS(world.getCamera(), fb, (int)AppConfig.screenX, (int)AppConfig.screenY ).normalize();;
Object[] res = world.calcMinDistanceAndObject3D(world.getCamera().getPosition(), dir, 10000 /*or whatever*/);
judgePicking(res[1]);
public void judgePicking(Object object)
{
if(object.equal(cube[1]))
{
Log.i("Path", "Picking");
}
else {
Log.i("Path", "NULL");
}
}
I always get "null" from the function of "judgePicking()". I don't know what goes wrong.
anyone could help me? Thanks very much.
-
you compare Object and Object3D...
...
judgePicking((Object3D)res[1]);
...
public void judgePicking(Object3D object){...}
-
you compare Object and Object3D...
...
judgePicking((Object3D)res[1]);
...
public void judgePicking(Object3D object){...}
Thank you for replying so quickly.
I did what you said above. It didn't work.
What's more I think it does needn't to do this because the Object3D is the subclass of Object.
the parameter Object of judgePicking(Object3D object) will do explicit casts.
-
and what you have in AppConfig.screenX?
-
and what you have in AppConfig.screenX?
The AppConfig class stores the values of the screen coordinate I got from the onTouchEvent(MotionEvent e).
The screenX and screenY are the static variables of AppConfig Class.
-
Thomas. I think I found what causes the question: It may be I don't subtract the offset of the title when I was using the screen coordinate.
It helps me a lot with the thread:http://www.jpct.net/forum2/index.php/topic,2191.msg16277.html#msg16277 (http://www.jpct.net/forum2/index.php/topic,2191.msg16277.html#msg16277)
I suggest that the doc would be better if the doc could be more detailed.
Thanks all who viewed this post.
Hisong
-
I may have had the same problem, and ended up removing the status and title bars from my program (which I would have done anyway for aesthetics):
protected void onCreate(Bundle savedInstanceState)
{
// Disable the title bar or it will throw off our picking coordinates.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Disable the status bar or it will throw off our picking coordinates.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
... (etc)