source: trunk/src/camera.cpp @ 1325

Last change on this file since 1325 was 1325, checked in by sam, 9 years ago

core: move some of the camera view logic from the Video class to the
Scene and Camera classes.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 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://sam.zoy.org/projects/COPYING.WTFPL 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#endif
23
24namespace lol
25{
26
27Camera::Camera(vec3 const &position, vec3 const &target, vec3 const &up)
28  : m_target(target),
29    m_up(up)
30{
31    m_gamegroup = GAMEGROUP_BEFORE;
32    m_drawgroup = DRAWGROUP_CAMERA;
33
34    SetPosition(position);
35}
36
37Camera::~Camera()
38{
39}
40
41void Camera::SetPosition(vec3 const &pos)
42{
43    m_position = pos;
44}
45
46mat4 const &Camera::GetViewMatrix()
47{
48    return m_view_matrix;
49}
50
51mat4 const &Camera::GetProjMatrix()
52{
53    return m_proj_matrix;
54}
55
56void Camera::TickGame(float seconds)
57{
58    WorldEntity::TickGame(seconds);
59
60    m_view_matrix = mat4::lookat(m_position, m_target, m_up);
61    m_proj_matrix = mat4::perspective(45.0f, 640.0f, 480.0f, 1.f, 1000.0f);
62    //m_proj_matrix = mat4::ortho(-160, 160, -120, 120, .1f, 2000.0f);
63}
64
65void Camera::TickDraw(float seconds)
66{
67    WorldEntity::TickDraw(seconds);
68
69    Scene::GetDefault()->SetViewMatrix(m_view_matrix);
70    Scene::GetDefault()->SetProjMatrix(m_proj_matrix);
71}
72
73} /* namespace lol */
74
Note: See TracBrowser for help on using the repository browser.