What type of Collision Shape are better for Terrain?

Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

What type of Collision Shape are better for Terrain?

Post 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
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post by xexuxjy »

Depends on the form of your terrain really. Theres a grid/heightmap based shape, or failing that bvhTriangleMesh for more complex versions.
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

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

Post 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.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post 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.
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

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

Post 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!
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post 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.
Attachments
VectorUtil.txt
(5.06 KiB) Downloaded 124 times
HeightfieldTerrainShape.txt
(21.05 KiB) Downloaded 146 times
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

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

Post by Chaz »

Image
Where I can find

Code: Select all

import cz.advel.stack.Stack;
? xD
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post 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
Last edited by xexuxjy on Tue Jan 20, 2015 4:36 pm, edited 1 time in total.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post by xexuxjy »

i've included a patched version of the jbullet jar below
Attachments
patched-jbullet.txt
(696.45 KiB) Downloaded 110 times
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

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

Post 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
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post 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
Attachments
patched-jbullet.txt
(713.94 KiB) Downloaded 116 times
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

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

Post by Chaz »

Thanks! Now all right! Going to understand how to initialize heightfield...
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

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

Post 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
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post by xexuxjy »

I'll get the heightfield demo working and let you know.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

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

Post 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 :(
Post Reply