瀏覽代碼

Finalize the port

Panagiotis Christopoulos Charitos 7 年之前
父節點
當前提交
a670013588

+ 4 - 18
CMakeLists.txt

@@ -137,8 +137,6 @@ set(CXX_FLAGS "")
 set(COMPILER_FLAGS "")
 set(LINKER_FLAGS "")
 
-add_definitions(-D_NEWTON_STATIC_LIB -D_CUSTOM_JOINTS_STATIC_LIB)
-
 if(NOT MSVC)
 	if(ARCH_64)
 		add_definitions(-D_POSIX_VER_64)
@@ -147,13 +145,6 @@ if(NOT MSVC)
 	endif()
 endif()
 
-# Newton wants that
-if(MINGW AND ARCH_64)
-	add_definitions(-D_MINGW_64_VER)
-elseif(MINGW AND ARCH_32)
-	add_definitions(-D_MINGW_32_VER)
-endif()
-
 if(MINGW)
 	set(COMPILER_FLAGS "${COMPILER_FLAGS} -mconsole ")
 endif()
@@ -235,7 +226,7 @@ endif()
 ################################################################################
 # Thirdparty                                                                   #
 ################################################################################
-set(ANKI_EXTERN_SUB_DIRS tinyxml2 lua z newton bullet)
+set(ANKI_EXTERN_SUB_DIRS tinyxml2 lua z bullet)
 
 # Bullet config
 option(BUILD_BULLET2_DEMOS OFF)
@@ -362,11 +353,6 @@ include_directories("src"
 	"${SDL2_INCLUDE_DIRS}"
 	"thirdparty/freetype/include"
 	"${CMAKE_CURRENT_BINARY_DIR}/thirdparty/freetype/include/freetype2"
-	"thirdparty/newton/coreLibrary_300/source/newton"
-	"thirdparty/newton/packages/dCustomJoints"
-	"thirdparty/newton/packages/dContainers"
-	"thirdparty/newton/packages/dMath"
-	"thirdparty/newton/packages/thirdParty/timeTracker/"
 	"thirdparty/khronos"
 	"${CMAKE_CURRENT_BINARY_DIR}"
 	"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glslang"
@@ -434,8 +420,8 @@ if(SDL)
 	set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} SDL2-static)
 endif()
 
-set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} ankispirvcross glslang SPIRV OGLCompiler OSDependent ankitinyexpr 
-	BulletCollision BulletDynamics BulletSoftBody)
+set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} BulletSoftBody BulletDynamics BulletCollision LinearMath 
+	ankispirvcross ankitinyxml2 ankilua ankiz glslang SPIRV OGLCompiler OSDependent ankitinyexpr)
 
 # Add anki sub libraries
 set(ANKI_SUB_DIRS core script renderer scene ui event input physics resource misc gr collision math util)
@@ -445,7 +431,7 @@ endforeach()
 
 separate_arguments(AK_SOURCES)
 add_library(anki ${AK_SOURCES})
-target_link_libraries(anki ankitinyxml2 ankilua ankiz ankinewton ${THIRD_PARTY_LIBS})
+target_link_libraries(anki ${THIRD_PARTY_LIBS})
 
 ################################################################################
 # AnKi extra                                                                   #

+ 26 - 6
src/anki/physics/Common.h

@@ -13,16 +13,11 @@
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Winfinite-recursion"
 #define BT_THREADSAFE 0
+#define BT_NO_PROFILE 1
 #include <btBulletCollisionCommon.h>
 #include <btBulletDynamicsCommon.h>
 #pragma GCC diagnostic pop
 
