1 /** 2 A helper node, mostly used in 3rd person cameras. 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.springarm; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.spatial; 25 import godot.node; 26 import godot.shape; 27 /** 28 A helper node, mostly used in 3rd person cameras. 29 30 The SpringArm node is a node that casts a ray (or collision shape) along its z axis and moves all its direct children to the collision point, minus a margin. 31 The most common use case for this is to make a 3rd person camera that reacts to collisions in the environment. 32 The SpringArm will either cast a ray, or if a shape is given, it will cast the shape in the direction of its z axis. 33 If you use the SpringArm as a camera controller for your player, you might need to exclude the player's collider from the SpringArm's collision check. 34 */ 35 @GodotBaseClass struct SpringArm 36 { 37 package(godot) enum string _GODOT_internal_name = "SpringArm"; 38 public: 39 @nogc nothrow: 40 union { /** */ godot_object _godot_object; /** */ Spatial _GODOT_base; } 41 alias _GODOT_base this; 42 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 43 package(godot) __gshared bool _classBindingInitialized = false; 44 package(godot) static struct GDNativeClassBinding 45 { 46 __gshared: 47 @GodotName("add_excluded_object") GodotMethod!(void, RID) addExcludedObject; 48 @GodotName("clear_excluded_objects") GodotMethod!(void) clearExcludedObjects; 49 @GodotName("get_collision_mask") GodotMethod!(long) getCollisionMask; 50 @GodotName("get_hit_length") GodotMethod!(double) getHitLength; 51 @GodotName("get_length") GodotMethod!(double) getLength; 52 @GodotName("get_margin") GodotMethod!(double) getMargin; 53 @GodotName("get_shape") GodotMethod!(Shape) getShape; 54 @GodotName("remove_excluded_object") GodotMethod!(bool, RID) removeExcludedObject; 55 @GodotName("set_collision_mask") GodotMethod!(void, long) setCollisionMask; 56 @GodotName("set_length") GodotMethod!(void, double) setLength; 57 @GodotName("set_margin") GodotMethod!(void, double) setMargin; 58 @GodotName("set_shape") GodotMethod!(void, Shape) setShape; 59 } 60 /// 61 pragma(inline, true) bool opEquals(in SpringArm other) const 62 { return _godot_object.ptr is other._godot_object.ptr; } 63 /// 64 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 65 { _godot_object.ptr = n; return null; } 66 /// 67 pragma(inline, true) bool opEquals(typeof(null) n) const 68 { return _godot_object.ptr is n; } 69 /// 70 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 71 mixin baseCasts; 72 /// Construct a new instance of SpringArm. 73 /// Note: use `memnew!SpringArm` instead. 74 static SpringArm _new() 75 { 76 static godot_class_constructor constructor; 77 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("SpringArm"); 78 if(constructor is null) return typeof(this).init; 79 return cast(SpringArm)(constructor()); 80 } 81 @disable new(size_t s); 82 /** 83 Adds the $(D PhysicsBody) object with the given $(D RID) to the list of $(D PhysicsBody) objects excluded from the collision check. 84 */ 85 void addExcludedObject(in RID RID) 86 { 87 checkClassBinding!(typeof(this))(); 88 ptrcall!(void)(GDNativeClassBinding.addExcludedObject, _godot_object, RID); 89 } 90 /** 91 Clears the list of $(D PhysicsBody) objects excluded from the collision check. 92 */ 93 void clearExcludedObjects() 94 { 95 checkClassBinding!(typeof(this))(); 96 ptrcall!(void)(GDNativeClassBinding.clearExcludedObjects, _godot_object); 97 } 98 /** 99 100 */ 101 long getCollisionMask() 102 { 103 checkClassBinding!(typeof(this))(); 104 return ptrcall!(long)(GDNativeClassBinding.getCollisionMask, _godot_object); 105 } 106 /** 107 Returns the spring arm's current length. 108 */ 109 double getHitLength() 110 { 111 checkClassBinding!(typeof(this))(); 112 return ptrcall!(double)(GDNativeClassBinding.getHitLength, _godot_object); 113 } 114 /** 115 116 */ 117 double getLength() const 118 { 119 checkClassBinding!(typeof(this))(); 120 return ptrcall!(double)(GDNativeClassBinding.getLength, _godot_object); 121 } 122 /** 123 124 */ 125 double getMargin() 126 { 127 checkClassBinding!(typeof(this))(); 128 return ptrcall!(double)(GDNativeClassBinding.getMargin, _godot_object); 129 } 130 /** 131 132 */ 133 Ref!Shape getShape() const 134 { 135 checkClassBinding!(typeof(this))(); 136 return ptrcall!(Shape)(GDNativeClassBinding.getShape, _godot_object); 137 } 138 /** 139 Removes the given $(D RID) from the list of $(D PhysicsBody) objects excluded from the collision check. 140 */ 141 bool removeExcludedObject(in RID RID) 142 { 143 checkClassBinding!(typeof(this))(); 144 return ptrcall!(bool)(GDNativeClassBinding.removeExcludedObject, _godot_object, RID); 145 } 146 /** 147 148 */ 149 void setCollisionMask(in long mask) 150 { 151 checkClassBinding!(typeof(this))(); 152 ptrcall!(void)(GDNativeClassBinding.setCollisionMask, _godot_object, mask); 153 } 154 /** 155 156 */ 157 void setLength(in double length) 158 { 159 checkClassBinding!(typeof(this))(); 160 ptrcall!(void)(GDNativeClassBinding.setLength, _godot_object, length); 161 } 162 /** 163 164 */ 165 void setMargin(in double margin) 166 { 167 checkClassBinding!(typeof(this))(); 168 ptrcall!(void)(GDNativeClassBinding.setMargin, _godot_object, margin); 169 } 170 /** 171 172 */ 173 void setShape(Shape shape) 174 { 175 checkClassBinding!(typeof(this))(); 176 ptrcall!(void)(GDNativeClassBinding.setShape, _godot_object, shape); 177 } 178 /** 179 The layers against which the collision check shall be done. See $(D url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks)Collision layers and masks$(D /url) in the documentation for more information. 180 */ 181 @property long collisionMask() 182 { 183 return getCollisionMask(); 184 } 185 /// ditto 186 @property void collisionMask(long v) 187 { 188 setCollisionMask(v); 189 } 190 /** 191 When the collision check is made, a candidate length for the SpringArm is given. 192 The margin is then subtracted to this length and the translation is applied to the child objects of the SpringArm. 193 This margin is useful for when the SpringArm has a $(D Camera) as a child node: without the margin, the $(D Camera) would be placed on the exact point of collision, while with the margin the $(D Camera) would be placed close to the point of collision. 194 */ 195 @property double margin() 196 { 197 return getMargin(); 198 } 199 /// ditto 200 @property void margin(double v) 201 { 202 setMargin(v); 203 } 204 /** 205 The $(D Shape) to use for the SpringArm. 206 When the shape is set, the SpringArm will cast the $(D Shape) on its z axis instead of performing a ray cast. 207 */ 208 @property Shape shape() 209 { 210 return getShape(); 211 } 212 /// ditto 213 @property void shape(Shape v) 214 { 215 setShape(v); 216 } 217 /** 218 The maximum extent of the SpringArm. This is used as a length for both the ray and the shape cast used internally to calculate the desired position of the SpringArm's child nodes. 219 To know more about how to perform a shape cast or a ray cast, please consult the $(D PhysicsDirectSpaceState) documentation. 220 */ 221 @property double springLength() 222 { 223 return getLength(); 224 } 225 /// ditto 226 @property void springLength(double v) 227 { 228 setLength(v); 229 } 230 }