1 /** 2 Camera node, displays from a point of view. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.camera; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.spatial; 24 import godot.environment; 25 import godot.node; 26 /** 27 Camera node, displays from a point of view. 28 29 Camera is a special node that displays what is visible from its current location. Cameras register themselves in the nearest $(D Viewport) node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the Camera will register in the global viewport. In other words, a Camera just provides $(I 3D) display capabilities to a $(D Viewport), and, without one, a scene registered in that $(D Viewport) (or higher viewports) can't be displayed. 30 */ 31 @GodotBaseClass struct Camera 32 { 33 enum string _GODOT_internal_name = "Camera"; 34 public: 35 @nogc nothrow: 36 union { godot_object _godot_object; Spatial _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct _classBinding 41 { 42 __gshared: 43 @GodotName("project_ray_normal") GodotMethod!(Vector3, Vector2) projectRayNormal; 44 @GodotName("project_local_ray_normal") GodotMethod!(Vector3, Vector2) projectLocalRayNormal; 45 @GodotName("project_ray_origin") GodotMethod!(Vector3, Vector2) projectRayOrigin; 46 @GodotName("unproject_position") GodotMethod!(Vector2, Vector3) unprojectPosition; 47 @GodotName("is_position_behind") GodotMethod!(bool, Vector3) isPositionBehind; 48 @GodotName("project_position") GodotMethod!(Vector3, Vector2) projectPosition; 49 @GodotName("set_perspective") GodotMethod!(void, double, double, double) setPerspective; 50 @GodotName("set_orthogonal") GodotMethod!(void, double, double, double) setOrthogonal; 51 @GodotName("make_current") GodotMethod!(void) makeCurrent; 52 @GodotName("clear_current") GodotMethod!(void, bool) clearCurrent; 53 @GodotName("set_current") GodotMethod!(void, bool) setCurrent; 54 @GodotName("is_current") GodotMethod!(bool) isCurrent; 55 @GodotName("get_camera_transform") GodotMethod!(Transform) getCameraTransform; 56 @GodotName("get_fov") GodotMethod!(double) getFov; 57 @GodotName("get_size") GodotMethod!(double) getSize; 58 @GodotName("get_zfar") GodotMethod!(double) getZfar; 59 @GodotName("get_znear") GodotMethod!(double) getZnear; 60 @GodotName("set_fov") GodotMethod!(void, double) setFov; 61 @GodotName("set_size") GodotMethod!(void, double) setSize; 62 @GodotName("set_zfar") GodotMethod!(void, double) setZfar; 63 @GodotName("set_znear") GodotMethod!(void, double) setZnear; 64 @GodotName("get_projection") GodotMethod!(Camera.Projection) getProjection; 65 @GodotName("set_projection") GodotMethod!(void, long) setProjection; 66 @GodotName("set_h_offset") GodotMethod!(void, double) setHOffset; 67 @GodotName("get_h_offset") GodotMethod!(double) getHOffset; 68 @GodotName("set_v_offset") GodotMethod!(void, double) setVOffset; 69 @GodotName("get_v_offset") GodotMethod!(double) getVOffset; 70 @GodotName("set_cull_mask") GodotMethod!(void, long) setCullMask; 71 @GodotName("get_cull_mask") GodotMethod!(long) getCullMask; 72 @GodotName("set_environment") GodotMethod!(void, Environment) setEnvironment; 73 @GodotName("get_environment") GodotMethod!(Environment) getEnvironment; 74 @GodotName("set_keep_aspect_mode") GodotMethod!(void, long) setKeepAspectMode; 75 @GodotName("get_keep_aspect_mode") GodotMethod!(Camera.KeepAspect) getKeepAspectMode; 76 @GodotName("set_doppler_tracking") GodotMethod!(void, long) setDopplerTracking; 77 @GodotName("get_doppler_tracking") GodotMethod!(Camera.DopplerTracking) getDopplerTracking; 78 @GodotName("set_cull_mask_bit") GodotMethod!(void, long, bool) setCullMaskBit; 79 @GodotName("get_cull_mask_bit") GodotMethod!(bool, long) getCullMaskBit; 80 } 81 bool opEquals(in Camera other) const { return _godot_object.ptr is other._godot_object.ptr; } 82 Camera opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 83 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 84 mixin baseCasts; 85 static Camera _new() 86 { 87 static godot_class_constructor constructor; 88 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Camera"); 89 if(constructor is null) return typeof(this).init; 90 return cast(Camera)(constructor()); 91 } 92 @disable new(size_t s); 93 /// 94 enum KeepAspect : int 95 { 96 /** 97 Preserves the horizontal aspect ratio. 98 */ 99 keepWidth = 0, 100 /** 101 Preserves the vertical aspect ratio. 102 */ 103 keepHeight = 1, 104 } 105 /// 106 enum Projection : int 107 { 108 /** 109 Perspective Projection (object's size on the screen becomes smaller when far away). 110 */ 111 projectionPerspective = 0, 112 /** 113 Orthogonal Projection (objects remain the same size on the screen no matter how far away they are). 114 */ 115 projectionOrthogonal = 1, 116 } 117 /// 118 enum DopplerTracking : int 119 { 120 /** 121 Disable Doppler effect simulation (default). 122 */ 123 dopplerTrackingDisabled = 0, 124 /** 125 Simulate Doppler effect by tracking positions of objects that are changed in `_process`. Changes in the relative velocity of this Camera compared to those objects affect how Audio is perceived (changing the Audio's `pitch shift`). 126 */ 127 dopplerTrackingIdleStep = 1, 128 /** 129 Simulate Doppler effect by tracking positions of objects that are changed in `_physics_process`. Changes in the relative velocity of this Camera compared to those objects affect how Audio is perceived (changing the Audio's `pitch shift`). 130 */ 131 dopplerTrackingPhysicsStep = 2, 132 } 133 /// 134 enum Constants : int 135 { 136 keepWidth = 0, 137 dopplerTrackingDisabled = 0, 138 projectionPerspective = 0, 139 keepHeight = 1, 140 dopplerTrackingIdleStep = 1, 141 projectionOrthogonal = 1, 142 dopplerTrackingPhysicsStep = 2, 143 } 144 /** 145 Returns a normal vector in worldspace, that is the result of projecting a point on the $(D Viewport) rectangle by the camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking. 146 */ 147 Vector3 projectRayNormal(in Vector2 screen_point) const 148 { 149 checkClassBinding!(typeof(this))(); 150 return ptrcall!(Vector3)(_classBinding.projectRayNormal, _godot_object, screen_point); 151 } 152 /** 153 Returns a normal vector from the screen point location directed along the camera. Orthogonal cameras are normalized. Perspective cameras account for perspective, screen width/height, etc. 154 */ 155 Vector3 projectLocalRayNormal(in Vector2 screen_point) const 156 { 157 checkClassBinding!(typeof(this))(); 158 return ptrcall!(Vector3)(_classBinding.projectLocalRayNormal, _godot_object, screen_point); 159 } 160 /** 161 Returns a 3D position in worldspace, that is the result of projecting a point on the $(D Viewport) rectangle by the camera projection. This is useful for casting rays in the form of (origin, normal) for object intersection or picking. 162 */ 163 Vector3 projectRayOrigin(in Vector2 screen_point) const 164 { 165 checkClassBinding!(typeof(this))(); 166 return ptrcall!(Vector3)(_classBinding.projectRayOrigin, _godot_object, screen_point); 167 } 168 /** 169 Returns the 2D coordinate in the $(D Viewport) rectangle that maps to the given 3D point in worldspace. 170 */ 171 Vector2 unprojectPosition(in Vector3 world_point) const 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(Vector2)(_classBinding.unprojectPosition, _godot_object, world_point); 175 } 176 /** 177 Returns `true` if the given position is behind the Camera. Note that a position which returns `false` may still be outside the Camera's field of view. 178 */ 179 bool isPositionBehind(in Vector3 world_point) const 180 { 181 checkClassBinding!(typeof(this))(); 182 return ptrcall!(bool)(_classBinding.isPositionBehind, _godot_object, world_point); 183 } 184 /** 185 Returns the 3D point in worldspace that maps to the given 2D coordinate in the $(D Viewport) rectangle. 186 */ 187 Vector3 projectPosition(in Vector2 screen_point) const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(Vector3)(_classBinding.projectPosition, _godot_object, screen_point); 191 } 192 /** 193 Sets the camera projection to perspective mode, by specifying a $(I FOV) Y angle in degrees (FOV means Field of View), and the $(I near) and $(I far) clip planes in worldspace units. 194 */ 195 void setPerspective(in double fov, in double z_near, in double z_far) 196 { 197 checkClassBinding!(typeof(this))(); 198 ptrcall!(void)(_classBinding.setPerspective, _godot_object, fov, z_near, z_far); 199 } 200 /** 201 Sets the camera projection to orthogonal mode, by specifying a width and the $(I near) and $(I far) clip planes in worldspace units. (As a hint, 2D games often use this projection, with values specified in pixels) 202 */ 203 void setOrthogonal(in double size, in double z_near, in double z_far) 204 { 205 checkClassBinding!(typeof(this))(); 206 ptrcall!(void)(_classBinding.setOrthogonal, _godot_object, size, z_near, z_far); 207 } 208 /** 209 Makes this camera the current Camera for the $(D Viewport) (see class description). If the Camera Node is outside the scene tree, it will attempt to become current once it's added. 210 */ 211 void makeCurrent() 212 { 213 checkClassBinding!(typeof(this))(); 214 ptrcall!(void)(_classBinding.makeCurrent, _godot_object); 215 } 216 /** 217 If this is the current Camera, remove it from being current. If `enable_next` is true, request to make the next Camera current, if any. 218 */ 219 void clearCurrent(in bool enable_next = true) 220 { 221 checkClassBinding!(typeof(this))(); 222 ptrcall!(void)(_classBinding.clearCurrent, _godot_object, enable_next); 223 } 224 /** 225 226 */ 227 void setCurrent(in bool arg0) 228 { 229 checkClassBinding!(typeof(this))(); 230 ptrcall!(void)(_classBinding.setCurrent, _godot_object, arg0); 231 } 232 /** 233 234 */ 235 bool isCurrent() const 236 { 237 checkClassBinding!(typeof(this))(); 238 return ptrcall!(bool)(_classBinding.isCurrent, _godot_object); 239 } 240 /** 241 Gets the camera transform. Subclassed cameras (such as CharacterCamera) may provide different transforms than the $(D Node) transform. 242 */ 243 Transform getCameraTransform() const 244 { 245 checkClassBinding!(typeof(this))(); 246 return ptrcall!(Transform)(_classBinding.getCameraTransform, _godot_object); 247 } 248 /** 249 250 */ 251 double getFov() const 252 { 253 checkClassBinding!(typeof(this))(); 254 return ptrcall!(double)(_classBinding.getFov, _godot_object); 255 } 256 /** 257 258 */ 259 double getSize() const 260 { 261 checkClassBinding!(typeof(this))(); 262 return ptrcall!(double)(_classBinding.getSize, _godot_object); 263 } 264 /** 265 266 */ 267 double getZfar() const 268 { 269 checkClassBinding!(typeof(this))(); 270 return ptrcall!(double)(_classBinding.getZfar, _godot_object); 271 } 272 /** 273 274 */ 275 double getZnear() const 276 { 277 checkClassBinding!(typeof(this))(); 278 return ptrcall!(double)(_classBinding.getZnear, _godot_object); 279 } 280 /** 281 282 */ 283 void setFov(in double arg0) 284 { 285 checkClassBinding!(typeof(this))(); 286 ptrcall!(void)(_classBinding.setFov, _godot_object, arg0); 287 } 288 /** 289 290 */ 291 void setSize(in double arg0) 292 { 293 checkClassBinding!(typeof(this))(); 294 ptrcall!(void)(_classBinding.setSize, _godot_object, arg0); 295 } 296 /** 297 298 */ 299 void setZfar(in double arg0) 300 { 301 checkClassBinding!(typeof(this))(); 302 ptrcall!(void)(_classBinding.setZfar, _godot_object, arg0); 303 } 304 /** 305 306 */ 307 void setZnear(in double arg0) 308 { 309 checkClassBinding!(typeof(this))(); 310 ptrcall!(void)(_classBinding.setZnear, _godot_object, arg0); 311 } 312 /** 313 314 */ 315 Camera.Projection getProjection() const 316 { 317 checkClassBinding!(typeof(this))(); 318 return ptrcall!(Camera.Projection)(_classBinding.getProjection, _godot_object); 319 } 320 /** 321 322 */ 323 void setProjection(in long arg0) 324 { 325 checkClassBinding!(typeof(this))(); 326 ptrcall!(void)(_classBinding.setProjection, _godot_object, arg0); 327 } 328 /** 329 330 */ 331 void setHOffset(in double ofs) 332 { 333 checkClassBinding!(typeof(this))(); 334 ptrcall!(void)(_classBinding.setHOffset, _godot_object, ofs); 335 } 336 /** 337 338 */ 339 double getHOffset() const 340 { 341 checkClassBinding!(typeof(this))(); 342 return ptrcall!(double)(_classBinding.getHOffset, _godot_object); 343 } 344 /** 345 346 */ 347 void setVOffset(in double ofs) 348 { 349 checkClassBinding!(typeof(this))(); 350 ptrcall!(void)(_classBinding.setVOffset, _godot_object, ofs); 351 } 352 /** 353 354 */ 355 double getVOffset() const 356 { 357 checkClassBinding!(typeof(this))(); 358 return ptrcall!(double)(_classBinding.getVOffset, _godot_object); 359 } 360 /** 361 362 */ 363 void setCullMask(in long mask) 364 { 365 checkClassBinding!(typeof(this))(); 366 ptrcall!(void)(_classBinding.setCullMask, _godot_object, mask); 367 } 368 /** 369 370 */ 371 long getCullMask() const 372 { 373 checkClassBinding!(typeof(this))(); 374 return ptrcall!(long)(_classBinding.getCullMask, _godot_object); 375 } 376 /** 377 378 */ 379 void setEnvironment(Environment env) 380 { 381 checkClassBinding!(typeof(this))(); 382 ptrcall!(void)(_classBinding.setEnvironment, _godot_object, env); 383 } 384 /** 385 386 */ 387 Ref!Environment getEnvironment() const 388 { 389 checkClassBinding!(typeof(this))(); 390 return ptrcall!(Environment)(_classBinding.getEnvironment, _godot_object); 391 } 392 /** 393 394 */ 395 void setKeepAspectMode(in long mode) 396 { 397 checkClassBinding!(typeof(this))(); 398 ptrcall!(void)(_classBinding.setKeepAspectMode, _godot_object, mode); 399 } 400 /** 401 402 */ 403 Camera.KeepAspect getKeepAspectMode() const 404 { 405 checkClassBinding!(typeof(this))(); 406 return ptrcall!(Camera.KeepAspect)(_classBinding.getKeepAspectMode, _godot_object); 407 } 408 /** 409 410 */ 411 void setDopplerTracking(in long mode) 412 { 413 checkClassBinding!(typeof(this))(); 414 ptrcall!(void)(_classBinding.setDopplerTracking, _godot_object, mode); 415 } 416 /** 417 418 */ 419 Camera.DopplerTracking getDopplerTracking() const 420 { 421 checkClassBinding!(typeof(this))(); 422 return ptrcall!(Camera.DopplerTracking)(_classBinding.getDopplerTracking, _godot_object); 423 } 424 /** 425 426 */ 427 void setCullMaskBit(in long layer, in bool enable) 428 { 429 checkClassBinding!(typeof(this))(); 430 ptrcall!(void)(_classBinding.setCullMaskBit, _godot_object, layer, enable); 431 } 432 /** 433 434 */ 435 bool getCullMaskBit(in long layer) const 436 { 437 checkClassBinding!(typeof(this))(); 438 return ptrcall!(bool)(_classBinding.getCullMaskBit, _godot_object, layer); 439 } 440 /** 441 The axis to lock during $(D fov)/$(D size) adjustments. Can be either `KEEP_WIDTH` or `KEEP_HEIGHT`. 442 */ 443 @property Camera.KeepAspect keepAspect() 444 { 445 return getKeepAspectMode(); 446 } 447 /// ditto 448 @property void keepAspect(long v) 449 { 450 setKeepAspectMode(v); 451 } 452 /** 453 The culling mask that describes which 3D render layers are rendered by this camera. 454 */ 455 @property long cullMask() 456 { 457 return getCullMask(); 458 } 459 /// ditto 460 @property void cullMask(long v) 461 { 462 setCullMask(v); 463 } 464 /** 465 The $(D Environment) to use for this Camera. 466 */ 467 @property Environment environment() 468 { 469 return getEnvironment(); 470 } 471 /// ditto 472 @property void environment(Environment v) 473 { 474 setEnvironment(v); 475 } 476 /** 477 The horizontal (X) offset of the Camera viewport. 478 */ 479 @property double hOffset() 480 { 481 return getHOffset(); 482 } 483 /// ditto 484 @property void hOffset(double v) 485 { 486 setHOffset(v); 487 } 488 /** 489 The vertical (Y) offset of the Camera viewport. 490 */ 491 @property double vOffset() 492 { 493 return getVOffset(); 494 } 495 /// ditto 496 @property void vOffset(double v) 497 { 498 setVOffset(v); 499 } 500 /** 501 If not `DOPPLER_TRACKING_DISABLED` this Camera will simulate the Doppler effect for objects changed in particular `_process` methods. Default value: `DOPPLER_TRACKING_DISABLED`. 502 */ 503 @property Camera.DopplerTracking dopplerTracking() 504 { 505 return getDopplerTracking(); 506 } 507 /// ditto 508 @property void dopplerTracking(long v) 509 { 510 setDopplerTracking(v); 511 } 512 /** 513 The camera's projection mode. In `PROJECTION_PERSPECTIVE` mode, objects' z-distance from the camera's local space scales their perceived size. 514 */ 515 @property Camera.Projection projection() 516 { 517 return getProjection(); 518 } 519 /// ditto 520 @property void projection(long v) 521 { 522 setProjection(v); 523 } 524 /** 525 If `true` the ancestor $(D Viewport) is currently using this Camera. Default value: `false`. 526 */ 527 @property bool current() 528 { 529 return isCurrent(); 530 } 531 /// ditto 532 @property void current(bool v) 533 { 534 setCurrent(v); 535 } 536 /** 537 The camera's field of view angle (in degrees). Only applicable in perspective mode. Since $(D keepAspect) locks one axis, `fov` sets the other axis' field of view angle. 538 */ 539 @property double fov() 540 { 541 return getFov(); 542 } 543 /// ditto 544 @property void fov(double v) 545 { 546 setFov(v); 547 } 548 /** 549 The camera's size measured as 1/2 the width or height. Only applicable in orthogonal mode. Since $(D keepAspect) locks on axis, `size` sets the other axis' size length. 550 */ 551 @property double size() 552 { 553 return getSize(); 554 } 555 /// ditto 556 @property void size(double v) 557 { 558 setSize(v); 559 } 560 /** 561 The distance to the near culling boundary for this Camera relative to its local z-axis. 562 */ 563 @property double near() 564 { 565 return getZnear(); 566 } 567 /// ditto 568 @property void near(double v) 569 { 570 setZnear(v); 571 } 572 /** 573 The distance to the far culling boundary for this Camera relative to its local z-axis. 574 */ 575 @property double far() 576 { 577 return getZfar(); 578 } 579 /// ditto 580 @property void far(double v) 581 { 582 setZfar(v); 583 } 584 }