-// Have all the newton headers here because they polute the global namespace
-#include <Newton.h>
-#include <dLinearAlgebra.h>
-#include <dCustomPlayerControllerManager.h>
-#include <anki/util/CleanupWindows.h>
-
 namespace anki
 {
 
@@ -77,6 +72,31 @@ ANKI_USE_RESULT inline btVector3 toBt(const Vec3& v)
 {
 	return btVector3(v.x(), v.y(), v.z());
 }
+
+ANKI_USE_RESULT inline btTransform toBt(const Transform& a)
+{
+	Mat4 mat(a);
+	mat.transpose();
+	btTransform out;
+	out.setFromOpenGLMatrix(&mat(0, 0));
+	return out;
+}
+
+ANKI_USE_RESULT inline Mat3x4 toAnki(const btMatrix3x3& m)
+{
+	Mat3x4 m3;
+	m3.setRows(Vec4(toAnki(m[0]), 0.0f), Vec4(toAnki(m[1]), 0.0f), Vec4(toAnki(m[2]), 0.0f));
+	return m3;
+}
+
+ANKI_USE_RESULT inline Transform toAnki(const btTransform& t)
+{
+	Transform out;
+	out.setRotation(toAnki(t.getBasis()));
+	out.setOrigin(Vec4(toAnki(t.getOrigin()), 0.0f));
+	out.setScale(1.0f);
+	return out;
+}
 /// @}
 
 } // end namespace anki

+ 34 - 91
src/anki/physics/PhysicsBody.cpp

@@ -10,119 +10,62 @@
 namespace anki
 {
 
-PhysicsBody::PhysicsBody(PhysicsWorld* world)
-	: PhysicsObject(PhysicsObjectType::BODY, world)
+class PhysicsBody::MotionState : public btMotionState
 {
-}
+public:
+	PhysicsBody* m_body = nullptr;
 
-PhysicsBody::~PhysicsBody()
-{
-	if(m_sceneCollisionProxy)
+	void getWorldTransform(btTransform& worldTrans) const override
 	{
-		NewtonCollision* scene = m_world->getNewtonScene();
-		NewtonSceneCollisionBeginAddRemove(scene);
-		NewtonSceneCollisionRemoveSubCollision(scene, m_sceneCollisionProxy);
-		NewtonSceneCollisionEndAddRemove(scene);
+		worldTrans = toBt(m_body->m_trf);
 	}
 
-	if(m_body)
+	void setWorldTransform(const btTransform& worldTrans) override
 	{
-		NewtonDestroyBody(m_body);
+		m_body->m_trf = toAnki(worldTrans);
+		m_body->m_updated = true;
 	}
-}
+};
 
-Error PhysicsBody::create(const PhysicsBodyInitInfo& init)
+PhysicsBody::PhysicsBody(PhysicsWorld* world, const PhysicsBodyInitInfo& init)
+	: PhysicsObject(PhysicsObjectType::BODY, world)
 {
-	// Create
-	dMatrix trf = toNewton(Mat4(init.m_startTrf));
-
 	if(init.m_static)
 	{
-		// Create static collision
-		NewtonCollision* scene = m_world->getNewtonScene();
-
-		NewtonSceneCollisionBeginAddRemove(scene);
-		m_sceneCollisionProxy = NewtonSceneCollisionAddSubCollision(scene, init.m_shape->getNewtonShape());
-		NewtonSceneCollisionEndAddRemove(scene);
-
-		NewtonSceneCollisionSetSubCollisionMatrix(scene, m_sceneCollisionProxy, &trf[0][0]);
-
-		return Error::NONE;
-	}
-	else if(init.m_kinematic)
-	{
-		ANKI_ASSERT(0 && "TODO");
-	}
-	else
-	{
-		m_body = NewtonCreateDynamicBody(m_world->getNewtonWorld(), init.m_shape->getNewtonShape(), &trf[0][0]);
-	}
-
-	if(!m_body)
-	{
-		ANKI_PHYS_LOGE("NewtonCreateXXBody() failed");
-		return Error::FUNCTION_FAILED;
+		ANKI_ASSERT(init.m_mass > 0.0f);
 	}
 
-	// Material
-	NewtonBodySetMaterialGroupID(m_body, NewtonMaterialGetDefaultGroupID(m_world->getNewtonWorld()));
+	// Create motion state
+	m_motionState = getAllocator().newInstance<MotionState>();
+	m_motionState->m_body = this;
 
-	// User data & callbacks
-	NewtonBodySetUserData(m_body, this);
-	NewtonBodySetTransformCallback(m_body, onTransformCallback);
-
-	// Set mass
-	NewtonCollision* shape = NewtonBodyGetCollision(m_body);
-	NewtonBodySetMassProperties(m_body, init.m_mass, shape);
-
-	// Set gravity
-	if(init.m_gravity)
+	// Compute inertia
+	btCollisionShape* shape = init.m_shape->getBtShape(!init.m_static);
+	btVector3 localInertia(0, 0, 0);
+	if(!init.m_static)
 	{
-		NewtonBodySetForceAndTorqueCallback(m_body, applyGravityForce);
+		shape->calculateLocalInertia(init.m_mass, localInertia);
 	}
 
-	// Activate
-	NewtonBodySetSimulationState(m_body, true);
+	// Create body
+	btRigidBody::btRigidBodyConstructionInfo cInfo(init.m_mass, m_motionState, shape, localInertia);
+	m_body = getAllocator().newInstance<btRigidBody>(cInfo);
 
-	return Error::NONE;
-}
-
-void PhysicsBody::setTransform(const Transform& trf)
-{
-	Mat4 mat(trf);
-	mat.transpose();
-	NewtonBodySetMatrix(m_body, &mat(0, 0));
+	getWorld().getBtWorld()->addRigidBody(m_body);
 }
 
