Daniele Bartolini пре 10 година
родитељ
комит
065691ab95

+ 0 - 481
engine/physics/actor.cpp

@@ -1,481 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#include "actor.h"
-#include "matrix4x4.h"
-#include "physics_resource.h"
-#include "quaternion.h"
-#include "scene_graph.h"
-#include "unit.h"
-#include "vector3.h"
-#include "world.h"
-#include "physics_world.h"
-#include "quaternion.h"
-#include "string_utils.h"
-#include "PxPhysicsAPI.h"
-#include "PxCooking.h"
-#include "PxDefaultStreams.h"
-
-using namespace physx;
-
-namespace crown
-{
-
-Actor::Actor(PhysicsWorld& pw, const ActorResource* ar, SceneGraph& sg, UnitId unit_id)
-	: m_world(pw)
-	, m_resource(ar)
-	, m_scene_graph(sg)
-	, m_unit(unit_id)
-{
-	create_objects();
-}
-
-Actor::~Actor()
-{
-	destroy_objects();
-}
-
-void Actor::create_objects()
-{
-	const ActorResource* actor = m_resource;
-
-	PxScene* scene = m_world.physx_scene();
-	PxPhysics* physics = m_world.physx_physics();
-	const PhysicsConfigResource* config = m_world.resource();
-	const PhysicsActor2* actor_class = physics_config_resource::actor(config, actor->actor_class);
-
-	// Create rigid body
-	TransformInstance ti = m_scene_graph.get(m_unit);
-	const Matrix4x4 tr = m_scene_graph.world_pose(ti);
-	const PxMat44 pose((PxReal*) matrix4x4::to_float_ptr(tr));
-
-	if (actor_class->flags & PhysicsActor2::DYNAMIC)
-	{
-		m_actor = physics->createRigidDynamic(PxTransform(pose));
-		if (actor_class->flags & PhysicsActor2::KINEMATIC)
-		{
-			static_cast<PxRigidDynamic*>(m_actor)->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, true);
-		}
-
-		if (actor->flags != 0)
-		{
-			PxD6Joint* d6 = PxD6JointCreate(*physics, m_actor, PxTransform::createIdentity(), NULL, PxTransform(pose));
-			d6->setMotion(PxD6Axis::eX, !(actor->flags & ActorFlags::LOCK_TRANSLATION_X) ? PxD6Motion::eFREE : PxD6Motion::eLOCKED);
-			d6->setMotion(PxD6Axis::eY, !(actor->flags & ActorFlags::LOCK_TRANSLATION_Y) ? PxD6Motion::eFREE : PxD6Motion::eLOCKED);
-			d6->setMotion(PxD6Axis::eZ, !(actor->flags & ActorFlags::LOCK_TRANSLATION_Z) ? PxD6Motion::eFREE : PxD6Motion::eLOCKED);
-			d6->setMotion(PxD6Axis::eTWIST, !(actor->flags & ActorFlags::LOCK_ROTATION_X) ? PxD6Motion::eFREE : PxD6Motion::eLOCKED);
-			d6->setMotion(PxD6Axis::eSWING1, !(actor->flags & ActorFlags::LOCK_ROTATION_Y) ? PxD6Motion::eFREE : PxD6Motion::eLOCKED);
-			d6->setMotion(PxD6Axis::eSWING2, !(actor->flags & ActorFlags::LOCK_ROTATION_Z) ? PxD6Motion::eFREE : PxD6Motion::eLOCKED);
-		}
-	}
-	else
-	{
-		m_actor = physics->createRigidStatic(PxTransform(pose));
-	}
-
-	// Create shapes
-	for (uint32_t i = 0; i < actor->num_shapes; ++i)
-	{
-		const ShapeResource* shape = actor_resource::shape(m_resource, i);
-		const PhysicsShape2* shape_class = physics_config_resource::shape(config, shape->shape_class);
-		const PhysicsMaterial* material = physics_config_resource::material(config, shape->material);
-
-		PxMaterial* mat = physics->createMaterial(material->static_friction, material->dynamic_friction, material->restitution);
-
-		PxShape* px_shape = NULL;
-		switch(shape->type)
-		{
-			case ShapeType::SPHERE:
-			{
-				px_shape = m_actor->createShape(PxSphereGeometry(shape->data_0), *mat);
-				break;
-			}
-			case ShapeType::CAPSULE:
-			{
-				px_shape = m_actor->createShape(PxCapsuleGeometry(shape->data_0, shape->data_1), *mat);
-				break;
-			}
-			case ShapeType::BOX:
-			{
-				px_shape = m_actor->createShape(PxBoxGeometry(shape->data_0, shape->data_1, shape->data_2), *mat);
-				break;
-			}
-			case ShapeType::PLANE:
-			{
-				px_shape = m_actor->createShape(PxPlaneGeometry(), *mat);
-				break;
-			}
-			case ShapeType::CONVEX_MESH:
-			{
-				// MeshResource* resource = (MeshResource*) device()->resource_manager()->get(MESH_TYPE, shape->resource.name);
-
-				// PxConvexMeshDesc convex_mesh_desc;
-				// convex_mesh_desc.points.count		= resource->num_vertices();
-				// convex_mesh_desc.points.stride		= sizeof(PxVec3);
-				// convex_mesh_desc.points.data		= (PxVec3*) resource->vertices();
-				// convex_mesh_desc.triangles.count	= resource->num_indices();
-				// convex_mesh_desc.triangles.stride	= 3 * sizeof(PxU16);
-				// convex_mesh_desc.triangles.data 	= (PxU16*) resource->indices();
-				// convex_mesh_desc.flags				= PxConvexFlag::eCOMPUTE_CONVEX;
-				// convex_mesh_desc.vertexLimit		= MAX_PHYSX_VERTICES;
-
-				// PxDefaultMemoryOutputStream buf;
-				// if(!m_world.physx_cooking()->cookConvexMesh(convex_mesh_desc, buf))
-				// 	CE_FATAL("");
-				// PxDefaultMemoryInputData input(buf.getData(), buf.getSize());
-				// PxConvexMesh* convex_mesh = physics->createConvexMesh(input);
-
-				// px_shape = m_actor->createShape(PxConvexMeshGeometry(convex_mesh), *mat);
-				break;
-			}
-			default:
-			{
-				CE_FATAL("Oops, unknown shape type");
-			}
-		}
-
-		// Setup shape pose
-		if (shape->type == ShapeType::PLANE)
-		{
-			px_shape->setLocalPose(PxTransformFromPlaneEquation(
-				PxPlane(shape->data_0, shape->data_1, shape->data_2, shape->data_3)));
-		}
-		else
-		{
-			px_shape->setLocalPose(PxTransform(
-				PxVec3(shape->position.x, shape->position.y, shape->position.z),
-				PxQuat(shape->rotation.x, shape->rotation.y, shape->rotation.z, shape->rotation.w).getNormalized()));
-		}
-
-		// Setup collision filters
-		PxFilterData filter_data;
-		filter_data.word0 = physics_config_resource::filter(config, shape_class->collision_filter)->me;
-		filter_data.word1 = physics_config_resource::filter(config, shape_class->collision_filter)->mask;
-		px_shape->setSimulationFilterData(filter_data);
-
-		if (shape_class->trigger)
-		{
-			px_shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false);
-			px_shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true);
-		}
-	}
-
-	if (is_dynamic())
-	{
-		PxRigidBodyExt::updateMassAndInertia(*static_cast<PxRigidBody*>(m_actor), actor->mass);
-	}
-	m_actor->userData = this;
-	scene->addActor(*m_actor);
-}
-
-void Actor::destroy_objects()
-{
-	if (m_actor)
-	{
-		m_world.physx_scene()->removeActor(*m_actor);
-		m_actor->release();
-	}
-}
-
-Vector3 Actor::world_position() const
-{
-	const PxTransform tr = m_actor->getGlobalPose();
-	return Vector3(tr.p.x, tr.p.y, tr.p.z);
-}
-
-Quaternion Actor::world_rotation() const
-{
-	const PxTransform tr = m_actor->getGlobalPose();
-	return Quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w);
-}
-
-Matrix4x4 Actor::world_pose() const
-{
-	const PxTransform tr = m_actor->getGlobalPose();
-	return Matrix4x4(Quaternion(tr.q.x, tr.q.y, tr.q.z, tr.q.w), Vector3(tr.p.x, tr.p.y, tr.p.z));
-}
-
-void Actor::teleport_world_position(const Vector3& p)
-{
-	PxTransform tr = m_actor->getGlobalPose();
-	tr.p.x = p.x;
-	tr.p.y = p.y;
-	tr.p.z = p.z;
-	m_actor->setGlobalPose(tr);
-}
-
-void Actor::teleport_world_rotation(const Quaternion& r)
-{
-	PxTransform tr = m_actor->getGlobalPose();
-	tr.q.x = r.x;
-	tr.q.y = r.y;
-	tr.q.z = r.z;
-	tr.q.w = r.w;
-	m_actor->setGlobalPose(tr);
-}
-
-void Actor::teleport_world_pose(const Matrix4x4& m)
-{
-	using namespace matrix4x4;
-
-	const PxVec3 x(m.x.x, m.x.y, m.x.z);
-	const PxVec3 y(m.y.x, m.y.y, m.y.z);
-	const PxVec3 z(m.z.x, m.z.y, m.z.z);
-	const PxVec3 t(translation(m).x, translation(m).y, translation(m).z);
-	m_actor->setGlobalPose(PxTransform(PxMat44(x, y, z, t)));
-}
-
-Vector3 Actor::center_of_mass() const
-{
-	if (is_static())
-		return Vector3(0, 0, 0);
-
-	const PxTransform tr = static_cast<PxRigidBody*>(m_actor)->getCMassLocalPose();
-	return Vector3(tr.p.x, tr.p.y, tr.p.z);
-}
-
-void Actor::enable_gravity()
-{
-	m_actor->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, false);
-}
-
-void Actor::disable_gravity()
-{
-	m_actor->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, true);
-}
-
-void Actor::enable_collision()
-{
-	// const PxU32 num_shapes = m_actor->getNbShapes();
-	// PxU32 idx = 0;
-
-	// while (idx != num_shapes)
-	// {
-	// 	PxShape* shapes[8];
-	// 	const PxU32 written = m_actor->getShapes(shapes, 8, idx);
-
-	// 	for (PxU32 i = 0; i < written; i++)
-	// 	{
-	// 		PxFilterData fdata;
-	// 		fdata.word0 = 0;
-	// 		fdata.word1 = 0;
-	// 		shapes[i]->setSimulationFilterData(fdata);
-	// 	}
-
-	// 	idx += written;
-	// }
-}
-
-void Actor::disable_collision()
-{
-}
-
-void Actor::set_collision_filter(const char* name)
-{
-	set_collision_filter(StringId32(name));
-}
-
-void Actor::set_collision_filter(StringId32 filter)
-{
-	const PhysicsCollisionFilter* pcf = physics_config_resource::filter(m_world.resource(), filter);
-
-	const PxU32 num_shapes = m_actor->getNbShapes();
-	PxU32 idx = 0;
-
-	while (idx != num_shapes)
-	{
-		PxShape* shapes[8];
-		const PxU32 written = m_actor->getShapes(shapes, 8, idx);
-
-		for (PxU32 i = 0; i < written; i++)
-		{
-			PxFilterData fdata;
-			fdata.word0 = pcf->me;
-			fdata.word1 = pcf->mask;
-			shapes[i]->setSimulationFilterData(fdata);
-		}
-
-		idx += written;
-	}
-}
-
-void Actor::set_kinematic(bool kinematic)
-{
-	if (is_static())
-		return;
-
-	static_cast<PxRigidBody*>(m_actor)->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, kinematic);
-}
-
-void Actor::move(const Vector3& pos)
-{
-	if (!is_kinematic())
-		return;
-
-	const PxVec3 position(pos.x, pos.y, pos.z);
-	static_cast<PxRigidDynamic*>(m_actor)->setKinematicTarget(PxTransform(position));
-}
-
-bool Actor::is_static() const
-{
-	return m_actor->getType() & PxActorType::eRIGID_STATIC;
-}
-
-bool Actor::is_dynamic() const
-{
-	return m_actor->getType() & PxActorType::eRIGID_DYNAMIC;
-}
-
-bool Actor::is_kinematic() const
-{
-	if (!is_dynamic())
-		return false;
-
-	return static_cast<PxRigidDynamic*>(m_actor)->getRigidDynamicFlags() & PxRigidDynamicFlag::eKINEMATIC;
-}
-
-bool Actor::is_nonkinematic() const
-{
-	return is_dynamic() && !is_kinematic();
-}
-
-float Actor::linear_damping() const
-{
-	if (is_static())
-		return 0;
-
-	return static_cast<PxRigidDynamic*>(m_actor)->getLinearDamping();
-}
-
-void Actor::set_linear_damping(float rate)
-{
-	if (is_static())
-		return;
-
-	static_cast<PxRigidDynamic*>(m_actor)->setLinearDamping(rate);
-}
-
-float Actor::angular_damping() const
-{
-	if (is_static())
-		return 0;
-
-	return static_cast<PxRigidDynamic*>(m_actor)->getAngularDamping();
-}
-
-void Actor::set_angular_damping(float rate)
-{
-	if (is_static())
-		return;
-
-	static_cast<PxRigidDynamic*>(m_actor)->setAngularDamping(rate);
-}
-
-Vector3 Actor::linear_velocity() const
-{
-	if (is_static())
-		return Vector3(0, 0, 0);
-
-	const PxVec3 vel = static_cast<PxRigidBody*>(m_actor)->getLinearVelocity();
-	return Vector3(vel.x, vel.y, vel.z);
-}
-
-void Actor::set_linear_velocity(const Vector3& vel)
-{
-	if (!is_nonkinematic())
-		return;
-
-	const PxVec3 velocity(vel.x, vel.y, vel.z);
-	static_cast<PxRigidBody*>(m_actor)->setLinearVelocity(velocity);
-}
-
-Vector3 Actor::angular_velocity() const
-{
-	if (is_static())
-		return Vector3(0, 0, 0);
-
-	const PxVec3 vel = static_cast<PxRigidBody*>(m_actor)->getAngularVelocity();
-	return Vector3(vel.x, vel.y, vel.z);
-}
-
-void Actor::set_angular_velocity(const Vector3& vel)
-{
-	if (!is_nonkinematic())
-		return;
-
-	const PxVec3 velocity(vel.x, vel.y, vel.z);
-	static_cast<PxRigidBody*>(m_actor)->setAngularVelocity(velocity);
-}
-
-void Actor::add_impulse(const Vector3& impulse)
-{
-	if (!is_nonkinematic())
-		return;
-
-	static_cast<PxRigidDynamic*>(m_actor)->addForce(PxVec3(impulse.x, impulse.y, impulse.z), PxForceMode::eIMPULSE);
-}
-
-void Actor::add_impulse_at(const Vector3& impulse, const Vector3& pos)
-{
-	if (!is_nonkinematic())
-		return;
-
-	PxRigidBodyExt::addForceAtPos(*static_cast<PxRigidDynamic*>(m_actor),
-		PxVec3(impulse.x, impulse.y, impulse.z),
-		PxVec3(pos.x, pos.y, pos.z),
-		PxForceMode::eIMPULSE);
-}
-
-void Actor::add_torque_impulse(const Vector3& i)
-{
-	if (!is_nonkinematic())
-		return;
-
-	static_cast<PxRigidBody*>(m_actor)->addTorque(PxVec3(i.x, i.y, i.z), PxForceMode::eIMPULSE);
-}
-
-void Actor::push(const Vector3& vel, float mass)
-{
-	add_impulse(vel * mass);
-}
-
-void Actor::push_at(const Vector3& vel, float mass, const Vector3& pos)
-{
-	add_impulse_at(vel * mass, pos);
-}
-
-bool Actor::is_sleeping()
-{
-	if (is_static())
-		return true;
-
-	return static_cast<PxRigidDynamic*>(m_actor)->isSleeping();
-}
-
-void Actor::wake_up()
-{
-	if (is_static())
-		return;
-
-	static_cast<PxRigidDynamic*>(m_actor)->wakeUp();
-}
-
-UnitId Actor::unit_id() const
-{
-	return m_unit;
-}
-
-Unit* Actor::unit()
-{
-	return (m_unit.id == INVALID_ID) ? NULL : m_world.world().get_unit(m_unit);
-}
-
-void Actor::update(const Matrix4x4& pose)
-{
-	TransformInstance ti = m_scene_graph.get(m_unit);
-	m_scene_graph.set_local_pose(ti, pose);
-}
-
-} // namespace crown

