From: Daniel Karbach Date: Sat, 29 Sep 2012 17:52:27 +0000 (+0200) Subject: added camera class X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=e9bdecf5f58fb9e5b2c067c20d0ce70f54f9ecb7;hp=4d4b40f06357392931cb309d0284875c40c2f2f0;p=l2e.git added camera class --- diff --git a/Debug/src/graphics/subdir.mk b/Debug/src/graphics/subdir.mk index c755a65..1f5268e 100644 --- a/Debug/src/graphics/subdir.mk +++ b/Debug/src/graphics/subdir.mk @@ -5,6 +5,7 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ ../src/graphics/Animation.cpp \ +../src/graphics/Camera.cpp \ ../src/graphics/ComplexAnimation.cpp \ ../src/graphics/Font.cpp \ ../src/graphics/Frame.cpp \ @@ -15,6 +16,7 @@ CPP_SRCS += \ OBJS += \ ./src/graphics/Animation.o \ +./src/graphics/Camera.o \ ./src/graphics/ComplexAnimation.o \ ./src/graphics/Font.o \ ./src/graphics/Frame.o \ @@ -25,6 +27,7 @@ OBJS += \ CPP_DEPS += \ ./src/graphics/Animation.d \ +./src/graphics/Camera.d \ ./src/graphics/ComplexAnimation.d \ ./src/graphics/Font.d \ ./src/graphics/Frame.d \ diff --git a/Release/src/graphics/subdir.mk b/Release/src/graphics/subdir.mk index 9e05a70..ed834d9 100644 --- a/Release/src/graphics/subdir.mk +++ b/Release/src/graphics/subdir.mk @@ -5,6 +5,7 @@ # Add inputs and outputs from these tool invocations to the build variables CPP_SRCS += \ ../src/graphics/Animation.cpp \ +../src/graphics/Camera.cpp \ ../src/graphics/ComplexAnimation.cpp \ ../src/graphics/Font.cpp \ ../src/graphics/Frame.cpp \ @@ -15,6 +16,7 @@ CPP_SRCS += \ OBJS += \ ./src/graphics/Animation.o \ +./src/graphics/Camera.o \ ./src/graphics/ComplexAnimation.o \ ./src/graphics/Font.o \ ./src/graphics/Frame.o \ @@ -25,6 +27,7 @@ OBJS += \ CPP_DEPS += \ ./src/graphics/Animation.d \ +./src/graphics/Camera.d \ ./src/graphics/ComplexAnimation.d \ ./src/graphics/Font.d \ ./src/graphics/Frame.d \ diff --git a/src/graphics/Camera.cpp b/src/graphics/Camera.cpp new file mode 100644 index 0000000..d43864a --- /dev/null +++ b/src/graphics/Camera.cpp @@ -0,0 +1,34 @@ +/* + * Camera.cpp + * + * Created on: Sep 29, 2012 + * Author: holy + */ + +#include "Camera.h" + +#include + +using geometry::Vector; + +namespace graphics { + +Camera::Camera(int width, int height, const Vector *target) +: target(target), halfWidth(width / 2), halfHeight(height / 2) { + assert(target && "construct camera without target"); +} + + +void Camera::SetTarget(const Vector *t) { + assert(t && "cannot change camera target to 0"); + target = t; +} + + +Vector Camera::CalculateOffset() const { + return Vector( + (target->X() - halfWidth) * -1, + (target->Y() - halfHeight) * -1); +} + +} diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h new file mode 100644 index 0000000..16c0caf --- /dev/null +++ b/src/graphics/Camera.h @@ -0,0 +1,36 @@ +/* + * Camera.h + * + * Created on: Sep 29, 2012 + * Author: holy + */ + +#ifndef GRAPHICS_CAMERA_H_ +#define GRAPHICS_CAMERA_H_ + +#include "../geometry/Vector.h" + +namespace graphics { + +class Camera { + +public: + Camera(int width, int height, const geometry::Vector *target); + ~Camera() { } + +public: + void Resize(int w, int h) { halfWidth = w / 2; halfHeight = h / 2; } + void SetTarget(const geometry::Vector *t); + + geometry::Vector CalculateOffset() const; + +private: + const geometry::Vector *target; + int halfWidth; + int halfHeight; + +}; + +} + +#endif /* GRAPHICS_CAMERA_H_ */ diff --git a/src/graphics/fwd.h b/src/graphics/fwd.h index e6cf864..6b438fe 100644 --- a/src/graphics/fwd.h +++ b/src/graphics/fwd.h @@ -12,6 +12,7 @@ namespace graphics { class Animation; class AnimationRunner; +class Camera; class Color; class ComplexAnimation; class Font;