-void PhysicsBody::onTransformCallback(const NewtonBody* const body, const dFloat* const matrix, int threadIndex)
-{
-	ANKI_ASSERT(body);
-	ANKI_ASSERT(matrix);
-
-	void* ud = NewtonBodyGetUserData(body);
-	ANKI_ASSERT(ud);
-	PhysicsBody* self = reinterpret_cast<PhysicsBody*>(ud);
-
-	Mat4 trf;
-	memcpy(&trf, matrix, sizeof(Mat4));
-	trf.transpose();
-	trf(3, 3) = 0.0;
-	self->m_trf = Transform(trf);
-	self->m_updated = true;
-}
-
-void PhysicsBody::applyGravityForce(const NewtonBody* body, dFloat timestep, int threadIndex)
+PhysicsBody::~PhysicsBody()
 {
-	dFloat Ixx;
-	dFloat Iyy;
-	dFloat Izz;
-	dFloat mass;
-
-	NewtonBodyGetMass(body, &mass, &Ixx, &Iyy, &Izz);
+	if(m_body)
+	{
+		getWorld().getBtWorld()->removeRigidBody(m_body);
+		getAllocator().deleteInstance(m_body);
+	}
 
-	const F32 GRAVITY = -9.8f;
-	Vec4 force(0.0f, mass * GRAVITY, 0.0f, 0.0f);
-	NewtonBodySetForce(body, &force[0]);
+	if(m_motionState)
+	{
+		getAllocator().deleteInstance(m_motionState);
+	}
 }
 
 } // end namespace anki

+ 10 - 12
src/anki/physics/PhysicsBody.h

@@ -29,12 +29,10 @@ public:
 class PhysicsBody : public PhysicsObject
 {
 public:
-	PhysicsBody(PhysicsWorld* world);
+	PhysicsBody(PhysicsWorld* world, const PhysicsBodyInitInfo& init);
 
 	~PhysicsBody();
 
-	ANKI_USE_RESULT Error create(const PhysicsBodyInitInfo& init);
-
 	const Transform& getTransform(Bool& updated)
 	{
 		updated = m_updated;
@@ -42,7 +40,10 @@ public:
 		return m_trf;
 	}
 
-	void setTransform(const Transform& trf);
+	void setTransform(const Transform& trf)
+	{
+		m_trf = trf;
+	}
 
 	F32 getFriction() const
 	{
@@ -70,19 +71,16 @@ public:
 	}
 
 private:
-	NewtonBody* m_body = nullptr;
-	void* m_sceneCollisionProxy = nullptr;
+	class MotionState;
+
+	MotionState* m_motionState = nullptr;
+	btRigidBody* m_body = nullptr;
+
 	Transform m_trf = Transform::getIdentity();
 	F32 m_friction = 0.03f;
 	F32 m_elasticity = 0.1f;
 	PhysicsMaterialBit m_materialBits = PhysicsMaterialBit::ALL;
 	Bool8 m_updated = true;
-
-	/// Newton callback.
-	static void onTransformCallback(const NewtonBody* const body, const dFloat* const matrix, int threadIndex);
-
-	/// Newton callback
-	static void applyGravityForce(const NewtonBody* body, dFloat timestep, int threadIndex);
 };
 /// @}
 

