You have to set the collision modes and call the collision methods...it's not much more than that. Here's a hacky test case of mine that i used to optimize the collision detection. Maybe it helps.
package com.threed.jpct.example;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.MemoryHelper;
public class HelloWorld_col extends Activity {
// Used to handle pause and resume...
private static HelloWorld_col master = null;
private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);
private Object3D sphere1 = null;
private Object3D sphere2 = null;
private Object3D sphere3 = null;
private Object3D cube=null;
private SimpleVector move=new SimpleVector(0,0.3,1);
private SimpleVector ellips=new SimpleVector(7,7,7);
private SimpleVector tmp=new SimpleVector();
protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
if (master != null) {
}
super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
// Ensure that we get a 16bit framebuffer. Otherwise, we'll fall
// back to Pixelflinger on some device (read: Samsung I7500)
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];
}
});
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}
protected void onStop() {
Logger.log("onStop");
super.onStop();
}
class MyRenderer implements GLSurfaceView.Renderer {
private int fps = 0;
private long time = System.currentTimeMillis();
private boolean stop = false;
public MyRenderer() {
Config.maxPolysVisible = 500;
Config.farPlane = 1500;
Config.glTransparencyMul = 0.1f;
Config.glTransparencyOffset = 0.1f;
Config.useVBO=true;
Texture.defaultToMipmapping(false);
Texture.defaultTo4bpp(true);
}
public void stop() {
stop = true;
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(gl, w, h);
if (master == null) {
world = new World();
Resources res = getResources();
TextureManager tm = TextureManager.getInstance();
Texture texture2 = new Texture(res.openRawResource(R.raw.alphatest));
tm.addTexture("texture2", texture2);
sphere1 = Primitives.getSphere(20, 20);
sphere1.calcTextureWrapSpherical();
sphere1.setTexture("texture2");
sphere2=sphere1.cloneObject();
sphere3=sphere1.cloneObject();
cube = Primitives.getCube(2);
sphere2.translate(0, 0, 20);
sphere3.translate(0, 0, 40);
cube.translate(10, -40, -30);//-40
cube.setAdditionalColor(RGBColor.GREEN);
world.addObject(sphere1);
world.addObject(sphere2);
world.addObject(sphere3);
world.addObject(cube);
// Setup collision modes
sphere1.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
sphere2.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
sphere3.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
cube.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
world.setAmbientLight(255, 255, 255);
world.buildAllObjects();
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.moveCamera(Camera.CAMERA_MOVEUP, 60);
cam.lookAt(sphere2.getTransformedCenter());
MemoryHelper.compact();
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
}
public void onDrawFrame(GL10 gl) {
try {
if (!stop) {
// Do collision dections
SimpleVector trsn=cube.checkForCollisionEllipsoid(move, ellips, 5);
//SimpleVector trsn=cube.checkForCollisionSpherical(move, 7);
cube.translate(trsn);
if (cube.getTranslation(tmp).z>100) {
// Restart at the beginning...
cube.clearTranslation();
cube.translate(10, -40, -30);
}
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
fps++;
if (System.currentTimeMillis()-time>=1000) {
System.out.println(fps+"fps");
fps=0;
time=System.currentTimeMillis();
}
} else {
if (fb != null) {
fb.dispose();
fb = null;
}
}
} catch (Exception e) {
e.printStackTrace();
Logger.log("Drawing thread terminated!", Logger.MESSAGE);
}
}
}
}