From e9bdecf5f58fb9e5b2c067c20d0ce70f54f9ecb7 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sat, 29 Sep 2012 19:52:27 +0200 Subject: [PATCH] added camera class --- Debug/src/graphics/subdir.mk | 3 +++ Release/src/graphics/subdir.mk | 3 +++ src/graphics/Camera.cpp | 34 ++++++++++++++++++++++++++++++++ src/graphics/Camera.h | 36 ++++++++++++++++++++++++++++++++++ src/graphics/fwd.h | 1 + 5 files changed, 77 insertions(+) create mode 100644 src/graphics/Camera.cpp create mode 100644 src/graphics/Camera.h 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; -- 2.39.2