Просмотр исходного кода

Merge functionalities of MovableCamera into Camera

Daniele Bartolini 12 лет назад
Родитель
Сommit
44636cef02
9 измененных файлов с 218 добавлено и 430 удалено
  1. 6 24
      samples/terrain/terrain.cpp
  2. 0 2
      src/CMakeLists.txt
  3. 123 69
      src/Camera.cpp
  4. 63 62
      src/Camera.h
  5. 1 26
      src/Crown.h
  6. 16 13
      src/FPSSystem.cpp
  7. 9 5
      src/FPSSystem.h
  8. 0 145
      src/MovableCamera.cpp
  9. 0 84
      src/MovableCamera.h

+ 6 - 24
samples/terrain/terrain.cpp

@@ -59,14 +59,6 @@ public:
 		{		
 		{		
 			terrain.PlotCircle(8, 8, 8, 2);
 			terrain.PlotCircle(8, 8, 8, 2);
 		}
 		}
-
-		if (event.key == KC_SPACE)
-		{
-			if (cam)
-			{
-				cam->SetActive(!cam->IsActive());
-			}
-		}
 	}
 	}
 
 
 	void button_pressed(const MouseEvent& event)
 	void button_pressed(const MouseEvent& event)
@@ -129,16 +121,9 @@ public:
 		Vec3 start = Vec3(0.0f, 10.0f, 0.0f);
 		Vec3 start = Vec3(0.0f, 10.0f, 0.0f);
 
 
 		// Add a movable camera
 		// Add a movable camera
-		cam = new MovableCamera(/*Vec3::ZERO*/start, true, 90.0f, 1.6f, true, 0.1, 2.5);
+		cam = new Camera(start, 90.0f, 1.6f);
 
 
-		if (cam)
-		{
-			cam->SetActive(true);
-			cam->SetSpeed(0.1);
-			cam->SetFarClipDistance(1000.0f);
-		}
-
-		system = new FPSSystem(cam);
+		system = new FPSSystem(cam, 0.1, 2.5);
 
 
 		// Add a skybox
 		// Add a skybox
 		skybox = new Skybox(Vec3::ZERO, true);
 		skybox = new Skybox(Vec3::ZERO, true);
@@ -169,7 +154,7 @@ public:
 		Renderer* renderer = device()->renderer();
 		Renderer* renderer = device()->renderer();
 		
 		
 		system->set_view_by_cursor();
 		system->set_view_by_cursor();
-		system->camera_render();
+		system->update();
 
 
 		renderer->set_lighting(false);
 		renderer->set_lighting(false);
 		renderer->set_texturing(0, false);
 		renderer->set_texturing(0, false);
@@ -179,11 +164,8 @@ public:
 			skybox->Render();
 			skybox->Render();
 		}
 		}
 
 
-		if (cam->IsActive())
-		{
-			ray.set_origin(cam->GetPosition());
-			ray.set_direction(cam->GetLookAt());
-		}
+		ray.set_origin(cam->position());
+		ray.set_direction(cam->look_at());
 
 
 		/* Render the terrain */
 		/* Render the terrain */
 		renderer->set_ambient_light(Color4(0.5f, 0.5f, 0.5f, 1.0f));
 		renderer->set_ambient_light(Color4(0.5f, 0.5f, 0.5f, 1.0f));
@@ -230,7 +212,7 @@ public:
 private:
 private:
 
 
 	FPSSystem* system;
 	FPSSystem* system;
-	MovableCamera* cam;
+	Camera* cam;
 	Skybox* skybox;
 	Skybox* skybox;
 	Mat4 ortho;
 	Mat4 ortho;
 	Terrain terrain;
 	Terrain terrain;

+ 0 - 2
src/CMakeLists.txt