+ 0 - 176
engine/physics/actor.h

@@ -1,176 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "types.h"
-#include "math_types.h"
-#include "physics_types.h"
-#include "id_array.h"
-#include "world_types.h"
-#include "resource_types.h"
-
-#include "PxPhysics.h"
-#include "PxScene.h"
-#include "PxRigidActor.h"
-#include "PxCooking.h"
-
-using physx::PxRigidActor;
-
-namespace crown
-{
-
-#define MAX_PHYSX_VERTICES 256
-
-struct Unit;
-struct SceneGraph;
-
-/// Represents a rigid body.
-///
-/// @ingroup Physics
-struct Actor
-{
-	Actor(PhysicsWorld& pw, const ActorResource* ar, SceneGraph& sg, UnitId unit_id);
-	~Actor();
-
-	/// Returns the world position of the actor.
-	Vector3 world_position() const;
-
-	/// Returns the world rotation of the actor.
-	Quaternion world_rotation() const;
-
-	/// Returns the world pose of the actor.
-	Matrix4x4 world_pose() const;
-
-	/// Teleports the actor to the given world position.
-	void teleport_world_position(const Vector3& p);
-
-	/// Teleports the actor to the given world rotation.
-	void teleport_world_rotation(const Quaternion& r);
-
-	/// Teleports the actor to the given world pose.
-	void teleport_world_pose(const Matrix4x4& m);
-
-	/// Returns the center of mass of the actor.
-	Vector3 center_of_mass() const;
-
-	/// Enables gravity for the actor.
-	void enable_gravity();
-
-	/// Disables gravity for the actor.
-	void disable_gravity();
-
-	/// Enables collision detection for the actor.
-	void enable_collision();
-
-	/// Disables collision detection for the actor.
-	void disable_collision();
-
-	/// Sets the collision filter of the actor.
-	void set_collision_filter(const char* filter);
-	void set_collision_filter(StringId32 filter);
-
-	/// Sets whether the actor is kinematic or not.
-	/// @note This call has no effect on static actors.
-	void set_kinematic(bool kinematic);
-
-	/// Moves the actor to @a pos
-	/// @note This call only affects nonkinematic actors.
-	void move(const Vector3& pos);
-
-	/// Returns whether the actor is static.
-	bool is_static() const;
-
-	/// Returns whether the actor is dynamic.
-	bool is_dynamic() const;
-
-	/// Returns whether the actor is kinematic (keyframed).
-	bool is_kinematic() const;
-
-	/// Returns whether the actor is nonkinematic (i.e. dynamic and not kinematic).
-	bool is_nonkinematic() const;
-
-	/// Returns the linear damping of the actor.
-	float linear_damping() const;
-
-	/// Sets the linear damping of the actor.
-	void set_linear_damping(float rate);
-
-	/// Returns the angular damping of the actor.
-	float angular_damping() const;
-
-	/// Sets the angular damping of the actor.
-	void set_angular_damping(float rate);
-
-	/// Returns the linear velocity of the actor.
-	Vector3 linear_velocity() const;
-
-	/// Sets the linear velocity of the actor.
-	/// @note This call only affects nonkinematic actors.
-	void set_linear_velocity(const Vector3& vel);
-
-	/// Returns the angular velocity of the actor.
-	Vector3 angular_velocity() const;
-
-	/// Sets the angular velocity of the actor.
-	/// @note This call only affects nonkinematic actors.
-	void set_angular_velocity(const Vector3& vel);
-
-	/// Adds a linear impulse (acting along the center of mass) to the actor.
-	/// @note This call only affects nonkinematic actors.
-	void add_impulse(const Vector3& impulse);
-
-	/// Adds a linear impulse (acting along the world position @a pos) to the actor.
-	/// @note This call only affects nonkinematic actors.
-	void add_impulse_at(const Vector3& impulse, const Vector3& pos);
-
-	/// Adds a torque impulse to the actor.
-	void add_torque_impulse(const Vector3& i);
-
-	/// Pushes the actor as if it was hit by a point object with the given @a mass
-	/// travelling at the given @a velocity.
-	/// @note This call only affects nonkinematic actors.
-	void push(const Vector3& vel, float mass);
-
-	/// Like push() but applies the force at the world position @a pos.
-	/// @note This call only affects nonkinematic actors.
-	void push_at(const Vector3& vel, float mass, const Vector3& pos);
-
-	/// Returns whether the actor is sleeping.
-	bool is_sleeping();
-
-	/// Wakes the actor up.
-	void wake_up();
-
-	/// Returns the id of the unit that owns the actor.
-	UnitId unit_id() const;
-
-	/// Returns the unit that owns the actor.
-	Unit* unit();
-
-	const ActorResource* resource() const { return m_resource; }
-
-private:
-
-	void create_objects();
-	void destroy_objects();
-
-	void update(const Matrix4x4& pose);
-
-public:
-
-	PhysicsWorld& m_world;
-	const ActorResource* m_resource;
-	PxRigidActor* m_actor;
-
-	SceneGraph& m_scene_graph;
-	UnitId m_unit;
-
-private:
-
-	friend class PhysicsWorld;
-};
-
-} // namespace crown

