4
Copyright (c) 2010 Carnegie Mellon University
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
/** @file CameraBoom.h
30
#ifndef __SOS_CAMERABOOM_H__
31
#define __SOS_CAMERABOOM_H__
33
//#include "core/CubMath.h"
34
//#include "core/BulletinBoard.h"
35
//#include "primitive/Vector3D.h"
36
#include "primitive/Transform.h"
37
#include "primitive/Matrix.h"
38
//#include "core/TaskManager_fwd.h"
40
class CameraBoom : public UnifiedMemory {
45
INLINE const Transform &getTransform() { return m_transform; }
46
INLINE Transform &modifyTransform() { m_dirty = true; return m_transform; }
47
INLINE void setTransform(const Transform &src) { m_dirty = true; m_transform = src; }
48
INLINE Vector3D getEyePosition() { return m_transform.getPosition(); }
49
INLINE Vector3D getForwardVector() { return m_yaxis; }
50
const Vector3D &getXAxis() { if (m_dirty) recalcMatrices(); return m_xaxis; }
51
const Vector3D &getYAxis() { if (m_dirty) recalcMatrices(); return m_yaxis; }
52
const Vector3D &getZAxis() { if (m_dirty) recalcMatrices(); return m_zaxis; }
53
const double getDepth(const Vector3D &point) { return (point-m_transform.getPosition()).dot(m_yaxis); }
55
const Matrix4x4 &getWorldToView() { if (m_dirty) recalcMatrices(); return m_worldToView; }
56
const Matrix4x4 &getViewToClip() { if (m_dirty) recalcMatrices(); return m_viewToClip; }
58
void recalcMatrices();
60
Vector3D worldToScreen(Vector3D point);
61
void screenToWorld(double x, double y,Vector3D &direction,Vector3D &origin);
65
Transform m_transform;
70
// Calculated camera parameters.
72
Matrix4x4 m_worldToView;
73
Matrix4x4 m_viewToClip;
74
double m_slopey; // Perspective only
75
double m_slopex; // Perspective only
76
double m_sizex; // Orthographic only
77
double m_sizey; // Orthographic only
80
// Explicitly-specified camera parameters.
87
DECLARE_SCRIPTNAME(CameraBoom);
89
DECLARE_SCRIPTMETHOD(__gc);
90
DECLARE_SCRIPTMETHOD(__tostring);
91
DECLARE_SCRIPTMETHOD(new);
92
DECLARE_SCRIPTMETHOD(clone);
93
DECLARE_SCRIPTMETHOD(setEyeFocus);
94
DECLARE_SCRIPTMETHOD(getTransform);
95
DECLARE_SCRIPTMETHOD(setTransform);
96
DECLARE_SCRIPTMETHOD(guiProject);
97
DECLARE_SCRIPTMETHOD(setFov);
98
DECLARE_SCRIPTMETHOD(getFov);
99
DECLARE_SCRIPTMETHOD(setNearFarPlanes);
100
DECLARE_SCRIPTMETHOD(getNearFarPlanes);
101
DECLARE_SCRIPTMETHOD(fitObjects);
102
DECLARE_SCRIPTMETHOD(objectIsWithin);
105
DEFINE_LUAFETCH(CameraBoom**,CameraBoom);
106
DEFINE_LUAFETCH_DEPTR(CameraBoom*);
107
DEFINE_LUAFETCH_UM(CameraBoom_ref, CameraBoom);
108
DEFINE_LUAINSTANTIATE_UM(CameraBoom_ref, CameraBoom);