@@ -6,7 +6,6 @@ set (SRC
 	Font.cpp
 	Font.cpp
 	Image.cpp
 	Image.cpp
 	MaterialResource.cpp
 	MaterialResource.cpp
-	MovableCamera.cpp
 	Pixel.cpp
 	Pixel.cpp
 	ResourceManager.cpp
 	ResourceManager.cpp
 	Skybox.cpp
 	Skybox.cpp
@@ -34,7 +33,6 @@ set (HEADERS
 	Glyph.h
 	Glyph.h
 	Image.h
 	Image.h
 	MaterialResource.h
 	MaterialResource.h
-	MovableCamera.h
 	Pixel.h
 	Pixel.h
 	Resource.h
 	Resource.h
 	ResourceManager.h
 	ResourceManager.h

+ 123 - 69
src/Camera.cpp

@@ -24,153 +24,207 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #include "Camera.h"
 #include "Camera.h"
-#include "Device.h"
 #include "Types.h"
 #include "Types.h"
-#include "Renderer.h"
+#include "MathUtils.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-Camera::Camera(const Vec3& position, bool visible, float fov, float aspect, bool active) :
-	mPosition(position),
-	mLookAt(0, 0, -1),
-	mUp(0, 1, 0),
-	mFOV(fov),
-	mAspect(aspect),
-	mNear(0.1f),
-	mFar(1000.0f),
-	mActive(active),
-	mAutoAspect(true)
+//-----------------------------------------------------------------------------
+Camera::Camera(const Vec3& position, float fov, float aspect) :
+	m_position(position),
+	m_look_at(0, 0, -1),
+	m_up(0, 1, 0),
+
+	m_rot_factor(0.0f, 0.0f),
+	m_angle_x(0.0f),
+	m_angle_y(0.0f),
+
+	m_FOV(fov),
+	m_aspect(aspect),
+	m_near(0.1f),
+	m_far(1000.0f)
 {
 {
-	UpdateProjectionMatrix();
-	UpdateViewMatrix();
-	UpdateFrustum();
+	update_projection_matrix();
+	update_view_matrix();
+	update_frustum();
 }
 }
 
 
-Camera::~Camera()
+//-----------------------------------------------------------------------------
+const Vec3& Camera::position() const
 {
 {
+	return m_position;
 }
 }
 
 
-void Camera::SetPosition(const Vec3& position)
+//-----------------------------------------------------------------------------
+void Camera::set_position(const Vec3& position)
 {
 {
-	mPosition = position;
-	UpdateViewMatrix();
+	m_position = position;
+
+	update_view_matrix();
 }
 }
 
 
-const Vec3& Camera::GetLookAt() const
+//-----------------------------------------------------------------------------
+const Vec3& Camera::look_at() const
 {
 {
-	return mLookAt;
+	return m_look_at;
 }
 }
 
 
-void Camera::SetLookAt(const Vec3& lookat)
+//-----------------------------------------------------------------------------
+void Camera::set_look_at(const Vec3& lookat)
 {
 {
-	mLookAt = lookat;
-	UpdateViewMatrix();
+	m_look_at = lookat;
+
+	update_view_matrix();
 }
 }
 
 
-const Vec3& Camera::GetUpVector() const
+//-----------------------------------------------------------------------
+void Camera::set_rotation(const float x, const float y)
 {
 {
-	return mUp;
+	Vec3 right(1, 0, 0);
+	Vec3 look;
+
+	look.x = 0.0f;
+	look.y = math::sin(x);
+	look.z = -math::cos(x);
+
+	Vec3 up = right.cross(look);
+	up.normalize();
+
+	Mat3 m;
+	m.build_rotation_y(y);
+	look = m * look;
+	m_up = m * up;
+
+	set_look_at(look);
 }
 }
 
 
-bool Camera::IsActive() const
+//-----------------------------------------------------------------------------
+const Vec3& Camera::up() const
 {
 {
-	return mActive;
+	return m_up;
 }
 }
 
 
-void Camera::SetActive(bool active)
+//-----------------------------------------------------------------------------
+float Camera::fov() const
 {
 {
-	mActive = active;
+	return m_FOV;
 }
 }
 
 
-float Camera::GetFOV() const
+//-----------------------------------------------------------------------------
+void Camera::set_fov(float fov)
 {
 {
-	return mFOV;
+	m_FOV = fov;
+
+	update_projection_matrix();
 }
 }
 
 
-void Camera::SetFOV(float fov)
+//-----------------------------------------------------------------------------
+float Camera::aspect() const
 {
 {
-	mFOV = fov;
-	UpdateProjectionMatrix();
+	return m_aspect;
 }
 }
 
 
-bool Camera::GetAutoAspect() const
+//-----------------------------------------------------------------------------
+void Camera::set_aspect(float aspect)
 {
 {
-	return mAutoAspect;
+	m_aspect = aspect;
+
+	update_projection_matrix();
 }
 }
 
 
-void Camera::SetAutoAspect(bool autoAspect)
+//-----------------------------------------------------------------------------
+float Camera::near_clip_distance() const
 {
 {
-	mAutoAspect = autoAspect;
+	return m_near;
 }
 }
 
 
-float Camera::GetAspect() const
+//-----------------------------------------------------------------------------
+void Camera::set_near_clip_distance(float near)
 {
 {
-	return mAspect;
+	m_near = near;
+
+	update_projection_matrix();
 }
 }
 
 
-void Camera::SetAspect(float aspect)
+//-----------------------------------------------------------------------------
+float Camera::far_clip_distance() const
 {
 {
-	mAspect = aspect;
-	UpdateProjectionMatrix();
+	return m_far;
 }
 }
 
 
-float Camera::GetNearClipDistance() const
+//-----------------------------------------------------------------------------
+void Camera::set_far_clip_distance(float far)
 {
 {
-	return mNear;
+	m_far = far;
+
+	update_projection_matrix();
 }
 }
 
 
-void Camera::SetNearClipDistance(float near)
+//-----------------------------------------------------------------------------
+const Mat4& Camera::projection_matrix() const
 {
 {
-	mNear = near;
-	UpdateProjectionMatrix();
+	return m_projection;
 }
 }
 
 
-float Camera::GetFarClipDistance() const
+//-----------------------------------------------------------------------------
+const Mat4& Camera::view_matrix() const
 {
 {
-	return mFar;
+	return m_view;
 }
 }
 
 
-void Camera::SetFarClipDistance(float far)
+//-----------------------------------------------------------------------------
+const Frustum& Camera::frustum() const
 {
 {
-	mFar = far;
-	UpdateProjectionMatrix();
+	return m_frustum;
 }
 }
 
 
-const Mat4& Camera::GetProjectionMatrix() const
+//-----------------------------------------------------------------------------
+void Camera::update_projection_matrix()
 {
 {
-	return mProjection;
+	m_projection.build_projection_perspective_rh(m_FOV, m_aspect, m_near, m_far);
 }
 }
 
 
-const Mat4& Camera::GetViewMatrix() const
+//-----------------------------------------------------------------------------
+void Camera::update_view_matrix()
 {
 {
-	return mView;
+	m_view.build_look_at_rh(m_position, m_position + m_look_at, m_up);
 }
 }
 
 
-const Frustum& Camera::GetFrustum() const
+//-----------------------------------------------------------------------------
+void Camera::update_frustum()
 {
 {
-	return mFrustum;
+	m_frustum.from_matrix(m_projection * m_view);
 }
 }
 
 
-void Camera::Render()
+//-----------------------------------------------------------------------------
+void Camera::move_forward(float meters)
 {
 {
-	device()->renderer()->set_matrix(MT_PROJECTION, mProjection);
-	device()->renderer()->set_matrix(MT_VIEW, mView);
+	set_position(m_position + m_look_at * meters);
 }
 }
 
 
-void Camera::UpdateProjectionMatrix()
+//-----------------------------------------------------------------------
+void Camera::move_backward(float meters)
 {
 {
-	mProjection.build_projection_perspective_rh(mFOV, mAspect, mNear, mFar);
+	set_position(m_position + m_look_at * -meters);
 }
 }
 
 
-void Camera::UpdateViewMatrix()
+//-----------------------------------------------------------------------
+void Camera::strafe_left(float meters)
 {
 {
-	mView.build_look_at_rh(mPosition, mPosition + mLookAt, mUp);
+	Vec3 left = m_up.cross(m_look_at);
+	left.normalize();
+
+	set_position(m_position + left * meters);
 }
 }
 
 
-void Camera::UpdateFrustum()
+//-----------------------------------------------------------------------
+void Camera::strafe_right(float meters)
 {
 {
-	mFrustum.from_matrix(mProjection * mView);
+	Vec3 left = m_up.cross(m_look_at);
+	left.normalize();
+
+	set_position(m_position + left * -meters);
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 63 - 62
src/Camera.h

@@ -28,107 +28,108 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Types.h"
 #include "Frustum.h"
 #include "Frustum.h"
 #include "Mat4.h"
 #include "Mat4.h"
+#include "Mat3.h"
 #include "Vec3.h"
 #include "Vec3.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
+/// Represents the point of view into the game world.
 class Camera
 class Camera
 {
 {
-
 public:
 public:
 
 
-	//! Constructor
-	Camera(const Vec3& position, bool visible, float fov, float aspect, bool active);
-
-	//! Destructor
-	virtual ~Camera();
+	/// Construct the camera placed at the given world-space @position
+	/// with the given @fov field of view and @aspect ratio.
+					Camera(const Vec3& position, float fov, float aspect);
 
 
-	//! Sets the camera's position
-	void SetPosition(const Vec3& position);
+	/// Returns the world-space position of the camera 
+	const Vec3&		position() const;
 
 
-	//! Returns the camera's lookat-point32_t
-	const Vec3& GetLookAt() const;
+	/// Sets the world-space @position of the camera
+	void			set_position(const Vec3& position);
 
 
-	//! Sets the camera's lookat-point32_t
-	void SetLookAt(const Vec3& lookat);
+	/// Returns the lookat-point of the camera
+	const Vec3&		look_at() const;
 
 
-	//! Returns the camera's up vector
-	const Vec3& GetUpVector() const;
+	/// Sets the lookat-point of the camera
+	void			set_look_at(const Vec3& lookat);
 
 
-	//! Returns whether the camera is active
-	bool IsActive() const;
+	/// Sets the rotation of the camera about the world's @x axis and @y axis
+	void			set_rotation(const float x, const float y);
 
 
-	//! Sets whether the camera is active
-	void SetActive(bool active);
+	/// Returns the up-vector of the camera
+	const Vec3&		up() const;
 
 
-	//! Returns the camera's Field Of View
-	float GetFOV() const;
+	/// Returns the field of view of the camera in degrees
+	float			fov() const;
 
 
-	//! Sets the camera's Field Of View
-	void SetFOV(float fov);
+	/// Sets the field of view of the camera
+	void			set_fov(float fov);
 
 
-	//! Returns whether the camera automatically adjusts aspect ratio based on the Viewport
-	bool GetAutoAspect() const;
+	/// Returns the aspect ratio of the camera
+	float			aspect() const;
 
 
-	//! Sets whether the camera automatically adjusts aspect ratio based on the Viewport
-	void SetAutoAspect(bool autoAspect);
+	/// Sets the aspect ration of the camera
+	void			set_aspect(float aspect);
 
 
-	//! Returns the camera's aspect ratio
-	float GetAspect() const;
+	/// Returns the near clipping distance of the camera
+	float			near_clip_distance() const;
 
 
-	//! Sets the camera's aspect ratio
-	void SetAspect(float aspect);
+	/// Sets the near clipping distance of the camera
+	void			set_near_clip_distance(float near);
 
 
-	//! Returns the camera's near clipping distance
-	float GetNearClipDistance() const;
+	/// Returns the far clipping distance of the camera
+	float			far_clip_distance() const;
 
 
-	//! Sets the camera's near clipping distance
-	void SetNearClipDistance(float near);
+	/// Sets the far clipping distance of the camera
+	void			set_far_clip_distance(float far);
 
 
-	//! Returns the camera's far clipping distance
-	float GetFarClipDistance() const;
+	/// Returns the view-frustum of the camera
+	const Frustum&	frustum() const;
 
 
-	//! Sets the camera's far clipping distance
-	void SetFarClipDistance(float far);
+	/// Returns the renderer-independent projection matrix used by the camera
+	const Mat4&		projection_matrix() const;
 
 
-	//! Returns the camera's view frustum
-	const Frustum& GetFrustum() const;
+	/// Returns the renderer-independent view matrix used by the camera
+	const Mat4&		view_matrix() const;
 
 
-	//! Returns the projection matrix
-	const Mat4& GetProjectionMatrix() const;
+	/// Moves the camera towards look direction by @meters meters
+	void			move_forward(float meters);
 
 
-	//! Returns the view matrix
-	const Mat4& GetViewMatrix() const;
+	/// Moves the camera towards the opposite look direction by @meters meters
+	void			move_backward(float meters);
 
 
-	//! Loads the view and projection matrix
-	virtual void Render();
+	/// Moves the camera along the axis perpendicular to the look direction by @meters meters
+	void			strafe_left(float meters);
 
 
-	const Vec3& GetPosition() const { return mPosition; }
+	/// Moves the camera along the axis perpendicular to the look direction by @meters meters
+	void			strafe_right(float meters);
 
 
 protected:
 protected:
 
 
-	void UpdateProjectionMatrix();
-	void UpdateViewMatrix();
-	void UpdateFrustum();
+	void			update_projection_matrix();
+	void			update_view_matrix();
+	void			update_frustum();
 
 
-	Vec3 mPosition;
-	Vec3 mLookAt;
-	Vec3 mUp;
+	Vec3			m_position;
+	Vec3			m_look_at;
+	Vec3			m_up;
 
 
-	Mat4 mView;
-	Mat4 mProjection;
+	Vec2			m_rot_factor;
+	float			m_angle_x;
+	float			m_angle_y;
 
 
-	Frustum mFrustum;
+	Mat4			m_view;
+	Mat4			m_projection;
 
 
-	float mFOV;
-	float mAspect;
+	Frustum			m_frustum;
 
 
-	float mNear;
-	float mFar;
+	float			m_FOV;
+	float			m_aspect;
 
 
-	bool mActive		: 1;
-	bool mAutoAspect	: 1;
+	float			m_near;
+	float			m_far;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 1 - 26
src/Crown.h

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 // Core
 // Core
 #include "Types.h"
 #include "Types.h"
 #include "Args.h"
 #include "Args.h"
+#include "Log.h"
 
 
 // Core/Math
 // Core/Math
 #include "Color4.h"
 #include "Color4.h"
@@ -97,8 +98,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Font.h"
 #include "Font.h"
 #include "Glyph.h"
 #include "Glyph.h"
 #include "Image.h"
 #include "Image.h"
-#include "Log.h"
-#include "MovableCamera.h"
 #include "Pixel.h"
 #include "Pixel.h"
 #include "ResourceArchive.h"
 #include "ResourceArchive.h"
 #include "ArchiveResourceArchive.h"
 #include "ArchiveResourceArchive.h"
@@ -129,27 +128,3 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Material.h"
 #include "Material.h"
 #include "Texture.h"
 #include "Texture.h"
 #include "DebugRenderer.h"
 #include "DebugRenderer.h"
-
-//// Engine/Windowing
-//#include "Bind.h"
-//#include "Button.h"
-//#include "DragArea.h"
-//#include "ItemsSelector.h"
-//#include "ItemsWidget.h"
-//#include "ListView.h"
-//#include "Property.h"
-//#include "ScrollArea.h"
-//#include "SpecificProperties.h"
-//#include "StackLayout.h"
-//#include "TextBox.h"
-//#include "Themes.h"
-//#include "ThemeSpriteWidget.h"
-//#include "TreeView.h"
-//#include "Widget.h"
-//#include "Window.h"
-//#include "WindowContext.h"
-//#include "WindowingEventArgs.h"
-//#include "WindowsManager.h"
-
-// Engine/Windowing/Toolbox
-//#include "TextInputWindow.h"

+ 16 - 13
src/FPSSystem.cpp

@@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 */
 
 
 #include "InputManager.h"
 #include "InputManager.h"
-#include "MovableCamera.h"
+#include "Camera.h"
 #include "FPSSystem.h"
 #include "FPSSystem.h"
 #include "Vec2.h"
 #include "Vec2.h"
 #include "Vec3.h"
 #include "Vec3.h"
@@ -36,8 +36,10 @@ namespace crown
 {
 {
 
 
 //-----------------------------------------------------------------------
 //-----------------------------------------------------------------------
-FPSSystem::FPSSystem(MovableCamera* camera) :
+FPSSystem::FPSSystem(Camera* camera, float speed, float sensibility) :
 	m_camera(camera),
 	m_camera(camera),
+	m_camera_speed(speed),
+	m_camera_sensibility(sensibility),
 
 
 	m_angle_x(0),
 	m_angle_x(0),
 	m_angle_y(0),
 	m_angle_y(0),
@@ -133,41 +135,42 @@ void FPSSystem::accelerometer_changed(const AccelerometerEvent& event)
 	set_view_by_cursor();
 	set_view_by_cursor();
 }
 }
 //-----------------------------------------------------------------------
 //-----------------------------------------------------------------------
-void FPSSystem::set_camera(MovableCamera* camera)
+void FPSSystem::set_camera(Camera* camera)
 {
 {
 	m_camera = camera;
 	m_camera = camera;
 }
 }
 
 
 //-----------------------------------------------------------------------
 //-----------------------------------------------------------------------
-MovableCamera* FPSSystem::get_camera()
+Camera* FPSSystem::camera()
 {
 {
 	return m_camera;
 	return m_camera;
 }
 }
 
 
 //-----------------------------------------------------------------------
 //-----------------------------------------------------------------------
-void FPSSystem::camera_render()
+void FPSSystem::update()
 {
 {
 	if (m_up_pressed)
 	if (m_up_pressed)
 	{
 	{
-		m_camera->MoveForward();
+		m_camera->move_forward(m_camera_speed);
 	}
 	}
 
 
 	if (m_left_pressed)
 	if (m_left_pressed)
 	{
 	{
-		m_camera->StrafeLeft();
+		m_camera->strafe_left(m_camera_speed);
 	}		
 	}		
 
 
 	if (m_down_pressed)
 	if (m_down_pressed)
 	{
 	{
-		m_camera->MoveBackward();
+		m_camera->move_backward(m_camera_speed);
 	}
 	}
 
 
 	if (m_right_pressed)
 	if (m_right_pressed)
 	{
 	{
-		m_camera->StrafeRight();
+		m_camera->strafe_right(m_camera_speed);
 	}
 	}
 
 
-	m_camera->Render();
+	device()->renderer()->set_matrix(MT_VIEW, m_camera->view_matrix());
+	device()->renderer()->set_matrix(MT_PROJECTION, m_camera->projection_matrix());
 }
 }
 
 
 //-----------------------------------------------------------------------	
 //-----------------------------------------------------------------------	
@@ -187,13 +190,13 @@ void FPSSystem::set_view_by_cursor()
 	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
 	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
 	lastPos = device()->input_manager()->get_cursor_relative_xy();
 	lastPos = device()->input_manager()->get_cursor_relative_xy();
 
 
-	m_angle_x += delta.y * m_camera->GetSensibility();
-	m_angle_y += delta.x * m_camera->GetSensibility();
+	m_angle_x += delta.y * m_camera_sensibility;
+	m_angle_y += delta.x * m_camera_sensibility;
 
 
 	m_angle_x = math::clamp_to_range(-89.999f * math::DEG_TO_RAD, 89.999f * math::DEG_TO_RAD, m_angle_x);
 	m_angle_x = math::clamp_to_range(-89.999f * math::DEG_TO_RAD, 89.999f * math::DEG_TO_RAD, m_angle_x);
 	m_angle_y = math::fmod(m_angle_y, math::TWO_PI);
 	m_angle_y = math::fmod(m_angle_y, math::TWO_PI);
 
 
-	m_camera->SetRotation(m_angle_x, m_angle_y);
+	m_camera->set_rotation(m_angle_x, m_angle_y);
 }
 }
 
 
 } // namespace crown
 } // namespace crown

+ 9 - 5
src/FPSSystem.h

@@ -32,6 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Keyboard.h"
 #include "Keyboard.h"
 #include "Touch.h"
 #include "Touch.h"
 #include "Accelerometer.h"
 #include "Accelerometer.h"
+#include "Renderer.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -41,12 +42,12 @@ class FPSSystem : public MouseListener, public KeyboardListener, public Accelero
 public:
 public:
 
 
 					/// Constructor
 					/// Constructor
-					FPSSystem(MovableCamera* camera);
+					FPSSystem(Camera* camera, float speed, float sensibility);
 
 
-	void 			set_camera(MovableCamera* camera);
-	MovableCamera*	get_camera();
+	void 			set_camera(Camera* camera);
+	Camera*			camera();
 
 
-	void			camera_render();
+	void			update();
 	void			set_view_by_cursor();	
 	void			set_view_by_cursor();	
 
 
 	virtual void 	key_pressed(const KeyboardEvent& event);
 	virtual void 	key_pressed(const KeyboardEvent& event);
@@ -55,7 +56,10 @@ public:
 
 
 private:
 private:
 
 
-	MovableCamera*	m_camera;
+	Camera*			m_camera;
+
+	float			m_camera_speed;
+	float			m_camera_sensibility;
 
 
 	real 			m_angle_x;
 	real 			m_angle_x;
 	real 			m_angle_y;
 	real 			m_angle_y;

+ 0 - 145
src/MovableCamera.cpp

@@ -1,145 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Device.h"
-#include "Mat3.h"
-#include "Types.h"
-#include "MovableCamera.h"
-#include "Device.h"
-#include "InputManager.h"
-
-namespace crown
-{
-//-----------------------------------------------------------------------
-MovableCamera::MovableCamera(const Vec3& position, bool visible, float fov, float aspect, bool active, float speed, float sensibility) :
-	Camera(position, visible, fov, aspect, active),
-	mSpeed(speed),
-	mSensibility(sensibility)
-{
-	mRotFactor = Vec2(0.0f, 0.0f);
-	mAngleX = 0.0f;
-	mAngleY = 0.0f;
-}
-
-//-----------------------------------------------------------------------
-MovableCamera::~MovableCamera()
-{
-}
-
-//-----------------------------------------------------------------------
-float MovableCamera::GetSensibility() const
-{
-	return mSensibility;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetActive(bool active)
-{
-	Camera::SetActive(active);
-	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetSensibility(float sensibility)
-{
-	mSensibility = sensibility;
-}
-
-//-----------------------------------------------------------------------
-float MovableCamera::GetSpeed() const
-{
-	return mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetSpeed(float speed)
-{
-	mSpeed = speed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::Render()
-{
-	if (!mActive)
-	{
-		return;
-	}
-
-	UpdateViewMatrix();
-
-	Camera::Render();
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::MoveForward()
-{
-	mPosition += mLookAt * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::MoveBackward()
-{
-	mPosition -= mLookAt * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::StrafeLeft()
-{
-	Vec3 left = mUp.cross(mLookAt);
-	left.normalize();
-	mPosition += left * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::StrafeRight()
-{
-	Vec3 left = mUp.cross(mLookAt);
-	left.normalize();
-	mPosition -= left * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetRotation(const float x, const float y)
-{
-	Vec3 right(1, 0, 0);
-	Vec3 look;
-
-	look.x = 0.0f;
-	look.y = math::sin(x);
-	look.z = -math::cos(x);
-
-	Vec3 up = right.cross(look);
-	up.normalize();
-
-	Mat3 m;
-	m.build_rotation_y(y);
-	look = m * look;
-	mUp = m * up;
-
-	Camera::SetLookAt(look);
-}
-
-} // namespace crown
-

+ 0 - 84
src/MovableCamera.h

@@ -1,84 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "Camera.h"
-#include "Vec2.h"
-#include "Mouse.h"
-#include "Keyboard.h"
-
-namespace crown
-{
-
-class MovableCamera : public Camera
-{
-
-public:
-
-	//! Constructor
-	MovableCamera(const Vec3& position, bool visible, float fov, float aspect,
-					bool active, float speed, float sensibility);
-
-	//! Destructor
-	~MovableCamera();
-
-	//! Returns the camera's movement sensibility
-	float GetSensibility() const;
-
-	//! Sets the camera's movement sensibility
-	void SetSensibility(float sensibility);
-
-	//! Returns the camera's speed
-	float GetSpeed() const;
-
-	//! Sets the camera speed
-	void SetSpeed(float speed);
-
-	void SetActive(bool active);
-
-	//! Loads the view matrix
-	virtual void Render();
-
-	void MoveForward();
-	void MoveBackward();
-	void StrafeLeft();
-	void StrafeRight();
-	void SetRotation(const real x, const real y);
-
-protected:
-
-	Vec2 mRotFactor;
-	float mAngleX;
-	float mAngleY;
-
-	float mSpeed;
-	float mSensibility;
-
-};
-
-} // namespace crown
-