Browse Source

Changes in the player controller

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
cf7bb26446

+ 1 - 1
sandbox/Main.cpp

@@ -76,7 +76,7 @@ Error MyApp::init(int argc, char* argv[])
 		"player", pnode, cam.getComponent<MoveComponent>().getLocalOrigin() - Vec4(0.0, 1.0, 0.0, 0.0)));
 		"player", pnode, cam.getComponent<MoveComponent>().getLocalOrigin() - Vec4(0.0, 1.0, 0.0, 0.0)));
 
 
 	cam.getComponent<MoveComponent>().setLocalTransform(
 	cam.getComponent<MoveComponent>().setLocalTransform(
-		Transform(Vec4(0.0), Mat3x4(Euler(toRad(0.0), toRad(180.0), toRad(0.0))), 1.0));
+		Transform(Vec4(0.0, 0.0, 0.0, 0.0), Mat3x4::getIdentity(), 1.0));
 
 
 	pnode->addChild(&cam);
 	pnode->addChild(&cam);
 #endif
 #endif

+ 1 - 0
src/anki/math/Functions.h

@@ -42,6 +42,7 @@ inline T tan(const T rad)
 template<typename T>
 template<typename T>
 inline T acos(const T x)
 inline T acos(const T x)
 {
 {
+	ANKI_ASSERT(x >= T(-1) && x <= T(1));
 	return std::acos(x);
 	return std::acos(x);
 }
 }
 
 

+ 7 - 1
src/anki/physics/PhysicsPlayerController.cpp

@@ -24,7 +24,13 @@ void CharacterControllerManager::ApplyPlayerMove(CustomPlayerController* const c
 	ANKI_ASSERT(player);
 	ANKI_ASSERT(player);
 
 
 	dVector gravity = toNewton(player->getWorld().getGravity());
 	dVector gravity = toNewton(player->getWorld().getGravity());
-	F32 angle = acos(Vec4(0.0, 0.0, -1.0, 0.0).dot(player->m_forwardDir));
+
+	// 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(
 	controller->SetPlayerVelocity(
 		player->m_forwardSpeed, player->m_strafeSpeed, player->m_jumpSpeed, angle, gravity, timestep);
 		player->m_forwardSpeed, player->m_strafeSpeed, player->m_jumpSpeed, angle, gravity, timestep);

+ 2 - 2
src/anki/scene/PlayerNode.cpp

@@ -42,7 +42,7 @@ public:
 			origin.y() += 1.9;
 			origin.y() += 1.9;
 
 
 			// Set rotation
 			// Set rotation
-			Mat3x4 rot(Euler(ang * y * -11.25, ang * x * -20.0, 0.0));
+			Mat3x4 rot(Euler(ang * y * 11.25, ang * x * -20.0, 0.0));
 
 
 			rot = move.getLocalRotation().combineTransformations(rot);
 			rot = move.getLocalRotation().combineTransformations(rot);
 
 
@@ -100,7 +100,7 @@ public:
 			moveVec.x() += 1.0;
 			moveVec.x() += 1.0;
 		}
 		}
 
 
-		Vec4 dir = move.getLocalRotation().getColumn(2).xyz0();
+		Vec4 dir = -move.getLocalRotation().getZAxis().xyz0();
 		dir.y() = 0.0;
 		dir.y() = 0.0;
 		dir.normalize();
 		dir.normalize();