+ 0 - 98
engine/physics/controller.cpp

@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#include "controller.h"
-#include "math_utils.h"
-#include "physics_resource.h"
-#include "scene_graph.h"
-#include "vector3.h"
-#include "physics_callback.h"
-
-#include "PxCapsuleController.h"
-#include "PxPhysicsAPI.h"
-using physx::PxCapsuleClimbingMode;
-using physx::PxCapsuleController;
-using physx::PxCapsuleControllerDesc;
-using physx::PxCCTNonWalkableMode;
-using physx::PxControllerFilters;
-using physx::PxControllerFlag;
-using physx::PxExtendedVec3;
-using physx::PxVec3;
-
-namespace crown
-{
-
-Controller::Controller(const ControllerResource* cr, SceneGraph& sg, UnitId id, PxPhysics* physics, PxControllerManager* manager)
-	: m_resource(cr)
-	, m_scene_graph(sg)
-	, _unit_id(id)
-	, m_manager(manager)
-	, m_controller(NULL)
-{
-	TransformInstance ti = sg.get(id);
-	const Vector3 pos = sg.world_position(ti);
-
-	PxCapsuleControllerDesc desc;
-	desc.climbingMode = PxCapsuleClimbingMode::eCONSTRAINED;
-	desc.nonWalkableMode = PxCCTNonWalkableMode::eFORCE_SLIDING;
-	desc.radius = cr->radius;
-	desc.height = cr->height;
-	desc.slopeLimit = cos(cr->slope_limit);
-	desc.stepOffset = cr->step_offset;
-	desc.contactOffset = cr->contact_offset;
-	desc.upDirection = PxVec3(0.0, 1.0, 0.0);
-	desc.material = physics->createMaterial(0.5f, 0.5f, 0.5f);
-	desc.position = PxExtendedVec3(pos.x, pos.y, pos.z);
-	desc.reportCallback = &m_callback;
-	CE_ASSERT(desc.isValid(), "Capsule is not valid");
-
-	m_controller = manager->createController(desc);
-	CE_ASSERT(m_controller, "Failed to create controller");
-}
-
-Controller::~Controller()
-{
-	m_controller->release();
-}
-
-void Controller::move(const Vector3& pos)
-{
-	const PxVec3 disp(pos.x, pos.y, pos.z);
-	m_flags = m_controller->move(disp, 0.001, 1.0 / 60.0, PxControllerFilters());
-}
-
-void Controller::set_height(float height)
-{
-	m_controller->resize(height);
-}
-
-Vector3 Controller::position() const
-{
-	PxExtendedVec3 pos = m_controller->getPosition();
-	return Vector3(pos.x, pos.y, pos.z);
-}
-
-bool Controller::collides_up() const
-{
-	return (m_flags & PxControllerFlag::eCOLLISION_UP) != 0;
-}
-
-bool Controller::collides_down() const
-{
-	return (m_flags & PxControllerFlag::eCOLLISION_DOWN) != 0;
-}
-
-bool Controller::collides_sides() const
-{
-	return (m_flags & PxControllerFlag::eCOLLISION_SIDES) != 0;
-}
-
-void Controller::update()
-{
-	TransformInstance ti = m_scene_graph.get(_unit_id);
-	m_scene_graph.set_local_position(ti, position());
-}
-
-} // namespace crown

