camera.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. /**************************************************************************/
  2. /* camera.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "collision_object.h"
  32. #include "core/engine.h"
  33. #include "core/math/camera_matrix.h"
  34. #include "core/math/transform_interpolator.h"
  35. #include "scene/resources/material.h"
  36. #include "scene/resources/surface_tool.h"
  37. #include "servers/visual/visual_server_constants.h"
  38. void Camera::_update_audio_listener_state() {
  39. }
  40. void Camera::_request_camera_update() {
  41. _update_camera();
  42. }
  43. void Camera::_update_camera_mode() {
  44. force_change = true;
  45. switch (mode) {
  46. case PROJECTION_PERSPECTIVE: {
  47. set_perspective(fov, near, far);
  48. } break;
  49. case PROJECTION_ORTHOGONAL: {
  50. set_orthogonal(size, near, far);
  51. } break;
  52. case PROJECTION_FRUSTUM: {
  53. set_frustum(size, frustum_offset, near, far);
  54. } break;
  55. }
  56. }
  57. void Camera::_validate_property(PropertyInfo &p_property) const {
  58. if (p_property.name == "fov") {
  59. if (mode != PROJECTION_PERSPECTIVE) {
  60. p_property.usage = PROPERTY_USAGE_NOEDITOR;
  61. }
  62. } else if (p_property.name == "size") {
  63. if (mode != PROJECTION_ORTHOGONAL && mode != PROJECTION_FRUSTUM) {
  64. p_property.usage = PROPERTY_USAGE_NOEDITOR;
  65. }
  66. } else if (p_property.name == "frustum_offset") {
  67. if (mode != PROJECTION_FRUSTUM) {
  68. p_property.usage = PROPERTY_USAGE_NOEDITOR;
  69. }
  70. }
  71. }
  72. void Camera::_update_camera() {
  73. if (!is_inside_tree()) {
  74. return;
  75. }
  76. if (!is_physics_interpolated_and_enabled()) {
  77. VisualServer::get_singleton()->camera_set_transform(camera, get_camera_transform());
  78. } else {
  79. // Ideally we shouldn't be moving a physics interpolated camera within a frame,
  80. // because it will break smooth interpolation, but it may occur on e.g. level load.
  81. if (!Engine::get_singleton()->is_in_physics_frame() && camera.is_valid()) {
  82. _physics_interpolation_ensure_transform_calculated(true);
  83. VisualServer::get_singleton()->camera_set_transform(camera, _interpolation_data.camera_xform_interpolated);
  84. }
  85. }
  86. // here goes listener stuff
  87. /*
  88. if (viewport_ptr && is_inside_scene() && is_current())
  89. get_viewport()->_camera_transform_changed_notify();
  90. */
  91. if (get_tree()->is_node_being_edited(this) || !is_current()) {
  92. return;
  93. }
  94. get_viewport()->_camera_transform_changed_notify();
  95. if (get_world().is_valid()) {
  96. get_world()->_update_camera(this);
  97. }
  98. }
  99. void Camera::_physics_interpolated_changed() {
  100. _update_process_mode();
  101. }
  102. void Camera::_physics_interpolation_ensure_data_flipped() {
  103. // The curr -> previous update can either occur
  104. // on the INTERNAL_PHYSICS_PROCESS OR
  105. // on NOTIFICATION_TRANSFORM_CHANGED,
  106. // if NOTIFICATION_TRANSFORM_CHANGED takes place
  107. // earlier than INTERNAL_PHYSICS_PROCESS on a tick.
  108. // This is to ensure that the data keeps flowing, but the new data
  109. // doesn't overwrite before prev has been set.
  110. // Keep the data flowing.
  111. uint64_t tick = Engine::get_singleton()->get_physics_frames();
  112. if (_interpolation_data.last_update_physics_tick != tick) {
  113. _interpolation_data.xform_prev = _interpolation_data.xform_curr;
  114. _interpolation_data.last_update_physics_tick = tick;
  115. physics_interpolation_flip_data();
  116. }
  117. }
  118. void Camera::_physics_interpolation_ensure_transform_calculated(bool p_force) const {
  119. DEV_CHECK_ONCE(!Engine::get_singleton()->is_in_physics_frame());
  120. InterpolationData &id = _interpolation_data;
  121. uint64_t frame = Engine::get_singleton()->get_frames_drawn();
  122. if (id.last_update_frame != frame || p_force) {
  123. id.last_update_frame = frame;
  124. TransformInterpolator::interpolate_transform(id.xform_prev, id.xform_curr, id.xform_interpolated, Engine::get_singleton()->get_physics_interpolation_fraction());
  125. Transform &tr = id.camera_xform_interpolated;
  126. tr = _get_adjusted_camera_transform(id.xform_interpolated);
  127. }
  128. }
  129. void Camera::set_desired_process_modes(bool p_process_internal, bool p_physics_process_internal) {
  130. _desired_process_internal = p_process_internal;
  131. _desired_physics_process_internal = p_physics_process_internal;
  132. _update_process_mode();
  133. }
  134. void Camera::_update_process_mode() {
  135. bool process = _desired_process_internal;
  136. bool physics_process = _desired_physics_process_internal;
  137. if (is_physics_interpolated_and_enabled()) {
  138. if (is_current()) {
  139. process = true;
  140. physics_process = true;
  141. }
  142. }
  143. set_process_internal(process);
  144. set_physics_process_internal(physics_process);
  145. }
  146. void Camera::_notification(int p_what) {
  147. switch (p_what) {
  148. case NOTIFICATION_ENTER_WORLD: {
  149. // Needs to track the Viewport because it's needed on NOTIFICATION_EXIT_WORLD
  150. // and Spatial will handle it first, including clearing its reference to the Viewport,
  151. // therefore making it impossible to subclasses to access it
  152. viewport = get_viewport();
  153. ERR_FAIL_COND(!viewport);
  154. bool first_camera = viewport->_camera_add(this);
  155. if (current || first_camera) {
  156. viewport->_camera_set(this);
  157. }
  158. } break;
  159. case NOTIFICATION_INTERNAL_PROCESS: {
  160. if (is_physics_interpolated_and_enabled() && camera.is_valid()) {
  161. _physics_interpolation_ensure_transform_calculated();
  162. #ifdef VISUAL_SERVER_DEBUG_PHYSICS_INTERPOLATION
  163. print_line("\t\tinterpolated Camera: " + rtos(_interpolation_data.xform_interpolated.origin.x) + "\t( prev " + rtos(_interpolation_data.xform_prev.origin.x) + ", curr " + rtos(_interpolation_data.xform_curr.origin.x) + " ) on tick " + itos(Engine::get_singleton()->get_physics_frames()));
  164. #endif
  165. VisualServer::get_singleton()->camera_set_transform(camera, _interpolation_data.camera_xform_interpolated);
  166. }
  167. } break;
  168. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  169. if (is_physics_interpolated_and_enabled()) {
  170. _physics_interpolation_ensure_data_flipped();
  171. _interpolation_data.xform_curr = get_global_transform();
  172. }
  173. } break;
  174. case NOTIFICATION_TRANSFORM_CHANGED: {
  175. if (is_physics_interpolated_and_enabled()) {
  176. _physics_interpolation_ensure_data_flipped();
  177. _interpolation_data.xform_curr = get_global_transform();
  178. #if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
  179. if (!Engine::get_singleton()->is_in_physics_frame()) {
  180. PHYSICS_INTERPOLATION_NODE_WARNING(get_instance_id(), "Interpolated Camera triggered from outside physics process");
  181. }
  182. #endif
  183. }
  184. _request_camera_update();
  185. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  186. velocity_tracker->update_position(get_global_transform().origin);
  187. }
  188. // Allow auto-reset when first adding to the tree, as a convenience.
  189. if (_is_physics_interpolation_reset_requested() && is_inside_tree()) {
  190. _notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION);
  191. _set_physics_interpolation_reset_requested(false);
  192. }
  193. } break;
  194. case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
  195. if (is_inside_tree()) {
  196. _interpolation_data.xform_curr = get_global_transform();
  197. _interpolation_data.xform_prev = _interpolation_data.xform_curr;
  198. }
  199. } break;
  200. case NOTIFICATION_EXIT_WORLD: {
  201. if (!get_tree()->is_node_being_edited(this)) {
  202. if (is_current()) {
  203. clear_current();
  204. current = true; //keep it true
  205. } else {
  206. current = false;
  207. }
  208. }
  209. if (viewport) {
  210. viewport->_camera_remove(this);
  211. viewport = nullptr;
  212. }
  213. } break;
  214. case NOTIFICATION_BECAME_CURRENT: {
  215. if (viewport) {
  216. viewport->find_world()->_register_camera(this);
  217. }
  218. _update_process_mode();
  219. } break;
  220. case NOTIFICATION_LOST_CURRENT: {
  221. if (viewport) {
  222. viewport->find_world()->_remove_camera(this);
  223. }
  224. _update_process_mode();
  225. } break;
  226. }
  227. }
  228. Transform Camera::_get_adjusted_camera_transform(const Transform &p_xform) const {
  229. Transform tr = p_xform.orthonormalized();
  230. tr.origin += tr.basis.get_axis(1) * v_offset;
  231. tr.origin += tr.basis.get_axis(0) * h_offset;
  232. return tr;
  233. }
  234. Transform Camera::get_camera_transform() const {
  235. if (is_physics_interpolated_and_enabled() && !Engine::get_singleton()->is_in_physics_frame()) {
  236. _physics_interpolation_ensure_transform_calculated();
  237. return _interpolation_data.camera_xform_interpolated;
  238. }
  239. return _get_adjusted_camera_transform(get_global_transform());
  240. }
  241. void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) {
  242. if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) {
  243. return;
  244. }
  245. fov = p_fovy_degrees;
  246. near = p_z_near;
  247. far = p_z_far;
  248. mode = PROJECTION_PERSPECTIVE;
  249. VisualServer::get_singleton()->camera_set_perspective(camera, fov, near, far);
  250. update_gizmo();
  251. force_change = false;
  252. }
  253. void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
  254. if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) {
  255. return;
  256. }
  257. size = p_size;
  258. near = p_z_near;
  259. far = p_z_far;
  260. mode = PROJECTION_ORTHOGONAL;
  261. force_change = false;
  262. VisualServer::get_singleton()->camera_set_orthogonal(camera, size, near, far);
  263. update_gizmo();
  264. }
  265. void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) {
  266. if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) {
  267. return;
  268. }
  269. size = p_size;
  270. frustum_offset = p_offset;
  271. near = p_z_near;
  272. far = p_z_far;
  273. mode = PROJECTION_FRUSTUM;
  274. force_change = false;
  275. VisualServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far);
  276. update_gizmo();
  277. }
  278. void Camera::set_projection(Camera::Projection p_mode) {
  279. if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL || p_mode == PROJECTION_FRUSTUM) {
  280. mode = p_mode;
  281. _update_camera_mode();
  282. _change_notify();
  283. }
  284. }
  285. RID Camera::get_camera() const {
  286. return camera;
  287. };
  288. void Camera::make_current() {
  289. current = true;
  290. if (!is_inside_tree()) {
  291. return;
  292. }
  293. get_viewport()->_camera_set(this);
  294. //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this);
  295. }
  296. void Camera::clear_current(bool p_enable_next) {
  297. current = false;
  298. if (!is_inside_tree()) {
  299. return;
  300. }
  301. if (get_viewport()->get_camera() == this) {
  302. get_viewport()->_camera_set(nullptr);
  303. if (p_enable_next) {
  304. get_viewport()->_camera_make_next_current(this);
  305. }
  306. }
  307. }
  308. void Camera::set_current(bool p_current) {
  309. if (p_current) {
  310. make_current();
  311. } else {
  312. clear_current();
  313. }
  314. }
  315. bool Camera::is_current() const {
  316. if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
  317. return get_viewport()->get_camera() == this;
  318. } else {
  319. return current;
  320. }
  321. }
  322. Vector3 Camera::project_ray_normal(const Point2 &p_pos) const {
  323. Vector3 ray = project_local_ray_normal(p_pos);
  324. return get_camera_transform().basis.xform(ray).normalized();
  325. };
  326. Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const {
  327. ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene.");
  328. Size2 viewport_size = get_viewport()->get_camera_rect_size();
  329. Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
  330. Vector3 ray;
  331. if (mode == PROJECTION_ORTHOGONAL) {
  332. ray = Vector3(0, 0, -1);
  333. } else {
  334. CameraMatrix cm;
  335. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  336. Vector2 screen_he = cm.get_viewport_half_extents();
  337. ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -near).normalized();
  338. }
  339. return ray;
  340. };
  341. Vector3 Camera::project_ray_origin(const Point2 &p_pos) const {
  342. ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene.");
  343. Size2 viewport_size = get_viewport()->get_camera_rect_size();
  344. Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
  345. ERR_FAIL_COND_V(viewport_size.y == 0, Vector3());
  346. if (mode == PROJECTION_PERSPECTIVE) {
  347. return get_camera_transform().origin;
  348. } else {
  349. Vector2 pos = cpos / viewport_size;
  350. float vsize, hsize;
  351. if (keep_aspect == KEEP_WIDTH) {
  352. vsize = size / viewport_size.aspect();
  353. hsize = size;
  354. } else {
  355. hsize = size * viewport_size.aspect();
  356. vsize = size;
  357. }
  358. Vector3 ray;
  359. ray.x = pos.x * (hsize)-hsize / 2;
  360. ray.y = (1.0 - pos.y) * (vsize)-vsize / 2;
  361. ray.z = -near;
  362. ray = get_camera_transform().xform(ray);
  363. return ray;
  364. };
  365. };
  366. bool Camera::is_position_behind(const Vector3 &p_pos) const {
  367. Transform t = get_global_transform();
  368. Vector3 eyedir = -t.basis.get_axis(2).normalized();
  369. return eyedir.dot(p_pos - t.origin) < near;
  370. }
  371. Vector<Vector3> Camera::get_near_plane_points() const {
  372. ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector<Vector3>(), "Camera is not inside scene.");
  373. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  374. CameraMatrix cm;
  375. if (mode == PROJECTION_ORTHOGONAL) {
  376. cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  377. } else {
  378. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  379. }
  380. Vector3 endpoints[8];
  381. cm.get_endpoints(Transform(), endpoints);
  382. Vector<Vector3> points;
  383. points.push_back(Vector3());
  384. for (int i = 0; i < 4; i++) {
  385. points.push_back(endpoints[i + 4]);
  386. }
  387. return points;
  388. }
  389. Point2 Camera::unproject_position(const Vector3 &p_pos) const {
  390. ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene.");
  391. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  392. CameraMatrix cm;
  393. if (mode == PROJECTION_ORTHOGONAL) {
  394. cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  395. } else {
  396. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  397. }
  398. Plane p(get_camera_transform().xform_inv(p_pos), 1.0);
  399. p = cm.xform4(p);
  400. // Prevent divide by zero.
  401. // TODO : Investigate, this was causing Nans.
  402. ERR_FAIL_COND_V(p.d == 0, Point2());
  403. p.normal /= p.d;
  404. Point2 res;
  405. res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x;
  406. res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y;
  407. return res;
  408. }
  409. Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const {
  410. ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene.");
  411. if (p_z_depth == 0 && mode != PROJECTION_ORTHOGONAL) {
  412. return get_global_transform().origin;
  413. }
  414. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  415. CameraMatrix cm;
  416. if (mode == PROJECTION_ORTHOGONAL) {
  417. cm.set_orthogonal(size, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH);
  418. } else {
  419. cm.set_perspective(fov, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH);
  420. }
  421. Vector2 vp_he = cm.get_viewport_half_extents();
  422. Vector2 point;
  423. point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0;
  424. point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0;
  425. point *= vp_he;
  426. Vector3 p(point.x, point.y, -p_z_depth);
  427. return get_camera_transform().xform(p);
  428. }
  429. /*
  430. void Camera::_camera_make_current(Node *p_camera) {
  431. if (p_camera==this) {
  432. VisualServer::get_singleton()->viewport_attach_camera(viewport_id,camera);
  433. active=true;
  434. } else {
  435. if (active && p_camera==NULL) {
  436. //detech camera because no one else will claim it
  437. VisualServer::get_singleton()->viewport_attach_camera(viewport_id,RID());
  438. }
  439. active=false;
  440. }
  441. }
  442. */
  443. void Camera::set_environment(const Ref<Environment> &p_environment) {
  444. environment = p_environment;
  445. if (environment.is_valid()) {
  446. VS::get_singleton()->camera_set_environment(camera, environment->get_rid());
  447. } else {
  448. VS::get_singleton()->camera_set_environment(camera, RID());
  449. }
  450. _update_camera_mode();
  451. }
  452. Ref<Environment> Camera::get_environment() const {
  453. return environment;
  454. }
  455. void Camera::set_keep_aspect_mode(KeepAspect p_aspect) {
  456. keep_aspect = p_aspect;
  457. VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH);
  458. _update_camera_mode();
  459. _change_notify();
  460. }
  461. Camera::KeepAspect Camera::get_keep_aspect_mode() const {
  462. return keep_aspect;
  463. }
  464. void Camera::set_doppler_tracking(DopplerTracking p_tracking) {
  465. if (doppler_tracking == p_tracking) {
  466. return;
  467. }
  468. doppler_tracking = p_tracking;
  469. if (p_tracking != DOPPLER_TRACKING_DISABLED) {
  470. velocity_tracker->set_track_physics_step(doppler_tracking == DOPPLER_TRACKING_PHYSICS_STEP);
  471. if (is_inside_tree()) {
  472. velocity_tracker->reset(get_global_transform().origin);
  473. }
  474. }
  475. _update_camera_mode();
  476. }
  477. Camera::DopplerTracking Camera::get_doppler_tracking() const {
  478. return doppler_tracking;
  479. }
  480. void Camera::_bind_methods() {
  481. ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera::project_ray_normal);
  482. ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera::project_local_ray_normal);
  483. ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera::project_ray_origin);
  484. ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera::unproject_position);
  485. ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera::is_position_behind);
  486. ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera::project_position);
  487. ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera::set_perspective);
  488. ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal);
  489. ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera::set_frustum);
  490. ClassDB::bind_method(D_METHOD("make_current"), &Camera::make_current);
  491. ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera::clear_current, DEFVAL(true));
  492. ClassDB::bind_method(D_METHOD("set_current", "enable"), &Camera::set_current);
  493. ClassDB::bind_method(D_METHOD("is_current"), &Camera::is_current);
  494. ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera::get_camera_transform);
  495. ClassDB::bind_method(D_METHOD("get_fov"), &Camera::get_fov);
  496. ClassDB::bind_method(D_METHOD("get_frustum_offset"), &Camera::get_frustum_offset);
  497. ClassDB::bind_method(D_METHOD("get_size"), &Camera::get_size);
  498. ClassDB::bind_method(D_METHOD("get_zfar"), &Camera::get_zfar);
  499. ClassDB::bind_method(D_METHOD("get_znear"), &Camera::get_znear);
  500. ClassDB::bind_method(D_METHOD("set_fov", "fov"), &Camera::set_fov);
  501. ClassDB::bind_method(D_METHOD("set_frustum_offset", "frustum_offset"), &Camera::set_frustum_offset);
  502. ClassDB::bind_method(D_METHOD("set_size", "size"), &Camera::set_size);
  503. ClassDB::bind_method(D_METHOD("set_zfar", "zfar"), &Camera::set_zfar);
  504. ClassDB::bind_method(D_METHOD("set_znear", "znear"), &Camera::set_znear);
  505. ClassDB::bind_method(D_METHOD("get_projection"), &Camera::get_projection);
  506. ClassDB::bind_method(D_METHOD("set_projection", "projection"), &Camera::set_projection);
  507. ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera::set_h_offset);
  508. ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera::get_h_offset);
  509. ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera::set_v_offset);
  510. ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera::get_v_offset);
  511. ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera::set_cull_mask);
  512. ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera::get_cull_mask);
  513. ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera::set_environment);
  514. ClassDB::bind_method(D_METHOD("get_environment"), &Camera::get_environment);
  515. ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera::set_keep_aspect_mode);
  516. ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera::get_keep_aspect_mode);
  517. ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera::set_doppler_tracking);
  518. ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera::get_doppler_tracking);
  519. ClassDB::bind_method(D_METHOD("get_frustum"), &Camera::get_frustum);
  520. ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera::get_camera);
  521. ClassDB::bind_method(D_METHOD("set_affect_lod", "enable"), &Camera::set_affect_lod);
  522. ClassDB::bind_method(D_METHOD("get_affect_lod"), &Camera::get_affect_lod);
  523. ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera::set_cull_mask_bit);
  524. ClassDB::bind_method(D_METHOD("get_cull_mask_bit", "layer"), &Camera::get_cull_mask_bit);
  525. //ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current );
  526. ADD_PROPERTY(PropertyInfo(Variant::INT, "keep_aspect", PROPERTY_HINT_ENUM, "Keep Width,Keep Height"), "set_keep_aspect_mode", "get_keep_aspect_mode");
  527. ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
  528. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
  529. ADD_PROPERTY(PropertyInfo(Variant::REAL, "h_offset"), "set_h_offset", "get_h_offset");
  530. ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_offset"), "set_v_offset", "get_v_offset");
  531. ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking");
  532. ADD_PROPERTY(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal,Frustum"), "set_projection", "get_projection");
  533. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current");
  534. ADD_PROPERTY(PropertyInfo(Variant::REAL, "fov", PROPERTY_HINT_RANGE, "1,179,0.1"), "set_fov", "get_fov");
  535. ADD_PROPERTY(PropertyInfo(Variant::REAL, "size", PROPERTY_HINT_RANGE, "0.001,16384,0.001"), "set_size", "get_size");
  536. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "frustum_offset"), "set_frustum_offset", "get_frustum_offset");
  537. ADD_PROPERTY(PropertyInfo(Variant::REAL, "near", PROPERTY_HINT_EXP_RANGE, "0.01,8192,0.01,or_greater"), "set_znear", "get_znear");
  538. ADD_PROPERTY(PropertyInfo(Variant::REAL, "far", PROPERTY_HINT_EXP_RANGE, "0.1,8192,0.1,or_greater"), "set_zfar", "get_zfar");
  539. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "affect_lod"), "set_affect_lod", "get_affect_lod");
  540. BIND_ENUM_CONSTANT(PROJECTION_PERSPECTIVE);
  541. BIND_ENUM_CONSTANT(PROJECTION_ORTHOGONAL);
  542. BIND_ENUM_CONSTANT(PROJECTION_FRUSTUM);
  543. BIND_ENUM_CONSTANT(KEEP_WIDTH);
  544. BIND_ENUM_CONSTANT(KEEP_HEIGHT);
  545. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_DISABLED);
  546. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_IDLE_STEP);
  547. BIND_ENUM_CONSTANT(DOPPLER_TRACKING_PHYSICS_STEP);
  548. }
  549. float Camera::get_fov() const {
  550. return fov;
  551. }
  552. float Camera::get_size() const {
  553. return size;
  554. }
  555. float Camera::get_znear() const {
  556. return near;
  557. }
  558. Vector2 Camera::get_frustum_offset() const {
  559. return frustum_offset;
  560. }
  561. float Camera::get_zfar() const {
  562. return far;
  563. }
  564. Camera::Projection Camera::get_projection() const {
  565. return mode;
  566. }
  567. void Camera::set_fov(float p_fov) {
  568. ERR_FAIL_COND(p_fov < 1 || p_fov > 179);
  569. fov = p_fov;
  570. _update_camera_mode();
  571. _change_notify("fov");
  572. }
  573. void Camera::set_size(float p_size) {
  574. ERR_FAIL_COND(p_size < 0.001 || p_size > 16384);
  575. size = p_size;
  576. _update_camera_mode();
  577. _change_notify("size");
  578. }
  579. void Camera::set_znear(float p_znear) {
  580. near = p_znear;
  581. _update_camera_mode();
  582. }
  583. void Camera::set_frustum_offset(Vector2 p_offset) {
  584. frustum_offset = p_offset;
  585. _update_camera_mode();
  586. }
  587. void Camera::set_zfar(float p_zfar) {
  588. far = p_zfar;
  589. _update_camera_mode();
  590. }
  591. void Camera::set_cull_mask(uint32_t p_layers) {
  592. layers = p_layers;
  593. VisualServer::get_singleton()->camera_set_cull_mask(camera, layers);
  594. _update_camera_mode();
  595. }
  596. uint32_t Camera::get_cull_mask() const {
  597. return layers;
  598. }
  599. void Camera::set_cull_mask_bit(int p_layer, bool p_enable) {
  600. ERR_FAIL_INDEX(p_layer, 32);
  601. if (p_enable) {
  602. set_cull_mask(layers | (1 << p_layer));
  603. } else {
  604. set_cull_mask(layers & (~(1 << p_layer)));
  605. }
  606. }
  607. bool Camera::get_cull_mask_bit(int p_layer) const {
  608. ERR_FAIL_INDEX_V(p_layer, 32, false);
  609. return (layers & (1 << p_layer));
  610. }
  611. Vector<Plane> Camera::get_frustum() const {
  612. ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());
  613. Size2 viewport_size = get_viewport()->get_visible_rect().size;
  614. CameraMatrix cm;
  615. if (mode == PROJECTION_PERSPECTIVE) {
  616. cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  617. } else {
  618. cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
  619. }
  620. return cm.get_projection_planes(get_camera_transform());
  621. }
  622. void Camera::set_v_offset(float p_offset) {
  623. v_offset = p_offset;
  624. _update_camera();
  625. }
  626. float Camera::get_v_offset() const {
  627. return v_offset;
  628. }
  629. void Camera::set_h_offset(float p_offset) {
  630. h_offset = p_offset;
  631. _update_camera();
  632. }
  633. float Camera::get_h_offset() const {
  634. return h_offset;
  635. }
  636. Vector3 Camera::get_doppler_tracked_velocity() const {
  637. if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
  638. return velocity_tracker->get_tracked_linear_velocity();
  639. } else {
  640. return Vector3();
  641. }
  642. }
  643. Camera::Camera() {
  644. camera = RID_PRIME(VisualServer::get_singleton()->camera_create());
  645. size = 1;
  646. fov = 0;
  647. frustum_offset = Vector2();
  648. near = 0;
  649. far = 0;
  650. current = false;
  651. viewport = nullptr;
  652. force_change = false;
  653. mode = PROJECTION_PERSPECTIVE;
  654. set_perspective(70.0, 0.05, 100.0);
  655. keep_aspect = KEEP_HEIGHT;
  656. layers = 0xfffff;
  657. v_offset = 0;
  658. h_offset = 0;
  659. VisualServer::get_singleton()->camera_set_cull_mask(camera, layers);
  660. //active=false;
  661. velocity_tracker.instance();
  662. doppler_tracking = DOPPLER_TRACKING_DISABLED;
  663. set_notify_transform(true);
  664. set_disable_scale(true);
  665. }
  666. Camera::~Camera() {
  667. VisualServer::get_singleton()->free(camera);
  668. }
  669. ////////////////////////////////////////
  670. void ClippedCamera::set_margin(float p_margin) {
  671. margin = p_margin;
  672. }
  673. float ClippedCamera::get_margin() const {
  674. return margin;
  675. }
  676. void ClippedCamera::set_process_mode(ProcessMode p_mode) {
  677. if (is_physics_interpolated_and_enabled() && p_mode == CLIP_PROCESS_IDLE) {
  678. p_mode = CLIP_PROCESS_PHYSICS;
  679. WARN_PRINT_ONCE("[Physics interpolation] Forcing ClippedCamera to PROCESS_PHYSICS mode.");
  680. }
  681. if (process_mode == p_mode) {
  682. return;
  683. }
  684. process_mode = p_mode;
  685. set_desired_process_modes(process_mode == CLIP_PROCESS_IDLE, process_mode == CLIP_PROCESS_PHYSICS);
  686. }
  687. ClippedCamera::ProcessMode ClippedCamera::get_process_mode() const {
  688. return process_mode;
  689. }
  690. void ClippedCamera::physics_interpolation_flip_data() {
  691. _interpolation_data.clip_offset_prev = _interpolation_data.clip_offset_curr;
  692. }
  693. void ClippedCamera::_physics_interpolated_changed() {
  694. // Switch process mode to physics if we are turning on interpolation.
  695. // Idle process mode doesn't work well with physics interpolation.
  696. set_process_mode(get_process_mode());
  697. Camera::_physics_interpolated_changed();
  698. }
  699. Transform ClippedCamera::_get_adjusted_camera_transform(const Transform &p_xform) const {
  700. Transform t = Camera::_get_adjusted_camera_transform(p_xform);
  701. t.origin += -t.basis.get_axis(Vector3::AXIS_Z).normalized() * clip_offset;
  702. return t;
  703. }
  704. void ClippedCamera::_notification(int p_what) {
  705. if (p_what == NOTIFICATION_ENTER_TREE) {
  706. // Switch process mode to physics if we are turning on interpolation.
  707. // Idle process mode doesn't work well with physics interpolation.
  708. set_process_mode(get_process_mode());
  709. }
  710. if (((p_what == NOTIFICATION_INTERNAL_PROCESS) && process_mode == CLIP_PROCESS_IDLE) || ((p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) && process_mode == CLIP_PROCESS_PHYSICS)) {
  711. Spatial *parent = Object::cast_to<Spatial>(get_parent());
  712. if (!parent) {
  713. return;
  714. }
  715. PhysicsDirectSpaceState *dspace = get_world()->get_direct_space_state();
  716. ERR_FAIL_COND(!dspace); // most likely physics set to threads
  717. Vector3 cam_fw = -get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized();
  718. Vector3 cam_pos = get_global_transform().origin;
  719. Vector3 parent_pos = parent->get_global_transform().origin;
  720. Plane parent_plane(parent_pos, cam_fw);
  721. if (parent_plane.is_point_over(cam_pos)) {
  722. //cam is beyond parent plane
  723. return;
  724. }
  725. Vector3 ray_from = parent_plane.project(cam_pos);
  726. _interpolation_data.clip_offset_curr = 0; // Reset by default.
  727. { //check if points changed
  728. Vector<Vector3> local_points = get_near_plane_points();
  729. bool all_equal = true;
  730. for (int i = 0; i < 5; i++) {
  731. if (points[i] != local_points[i]) {
  732. all_equal = false;
  733. break;
  734. }
  735. }
  736. if (!all_equal) {
  737. PhysicsServer::get_singleton()->shape_set_data(pyramid_shape, local_points);
  738. points = local_points;
  739. }
  740. }
  741. Transform xf = get_global_transform();
  742. xf.origin = ray_from;
  743. xf.orthonormalize();
  744. float closest_safe = 1.0f, closest_unsafe = 1.0f;
  745. if (dspace->cast_motion(pyramid_shape, xf, cam_pos - ray_from, margin, closest_safe, closest_unsafe, exclude, collision_mask, clip_to_bodies, clip_to_areas)) {
  746. _interpolation_data.clip_offset_curr = cam_pos.distance_to(ray_from + (cam_pos - ray_from) * closest_safe);
  747. }
  748. // Default to use the current value
  749. // (in the case of non-interpolated).
  750. if (!is_physics_interpolated_and_enabled()) {
  751. clip_offset = _interpolation_data.clip_offset_curr;
  752. }
  753. _update_camera();
  754. }
  755. if (is_physics_interpolated_and_enabled() && (p_what == NOTIFICATION_INTERNAL_PROCESS)) {
  756. clip_offset = ((_interpolation_data.clip_offset_curr - _interpolation_data.clip_offset_prev) * Engine::get_singleton()->get_physics_interpolation_fraction()) + _interpolation_data.clip_offset_prev;
  757. }
  758. if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
  759. update_gizmo();
  760. }
  761. if (p_what == NOTIFICATION_RESET_PHYSICS_INTERPOLATION) {
  762. _interpolation_data.clip_offset_prev = _interpolation_data.clip_offset_curr;
  763. }
  764. }
  765. void ClippedCamera::set_collision_mask(uint32_t p_mask) {
  766. collision_mask = p_mask;
  767. }
  768. uint32_t ClippedCamera::get_collision_mask() const {
  769. return collision_mask;
  770. }
  771. void ClippedCamera::set_collision_mask_bit(int p_bit, bool p_value) {
  772. ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision layer bit must be between 0 and 31 inclusive.");
  773. uint32_t mask = get_collision_mask();
  774. if (p_value) {
  775. mask |= 1 << p_bit;
  776. } else {
  777. mask &= ~(1 << p_bit);
  778. }
  779. set_collision_mask(mask);
  780. }
  781. bool ClippedCamera::get_collision_mask_bit(int p_bit) const {
  782. ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive.");
  783. return get_collision_mask() & (1 << p_bit);
  784. }
  785. void ClippedCamera::add_exception_rid(const RID &p_rid) {
  786. exclude.insert(p_rid);
  787. }
  788. void ClippedCamera::add_exception(const Object *p_object) {
  789. ERR_FAIL_NULL(p_object);
  790. const CollisionObject *co = Object::cast_to<CollisionObject>(p_object);
  791. ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject.");
  792. add_exception_rid(co->get_rid());
  793. }
  794. void ClippedCamera::remove_exception_rid(const RID &p_rid) {
  795. exclude.erase(p_rid);
  796. }
  797. void ClippedCamera::remove_exception(const Object *p_object) {
  798. ERR_FAIL_NULL(p_object);
  799. const CollisionObject *co = Object::cast_to<CollisionObject>(p_object);
  800. ERR_FAIL_COND_MSG(!co, "The passed Node must be an instance of CollisionObject.");
  801. remove_exception_rid(co->get_rid());
  802. }
  803. void ClippedCamera::clear_exceptions() {
  804. exclude.clear();
  805. }
  806. float ClippedCamera::get_clip_offset() const {
  807. return clip_offset;
  808. }
  809. void ClippedCamera::set_clip_to_areas(bool p_clip) {
  810. clip_to_areas = p_clip;
  811. }
  812. bool ClippedCamera::is_clip_to_areas_enabled() const {
  813. return clip_to_areas;
  814. }
  815. void ClippedCamera::set_clip_to_bodies(bool p_clip) {
  816. clip_to_bodies = p_clip;
  817. }
  818. bool ClippedCamera::is_clip_to_bodies_enabled() const {
  819. return clip_to_bodies;
  820. }
  821. void ClippedCamera::_bind_methods() {
  822. ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera::set_margin);
  823. ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera::get_margin);
  824. ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera::set_process_mode);
  825. ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera::get_process_mode);
  826. ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera::set_collision_mask);
  827. ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera::get_collision_mask);
  828. ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera::set_collision_mask_bit);
  829. ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera::get_collision_mask_bit);
  830. ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera::add_exception_rid);
  831. ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera::add_exception);
  832. ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera::remove_exception_rid);
  833. ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera::remove_exception);
  834. ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera::set_clip_to_areas);
  835. ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera::is_clip_to_areas_enabled);
  836. ClassDB::bind_method(D_METHOD("get_clip_offset"), &ClippedCamera::get_clip_offset);
  837. ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera::set_clip_to_bodies);
  838. ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera::is_clip_to_bodies_enabled);
  839. ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera::clear_exceptions);
  840. ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_margin", "get_margin");
  841. ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode");
  842. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  843. ADD_GROUP("Clip To", "clip_to");
  844. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_to_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_clip_to_areas", "is_clip_to_areas_enabled");
  845. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_to_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_clip_to_bodies", "is_clip_to_bodies_enabled");
  846. BIND_ENUM_CONSTANT(CLIP_PROCESS_PHYSICS);
  847. BIND_ENUM_CONSTANT(CLIP_PROCESS_IDLE);
  848. }
  849. ClippedCamera::ClippedCamera() {
  850. margin = 0;
  851. // Force initializing to physics (prevent noop check).
  852. process_mode = CLIP_PROCESS_IDLE;
  853. set_process_mode(CLIP_PROCESS_PHYSICS);
  854. collision_mask = 1;
  855. set_notify_local_transform(Engine::get_singleton()->is_editor_hint());
  856. points.resize(5);
  857. pyramid_shape = RID_PRIME(PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON));
  858. clip_to_areas = false;
  859. clip_to_bodies = true;
  860. }
  861. ClippedCamera::~ClippedCamera() {
  862. PhysicsServer::get_singleton()->free(pyramid_shape);
  863. }