How to scale a HeightfieldCollisionShape correctly?

Hello,

today’s problem, scaling of a HeightfieldCollisionShape.

The problem is that i can’t seem to find a method to calculate the scale factor of the collisionshape. The shape is generated from a AbstractHeightmap.
I cannot create the collisionshape from the model, because i need the collisionshape on the server where i don’t want to generate the model first.

Hard to say without knowing what the scale should be ^^ Normally it works pretty much like normal scaling… Maybe you can try and reformulate the question?

Ok, here is the math:

The map scale is 20.000
I allow different heightmap sizes based on the clients gpu and scale the resulting model with the formula:
[java]
float scale = 20000 / textureSize;
terrainNode.setLocalScale(new Vector3f(scale,terrainHeight/255,scale));
[/java]

trough this i get the same mesh for all texture sizes… well at least the same size.
The HeightmapCollisionShape gets build like:
[java]
CollisionShape collisionShape = new HeightfieldCollisionShape(terrainData.terrainHeightMap.getHeightMap());
collisionShape.setScale(?,?,?);
[/java]

The question is what values to i put in here? using the same calculation for x and z results in a mesh *very *very *very much larger then the model itself. And so does height…

Use the constructor that allows you to set the scale and set the same thing as for the terrain localScale.

1 Like

Nervermind, the scale works right, it’s just the debugmesh that is way of. Well, i can life with that i think.

As a side note, i noticed different physics behaviour between jBullet and Native, is that as expected? (Like different values for gravity and the collision mesh seems slightly moved)

Sure, both have different bugs ^^

1 Like
@normen said: Sure, both have different bugs ^^

good to know