MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
camera_2d.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include <iostream>
11
12#include "math/matrix_tools.h"
13#include "ogl/opengl.h"
14#include "ogl/camera_2d.h"
15
17
18Cam2D::Cam2D(void)
19{
20 this->radius = 1.0f;
21 this->center = math::Vec3f(0.0f);
22 this->mousePos = math::Vec2f(0.0f);
23 this->tocam = math::Vec3f(0.0f, 0.0f, 1.0f);
24 this->upvec = math::Vec3f(0.0f, 1.0f, 0.0f);
25}
26
27void
28Cam2D::consume_event(const MouseEvent &event)
29{
30 if (event.type == MOUSE_EVENT_PRESS)
31 {
32 if (event.button == MOUSE_BUTTON_LEFT)
33 {
34 this->mousePos[0] = event.x;
35 this->mousePos[1] = event.y;
36 }
37 }
38 else if (event.type == MOUSE_EVENT_MOVE)
39 {
40 // Center is translated by the position difference (in pixel)
41 // TODO Make this Viewport dependent?
42 // Conflict between projective/orthographic assumptions
44 {
45 this->center[0] += (this->mousePos[0] - event.x);
46 this->center[1] += (this->mousePos[1] - event.y);
47 this->mousePos[0] = event.x;
48 this->mousePos[1] = event.y;
49 }
50 }
51 else if (event.type == MOUSE_EVENT_WHEEL_UP)
52 {
53 this->radius += this->radius / 10.0f;
54 this->radius = std::min(40.0f, this->radius);
55 }
56 else if (event.type == MOUSE_EVENT_WHEEL_DOWN)
57 {
58 this->radius -= this->radius / 10.0f;
59 this->radius = std::max(0.01f, this->radius);
60 }
61
62}
63
64void
65Cam2D::consume_event(KeyboardEvent const& /*event*/)
66{
67}
68
69math::Vec3f Cam2D::get_campos()
70{
71 return this->center + this->tocam * this->radius;
72}
73
74math::Vec3f Cam2D::get_viewdir()
75{
76 return -this->tocam;
77}
78
79math::Vec3f Cam2D::get_upvec()
80{
81 return this->upvec;
82}
83
84void Cam2D::set_camera (Camera *camera)
85{
86 this->cam = camera;
87}
88
Vector class for arbitrary dimensions and types.
Definition vector.h:87
A camera class that manages viewing and projection matrices.
Definition camera.h:33
Vector< float, 2 > Vec2f
Definition vector.h:30
Vector< float, 3 > Vec3f
Definition vector.h:31
@ MOUSE_EVENT_MOVE
Definition events.h:22
@ MOUSE_EVENT_PRESS
Definition events.h:20
@ MOUSE_EVENT_WHEEL_UP
Definition events.h:23
@ MOUSE_EVENT_WHEEL_DOWN
Definition events.h:24
@ MOUSE_BUTTON_LEFT
Definition events.h:31
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13
Keyboard event.
Definition events.h:57
Mouse event.
Definition events.h:40
MouseEventType type
Type of event.
Definition events.h:41
MouseButton button
Button that caused the event.
Definition events.h:42
int button_mask
Button state when event was generated.
Definition events.h:43