~etc-pgh-launchpad/wildpockets/trunk

« back to all changes in this revision

Viewing changes to render/CameraBoom.h

  • Committer: etc-pgh-launchpad at cmu
  • Date: 2010-11-30 20:56:30 UTC
  • Revision ID: etc-pgh-launchpad@lists.andrew.cmu.edu-20101130205630-0blbkcz28ovjl8wj
Committing the Wild Pockets code base to Launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
Wild Pockets
 
3
 
 
4
Copyright (c) 2010 Carnegie Mellon University
 
5
 
 
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:
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
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
 
22
THE SOFTWARE.
 
23
 
 
24
**/
 
25
 
 
26
 
 
27
/** @file CameraBoom.h
 
28
 **/
 
29
 
 
30
#ifndef __SOS_CAMERABOOM_H__
 
31
#define __SOS_CAMERABOOM_H__
 
32
 
 
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"
 
39
 
 
40
class CameraBoom : public UnifiedMemory {
 
41
  public:
 
42
    CameraBoom();
 
43
    ~CameraBoom();
 
44
 
 
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); }
 
54
 
 
55
    const Matrix4x4 &getWorldToView() { if (m_dirty) recalcMatrices(); return m_worldToView; }
 
56
    const Matrix4x4 &getViewToClip() { if (m_dirty) recalcMatrices(); return m_viewToClip; }
 
57
    
 
58
    void recalcMatrices();
 
59
 
 
60
    Vector3D worldToScreen(Vector3D point);
 
61
    void screenToWorld(double x, double y,Vector3D &direction,Vector3D &origin);
 
62
 
 
63
  private:
 
64
 
 
65
    Transform m_transform;
 
66
    Vector3D m_xaxis;
 
67
    Vector3D m_yaxis;
 
68
    Vector3D m_zaxis;
 
69
 
 
70
    // Calculated camera parameters.
 
71
 
 
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
 
78
    bool m_dirty;
 
79
 
 
80
    // Explicitly-specified camera parameters.
 
81
    double m_nearPlane;
 
82
    double m_farPlane;
 
83
    double m_fov;
 
84
    bool m_orthographic;
 
85
 
 
86
public:
 
87
    DECLARE_SCRIPTNAME(CameraBoom);
 
88
 
 
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);
 
103
};
 
104
 
 
105
DEFINE_LUAFETCH(CameraBoom**,CameraBoom);
 
106
DEFINE_LUAFETCH_DEPTR(CameraBoom*);
 
107
DEFINE_LUAFETCH_UM(CameraBoom_ref, CameraBoom);
 
108
DEFINE_LUAINSTANTIATE_UM(CameraBoom_ref, CameraBoom);
 
109
 
 
110
#endif