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.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.node; 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 descendants of this node. Then, when setting an offset in this node, the descendant nodes will move accordingly. 30 */ 31 @GodotBaseClass struct PathFollow 32 { 33 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 _classBinding 41 { 42 __gshared: 43 @GodotName("set_offset") GodotMethod!(void, double) setOffset; 44 @GodotName("get_offset") GodotMethod!(double) getOffset; 45 @GodotName("set_h_offset") GodotMethod!(void, double) setHOffset; 46 @GodotName("get_h_offset") GodotMethod!(double) getHOffset; 47 @GodotName("set_v_offset") GodotMethod!(void, double) setVOffset; 48 @GodotName("get_v_offset") GodotMethod!(double) getVOffset; 49 @GodotName("set_unit_offset") GodotMethod!(void, double) setUnitOffset; 50 @GodotName("get_unit_offset") GodotMethod!(double) getUnitOffset; 51 @GodotName("set_rotation_mode") GodotMethod!(void, long) setRotationMode; 52 @GodotName("get_rotation_mode") GodotMethod!(PathFollow.RotationMode) getRotationMode; 53 @GodotName("set_cubic_interpolation") GodotMethod!(void, bool) setCubicInterpolation; 54 @GodotName("get_cubic_interpolation") GodotMethod!(bool) getCubicInterpolation; 55 @GodotName("set_loop") GodotMethod!(void, bool) setLoop; 56 @GodotName("has_loop") GodotMethod!(bool) hasLoop; 57 } 58 bool opEquals(in PathFollow other) const { return _godot_object.ptr is other._godot_object.ptr; } 59 PathFollow opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 60 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 61 mixin baseCasts; 62 static PathFollow _new() 63 { 64 static godot_class_constructor constructor; 65 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PathFollow"); 66 if(constructor is null) return typeof(this).init; 67 return cast(PathFollow)(constructor()); 68 } 69 @disable new(size_t s); 70 /// 71 enum RotationMode : int 72 { 73 /** 74 Forbids the PathFollow to rotate. 75 */ 76 rotationNone = 0, 77 /** 78 Allows the PathFollow to rotate in the Y axis only. 79 */ 80 rotationY = 1, 81 /** 82 Allows the PathFollow to rotate in both the X, and Y axes. 83 */ 84 rotationXy = 2, 85 /** 86 Allows the PathFollow to rotate in any axis. 87 */ 88 rotationXyz = 3, 89 } 90 /// 91 enum Constants : int 92 { 93 rotationNone = 0, 94 rotationY = 1, 95 rotationXy = 2, 96 rotationXyz = 3, 97 } 98 /** 99 100 */ 101 void setOffset(in double offset) 102 { 103 checkClassBinding!(typeof(this))(); 104 ptrcall!(void)(_classBinding.setOffset, _godot_object, offset); 105 } 106 /** 107 108 */ 109 double getOffset() const 110 { 111 checkClassBinding!(typeof(this))(); 112 return ptrcall!(double)(_classBinding.getOffset, _godot_object); 113 } 114 /** 115 116 */ 117 void setHOffset(in double h_offset) 118 { 119 checkClassBinding!(typeof(this))(); 120 ptrcall!(void)(_classBinding.setHOffset, _godot_object, h_offset); 121 } 122 /** 123 124 */ 125 double getHOffset() const 126 { 127 checkClassBinding!(typeof(this))(); 128 return ptrcall!(double)(_classBinding.getHOffset, _godot_object); 129 } 130 /** 131 132 */ 133 void setVOffset(in double v_offset) 134 { 135 checkClassBinding!(typeof(this))(); 136 ptrcall!(void)(_classBinding.setVOffset, _godot_object, v_offset); 137 } 138 /** 139 140 */ 141 double getVOffset() const 142 { 143 checkClassBinding!(typeof(this))(); 144 return ptrcall!(double)(_classBinding.getVOffset, _godot_object); 145 } 146 /** 147 148 */ 149 void setUnitOffset(in double unit_offset) 150 { 151 checkClassBinding!(typeof(this))(); 152 ptrcall!(void)(_classBinding.setUnitOffset, _godot_object, unit_offset); 153 } 154 /** 155 156 */ 157 double getUnitOffset() const 158 { 159 checkClassBinding!(typeof(this))(); 160 return ptrcall!(double)(_classBinding.getUnitOffset, _godot_object); 161 } 162 /** 163 164 */ 165 void setRotationMode(in long rotation_mode) 166 { 167 checkClassBinding!(typeof(this))(); 168 ptrcall!(void)(_classBinding.setRotationMode, _godot_object, rotation_mode); 169 } 170 /** 171 172 */ 173 PathFollow.RotationMode getRotationMode() const 174 { 175 checkClassBinding!(typeof(this))(); 176 return ptrcall!(PathFollow.RotationMode)(_classBinding.getRotationMode, _godot_object); 177 } 178 /** 179 180 */ 181 void setCubicInterpolation(in bool enable) 182 { 183 checkClassBinding!(typeof(this))(); 184 ptrcall!(void)(_classBinding.setCubicInterpolation, _godot_object, enable); 185 } 186 /** 187 188 */ 189 bool getCubicInterpolation() const 190 { 191 checkClassBinding!(typeof(this))(); 192 return ptrcall!(bool)(_classBinding.getCubicInterpolation, _godot_object); 193 } 194 /** 195 196 */ 197 void setLoop(in bool loop) 198 { 199 checkClassBinding!(typeof(this))(); 200 ptrcall!(void)(_classBinding.setLoop, _godot_object, loop); 201 } 202 /** 203 204 */ 205 bool hasLoop() const 206 { 207 checkClassBinding!(typeof(this))(); 208 return ptrcall!(bool)(_classBinding.hasLoop, _godot_object); 209 } 210 /** 211 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. 212 */ 213 @property double offset() 214 { 215 return getOffset(); 216 } 217 /// ditto 218 @property void offset(double v) 219 { 220 setOffset(v); 221 } 222 /** 223 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. 224 */ 225 @property double unitOffset() 226 { 227 return getUnitOffset(); 228 } 229 /// ditto 230 @property void unitOffset(double v) 231 { 232 setUnitOffset(v); 233 } 234 /** 235 The node's offset along the curve. 236 */ 237 @property double hOffset() 238 { 239 return getHOffset(); 240 } 241 /// ditto 242 @property void hOffset(double v) 243 { 244 setHOffset(v); 245 } 246 /** 247 The node's offset perpendicular to the curve. 248 */ 249 @property double vOffset() 250 { 251 return getVOffset(); 252 } 253 /// ditto 254 @property void vOffset(double v) 255 { 256 setVOffset(v); 257 } 258 /** 259 Allows or forbids rotation on one or more axes, depending on the constants being used. 260 */ 261 @property PathFollow.RotationMode rotationMode() 262 { 263 return getRotationMode(); 264 } 265 /// ditto 266 @property void rotationMode(long v) 267 { 268 setRotationMode(v); 269 } 270 /** 271 If `true` the position between two cached points is interpolated cubically, and linearly otherwise. 272 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. 273 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. 274 */ 275 @property bool cubicInterp() 276 { 277 return getCubicInterpolation(); 278 } 279 /// ditto 280 @property void cubicInterp(bool v) 281 { 282 setCubicInterpolation(v); 283 } 284 /** 285 If `true`, any offset outside the path's length will wrap around, instead of stopping at the ends. Use it for cyclic paths. 286 */ 287 @property bool loop() 288 { 289 return hasLoop(); 290 } 291 /// ditto 292 @property void loop(bool v) 293 { 294 setLoop(v); 295 } 296 }