camera.h
1 /*************************************************************************/
2 /* camera.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef CAMERA_H
30 #define CAMERA_H
31 
32 
33 #include "scene/3d/spatial.h"
34 #include "scene/main/viewport.h"
35 #include "scene/resources/environment.h"
39 class Camera : public Spatial {
40 
41  OBJ_TYPE( Camera, Spatial );
42 public:
43  enum Projection {
44 
45  PROJECTION_PERSPECTIVE,
46  PROJECTION_ORTHOGONAL
47  };
48 
49  enum KeepAspect {
50  KEEP_WIDTH,
51  KEEP_HEIGHT
52  };
53 
54 private:
55 
56  bool force_change;
57  bool current;
58 
59  Projection mode;
60 
61  float fov;
62  float size;
63  float near,far;
64  float v_offset;
65  float h_offset;
66  KeepAspect keep_aspect;
67 
68  RID camera;
69  RID scenario_id;
70 
71  //String camera_group;
72 
73  uint32_t layers;
74 
75  Ref<Environment> environment;
76 
77  virtual bool _can_gizmo_scale() const;
78  virtual RES _get_gizmo_geometry() const;
79 
80 
81  //void _camera_make_current(Node *p_camera);
82 friend class Viewport;
83  void _update_audio_listener_state();
84 protected:
85 
86  void _update_camera();
87  virtual void _request_camera_update();
88  void _update_camera_mode();
89 
90  bool _set(const StringName& p_name, const Variant& p_value);
91  bool _get(const StringName& p_name,Variant &r_ret) const;
92  void _get_property_list( List<PropertyInfo> *p_list) const;
93  void _notification(int p_what);
94 
95  static void _bind_methods();
96 
97 public:
98 
99  enum {
100 
101  NOTIFICATION_BECAME_CURRENT=50,
102  NOTIFICATION_LOST_CURRENT=51
103  };
104 
105  void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far);
106  void set_orthogonal(float p_size, float p_z_near, float p_z_far);
107 
108  void make_current();
109  void clear_current();
110  bool is_current() const;
111 
112  RID get_camera() const;
113 
114  float get_fov() const;
115  float get_size() const;
116  float get_zfar() const;
117  float get_znear() const;
118  Projection get_projection() const;
119 
120  virtual Transform get_camera_transform() const;
121 
122  Vector3 project_ray_normal(const Point2& p_point) const;
123  Vector3 project_ray_origin(const Point2& p_point) const;
124  Vector3 project_local_ray_normal(const Point2& p_point) const;
125  Point2 unproject_position(const Vector3& p_pos) const;
126  bool is_position_behind(const Vector3& p_pos) const;
127  Vector3 project_position(const Point2& p_point) const;
128 
129  void set_visible_layers(uint32_t p_layers);
130  uint32_t get_visible_layers() const;
131 
132  Vector<Plane> get_frustum() const;
133 
134  void set_environment(const Ref<Environment>& p_environment);
135  Ref<Environment> get_environment() const;
136 
137  void set_keep_aspect_mode(KeepAspect p_aspect);
138  KeepAspect get_keep_aspect_mode() const;
139 
140 
141  void set_v_offset(float p_offset);
142  float get_v_offset() const;
143 
144  void set_h_offset(float p_offset);
145  float get_h_offset() const;
146 
147 
148  Camera();
149  ~Camera();
150 
151 };
152 
153 
154 VARIANT_ENUM_CAST( Camera::Projection );
155 VARIANT_ENUM_CAST( Camera::KeepAspect );
156 
157 #endif
Definition: viewport.h:75
Definition: variant.h:74
Definition: camera.h:39
Definition: string_db.h:48
Definition: vector3.h:38
Definition: transform.h:38
Definition: rid.h:47
Definition: math_2d.h:65
Definition: spatial.h:56