1 /** 2 Point sampler for a $(D Path). 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.pathfollow; 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 /** 26 Point sampler for a $(D Path). 27 28 This node takes its parent $(D Path), and returns the coordinates of a point within it, given a distance from the first vertex. 29 It is useful for making other nodes follow a path, without coding the movement pattern. For that, the nodes must be children of this node. The descendant nodes will then move accordingly when setting an offset in this node. 30 */ 31 @GodotBaseClass struct PathFollow 32 { 33 package(godot) enum string _GODOT_internal_name = "PathFollow"; 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 GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("get_cubic_interpolation") GodotMethod!(bool) getCubicInterpolation; 44 @GodotName("get_h_offset") GodotMethod!(double) getHOffset; 45 @GodotName("get_offset") GodotMethod!(double) getOffset; 46 @GodotName("get_rotation_mode") GodotMethod!(PathFollow.RotationMode) getRotationMode; 47 @GodotName("get_unit_offset") GodotMethod!(double) getUnitOffset; 48 @GodotName("get_v_offset") GodotMethod!(double) getVOffset; 49 @GodotName("has_loop") GodotMethod!(bool) hasLoop; 50 @GodotName("set_cubic_interpolation") GodotMethod!(void, bool) setCubicInterpolation; 51 @GodotName("set_h_offset") GodotMethod!(void, double) setHOffset; 52 @GodotName("set_loop") GodotMethod!(void, bool) setLoop; 53 @GodotName("set_offset") GodotMethod!(void, double) setOffset; 54 @GodotName("set_rotation_mode") GodotMethod!(void, long) setRotationMode; 55 @GodotName("set_unit_offset") GodotMethod!(void, double) setUnitOffset; 56 @GodotName("set_v_offset") GodotMethod!(void, double) setVOffset; 57 } 58 /// 59 pragma(inline, true) bool opEquals(in PathFollow other) const 60 { return _godot_object.ptr is other._godot_object.ptr; } 61 /// 62 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 63 { _godot_object.ptr = n; return null; } 64 /// 65 pragma(inline, true) bool opEquals(typeof(null) n) const 66 { return _godot_object.ptr is n; } 67 /// 68 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 69 mixin baseCasts; 70 /// Construct a new instance of PathFollow. 71 /// Note: use `memnew!PathFollow` instead. 72 static PathFollow _new() 73 { 74 static godot_class_constructor constructor; 75 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PathFollow"); 76 if(constructor is null) return typeof(this).init; 77 return cast(PathFollow)(constructor()); 78 } 79 @disable new(size_t s); 80 /// 81 enum RotationMode : int 82 { 83 /** 84 Forbids the PathFollow to rotate. 85 */ 86 rotationNone = 0, 87 /** 88 Allows the PathFollow to rotate in the Y axis only. 89 */ 90 rotationY = 1, 91 /** 92 Allows the PathFollow to rotate in both the X, and Y axes. 93 */ 94 rotationXy = 2, 95 /** 96 Allows the PathFollow to rotate in any axis. 97 */ 98 rotationXyz = 3, 99 /** 100 Uses the up vector information in a $(D Curve3D) to enforce orientation. This rotation mode requires the $(D Path)'s $(D Curve3D.upVectorEnabled) property to be set to `true`. 101 */ 102 rotationOriented = 4, 103 } 104 /// 105 enum Constants : int 106 { 107 rotationNone = 0, 108 rotationY = 1, 109 rotationXy = 2, 110 rotationXyz = 3, 111 rotationOriented = 4, 112 } 113 /** 114 115 */ 116 bool getCubicInterpolation() const 117 { 118 checkClassBinding!(typeof(this))(); 119 return ptrcall!(bool)(GDNativeClassBinding.getCubicInterpolation, _godot_object); 120 } 121 /** 122 123 */ 124 double getHOffset() const 125 { 126 checkClassBinding!(typeof(this))(); 127 return ptrcall!(double)(GDNativeClassBinding.getHOffset, _godot_object); 128 } 129 /** 130 131 */ 132 double getOffset() const 133 { 134 checkClassBinding!(typeof(this))(); 135 return ptrcall!(double)(GDNativeClassBinding.getOffset, _godot_object); 136 } 137 /** 138 139 */ 140 PathFollow.RotationMode getRotationMode() const 141 { 142 checkClassBinding!(typeof(this))(); 143 return ptrcall!(PathFollow.RotationMode)(GDNativeClassBinding.getRotationMode, _godot_object); 144 } 145 /** 146 147 */ 148 double getUnitOffset() const 149 { 150 checkClassBinding!(typeof(this))(); 151 return ptrcall!(double)(GDNativeClassBinding.getUnitOffset, _godot_object); 152 } 153 /** 154 155 */ 156 double getVOffset() const 157 { 158 checkClassBinding!(typeof(this))(); 159 return ptrcall!(double)(GDNativeClassBinding.getVOffset, _godot_object); 160 } 161 /** 162 163 */ 164 bool hasLoop() const 165 { 166 checkClassBinding!(typeof(this))(); 167 return ptrcall!(bool)(GDNativeClassBinding.hasLoop, _godot_object); 168 } 169 /** 170 171 */ 172 void setCubicInterpolation(in bool enable) 173 { 174 checkClassBinding!(typeof(this))(); 175 ptrcall!(void)(GDNativeClassBinding.setCubicInterpolation, _godot_object, enable); 176 } 177 /** 178 179 */ 180 void setHOffset(in double h_offset) 181 { 182 checkClassBinding!(typeof(this))(); 183 ptrcall!(void)(GDNativeClassBinding.setHOffset, _godot_object, h_offset); 184 } 185 /** 186 187 */ 188 void setLoop(in bool loop) 189 { 190 checkClassBinding!(typeof(this))(); 191 ptrcall!(void)(GDNativeClassBinding.setLoop, _godot_object, loop); 192 } 193 /** 194 195 */ 196 void setOffset(in double offset) 197 { 198 checkClassBinding!(typeof(this))(); 199 ptrcall!(void)(GDNativeClassBinding.setOffset, _godot_object, offset); 200 } 201 /** 202 203 */ 204 void setRotationMode(in long rotation_mode) 205 { 206 checkClassBinding!(typeof(this))(); 207 ptrcall!(void)(GDNativeClassBinding.setRotationMode, _godot_object, rotation_mode); 208 } 209 /** 210 211 */ 212 void setUnitOffset(in double unit_offset) 213 { 214 checkClassBinding!(typeof(this))(); 215 ptrcall!(void)(GDNativeClassBinding.setUnitOffset, _godot_object, unit_offset); 216 } 217 /** 218 219 */ 220 void setVOffset(in double v_offset) 221 { 222 checkClassBinding!(typeof(this))(); 223 ptrcall!(void)(GDNativeClassBinding.setVOffset, _godot_object, v_offset); 224 } 225 /** 226 If `true`, the position between two cached points is interpolated cubically, and linearly otherwise. 227 The points along the $(D Curve3D) of the $(D Path) are precomputed before use, for faster calculations. The point at the requested offset is then calculated interpolating between two adjacent cached points. This may present a problem if the curve makes sharp turns, as the cached points may not follow the curve closely enough. 228 There are two answers to this problem: either increase the number of cached points and increase memory consumption, or make a cubic interpolation between two points at the cost of (slightly) slower calculations. 229 */ 230 @property bool cubicInterp() 231 { 232 return getCubicInterpolation(); 233 } 234 /// ditto 235 @property void cubicInterp(bool v) 236 { 237 setCubicInterpolation(v); 238 } 239 /** 240 The node's offset along the curve. 241 */ 242 @property double hOffset() 243 { 244 return getHOffset(); 245 } 246 /// ditto 247 @property void hOffset(double v) 248 { 249 setHOffset(v); 250 } 251 /** 252 If `true`, any offset outside the path's length will wrap around, instead of stopping at the ends. Use it for cyclic paths. 253 */ 254 @property bool loop() 255 { 256 return hasLoop(); 257 } 258 /// ditto 259 @property void loop(bool v) 260 { 261 setLoop(v); 262 } 263 /** 264 The distance from the first vertex, measured in 3D units along the path. This sets this node's position to a point within the path. 265 */ 266 @property double offset() 267 { 268 return getOffset(); 269 } 270 /// ditto 271 @property void offset(double v) 272 { 273 setOffset(v); 274 } 275 /** 276 Allows or forbids rotation on one or more axes, depending on the $(D rotationmode) constants being used. 277 */ 278 @property PathFollow.RotationMode rotationMode() 279 { 280 return getRotationMode(); 281 } 282 /// ditto 283 @property void rotationMode(long v) 284 { 285 setRotationMode(v); 286 } 287 /** 288 The distance from the first vertex, considering 0.0 as the first vertex and 1.0 as the last. This is just another way of expressing the offset within the path, as the offset supplied is multiplied internally by the path's length. 289 */ 290 @property double unitOffset() 291 { 292 return getUnitOffset(); 293 } 294 /// ditto 295 @property void unitOffset(double v) 296 { 297 setUnitOffset(v); 298 } 299 /** 300 The node's offset perpendicular to the curve. 301 */ 302 @property double vOffset() 303 { 304 return getVOffset(); 305 } 306 /// ditto 307 @property void vOffset(double v) 308 { 309 setVOffset(v); 310 } 311 }