Page 1 of 2

What type of Collision Shape are better for Terrain?

Posted: Mon Jan 19, 2015 6:19 pm
by Chaz
Hello. Actually I use JBullet so I have power from Bullet 2.72.
Please, give me an advice, what type of collision shape will be better for terrain?
p.s. my english is not so good and first time i have used ConvexHullShape, it was so big failure xD

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 9:49 am
by xexuxjy
Depends on the form of your terrain really. Theres a grid/heightmap based shape, or failing that bvhTriangleMesh for more complex versions.

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 10:54 am
by Chaz
xexuxjy wrote:Depends on the form of your terrain really. Theres a grid/heightmap based shape, or failing that bvhTriangleMesh for more complex versions.
Yeah, it's like heightmap based. There are no caves or something like this, if you meant it.

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 11:44 am
by xexuxjy
Yep exactly. In which case btHeightfieldTerrainShape should do the trick.
Just had a quick look and seems as though it doesn't exist in JBullet as it stands, which is a bit annoying. It's a pretty simple shape collision shape though so shouldn't be too difficult to add in. I'll see if I can drag together a version that works.

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 12:34 pm
by Chaz
xexuxjy wrote:Yep exactly. In which case btHeightfieldTerrainShape should do the trick.
Just had a quick look and seems as though it doesn't exist in JBullet as it stands, which is a bit annoying. It's a pretty simple shape collision shape though so shouldn't be too difficult to add in. I'll see if I can drag together a version that works.
I will be very grateful!

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 1:54 pm
by xexuxjy
Give this a try... (you'll need to rename the .txt to .java) , it's based off my c# version and hopefully I've found all the stack.allocs needed for JBullet. As it stands it expects the heightmap data as a float[] but you can change that.

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 2:21 pm
by Chaz
Image
Where I can find

Code: Select all

import cz.advel.stack.Stack;
? xD

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 2:55 pm
by xexuxjy
it should be in lib/jstackalloc/stack-alloc.jar as part of the normal jbullet distribution.

Have you built JBullet from source before? if not it's a little tricky making sure that the instrumentor runs correctly on it.

If you're using eclipse, you might find this project setup helpful :

http://code.google.com/p/bullet-xna/dow ... akechanges

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 3:09 pm
by xexuxjy
i've included a patched version of the jbullet jar below

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 4:15 pm
by Chaz
Thanks! You know, with patcher-bullet i have exception
Exception in thread "main" java.lang.Error: not instrumented
at cz.advel.stack.Stack.alloc(Stack.java:110)
at com.bulletphysics.collision.shapes.ConvexHullShape.batchedUnitVectorGetSupportingVertexWithoutMargin(ConvexHullShape.java:124)
at com.bulletphysics.collision.shapes.PolyhedralConvexShape.recalcLocalAabb(PolyhedralConvexShape.java:179)
at com.bulletphysics.collision.shapes.ConvexHullShape.<init>(ConvexHullShape.java:57)
at Main.setUpPhysics(Main.java:119)
at Main.main(Main.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
It appears when i call

Code: Select all

      CollisionShape terrainShape = new ConvexHullShape(terrain.GetVertexes());
But with standart JBullet all is okey

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 4:35 pm
by xexuxjy
oops. sorry .looks like i added my original project version rather than the instrumented one. try this.

If you're using eclipse, you might find this project setup helpful :

http://code.google.com/p/bullet-xna/dow ... akechanges

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 4:53 pm
by Chaz
Thanks! Now all right! Going to understand how to initialize heightfield...

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 6:20 pm
by Chaz
Heh. Can you explain me plz how to initialize it?
Now I trying like this

Code: Select all

CollisionShape terrainShape = new HeightfieldTerrainShape(10,10,new float[]{0,0,0,0,0,0,0,0,0,0},1,0,0,1,true);
        Transform terrainTransform = new Transform(new Matrix4f(new Quat4f(0,0,0.0f,1),new Vector3f(0,0,0),1.0f));
        MotionState terrainMotionState = new DefaultMotionState();
        RigidBodyConstructionInfo terrainBodyConstructionInfo = new RigidBodyConstructionInfo(0, terrainMotionState, terrainShape, new Vector3f(0,0,0));
        terrainBodyConstructionInfo.restitution=0.25f;
        terrainRigidBody = new RigidBody(terrainBodyConstructionInfo);
        dynamicsWorld.addRigidBody(terrainRigidBody);
and throw a ball at Vector3f(5,10,5), but ball goes through

Re: What type of Collision Shape are better for Terrain?

Posted: Tue Jan 20, 2015 9:29 pm
by xexuxjy
I'll get the heightfield demo working and let you know.

Re: What type of Collision Shape are better for Terrain?

Posted: Fri Jan 23, 2015 1:02 pm
by xexuxjy
well I'm stumped at the moment I'm afraid. Height map works 'inconsistently' unless all all the height values are the same, i.e. it's flat. Mesh renders correctly in debug draw and normals for surfaces seem correct just most of the time things fall through the world anyway. Changing collision shape size or initial speed don't seem to help much and for the life of me I can't see how it's being handled any differently then in the concave mesh demo in terms of the triangle processing. If I have any flashes of inspiration I'll update this but stuck for now sorry :(