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.


Messages - MarianAldenhoevel

Pages: [1]
1
Projects / Got it
« on: July 26, 2013, 03:15:52 pm »
Hi,

Sometimes very little education helps a lot!

There was indeed a bug in the original example that never surfaced because the initial cubes are all axis-aligned.

Exhibit A:

Code: [Select]
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();
matrixGfx.fillDump(matDump);
MatrixUtil.getOpenGLSubMatrix(tran.basis, matDump);
}

This is supposed to update the physics transform tran from the position of the graphic object. But where it says getOpenGLSubMatrix() we need setFromOpenGLSubMatrix(). We want to update tran from matDump, not the other way round.

Code: [Select]
private void setTransformFromGraphic(Transform tran) {
SimpleVector p = obj3d.getTransformedCenter();
tran.origin.set(p.x, -p.y, -p.z);

Matrix matrixGfx = obj3d.getRotationMatrix();
matrixGfx.fillDump(matDump);
MatrixUtil.setFromOpenGLSubMatrix(tran.basis, matDump);
}

That is all. Works perfectly now.

Thank you very much again! I'm happy for now.

Ciao, MM

2
Projects / Re: Physics example
« on: July 26, 2013, 02:17:45 pm »
Thank you very much for your reply.

Do you think I have to work on the physics-side of things even on the initial creation? Translation works fine, the boxes all show up where I want them and then drop under the influence of gravity. I just can't make them appear initially not aligned with the axes.

The graphic objects are created first, then the RigidBodies to go with them and the initial position gets picked up nicely.

I tried your suggestion but to simply rotate the RigidBody I need to understand jBullets Quaternions first, I think. I did try a quick applyTorqueImpulse after the creation, but they did not care and still only fell straight down without any sign of rotation.

I think the problem is in the MotionState setTransformFromGraphic. I have a feeling that does not pick up rotation correctly. But see above for how well I understand that :-).

I'll go back and study a bit...

Ciao, MM

3
Projects / Re: Physics example
« on: July 26, 2013, 01:02:48 pm »
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():

Code: [Select]
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

Code: [Select]
boxgfx.rotateX(30f);
or

Code: [Select]
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:

Code: [Select]
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

Pages: [1]