Page 1 of 1

btHeightfieldTerrainShape has wrong heights

Posted: Tue Apr 07, 2015 11:28 am
by Chaz
Hello. Actually I use JNI wrapper of Bullet and want to create btHeightfieldTerrainShape using this code.

Code: Select all

 int res = 300;
        ByteBuffer bytes = ByteBuffer.allocateDirect(res*res*4);

        for(int i=0; i<res*res; i++)
        {
            bytes.putFloat(0);
        }

        terrainShape=new btHeightfieldTerrainShape(res,res,bytes.asFloatBuffer(),1,0.0f,0.0f,1,false);
As you can see it's just a simple plain with all height are 0.
Then i check the terrain by raycasting and creating an object in hit point.

Code: Select all

public void MylRayTest(ArrayList<ModelInstance> instances, Model model)
    {
        float max = Float.MIN_VALUE;
        float min = Float.MAX_VALUE;

        for(int i=-500; i<500; i+=5)
        {
            for(int j=-500; j<500; j+=5)
            {
                Vector3 from=new Vector3(new Vector3(i,10000,j));
                Vector3 to = new Vector3(new Vector3(i,-10000,j));
                ClosestRayResultCallback callback = new ClosestRayResultCallback(from, to);
                world.rayTest(from, to, callback);

                if(callback.hasHit())
                {
                    Vector3 t = new Vector3();
                    callback.getHitPointWorld(t);

                    instances.add(new ModelInstance(model, t));

                    float tt = t.y;
                    if(tt>max) max=tt;
                    if(tt<min) min=tt;
                }
                callback.dispose();
            }
        }
        System.out.println("Max: "+max+" Min: "+min);
    }
And what i got.
Image
As you can see it's not a simple plain. It's broken plain!
Why it happens? What is wrong?

Re: btHeightfieldTerrainShape has wrong heights

Posted: Thu Apr 09, 2015 1:40 pm
by xexuxjy
Seems reasonable, are the errors consistent, i.e. do you always see the same pattern of incorrect height values or does it vary? does changing the resolution of your heightmap alter things at all?

Re: btHeightfieldTerrainShape has wrong heights

Posted: Fri Apr 10, 2015 10:35 pm
by Chaz
xexuxjy wrote:Seems reasonable, are the errors consistent, i.e. do you always see the same pattern of incorrect height values or does it vary? does changing the resolution of your heightmap alter things at all?
It was vary. Changing the resolution of heightmap alter things, aha.
Buuut... I had that error only with FloatBuffer as heights array.
With byte array it's good.