camera.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*************************************************************************/
  2. /* camera.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "camera.h"
  31. #include "camera_matrix.h"
  32. #include "scene/resources/material.h"
  33. #include "scene/resources/surface_tool.h"
  34. void Camera::_update_audio_listener_state() {
  35. }
  36. void Camera::_request_camera_update() {
  37. _update_camera();
  38. }
  39. void Camera::_update_camera_mode() {
  40. force_change = true;
  41. switch (mode) {
  42. case PROJECTION_PERSPECTIVE: {
  43. set_perspective(fov, near, far);
  44. } break;
  45. case PROJECTION_ORTHOGONAL: {
  46. set_orthogonal(size, near, far);
  47. } break;
  48. }
  49. }
  50. void Camera::_validate_property(PropertyInfo &p_property) const {
  51. if (p_property.name == "fov") {
  52. if (mode == PROJECTION_ORTHOGONAL) {
  53. p_property.usage = PROPERTY_USAGE_NOEDITOR;
  54. }
  55. } else if (p_property.name == "size") {
  56. if (mode == PROJECTION_PERSPECTIVE) {
  57. p_property.usage = PROPERTY_USAGE_NOEDITOR;
  58. }
  59. }
  60. }
  61. void Camera::_update_camera() {
  62. if (!is_inside_tree())
  63. return;
  64. Transform tr = get_camera_transform();
  65. tr.origin += tr.basis.get_axis(1) * v_offset;
  66. tr.origin += tr.basis.get_axis(0) * h_offset;
  67. VisualServer::get_singleton()->camera_set_transform(camera, tr);
  68. // here goes listener stuff
  69. /*
  70. if (viewport_ptr && is_inside_scene() && is_current())
  71. get_viewport()->_camera_transform_changed_notify();
  72. */
  73. if (get_tree()->is_node_being_edited(this) || !is_current())
  74. return;
  75. get_viewport()->_camera_transform_changed_notify();
  76. if (get_world().is_valid()) {
  77. get_world()->_update_camera(this);
  78. }
  79. }
  80. void Camera::_notification(int p_what) {
  81. switch (p_what) {
  82. case NOTIFICATION_ENTER_WORLD: {
  83. bool first_camera = get_viewport()->_camera_add(this);
  84. if (!get_tree()->is_node_being_edited(this) && (current || first_camera))
  85. make_current();
  86. } break;
  87. case NOTIFICATION_TRANSFORM_CHANGED: {
  88. _request_camera_update();
  89. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  90. velocity_tracker->update_position(get_global_transform().origin);
  91. }
  92. } break;
  93. case NOTIFICATION_EXIT_WORLD: {
  94. if (!get_tree()->is_node_being_edited(this)) {
  95. if (is_current()) {
  96. clear_current();
  97. current = true; //keep it true
  98. } else {
  99. current = false;
  100. }
  101. }
  102. get_viewport()->_camera_remove(this);
  103. } break;
  104. case NOTIFICATION_BECAME_CURRENT: {
  105. if (get_world().is_valid()) {
  106. get_world()->_register_camera(this);
  107. }
  108. } break;
  109. case NOTIFICATION_LOST_CURRENT: {
  110. if (get_world().is_valid()) {
  111. get_world()->_remove_camera(this);
  112. }
  113. } break;
  114. }
  115. }
  116. Transform Camera::get_camera_transform() const {
  117. return get_global_transform().orthonormalized();
  118. }
  119. void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) {
  120. if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE)
  121. return;
  122. fov = p_fovy_degrees;
  123. near = p_z_near;
  124. far = p_z_far;
  125. mode = PROJECTION_PERSPECTIVE;
  126. VisualServer::get_singleton()->camera_set_perspective(camera, fov, near, far);
  127. update_gizmo();
  128. force_change = false;
  129. }
  130. void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
  131. if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL)
  132. return;
  133. size = p_size;
  134. near = p_z_near;
  135. far = p_z_far;
  136. mode = PROJECTION_ORTHOGONAL;
  137. force_change = false;
  138. VisualServer::get_singleton()->camera_set_orthogonal(camera, size, near, far);
  139. update_gizmo();
  140. }
  141. void Camera::set_projection(Camera::Projection p_mode) {
  142. if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL) {
  143. mode = p_mode;
  144. _update_camera_mode();
  145. _change_notify();
  146. }
  147. }
  148. RID Camera::get_camera() const {
  149. return camera;
  150. };
  151. void Camera::make_current() {
  152. current = true;
  153. if (!is_inside_tree())
  154. return;
  155. get_viewport()->_camera_set(this);
  156. //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this);
  157. }
  158. void Camera::clear_current(bool p_enable_next) {
  159. current = false;
  160. if (!is_inside_tree())
  161. return;
  162. if (get_viewport()->get_camera() == this) {
  163. get_viewport()->_camera_set(NULL);
  164. if (p_enable_next) {
  165. get_viewport()->_camera_make_next_current(this);
  166. }
  167. }
  168. }
  169. void Camera::set_current(bool p_current) {
  170. if (p_current) {
  171. make_current();
  172. } else {
  173. clear_current();
  174. }
  175. }
  176. bool Camera::is_current() const {
  177. if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
  178. return get_viewport()->get_camera() == this;
  179. } else
  180. return current;
  181. return false;
  182. }
  183. bool Camera::_can_gizmo_scale() const {
  184. return false;
  185. }
  186. Vector3 Camera::project_ray_normal(const Point2 &p_pos) const {
  187. Vector3 ray = project_local_ray_normal(p_pos);
  188. return get_camera_transform().basis.xform(ray).normalized();
  189. };
  190. Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const {
  191. if (!is_inside_tree()) {
  192. ERR_EXPLAIN("Camera is not inside scene.");
  193. ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
  194. }
  195. Size2 viewport_size = get_viewport()->get_camera_rect_size();
  196. Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
  197. Vector3 ray;
  198. if (mode == PROJECTION_ORTHOGONAL) {
  199. ray = Vector3(0, 0, -1);
  200. } else {
  201. CameraMatrix cm;
  202. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  203. float screen_w, screen_h;
  204. cm.get_viewport_size(screen_w, screen_h);
  205. ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_w, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_h, -near).normalized();
  206. }
  207. return ray;
  208. };
  209. Vector3 Camera::project_ray_origin(const Point2 &p_pos) const {
  210. if (!is_inside_tree()) {
  211. ERR_EXPLAIN("Camera is not inside scene.");
  212. ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
  213. }
  214. Size2 viewport_size = get_viewport()->get_camera_rect_size();
  215. Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
  216. ERR_FAIL_COND_V(viewport_size.y == 0, Vector3());
  217. if (mode == PROJECTION_PERSPECTIVE) {
  218. return get_camera_transform().origin;
  219. } else {
  220. Vector2 pos = cpos / viewport_size;
  221. float vsize, hsize;
  222. if (keep_aspect == KEEP_WIDTH) {
  223. vsize = size / viewport_size.aspect();
  224. hsize = size;
  225. } else {
  226. hsize = size * viewport_size.aspect();
  227. vsize = size;
  228. }
  229. Vector3 ray;
  230. ray.x = pos.x * (hsize)-hsize / 2;
  231. ray.y = (1.0 - pos.y) * (vsize)-vsize / 2;
  232. ray.z = -near;
  233. ray = get_camera_transform().xform(ray);
  234. return ray;
  235. };
  236. };
  237. bool Camera::is_position_behind(const Vector3 &p_pos) const {
  238. Transform t = get_global_transform();
  239. Vector3 eyedir = -get_global_transform().basis.get_axis(2).normalized();
  240. return eyedir.dot(p_pos) < (eyedir.dot(t.origin) + near);
  241. }
  242. Point2 Camera::unproject_position(const Vector3 &p_pos) const {
  243. if (!is_inside_tree()) {
  244. ERR_EXPLAIN("Camera is not inside scene.");
  245. ERR_FAIL_COND_V(!is_inside_tree(), Vector2());
  246. }
  247. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  248. CameraMatrix cm;
  249. if (mode == PROJECTION_ORTHOGONAL)
  250. cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  251. else
  252. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  253. Plane p(get_camera_transform().xform_inv(p_pos), 1.0);
  254. p = cm.xform4(p);
  255. p.normal /= p.d;
  256. Point2 res;
  257. res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x;
  258. res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y;
  259. return res;
  260. }
  261. Vector3 Camera::project_position(const Point2 &p_point) const {
  262. if (!is_inside_tree()) {
  263. ERR_EXPLAIN("Camera is not inside scene.");
  264. ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
  265. }
  266. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  267. CameraMatrix cm;
  268. if (mode == PROJECTION_ORTHOGONAL)
  269. cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  270. else
  271. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  272. Size2 vp_size;
  273. cm.get_viewport_size(vp_size.x, vp_size.y);
  274. Vector2 point;
  275. point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0;
  276. point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0;
  277. point *= vp_size;
  278. Vector3 p(point.x, point.y, -near);
  279. return get_camera_transform().xform(p);
  280. }
  281. /*
  282. void Camera::_camera_make_current(Node *p_camera) {
  283. if (p_camera==this) {
  284. VisualServer::get_singleton()->viewport_attach_camera(viewport_id,camera);
  285. active=true;
  286. } else {
  287. if (active && p_camera==NULL) {
  288. //detech camera because no one else will claim it
  289. VisualServer::get_singleton()->viewport_attach_camera(viewport_id,RID());
  290. }
  291. active=false;
  292. }
  293. }
  294. */
  295. void Camera::set_environment(const Ref<Environment> &p_environment) {
  296. environment = p_environment;
  297. if (environment.is_valid())
  298. VS::get_singleton()->camera_set_environment(camera, environment->get_rid());
  299. else
  300. VS::get_singleton()->camera_set_environment(camera, RID());
  301. _update_camera_mode();
  302. }
  303. Ref<Environment> Camera::get_environment() const {
  304. return environment;
  305. }
  306. void Camera::set_keep_aspect_mode(KeepAspect p_aspect) {
  307. keep_aspect = p_aspect;
  308. VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH);
  309. _update_camera_mode();
  310. _change_notify();
  311. }
  312. Camera::KeepAspect Camera::get_keep_aspect_mode() const {
  313. return keep_aspect;
  314. }
  315. void Camera::set_doppler_tracking(DopplerTracking p_tracking) {
  316. if (doppler_tracking == p_tracking)
  317. return;
  318. doppler_tracking = p_tracking;
  319. if (p_tracking != DOPPLER_TRACKING_DISABLED) {
  320. velocity_tracker->set_track_physics_step(doppler_tracking == DOPPLER_TRACKING_PHYSICS_STEP);
  321. velocity_tracker->reset(get_global_transform().origin);
  322. }
  323. _update_camera_mode();
  324. }
  325. Camera::DopplerTracking Camera::get_doppler_tracking() const {
  326. return doppler_tracking;
  327. }
  328. void Camera::_bind_methods() {
  329. ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera::project_ray_normal);
  330. ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera::project_local_ray_normal);
  331. ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera::project_ray_origin);
  332. ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera::unproject_position);
  333. ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera::is_position_behind);
  334. ClassDB::bind_method(D_METHOD("project_position", "screen_point"), &Camera::project_position);
  335. ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera::set_perspective);
  336. ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal);
  337. ClassDB::bind_method(D_METHOD("make_current"), &Camera::make_current);
  338. ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera::clear_current, DEFVAL(true));
  339. ClassDB::bind_method(D_METHOD("set_current"), &Camera::set_current);
  340. ClassDB::bind_method(D_METHOD("is_current"), &Camera::is_current);
  341. ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera::get_camera_transform);
  342. ClassDB::bind_method(D_METHOD("get_fov"), &Camera::get_fov);
  343. ClassDB::bind_method(D_METHOD("get_size"), &Camera::get_size);
  344. ClassDB::bind_method(D_METHOD("get_zfar"), &Camera::get_zfar);
  345. ClassDB::bind_method(D_METHOD("get_znear"), &Camera::get_znear);
  346. ClassDB::bind_method(D_METHOD("set_fov"), &Camera::set_fov);
  347. ClassDB::bind_method(D_METHOD("set_size"), &Camera::set_size);
  348. ClassDB::bind_method(D_METHOD("set_zfar"), &Camera::set_zfar);
  349. ClassDB::bind_method(D_METHOD("set_znear"), &Camera::set_znear);
  350. ClassDB::bind_method(D_METHOD("get_projection"), &Camera::get_projection);
  351. ClassDB::bind_method(D_METHOD("set_projection"), &Camera::set_projection);
  352. ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera::set_h_offset);
  353. ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera::get_h_offset);
  354. ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera::set_v_offset);
  355. ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera::get_v_offset);
  356. ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera::set_cull_mask);
  357. ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera::get_cull_mask);
  358. ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera::set_environment);
  359. ClassDB::bind_method(D_METHOD("get_environment"), &Camera::get_environment);
  360. ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera::set_keep_aspect_mode);
  361. ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera::get_keep_aspect_mode);
  362. ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera::set_doppler_tracking);
  363. ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera::get_doppler_tracking);
  364. //ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current );
  365. ADD_PROPERTY(PropertyInfo(Variant::INT, "keep_aspect", PROPERTY_HINT_ENUM, "Keep Width,Keep Height"), "set_keep_aspect_mode", "get_keep_aspect_mode");
  366. ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
  367. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
  368. ADD_PROPERTY(PropertyInfo(Variant::REAL, "h_offset"), "set_h_offset", "get_h_offset");
  369. ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_offset"), "set_v_offset", "get_v_offset");
  370. ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking");
  371. ADD_PROPERTY(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal"), "set_projection", "get_projection");
  372. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current");
  373. ADD_PROPERTY(PropertyInfo(Variant::REAL, "fov", PROPERTY_HINT_RANGE, "1,179,0.1"), "set_fov", "get_fov");
  374. ADD_PROPERTY(PropertyInfo(Variant::REAL, "size", PROPERTY_HINT_RANGE, "0.1,16384,0.01"), "set_size", "get_size");
  375. ADD_PROPERTY(PropertyInfo(Variant::REAL, "near", PROPERTY_HINT_EXP_RANGE, "0.1,8192,0.1,or_greater"), "set_znear", "get_znear");
  376. ADD_PROPERTY(PropertyInfo(Variant::REAL, "far", PROPERTY_HINT_EXP_RANGE, "0.1,8192,0.1,or_greater"), "set_zfar", "get_zfar");
  377. BIND_ENUM_CONSTANT(PROJECTION_PERSPECTIVE);
  378. BIND_ENUM_CONSTANT(PROJECTION_ORTHOGONAL);
  379. BIND_ENUM_CONSTANT(KEEP_WIDTH);
  380. BIND_ENUM_CONSTANT(KEEP_HEIGHT);
  381. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_DISABLED)
  382. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_IDLE_STEP)
  383. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_PHYSICS_STEP)
  384. }
  385. float Camera::get_fov() const {
  386. return fov;
  387. }
  388. float Camera::get_size() const {
  389. return size;
  390. }
  391. float Camera::get_znear() const {
  392. return near;
  393. }
  394. float Camera::get_zfar() const {
  395. return far;
  396. }
  397. Camera::Projection Camera::get_projection() const {
  398. return mode;
  399. }
  400. void Camera::set_fov(float p_fov) {
  401. fov = p_fov;
  402. _update_camera_mode();
  403. }
  404. void Camera::set_size(float p_size) {
  405. size = p_size;
  406. _update_camera_mode();
  407. }
  408. void Camera::set_znear(float p_znear) {
  409. near = p_znear;
  410. _update_camera_mode();
  411. }
  412. void Camera::set_zfar(float p_zfar) {
  413. far = p_zfar;
  414. _update_camera_mode();
  415. }
  416. void Camera::set_cull_mask(uint32_t p_layers) {
  417. layers = p_layers;
  418. VisualServer::get_singleton()->camera_set_cull_mask(camera, layers);
  419. _update_camera_mode();
  420. }
  421. uint32_t Camera::get_cull_mask() const {
  422. return layers;
  423. }
  424. Vector<Plane> Camera::get_frustum() const {
  425. ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());
  426. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  427. CameraMatrix cm;
  428. if (mode == PROJECTION_PERSPECTIVE)
  429. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  430. else
  431. cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  432. return cm.get_projection_planes(get_camera_transform());
  433. }
  434. void Camera::set_v_offset(float p_offset) {
  435. v_offset = p_offset;
  436. _update_camera();
  437. }
  438. float Camera::get_v_offset() const {
  439. return v_offset;
  440. }
  441. void Camera::set_h_offset(float p_offset) {
  442. h_offset = p_offset;
  443. _update_camera();
  444. }
  445. float Camera::get_h_offset() const {
  446. return h_offset;
  447. }
  448. Vector3 Camera::get_doppler_tracked_velocity() const {
  449. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  450. return velocity_tracker->get_tracked_linear_velocity();
  451. } else {
  452. return Vector3();
  453. }
  454. }
  455. Camera::Camera() {
  456. camera = VisualServer::get_singleton()->camera_create();
  457. size = 1;
  458. fov = 0;
  459. near = 0;
  460. far = 0;
  461. current = false;
  462. force_change = false;
  463. mode = PROJECTION_PERSPECTIVE;
  464. set_perspective(70.0, 0.05, 100.0);
  465. keep_aspect = KEEP_HEIGHT;
  466. layers = 0xfffff;
  467. v_offset = 0;
  468. h_offset = 0;
  469. VisualServer::get_singleton()->camera_set_cull_mask(camera, layers);
  470. //active=false;
  471. velocity_tracker.instance();
  472. doppler_tracking = DOPPLER_TRACKING_DISABLED;
  473. set_notify_transform(true);
  474. set_disable_scale(true);
  475. }
  476. Camera::~Camera() {
  477. VisualServer::get_singleton()->free(camera);
  478. }