Problem with terrain

shanefarris
Posts: 1
Joined: Sat Sep 19, 2009 9:06 pm

Problem with terrain

Post by shanefarris »

I am having a problem using a hightmap shape with bullet and ogre as the rendering engine. I think I am not setting the terrrain position correctly, can someone help me out? Here is the code I have:

Code: Select all

int upIndex = 1;
			bool useFloatDatam=true;
			bool flipQuadEdges=bFlip;

			btHeightfieldTerrainShape* pHeightShape = 
				new btHeightfieldTerrainShape(width, length, pHeightData, scale.y, upIndex, useFloatDatam, flipQuadEdges);
			pHeightShape->setUseDiamondSubdivision(true);

			mShape = pHeightShape;

			btVector3 sc(scale.x, scale.y, scale.z);
			mShape->setLocalScaling(sc);
This is the position, and I think this may be wrong:

Code: Select all

reVector3Df terrainShiftPos(page_size, 0.0, page_size);
terrainShiftPos *= terrainScale;
terrainShiftPos /= 2;
Then adding the rigid body:

Code: Select all

mState = new ObjectState(this);

        mRootNode = node;

        mShapeNode = mRootNode->createChildSceneNode(mName + "Node");
        mShapeNode->attachObject(this);

        node->setPosition (pos);
        node->setOrientation (quat);

        mShape = shape;
        showDebugShape(mWorld->getShowDebugShapes());

        btRigidBody *body = new btRigidBody(0.0, mState, mShape->getBulletShape ());

        body->setRestitution(bodyRestitution);
        body->setFriction(bodyFriction);

        body->getWorldTransform().setOrigin(btVector3(pos.x, pos.y, pos.z));
        body->getWorldTransform().setRotation(btQuaternion(quat.x, quat.y, quat.z, quat.w));

        mObject = body;
		getDynamicsWorld()->addRigidBody(this, mCollisionGroup, mCollisionMask);
As you can see the code is wrapped a little bit, but you get the idea. I read someone that in 2.74 the way we tell bullet the terrain position has changed. I looked around and can't find the correct way of informing Bullet the position. On top of that, I think I could be totally wrong on how I am implementing this.

Right now the only thing that happens is my test object just falls through the terrain. If I change the position to:

Code: Select all

reVector3Df terrainShiftPos( (terrainScale.x * (page_size - 1) / 2), \
                                   (terrainScale.y * terrainScale.y / 2), \
                                  (terrainScale.z * (page_size - 1) / 2));

The test object will seem to randomly bump into the air, and then slid horizontally in a straight like in the air along the terrain.

Any ideas?