Ejemplo n.º 1
0
	TemporalObject::TemporalObject(const CollisionShape3D *shape, const PhysicsTransform &from, const PhysicsTransform &to) :
		shape(shape),
		localObject(shape->toConvexObject(PhysicsTransform())),
		from(from),
		to(to)
	{

	}
Ejemplo n.º 2
0
	void BodyShapeDisplayer::displayBodyShapeFor(const SceneObject *sceneObject)
	{
		cleanCurrentDisplay();

		if(sceneObject)
		{
			const Transform<float> &modelTransform = sceneObject->getModel()->getTransform();
			std::shared_ptr<const CollisionShape3D> bodyShape = sceneObject->getRigidBody()->getScaledShape();

			if(bodyShape->isConcave())
			{
				PhysicsTransform transform(modelTransform.getPosition(), modelTransform.getOrientation());
				AABBox<float> heightfieldAABBox = bodyShape->toAABBox(transform);

				GeometryModel *geometryModel = new AABBoxModel(heightfieldAABBox);
				geometryModel->setColor(0.0, 1.0, 0.0);
				bodyShapeModels.push_back(geometryModel);
			} else if(bodyShape->isCompound())
			{
				const auto *compoundShape = dynamic_cast<const CollisionCompoundShape *>(bodyShape.get());
				const std::vector<std::shared_ptr<const LocalizedCollisionShape>> &localizedShapes = compoundShape->getLocalizedShapes();
				for (const auto &localizedShape : localizedShapes)
				{
					PhysicsTransform transform = PhysicsTransform(modelTransform.getPosition(), modelTransform.getOrientation()) * localizedShape->transform;
					std::unique_ptr<CollisionConvexObject3D, ObjectDeleter> bodyObject = localizedShape->shape->toConvexObject(transform);

					GeometryModel *geometryModel = retrieveSingleGeometry(localizedShape->shape->getShapeType(), bodyObject);

					if (selectedCompoundShapeComponent != nullptr && selectedCompoundShapeComponent->position == localizedShape->position)
					{
						geometryModel->setColor(1.0, 1.0, 1.0);
					} else
					{
						geometryModel->setColor(0.0, 1.0, 0.0);
					}

					bodyShapeModels.push_back(geometryModel);
				}
			} else if(bodyShape->isConvex())
			{
				PhysicsTransform transform(modelTransform.getPosition(), modelTransform.getOrientation());
				std::unique_ptr<CollisionConvexObject3D, ObjectDeleter> bodyObject = bodyShape->toConvexObject(transform);

				GeometryModel *geometryModel = retrieveSingleGeometry(bodyShape->getShapeType(), bodyObject);
				geometryModel->setColor(0.0, 1.0, 0.0);
				bodyShapeModels.push_back(geometryModel);
			} else
			{
				throw std::invalid_argument("Unknown shape type category: " + std::to_string(bodyShape->getShapeType()));
			}

			for (auto &bodyShapeModel : bodyShapeModels)
			{
				sceneManager->getActiveRenderer3d()->getGeometryManager()->addGeometry(bodyShapeModel);
			}
		}
	}
	Vector3<float> CollisionConvexHullShape::computeLocalInertia(float mass) const
	{
		AABBox<float> aabbox = toAABBox(PhysicsTransform());
		float width = 2.0 * aabbox.getHalfSize(0);
		float height = 2.0 * aabbox.getHalfSize(1);
		float depth = 2.0 * aabbox.getHalfSize(2);

		float localInertia1 = (1.0/12.0) * mass * (height*height + depth*depth);
		float localInertia2 = (1.0/12.0) * mass * (width*width + depth*depth);
		float localInertia3 = (1.0/12.0) * mass * (width*width + height*height);
		return Vector3<float>(localInertia1, localInertia2, localInertia3);
	}
	void CollisionConvexHullShape::initializeDistances()
	{
		AABBox<float> aabbox = toAABBox(PhysicsTransform());
		maxDistanceToCenter = aabbox.getMaxHalfSize();
		minDistanceToCenter = aabbox.getMinHalfSize();
	}