btHeightfieldTerrainShape has wrong heights

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

btHeightfieldTerrainShape has wrong heights

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

Re: btHeightfieldTerrainShape has wrong heights

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

Re: btHeightfieldTerrainShape has wrong heights

Post 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.
Post Reply