+ 0 - 65
engine/physics/controller.h

@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "physics_callback.h"
-#include "world_types.h"
-#include "resource_types.h"
-#include "math_types.h"
-#include "PxController.h"
-#include "PxControllerManager.h"
-
-using physx::PxController;
-using physx::PxControllerManager;
-using physx::PxPhysics;
-using physx::PxScene;
-using physx::PxU32;
-
-namespace crown
-{
-
-struct SceneGraph;
-
-///
-/// @ingroup Physics
-struct Controller
-{
-	Controller(const ControllerResource* cr, SceneGraph& sg, UnitId id, PxPhysics* physics, PxControllerManager* manager);
-	~Controller();
-
-	/// Moves the controller to @a pos.
-	void move(const Vector3& pos);
-
-	/// Sets the contoller height.
-	void set_height(float height);
-
-	/// Returns whether the contoller collides upwards.
-	bool collides_up() const;
-
-	/// Returns whether the controller collides downwards.
-	bool collides_down() const;
-
-	/// Returns whether the controller collides sidewards.
-	bool collides_sides() const;
-
-	/// Returns the position of the controller.
-	Vector3 position() const;
-
-	void update();
-
-private:
-
-	const ControllerResource* m_resource;
-
-	SceneGraph& m_scene_graph;
-	UnitId _unit_id;
-	PxControllerManager* m_manager;
-	PxController* m_controller;
-	PxU32 m_flags;
-	PhysicsControllerCallback m_callback;
-};
-
-} // namespace crown

