i need to add features of my android project, to get each name of the 3d objects. The objects are irregular and it can be rotate based on the user's gesture. I have lots of reading on openGL ray picking but still cant figure out how to make it work. I am using 3d min to load the .obj file. Thanks for advance.
Asked
Active
Viewed 632 times
1 Answers
0
The creator of min3d has deprecated the library and has an updated version called Rajawali built off of the same principles which you can find here.
Setting up your scene/project will be very similar if not the same. Better performance too.
As for getting 3d objects name after touching the object, do this:
In your main activity;
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
mRenderer.getObjectAt(event.getX(), event.getY());
}
return super.onTouchEvent(event);
}
In your renderer, you have to register the "selectable" objects in the initScene;
public class Renderer extends RajawaliRenderer implements OnObjectPickedListener {
private PointLight mLight;
private BaseObject3D object1, object2;
private ObjectColorPicker mPicker;
public RajawaliObjectPickingRenderer(Context context) {
super(context);
setFrameRate(60);
}
protected void initScene() {
mPicker = new ObjectColorPicker(this);
mPicker.setOnObjectPickedListener(this);
mLight = new PointLight();
mLight.setPosition(-2, 1, 4);
mLight.setPower(1.5f);
mCamera.setPosition(0, 0, 7);
object1 = new BaseObject3D(serializedMonkey);
object1.addLight(mLight);
object1.setScale(.7f);
object1.setPosition(-1, 1, 0);
object1.setRotY(0);
addChild(object1);
object2 = object1.clone();
object2.addLight(mLight);
object2.setScale(.7f);
object2.setPosition(1, 1, 0);
object2.setRotY(45);
addChild(object2);
mPicker.registerObject(mMonkey3);
mPicker.registerObject(mMonkey4);
}
public void getObjectAt(float x, float y) {
mPicker.getObjectAt(x, y);
}
public void onObjectPicked(BaseObject3D object) {
//Do whatever you want here once the object is touched
if object.picked == mObject1{
//print line here or toast
//just an example, not legit code
}
}
}
If you have any issues, feel free to ask. I've been using Rajawali since way back when min3d was created. ;)

Steve C.
- 1,333
- 3
- 19
- 50
-
i am looking to Rajawali. However, i still cannot get why BaseObject3D cannot be resolve in android studio, Is there something that i missed? – sarabrown Dec 16 '15 at 04:00