示例#1
0
	CollisionMesh::CollisionMesh(std::shared_ptr<Mesh> mesh, bool dynamic) : CollisionBody((dynamic ? DYNAMIC_MESH : STATIC_MESH)), mesh_file(mesh) {
		this->mesh_file = mesh;
		this->mesh = GenerateTriangleMesh(this->mesh_file);
		if (!this->mesh) {
			return;
		}
		glm::vec3 entity_scale(1.0);
		switch (this->collision_shape) {
			case STATIC_MESH:
				{
					auto mesh_shape = std::make_shared<btBvhTriangleMeshShape>(this->mesh.get(), true);
					mesh_shape->setLocalScaling(btVector3(entity_scale.x, entity_scale.y, entity_scale.z));
					this->shape = mesh_shape;
				}

				// Static BvhTriangleMehes must have a mass of 0.
				this->mass = 0;
				break;
			case DYNAMIC_MESH:
				{
					auto mesh_shape = std::make_shared<btGImpactMeshShape>(this->mesh.get());
					mesh_shape->setLocalScaling(btVector3(entity_scale.x, entity_scale.y, entity_scale.z));
					mesh_shape->updateBound();
					this->shape = mesh_shape;
				}
				break;
		}
	}
BulletHeightFieldShape::BulletHeightFieldShape(Texture * _heightMap, glm::vec3 _scale, unsigned long int _upAxis) :
	heightMap(_heightMap),
	btHeightfieldTerrainShape(_heightMap->width, _heightMap->height, _heightMap->data, (_upAxis == 0 ? _scale.x : (_upAxis == 1 ? _scale.y : _scale.z)), sweet::TextureUtils::getMin(_heightMap), sweet::TextureUtils::getMax(_heightMap), _upAxis, PHY_ScalarType::PHY_UCHAR, false)
{
	heightMap->incrementReferenceCount();
	setLocalScaling(btVector3(_upAxis == 0 ? 1 : _scale.x, _upAxis == 1 ? 1 : _scale.y, _upAxis == 2 ? 1 : _scale.z));
}