+ 0 - 138
engine/physics/joint.cpp

@@ -1,138 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#include "joint.h"
-#include "actor.h"
-#include "vector3.h"
-#include "physics_resource.h"
-#include "scene_graph.h"
-#include "math_utils.h"
-
-#include "PxVec3.h"
-#include "PxMat44.h"
-#include "PxRigidActor.h"
-#include "PxRigidDynamic.h"
-#include "PxRigidStatic.h"
-#include "PxBoxGeometry.h"
-
-#include "PxFixedJoint.h"
-#include "PxSphericalJoint.h"
-#include "PxRevoluteJoint.h"
-#include "PxPrismaticJoint.h"
-#include "PxDistanceJoint.h"
-#include "PxJointLimit.h"
-#include "PxTolerancesScale.h"
-#include "actor.h"
-
-using physx::PxPhysics;
-using physx::PxScene;
-
-using physx::PxTransform;
-using physx::PxVec3;
-using physx::PxMat44;
-using physx::PxRigidActor;
-using physx::PxBoxGeometry;
-using physx::PxReal;
-using physx::PxPi;
-using physx::PxConstraintFlag;
-
-using physx::PxJoint;
-using physx::PxFixedJoint;
-using physx::PxFixedJointCreate;
-
-using physx::PxSphericalJoint;
-using physx::PxSphericalJointCreate;
-using physx::PxSphericalJointFlag;
-using physx::PxJointLimitCone;
-
-using physx::PxRevoluteJoint;
-using physx::PxRevoluteJointCreate;
-using physx::PxRevoluteJointFlag;
-
-using physx::PxPrismaticJoint;
-using physx::PxPrismaticJointCreate;
-using physx::PxPrismaticJointFlag;
-
-using physx::PxDistanceJoint;
-using physx::PxDistanceJointCreate;
-using physx::PxDistanceJointFlag;
-using physx::PxJointLinearLimitPair;
-using physx::PxTolerancesScale;
-using physx::PxJointAngularLimitPair;
-
-namespace crown
-{
-
-Joint::Joint(PxPhysics* physics, const JointResource* jr, const Actor& actor_0, const Actor& actor_1)
-	: m_resource(jr)
-{
-	PxVec3 anchor_0(jr->anchor_0.x, jr->anchor_0.y, jr->anchor_0.z);
-	PxVec3 anchor_1(jr->anchor_1.x, jr->anchor_1.y, jr->anchor_1.z);
-
-	switch(jr->type)
-	{
-		case JointType::FIXED:
-		{
-			m_joint = PxFixedJointCreate(*physics, actor_0.m_actor, PxTransform(anchor_0), actor_1.m_actor, PxTransform(anchor_1));
-
-			break;
-		}
-		case JointType::SPHERICAL:
-		{
-			PxJointLimitCone limit_cone(jr->y_limit_angle, jr->z_limit_angle, jr->contact_dist);
-			limit_cone.restitution = jr->restitution;
-			limit_cone.damping = jr->damping;
-			limit_cone.contactDistance = jr->distance;
-
-			m_joint = PxSphericalJointCreate(*physics, actor_0.m_actor, PxTransform(anchor_0), actor_1.m_actor, PxTransform(anchor_1));
-			static_cast<PxSphericalJoint*>(m_joint)->setLimitCone(limit_cone);
-			static_cast<PxSphericalJoint*>(m_joint)->setSphericalJointFlag(PxSphericalJointFlag::eLIMIT_ENABLED, true);
-
-			break;
-		}
-		case JointType::REVOLUTE:
-		{
-			PxJointAngularLimitPair limit_pair(jr->lower_limit, jr->upper_limit, jr->contact_dist);
-			limit_pair.damping = jr->damping;
-
-			m_joint = PxRevoluteJointCreate(*physics, actor_0.m_actor, PxTransform(anchor_0), actor_1.m_actor, PxTransform(anchor_1));
-			static_cast<PxRevoluteJoint*>(m_joint)->setLimit(limit_pair);
-			static_cast<PxRevoluteJoint*>(m_joint)->setRevoluteJointFlag(PxRevoluteJointFlag::eLIMIT_ENABLED, true);
-
-			static_cast<PxRevoluteJoint*>(m_joint)->setDriveVelocity(10.0f);
-			static_cast<PxRevoluteJoint*>(m_joint)->setRevoluteJointFlag(PxRevoluteJointFlag::eDRIVE_ENABLED, true);
-
-			break;
-		}
-		case JointType::PRISMATIC:
-		{
-			PxJointLinearLimitPair limit_pair(PxTolerancesScale(), jr->lower_limit, jr->upper_limit, jr->contact_dist);
-			limit_pair.damping = jr->damping;
-
-			m_joint = PxPrismaticJointCreate(*physics, actor_0.m_actor, PxTransform(anchor_0), actor_1.m_actor, PxTransform(anchor_1));
-			static_cast<PxPrismaticJoint*>(m_joint)->setLimit(limit_pair);
-			static_cast<PxPrismaticJoint*>(m_joint)->setPrismaticJointFlag(PxPrismaticJointFlag::eLIMIT_ENABLED, true);
-
-			break;
-		}
-		case JointType::DISTANCE:
-		{
-			m_joint = PxDistanceJointCreate(*physics, actor_0.m_actor, PxTransform(anchor_0), actor_1.m_actor, PxTransform(anchor_1));
-			static_cast<PxDistanceJoint*>(m_joint)->setMaxDistance(jr->max_distance);
-			static_cast<PxDistanceJoint*>(m_joint)->setDistanceJointFlag(PxDistanceJointFlag::eMAX_DISTANCE_ENABLED, true);
-
-			break;
-		}
-		default:
-		{
-			CE_FATAL("Bad joint type");
-			break;
-		}
-	}
-
-	if (jr->breakable) m_joint->setBreakForce(jr->break_force, jr->break_torque);
-}
-
-} // namespace crown

