]> git.localhorst.tv Git - l2e.git/commitdiff
added camera class
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Sep 2012 17:52:27 +0000 (19:52 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Sep 2012 17:52:27 +0000 (19:52 +0200)
Debug/src/graphics/subdir.mk
Release/src/graphics/subdir.mk
src/graphics/Camera.cpp [new file with mode: 0644]
src/graphics/Camera.h [new file with mode: 0644]
src/graphics/fwd.h

index c755a65ad3f45555602c49fe91c1b97171d85316..1f5268e567c9c2ca42d7873c1b16e7a31eb436db 100644 (file)
@@ -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 \
index 9e05a70ba1fc3e589b80d3d086a5fd2a62614247..ed834d987c9abe69be39cd275414a9b2f77b6e68 100644 (file)
@@ -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 (file)
index 0000000..d43864a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Camera.cpp
+ *
+ *  Created on: Sep 29, 2012
+ *      Author: holy
+ */
+
+#include "Camera.h"
+
+#include <cassert>
+
+using geometry::Vector;
+
+namespace graphics {
+
+Camera::Camera(int width, int height, const Vector<int> *target)
+: target(target), halfWidth(width / 2), halfHeight(height / 2) {
+       assert(target && "construct camera without target");
+}
+
+
+void Camera::SetTarget(const Vector<int> *t) {
+       assert(t && "cannot change camera target to 0");
+       target = t;
+}
+
+
+Vector<int> Camera::CalculateOffset() const {
+       return Vector<int>(
+                       (target->X() - halfWidth) * -1,
+                       (target->Y() - halfHeight) * -1);
+}
+
+}
diff --git a/src/graphics/Camera.h b/src/graphics/Camera.h
new file mode 100644 (file)
index 0000000..16c0caf
--- /dev/null
@@ -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<int> *target);
+       ~Camera() { }
+
+public:
+       void Resize(int w, int h) { halfWidth = w / 2; halfHeight = h / 2; }
+       void SetTarget(const geometry::Vector<int> *t);
+
+       geometry::Vector<int> CalculateOffset() const;
+
+private:
+       const geometry::Vector<int> *target;
+       int halfWidth;
+       int halfHeight;
+
+};
+
+}
+
+#endif /* GRAPHICS_CAMERA_H_ */
index e6cf864de7b34f14f3645f7ba682e9cdbab6c401..6b438fe6c20af7be91acde63a8cd858efba4c611 100644 (file)
@@ -12,6 +12,7 @@ namespace graphics {
 
 class Animation;
 class AnimationRunner;
+class Camera;
 class Color;
 class ComplexAnimation;
 class Font;