Hello,
I am into the first few hours of learning to build Android apps and my (overambitious) toy-project uses jPCT-AE and jBullet for graphics and physics.
Your example has been fantastic: It gave me a working sample to dissect and play with and flattened the learning-curve a lot for me.
Still I am merely a stumbling idiot in these things, but maybe you can give me a pointer in one simple area: I can't make the initial positions of the boxes rotated.
In your example I tried to hack into addBox():
public void addBox(int x, int y, int z) {
BoxShape shape = new BoxShape(new Vector3f(2, 2, 2));
float mass = 20;
Vector3f localInertia = new Vector3f(0, 0, 0);
shape.calculateLocalInertia(mass, localInertia);
Object3D boxgfx = new Object3D(sBox);
boxgfx.translate(x, y, z);
boxgfx.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
boxgfx.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
boxgfx.build();
world.addObject(boxgfx);
JPCTBulletMotionState ms = new JPCTBulletMotionState(boxgfx);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, shape, localInertia);
RigidBody body = new RigidBody(rbInfo);
body.setRestitution(0.3f);
body.setFriction(0.8f);
body.setDamping(0, 0);
body.setUserPointer(boxgfx);
boxgfx.setUserObject(body);
bodyList.add(body);
dynamicWorld.addRigidBody(body);
}
I can see the call to boxgfx.translate that puts the graphical representation of the box into the place specified by the caller. Later that transform is picked up by the MotionState and transferred to the jBullet RigidBody to take part in the physics simulation.
So I thought to make things more interesting I would only have to rotate boxgfx in addition to the translation. So I tried something like
boxgfx.rotateX(30f);
or
boxgfx.rotateAxis(new SimpleVector(0, 1, 0), 30);
but neither makes any difference. The boxes are still neatly aligned with the axes.
For reference here's the MotionState-method that copies from graphic representation to jBullet. It looks pretty to me and seems to handle rotation:
private void setTransformFromGraphic(Transform tran) {
SimpleVector p = SimpleVector.create();
obj3d.getTransformedCenter(p);
tran.origin.set(p.x, -p.y, -p.z);
Matrix matrixGfx = obj3d.getRotationMatrix();
Log.v(JoggleBoardActivity.TAG, matrixGfx.toString());
matrixGfx.fillDump(matDump);
MatrixUtil.getOpenGLSubMatrix(tran.basis, matDump);
}
Thanks to anyone that looks at this questions, I am happy with any hinton what to try or what to read next.
Ciao, MM