+ 0 - 38
engine/physics/joint.h

@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "types.h"
-#include "resource_types.h"
-
-#include "PxPhysics.h"
-#include "PxJoint.h"
-#include "PxMaterial.h"
-
-using physx::PxPhysics;
-using physx::PxJoint;
-using physx::PxMaterial;
-
-namespace crown
-{
-
-struct Actor;
-
-///
-/// @ingroup Physics
-struct Joint
-{
-	Joint(PxPhysics* physics, const JointResource* jr, const Actor& actor_0, const Actor& actor_1);
-
-public:
-
-	const JointResource* 	m_resource;
-
-	PxJoint* 			m_joint;
-	PxMaterial* 		m_mat;
-};
-
-} // namespace crown

+ 0 - 165
engine/physics/physics_callback.h

@@ -1,165 +0,0 @@
-/*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "event_stream.h"
-#include "physics_types.h"
-#include "PxActor.h"
-#include "PxRigidActor.h"
-#include "PxController.h"
-#include "PxSimulationEventCallback.h"
-#include "PxQueryReport.h"
-#include "PxQueryFiltering.h"
-
-
-using physx::PxActor;
-using physx::PxConstraintInfo;
-using physx::PxContactPair;
-using physx::PxContactPairHeader;
-using physx::PxContactPairHeader;
-using physx::PxContactPairHeaderFlag;
-using physx::PxContactPairPoint;
-using physx::PxControllerObstacleHit;
-using physx::PxControllerShapeHit;
-using physx::PxControllersHit;
-using physx::PxSimulationEventCallback;
-using physx::PxTriggerPair;
-using physx::PxTriggerPairFlag;
-using physx::PxU32;
-using physx::PxUserControllerHitReport;
-using physx::PxVec3;
-using physx::PxRaycastCallback;
-using physx::PxAgain;
-using physx::PxRaycastHit;
-using physx::PxPairFlag;
-using physx::PxContactPairFlag;
-
-namespace crown
-{
-
-class PhysicsWorld;
-
-class PhysicsSimulationCallback : public PxSimulationEventCallback
-{
-public:
-
-	PhysicsSimulationCallback(EventStream& stream)
-		: m_events(stream)
-	{
-	}
-
-	void onConstraintBreak(PxConstraintInfo* /*constraints*/, PxU32 /*count*/)
-	{
-		// printf("COSTRAINTBREAK\n");
-	}
-
-	void onContact(const PxContactPairHeader& pair_header, const PxContactPair* pairs, PxU32 num_pairs)
-	{
-		// Do not report contact if either actor0 or actor1 or both have been deleted
-		if (pair_header.flags & PxContactPairHeaderFlag::eDELETED_ACTOR_0 ||
-			pair_header.flags & PxContactPairHeaderFlag::eDELETED_ACTOR_1) return;
-
-		for (PxU32 pp = 0; pp < num_pairs; pp++)
-		{
-			const PxContactPair& cp = pairs[pp];
-
-			// We are only interested in touch found or lost
-			if ((cp.events & PxPairFlag::eNOTIFY_TOUCH_FOUND) == (PxPairFlag::Enum)0 &&
-				(cp.events & PxPairFlag::eNOTIFY_TOUCH_LOST) == (PxPairFlag::Enum)0) continue;
-
-			// Skip if either shape0 or shape1 or both have been deleted
-			if (cp.flags & PxContactPairFlag::eDELETED_SHAPE_0 ||
-				cp.flags & PxContactPairFlag::eDELETED_SHAPE_1) continue;
-
-			PxContactPairPoint points[8];
-			const PxU32 num_points = cp.extractContacts(points, 8);
-
-			PxVec3 where(0, 0, 0);
-			PxVec3 normal(0, 0, 0);
-			for (PxU32 i = 0; i < num_points; i++)
-			{
-				where = points[i].position;
-				normal = points[i].normal;
-			}
-
-			post_collision_event((Actor*) pair_header.actors[0]->userData,
-				(Actor*) pair_header.actors[1]->userData,
-				Vector3(where.x, where.y, where.z),
-				Vector3(normal.x, normal.y, normal.z),
-				(cp.events & PxPairFlag::eNOTIFY_TOUCH_FOUND) ?
-					physics_world::CollisionEvent::BEGIN_TOUCH :
-					physics_world::CollisionEvent::END_TOUCH);
-		}
-	}
-
-	void onTrigger(PxTriggerPair* pairs, PxU32 count)
-	{
-		for (PxU32 pp = 0; pp < count; pp++)
-		{
-			const PxTriggerPair& tp = pairs[pp];
-
-			// Do not report event if either trigger ot other shape or both have been deleted
-			if (tp.flags & PxTriggerPairFlag::eDELETED_SHAPE_TRIGGER ||
-				tp.flags & PxTriggerPairFlag::eDELETED_SHAPE_OTHER) continue;
-
-			post_trigger_event((Actor*)tp.triggerActor->userData,
-				(Actor*)tp.otherActor->userData,
-				(tp.status & PxPairFlag::eNOTIFY_TOUCH_FOUND ?
-				physics_world::TriggerEvent::BEGIN_TOUCH : physics_world::TriggerEvent::END_TOUCH));
-		}
-	}
-
-	void onWake(PxActor** /*actors*/, PxU32 /*count*/)
-	{
-	}
-
-	void onSleep(PxActor** /*actors*/, PxU32 /*count*/)
-	{
-	}
-
-private:
-
-	void post_collision_event(Actor* actor0, Actor* actor1, const Vector3& where, const Vector3& normal, physics_world::CollisionEvent::Type type)
-	{
-		physics_world::CollisionEvent ev;
-		ev.type = type;
-		ev.actors[0] = actor0;
-		ev.actors[1] = actor1;
-		ev.where = where;
-		ev.normal = normal;
-		event_stream::write(m_events, physics_world::EventType::COLLISION, ev);
-	}
-
-	void post_trigger_event(Actor* trigger, Actor* other, physics_world::TriggerEvent::Type type)
-	{
-		physics_world::TriggerEvent ev;
-		ev.type = type;
-		ev.trigger = trigger;
-		ev.other = other;
-		event_stream::write(m_events, physics_world::EventType::TRIGGER, ev);
-	}
-
-private:
-
-	EventStream& m_events;
-};
-
-class PhysicsControllerCallback : public PxUserControllerHitReport
-{
-	void onShapeHit(const PxControllerShapeHit& /*hit*/)
-	{
-	}
-
-	void onControllerHit(const PxControllersHit& /*hit*/)
-	{
-	}
-
-	void onObstacleHit(const PxControllerObstacleHit& /*hit*/)
-	{
-	}
-};
-
-} // namespace crown