What type of Collision Shape are better for Terrain?
What type of Collision Shape are better for Terrain?
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
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?
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?
Yeah, it's like heightmap based. There are no caves or something like this, if you meant it.xexuxjy wrote: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?
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.
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?
I will be very grateful!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.
Re: What type of Collision Shape are better for Terrain?
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 356 times
-
- HeightfieldTerrainShape.txt
- (21.05 KiB) Downloaded 413 times
Re: What type of Collision Shape are better for Terrain?
Where I can find
Code: Select all
import cz.advel.stack.Stack;
Re: What type of Collision Shape are better for Terrain?
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
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.
Re: What type of Collision Shape are better for Terrain?
i've included a patched version of the jbullet jar below
- Attachments
-
- patched-jbullet.txt
- (696.45 KiB) Downloaded 356 times
Re: What type of Collision Shape are better for Terrain?
Thanks! You know, with patcher-bullet i have exception
But with standart JBullet all is okey
It appears when i callException 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)
Code: Select all
CollisionShape terrainShape = new ConvexHullShape(terrain.GetVertexes());
Re: What type of Collision Shape are better for Terrain?
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
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 348 times
Re: What type of Collision Shape are better for Terrain?
Thanks! Now all right! Going to understand how to initialize heightfield...
Re: What type of Collision Shape are better for Terrain?
Heh. Can you explain me plz how to initialize it?
Now I trying like this
and throw a ball at Vector3f(5,10,5), but ball goes through
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);
Re: What type of Collision Shape are better for Terrain?
I'll get the heightfield demo working and let you know.
Re: What type of Collision Shape are better for Terrain?
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