+ 15 - 1
src/anki/physics/PhysicsCollisionShape.cpp

@@ -40,12 +40,26 @@ PhysicsTriangleSoup::PhysicsTriangleSoup(
 			toBt(positions[indices[i]]), toBt(positions[indices[i + 1]]), toBt(positions[indices[i + 2]]));
 	}
 
-	m_shape = getAllocator().newInstance<btGImpactMeshShape>(m_mesh);
+	// Create the dynamic shape
+	btGImpactMeshShape* shape = getAllocator().newInstance<btGImpactMeshShape>(m_mesh);
+	shape->updateBound();
+	m_shape = shape;
+
+	// And the static one
+	btBvhTriangleMeshShape* triShape = getAllocator().newInstance<btBvhTriangleMeshShape>(m_mesh, true);
+	m_staticShape = triShape;
 }
 
 PhysicsTriangleSoup::~PhysicsTriangleSoup()
 {
+	getAllocator().deleteInstance(m_staticShape);
+	getAllocator().deleteInstance(m_shape);
 	getAllocator().deleteInstance(m_mesh);
 }
 
+btCollisionShape* PhysicsTriangleSoup::getBtShape(Bool forDynamicBodies) const
+{
+	return (forDynamicBodies) ? m_shape : m_staticShape;
+}
+
 } // end namespace anki

+ 4 - 1
src/anki/physics/PhysicsCollisionShape.h

@@ -26,7 +26,7 @@ public:
 	~PhysicsCollisionShape();
 
 anki_internal:
-	btCollisionShape* getBtShape() const
+	virtual btCollisionShape* getBtShape(Bool forDynamicBodies = false) const
 	{
 		ANKI_ASSERT(m_shape);
 		return m_shape;
@@ -67,6 +67,9 @@ public:
 
 private:
 	btTriangleMesh* m_mesh = nullptr;
+	btCollisionShape* m_staticShape = nullptr;
+
+	btCollisionShape* getBtShape(Bool forDynamicBodies = false) const override;
 };
 /// @}
 

+ 3 - 102
src/anki/physics/PhysicsDrawer.cpp

