diff --git a/src/Makefile.am b/src/Makefile.am index 1537c453..905158d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,7 @@ liblol_a_SOURCES = \ world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \ worldentity.cpp worldentity.h gradient.cpp gradient.h \ - platform.cpp platform.h sprite.cpp sprite.h \ + platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ \ lol/unit.h lol/debug.h \ lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ diff --git a/src/camera.cpp b/src/camera.cpp new file mode 100644 index 00000000..3cf706da --- /dev/null +++ b/src/camera.cpp @@ -0,0 +1,70 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#include "core.h" + +#if defined _WIN32 || defined _XBOX +# define strcasecmp _stricmp +#endif + +namespace lol +{ + +Camera::Camera(vec3 const &position, vec3 const &target, vec3 const &up) + : m_target(target), + m_up(up) +{ + m_gamegroup = GAMEGROUP_BEFORE; + + SetPosition(position); +} + +Camera::~Camera() +{ +} + +void Camera::SetPosition(vec3 const &pos) +{ + m_position = pos; +} + +mat4 const &Camera::GetViewMatrix() +{ + return m_view_matrix; +} + +mat4 const &Camera::GetProjMatrix() +{ + return m_proj_matrix; +} + +void Camera::TickGame(float deltams) +{ + WorldEntity::TickGame(deltams); + + m_view_matrix = mat4::lookat(m_position, m_target, m_up); + m_proj_matrix = mat4::perspective(45.0f, 640.0f, 480.0f, 1.f, 1000.0f); + //m_proj_matrix = mat4::ortho(-160, 160, -120, 120, .1f, 2000.0f); +} + +void Camera::TickDraw(float deltams) +{ + WorldEntity::TickDraw(deltams); +} + +} /* namespace lol */ + diff --git a/src/camera.h b/src/camera.h new file mode 100644 index 00000000..b9483af8 --- /dev/null +++ b/src/camera.h @@ -0,0 +1,49 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The Camera class +// ---------------- +// + +#if !defined __CAMERA_H__ +#define __CAMERA_H__ + +#include "worldentity.h" + +namespace lol +{ + +class Camera : public WorldEntity +{ +public: + Camera(vec3 const &position, vec3 const &target, vec3 const &up); + ~Camera(); + + char const *GetName() { return ""; } + + void SetPosition(vec3 const &pos); + + mat4 const &GetViewMatrix(); + mat4 const &GetProjMatrix(); + +protected: + virtual void TickGame(float deltams); + virtual void TickDraw(float deltams); + +private: + mat4 m_view_matrix, m_proj_matrix; + vec3 m_target, m_up; +}; + +} /* namespace lol */ + +#endif /* __CAMERA_H__ */ + diff --git a/src/core.h b/src/core.h index 719f9b12..2789ba17 100644 --- a/src/core.h +++ b/src/core.h @@ -85,6 +85,7 @@ static inline int isnan(float f) #include "entity.h" #include "worldentity.h" +#include "camera.h" #include "emitter.h" #include "font.h" #include "gradient.h" diff --git a/win32/lolcore.vcxproj b/win32/lolcore.vcxproj index 8c38d6ec..a0029279 100644 --- a/win32/lolcore.vcxproj +++ b/win32/lolcore.vcxproj @@ -74,6 +74,7 @@ + @@ -128,6 +129,7 @@ + @@ -185,4 +187,4 @@ - \ No newline at end of file + diff --git a/win32/lolcore.vcxproj.filters b/win32/lolcore.vcxproj.filters index fd73beee..9a62fa89 100644 --- a/win32/lolcore.vcxproj.filters +++ b/win32/lolcore.vcxproj.filters @@ -70,6 +70,9 @@ src + + src + src @@ -225,6 +228,9 @@ src + + src + src @@ -365,4 +371,4 @@ src - \ No newline at end of file + diff --git a/win32/orbital.vcxproj b/win32/orbital.vcxproj index 601673c7..f6662cf0 100644 --- a/win32/orbital.vcxproj +++ b/win32/orbital.vcxproj @@ -27,7 +27,6 @@ - @@ -58,4 +57,4 @@ - \ No newline at end of file + diff --git a/win32/orbital.vcxproj.filters b/win32/orbital.vcxproj.filters index 9e8b8f7d..ed3dae58 100644 --- a/win32/orbital.vcxproj.filters +++ b/win32/orbital.vcxproj.filters @@ -2,7 +2,6 @@ - @@ -13,4 +12,4 @@ - \ No newline at end of file +