source: trunk/src/camera.cpp @ 2476

Last change on this file since 2476 was 2476, checked in by sam, 7 years ago

scene: start refactoring the camera code; we now have a stack of cameras
in the scene where we can push and pop cameras.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstring>
16#include <cstdlib>
17
18#include "core.h"
19
20#if defined _WIN32 || defined _XBOX
21#   define strcasecmp _stricmp
22#   undef near
23#   undef far
24#endif
25
26namespace lol
27{
28
29Camera::Camera()
30{
31    m_gamegroup = GAMEGROUP_BEFORE;
32    m_drawgroup = DRAWGROUP_CAMERA;
33
34    /* Create a default perspective */
35    SetProjection(mat4::perspective(45.f, 800.f, 600.f, -1000.f, 1000.f));
36    SetView(mat4::lookat(vec3(0.f, 50.f, 50.f),
37                         vec3(0.f),
38                         vec3(0.f, 1.f, 0.f)));
39}
40
41Camera::~Camera()
42{
43}
44
45void Camera::SetView(mat4 const &view)
46{
47    m_view_matrix = view;
48    m_position = inverse(view)[3].xyz;
49}
50
51void Camera::SetView(vec3 eye, vec3 target, vec3 up)
52{
53    m_view_matrix = mat4::lookat(eye, target, up);
54    m_position = eye;
55}
56
57void Camera::SetView(vec3 pos, quat rot)
58{
59    m_view_matrix = mat4::lookat(pos,
60                                 pos + rot.transform(vec3(0.f, 0.f, -1.f)),
61                                 rot.transform(vec3(0.f, 1.f, 0.f)));
62    m_position = pos;
63}
64
65void Camera::SetProjection(mat4 const &proj)
66{
67    m_proj_matrix = proj;
68}
69
70mat4 Camera::GetView()
71{
72    return m_view_matrix;
73}
74
75mat4 Camera::GetProjection()
76{
77    return m_proj_matrix;
78}
79
80vec3 Camera::GetPosition()
81{
82    return m_position;
83}
84
85void Camera::TickGame(float seconds)
86{
87    WorldEntity::TickGame(seconds);
88}
89
90void Camera::TickDraw(float seconds)
91{
92    WorldEntity::TickDraw(seconds);
93}
94
95} /* namespace lol */
96
Note: See TracBrowser for help on using the repository browser.