@@ -9,111 +9,12 @@
 namespace anki
 {
 
-struct CallbackData
-{
-	const NewtonBody* m_body;
-	PhysicsDrawer* m_drawer;
-};
-
 void PhysicsDrawer::drawWorld(const PhysicsWorld& world)
 {
-	NewtonWorld* nworld = world.getNewtonWorld();
-	for(NewtonBody* body = NewtonWorldGetFirstBody(nworld); body != nullptr;
-		body = NewtonWorldGetNextBody(nworld, body))
-	{
-		if(m_drawAabbs)
-		{
-			drawAabb(body);
-		}
-
-		if(m_drawCollision)
-		{
-			drawCollision(body);
-		}
-	}
-}
-
-void PhysicsDrawer::drawAabb(const NewtonBody* body)
-{
-	Vec4 p0;
-	Vec4 p1;
-	Mat4 matrix;
-
-	NewtonCollision* collision = NewtonBodyGetCollision(body);
-	NewtonBodyGetMatrix(body, &matrix[0]);
-	NewtonCollisionCalculateAABB(collision, &matrix[0], &p0[0], &p1[0]);
-
-	Vec3 lines[] = {Vec3(p0.x(), p0.y(), p0.z()),
-		Vec3(p1.x(), p0.y(), p0.z()),
-		Vec3(p0.x(), p1.y(), p0.z()),
-		Vec3(p1.x(), p1.y(), p0.z()),
-		Vec3(p0.x(), p1.y(), p1.z()),
-		Vec3(p1.x(), p1.y(), p1.z()),
-		Vec3(p0.x(), p0.y(), p1.z()),
-		Vec3(p1.x(), p0.y(), p1.z()),
-		Vec3(p0.x(), p0.y(), p0.z()),
-		Vec3(p0.x(), p1.y(), p0.z()),
-		Vec3(p1.x(), p0.y(), p0.z()),
-		Vec3(p1.x(), p1.y(), p0.z()),
-		Vec3(p0.x(), p0.y(), p1.z()),
-		Vec3(p0.x(), p1.y(), p1.z()),
-		Vec3(p1.x(), p0.y(), p1.z()),
-		Vec3(p1.x(), p1.y(), p1.z()),
-		Vec3(p0.x(), p0.y(), p0.z()),
-		Vec3(p0.x(), p0.y(), p1.z()),
-		Vec3(p1.x(), p0.y(), p0.z()),
-		Vec3(p1.x(), p0.y(), p1.z()),
-		Vec3(p0.x(), p1.y(), p0.z()),
-		Vec3(p0.x(), p1.y(), p1.z()),
-		Vec3(p1.x(), p1.y(), p0.z()),
-		Vec3(p1.x(), p1.y(), p1.z())};
-
-	const U32 linesCount = sizeof(lines) / sizeof(Vec3) / 2;
-	drawLines(lines, linesCount, Vec4(0.0, 0.0, 1.0, 0.5));
-}
-
-void PhysicsDrawer::drawCollision(const NewtonBody* body)
-{
-	Mat4 matrix;
-	NewtonBodyGetMatrix(body, &matrix[0]);
-
-	CallbackData data;
-	data.m_body = body;
-	data.m_drawer = this;
-
-	NewtonCollisionForEachPolygonDo(
-		NewtonBodyGetCollision(body), &matrix[0], drawGeometryCallback, static_cast<void*>(&data));
-}
-
-void PhysicsDrawer::drawGeometryCallback(void* userData, int vertexCount, const dFloat* const faceVertec, int id)
-{
-	CallbackData* data = static_cast<CallbackData*>(userData);
-	const NewtonBody* body = data->m_body;
-
-	Vec4 color(1.0);
-	if(NewtonBodyGetType(body) == NEWTON_DYNAMIC_BODY)
-	{
-		I sleepState = NewtonBodyGetSleepState(body);
-		if(sleepState == 1)
-		{
-			// Sleeping
-			color = Vec4(0.3, 0.3, 0.3, 1.0);
-		}
-	}
-
-	U i = vertexCount - 1;
-
-	Array<Vec3, 2> points;
-	points[0] = Vec3(faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
-
-	for(I i = 0; i < vertexCount; i++)
-	{
-		points[1] = Vec3(faceVertec[i * 3 + 0], faceVertec[i * 3 + 1], faceVertec[i * 3 + 2]);
-
-		data->m_drawer->drawLines(&points[0], 1, color);
+	btDynamicsWorld& btWorld = *world.getBtWorld();
 
-		points[0] = points[1];
-	}
+	btWorld.setDebugDrawer(&m_debugDraw);
+	btWorld.debugDrawWorld();
 }
 
 } // end namespace anki

+ 47 - 24
src/anki/physics/PhysicsDrawer.h

@@ -7,9 +7,6 @@
 
 #include <anki/physics/Common.h>
 
-// Forward
-class NewtonBody;
-
 namespace anki
 {
 
@@ -20,39 +17,65 @@ namespace anki
 class PhysicsDrawer
 {
 public:
+	PhysicsDrawer()
+		: m_debugDraw(this)
+	{
+	}
+
 	/// Draw a line.
 	virtual void drawLines(const Vec3* lines, const U32 linesCount, const Vec4& color) = 0;
 
 	void drawWorld(const PhysicsWorld& world);
 
-	void setDrawAabbs(Bool draw)
+private:
+	class DebugDraw : public btIDebugDraw
 	{
-		m_drawAabbs = draw;
-	}
+	public:
+		PhysicsDrawer* m_drawer = nullptr;
 
-	Bool getDrawAabbs() const
-	{
-		return m_drawAabbs;
-	}
+		DebugDraw(PhysicsDrawer* drawer)
+			: m_drawer(drawer)
+		{
+		}
 
-	void setDrawCollision(Bool draw)
-	{
-		m_drawCollision = draw;
-	}
+		void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override
+		{
+			Array<Vec3, 2> lines = {{toAnki(from), toAnki(to)}};
+			m_drawer->drawLines(&lines[0], 2, Vec4(toAnki(color), 1.0f));
+		}
 
-	Bool getDrawCollision() const
-	{
-		return m_drawCollision;
-	}
+		void drawContactPoint(const btVector3& PointOnB,
+			const btVector3& normalOnB,
+			btScalar distance,
+			int lifeTime,
+			const btVector3& color) override
+		{
+			// TODO
+		}
 
-private:
-	Bool8 m_drawAabbs = true;
-	Bool8 m_drawCollision = true;
+		void reportErrorWarning(const char* warningString) override
+		{
+			ANKI_PHYS_LOGW(warningString);
+		}
+
+		void draw3dText(const btVector3& location, const char* textString) override
+		{
+			// TODO
+		}
+
+		void setDebugMode(int debugMode) override
+		{
+			// TODO
+		}
 
-	void drawAabb(const NewtonBody* body);
-	void drawCollision(const NewtonBody* body);
+		int getDebugMode() const override
+		{
+			// TODO
+			return 0;
+		}
+	};
 
-	static void drawGeometryCallback(void* userData, int vertexCount, const dFloat* const faceVertec, int id);
+	DebugDraw m_debugDraw;
 };
 /// @}
 

+ 0 - 61
src/anki/physics/PhysicsPlayerController.cpp

@@ -9,69 +9,8 @@
 namespace anki
 {
 
-CharacterControllerManager::CharacterControllerManager(PhysicsWorld* world)
-	: dCustomPlayerControllerManager(world->getNewtonWorld())
-	, m_world(world)
-{
-}
-
-void CharacterControllerManager::ApplyPlayerMove(dCustomPlayerController* const controller, dFloat timestep)
-{
-	ANKI_ASSERT(controller);
-
-	NewtonBody* body = controller->GetBody();
-	PhysicsPlayerController* player = static_cast<PhysicsPlayerController*>(NewtonBodyGetUserData(body));
-	ANKI_ASSERT(player);
-
-	dVector gravity = toNewton(player->getWorld().getGravity());
-
-	// Compute the angle the way newton wants it
-	Vec4 forwardDir{player->m_forwardDir.x(), 0.0, player->m_forwardDir.z(), 0.0f};
-	F32 cosTheta = clamp(Vec4(0.0, 0.0, -1.0, 0.0).dot(forwardDir), -1.0f, 1.0f);
-	F32 sign = Vec4(0.0, 0.0, -1.0, 0.0).cross(forwardDir).y();
-	sign = (!isZero(sign)) ? (absolute(sign) / sign) : 1.0f;
-	F32 angle = acos(cosTheta) * sign;
-
-	controller->SetPlayerVelocity(
-		player->m_forwardSpeed, player->m_strafeSpeed, player->m_jumpSpeed, angle, gravity, timestep);
-}
-
 PhysicsPlayerController::~PhysicsPlayerController()
 {
-	if(m_newtonPlayer)
-	{
-		getWorld().getCharacterControllerManager().DestroyController(m_newtonPlayer);
-	}
-}
-
-Error PhysicsPlayerController::create(const PhysicsPlayerControllerInitInfo& init)
-{
-	dMatrix playerAxis;
-	playerAxis[0] = dVector(0.0f, 1.0f, 0.0f, 0.0f); // the y axis is the character up vector
-	playerAxis[1] = dVector(0.0f, 0.0f, -1.0f, 0.0f); // the x axis is the character front direction
-	playerAxis[2] = playerAxis[0].CrossProduct(playerAxis[1]);
-	playerAxis[3] = dVector(0.0f, 0.0f, 0.0f, 1.0f);
-
-	m_newtonPlayer = getWorld().getCharacterControllerManager().CreatePlayer(
-		init.m_mass, init.m_outerRadius, init.m_innerRadius, init.m_height, init.m_stepHeight, playerAxis);
-
-	if(m_newtonPlayer == nullptr)
-	{
-		return Error::FUNCTION_FAILED;
-	}
-
-	// Set some data
-	NewtonBody* body = m_newtonPlayer->GetBody();
-	NewtonBodySetUserData(body, this);
-	NewtonBodySetTransformCallback(body, onTransformUpdateCallback);
-
-	dMatrix location(dGetIdentityMatrix());
-	location.m_posit.m_x = init.m_position.x();
-	location.m_posit.m_y = init.m_position.y();
-	location.m_posit.m_z = init.m_position.z();
-	NewtonBodySetMatrix(body, &location[0][0]);
-
-	return Error::NONE;
 }
 
 void PhysicsPlayerController::moveToPosition(const Vec4& position)

+ 5 - 55
src/anki/physics/PhysicsPlayerController.h

@@ -13,21 +13,6 @@ namespace anki
 /// @addtogroup physics
 /// @{
 
-/// The implementation of the Newton manager.
-class CharacterControllerManager : public dCustomPlayerControllerManager
-{
-public:
-	PhysicsWorld* m_world;
-
-	CharacterControllerManager(PhysicsWorld* world);
-
-	~CharacterControllerManager()
-	{
-	}
-
-	void ApplyPlayerMove(dCustomPlayerController* const controller, dFloat timestep);
-};
-
 /// Init info for PhysicsPlayerController.
 class PhysicsPlayerControllerInitInfo
 {
@@ -43,64 +28,29 @@ public:
 /// A player controller that walks the world.
 class PhysicsPlayerController final : public PhysicsObject
 {
-	friend class CharacterControllerManager;
-
 public:
-	PhysicsPlayerController(PhysicsWorld* world)
+	PhysicsPlayerController(PhysicsWorld* world, const PhysicsPlayerControllerInitInfo& init)
 		: PhysicsObject(PhysicsObjectType::PLAYER_CONTROLLER, world)
 	{
 	}
 
 	~PhysicsPlayerController();
 
-	ANKI_USE_RESULT Error create(const PhysicsPlayerControllerInitInfo& init);
-
 	// Update the state machine
 	void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed, const Vec4& forwardDir)
 	{
-		m_forwardSpeed = forwardSpeed;
-		m_strafeSpeed = strafeSpeed;
-		m_jumpSpeed = jumpSpeed;
-		m_forwardDir = forwardDir;
+		// TODO
 	}
 
 	void moveToPosition(const Vec4& position);
 
-	const Transform& getTransform(Bool& updated)
+	Transform getTransform(Bool& updated)
 	{
-		updated = m_updated;
-		m_updated = false;
-		return m_trf;
+		return Transform();
 	}
 
 private:
-	dCustomPlayerController* m_newtonPlayer = nullptr;
-	Transform m_trf = Transform::getIdentity();
-	Bool m_updated = true;
-
-	// State
-	F32 m_forwardSpeed = 0.0;
-	F32 m_strafeSpeed = 0.0;
-	F32 m_jumpSpeed = 0.0;
-	Vec4 m_forwardDir = Vec4(0.0, 0.0, -1.0, 0.0);
-
-	static void onTransformUpdateCallback(const NewtonBody* body, const dFloat* matrix, int threadIndex)
-	{
-		ANKI_ASSERT(body && matrix);
-		Transform trf = Transform(toAnki(dMatrix(matrix)));
-		void* ud = NewtonBodyGetUserData(body);
-		ANKI_ASSERT(ud);
-		static_cast<PhysicsPlayerController*>(ud)->onTransformUpdate(trf);
-	}
-
-	void onTransformUpdate(const Transform& trf)
-	{
-		if(trf != m_trf)
-		{
-			m_updated = true;
-			m_trf = trf;
-		}
-	}
+	// TODO
 };
 /// @}
 

+ 12 - 27
src/anki/physics/PhysicsWorld.h

@@ -24,11 +24,22 @@ public:
 	ANKI_USE_RESULT Error create(AllocAlignedCallback allocCb, void* allocCbData);
 
 	template<typename T, typename... TArgs>
-	PhysicsPtr<T> newInstance(TArgs&&... args);
+	PhysicsPtr<T> newInstance(TArgs&&... args)
+	{
+		PhysicsPtr<T> out;
+		T* ptr = m_alloc.template newInstance<T>(this, std::forward<TArgs>(args)...);
+		out.reset(ptr);
+		return out;
+	}
 
 	/// Do the update.
 	Error update(Second dt);
 
+	HeapAllocator<U8> getAllocator()
+	{
+		return m_alloc;
+	}
+
 anki_internal:
 	btDynamicsWorld* getBtWorld() const
 	{
@@ -59,32 +70,6 @@ private:
 
 	void cleanupMarkedForDeletion();
 };
-
-template<typename T, typename... TArgs>
-inline PhysicsPtr<T> PhysicsWorld::newInstance(TArgs&&... args)
-{
-	Error err = Error::NONE;
-	PhysicsPtr<T> out;
-
-	T* ptr = m_alloc.template newInstance<T>(this);
-	err = ptr->create(std::forward<TArgs>(args)...);
-
-	if(!err)
-	{
-		out.reset(ptr);
-	}
-	else
-	{
-		ANKI_PHYS_LOGE("Failed to create physics object");
-
-		if(ptr)
-		{
-			m_alloc.deleteInstance(ptr);
-		}
-	}
-
-	return out;
-}
 /// @}
 
 } // end namespace anki

+ 3 - 5
src/anki/resource/CollisionResource.cpp

@@ -29,19 +29,18 @@ Error CollisionResource::load(const ResourceFilename& filename, Bool async)
 	ANKI_CHECK(collEl.getChildElement("value", valEl));
 
 	PhysicsWorld& physics = getManager().getPhysicsWorld();
-	PhysicsCollisionShapeInitInfo csInit;
 
 	if(type == "sphere")
 	{
 		F64 tmp;
 		ANKI_CHECK(valEl.getNumber(tmp));
-		m_physicsShape = physics.newInstance<PhysicsSphere>(csInit, tmp);
+		m_physicsShape = physics.newInstance<PhysicsSphere>(tmp);
 	}
 	else if(type == "box")
 	{
 		Vec3 extend;
 		ANKI_CHECK(valEl.getVec3(extend));
-		m_physicsShape = physics.newInstance<PhysicsBox>(csInit, extend);
+		m_physicsShape = physics.newInstance<PhysicsBox>(extend);
 	}
 	else if(type == "staticMesh")
 	{
@@ -55,8 +54,7 @@ Error CollisionResource::load(const ResourceFilename& filename, Bool async)
 		DynamicArrayAuto<Vec3> positions(getTempAllocator());
 		ANKI_CHECK(loader.storeIndicesAndPosition(indices, positions));
 
-		m_physicsShape = physics.newInstance<PhysicsTriangleSoup>(
-			csInit, &positions[0], sizeof(Vec3), &indices[0], indices.getSize());
+		m_physicsShape = physics.newInstance<PhysicsTriangleSoup>(positions, indices);
 	}
 	else
 	{

+ 1 - 2
src/anki/scene/SceneGraph.cpp

@@ -221,8 +221,7 @@ Error SceneGraph::update(Second prevUpdateTime, Second crntTime)
 	// Update
 	{
 		ANKI_TRACE_SCOPED_EVENT(SCENE_PHYSICS_UPDATE);
-		m_physics->updateAsync(crntTime - prevUpdateTime);
-		m_physics->waitUpdate();
+		m_physics->update(crntTime - prevUpdateTime);
 	}
 
 	{