Browse Source

- Rotate X and Y axis of camera's MoveComponent and provide an updated rotation matrix to the transform.
- Get rid of wrap function
- Replace missing occurrence of "Second"

Sergio 5 years ago
parent
commit
ebfef1c42d

+ 6 - 6
samples/common/Framework.cpp

@@ -209,13 +209,13 @@ Error SampleApp::userMainLoop(Bool& quit, Second elapsedTime)
 
 		if(in.getMousePosition() != Vec2(0.0))
 		{
-			static Vec2 sEulerYawPitch = Vec2(0.0f);
-			static Vec2 sDeadArea = Vec2(0.0f, 0.01f); // Define smooth transition area (TODO: Read this from config)
-
 			Vec2 velocity = in.getMousePosition();
-			sEulerYawPitch += velocity * Vec2(360.0f) * elapsedTime * MOUSE_SENSITIVITY;
-			sEulerYawPitch.y() = clamp(sEulerYawPitch.y(), -90.0f, 90.0f); // Avoid cycle in Y axis
-			mover->setPitchYawRoll(toRad(sEulerYawPitch.y()), toRad(sEulerYawPitch.x()), 0.0f);
+			Euler angles(mover->getLocalRotation().getRotationPart());
+			angles.x() += velocity.y() * toRad(360.0f) * F32(elapsedTime) * MOUSE_SENSITIVITY;
+			angles.x() = clamp(angles.x(), toRad(-90.0f), toRad(90.0f)); // Avoid cycle in Y axis
+			angles.y() += -velocity.x() * toRad(360.0f) * F32(elapsedTime) * MOUSE_SENSITIVITY;
+			angles.z() = 0.0f;
+			mover->setLocalRotation(Mat3x4(angles));
 		}
 	}
 	else

+ 1 - 1
samples/common/Framework.h

@@ -11,7 +11,7 @@ class SampleApp : public anki::App
 {
 public:
 	anki::Error init(int argc, char** argv, anki::CString sampleName);
-	anki::Error userMainLoop(anki::Bool& quit, anki::F64 elapsedTime) override;
+	anki::Error userMainLoop(anki::Bool& quit, anki::Second elapsedTime) override;
 
 	virtual anki::Error sampleExtraInit() = 0;
 };

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

@@ -156,14 +156,6 @@ inline T sign(T v)
 	return v > 0 ? 1 : -1;
 }
 
-/// When a value goes out of bounds it cycles rom the other side
-template <typename T>
-inline T wrap(T value, T min, T max) 
-{
-	ANKI_ASSERT(min < max);
-	return (value < min) ? (max - (min - value)) : ((value > max) ? (min + (value - max)) : value);
-}
-
 /// Same as smoothstep in glsl
 template <typename T>
 inline T smoothstep(T edge0, T edge1, T value) 

+ 1 - 3
src/anki/scene/components/MoveComponent.h

@@ -156,9 +156,7 @@ public:
 
 	void setPitchYawRoll(F32 radPitch, F32 radYaw, F32 radRoll) 
 	{
-		const Vec4 forward = Vec4(	cos(radYaw) * cos(radPitch),
-								sin(radPitch),
-								sin(radYaw) * cos(radPitch), 0.0f).getNormalized();
+		const Vec4 forward = Vec4(	cos(radYaw) * cos(radPitch), sin(radPitch),	sin(radYaw) * cos(radPitch), 0.0f).getNormalized();
 		lookAtPoint(m_ltrf.getOrigin() + forward);
 	}
 	/// @}