1 /** 2 Physics object that simulates the behaviour of a wheel. 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.vehiclewheel; 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 Physics object that simulates the behaviour of a wheel. 27 28 This node needs to be used as a child node of $(D VehicleBody) and simulates the behaviour of one of its wheels. This node also acts as a collider to detect if the wheel is touching a surface. 29 */ 30 @GodotBaseClass struct VehicleWheel 31 { 32 enum string _GODOT_internal_name = "VehicleWheel"; 33 public: 34 @nogc nothrow: 35 union { godot_object _godot_object; Spatial _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct _classBinding 40 { 41 __gshared: 42 @GodotName("set_radius") GodotMethod!(void, double) setRadius; 43 @GodotName("get_radius") GodotMethod!(double) getRadius; 44 @GodotName("set_suspension_rest_length") GodotMethod!(void, double) setSuspensionRestLength; 45 @GodotName("get_suspension_rest_length") GodotMethod!(double) getSuspensionRestLength; 46 @GodotName("set_suspension_travel") GodotMethod!(void, double) setSuspensionTravel; 47 @GodotName("get_suspension_travel") GodotMethod!(double) getSuspensionTravel; 48 @GodotName("set_suspension_stiffness") GodotMethod!(void, double) setSuspensionStiffness; 49 @GodotName("get_suspension_stiffness") GodotMethod!(double) getSuspensionStiffness; 50 @GodotName("set_suspension_max_force") GodotMethod!(void, double) setSuspensionMaxForce; 51 @GodotName("get_suspension_max_force") GodotMethod!(double) getSuspensionMaxForce; 52 @GodotName("set_damping_compression") GodotMethod!(void, double) setDampingCompression; 53 @GodotName("get_damping_compression") GodotMethod!(double) getDampingCompression; 54 @GodotName("set_damping_relaxation") GodotMethod!(void, double) setDampingRelaxation; 55 @GodotName("get_damping_relaxation") GodotMethod!(double) getDampingRelaxation; 56 @GodotName("set_use_as_traction") GodotMethod!(void, bool) setUseAsTraction; 57 @GodotName("is_used_as_traction") GodotMethod!(bool) isUsedAsTraction; 58 @GodotName("set_use_as_steering") GodotMethod!(void, bool) setUseAsSteering; 59 @GodotName("is_used_as_steering") GodotMethod!(bool) isUsedAsSteering; 60 @GodotName("set_friction_slip") GodotMethod!(void, double) setFrictionSlip; 61 @GodotName("get_friction_slip") GodotMethod!(double) getFrictionSlip; 62 @GodotName("is_in_contact") GodotMethod!(bool) isInContact; 63 @GodotName("set_roll_influence") GodotMethod!(void, double) setRollInfluence; 64 @GodotName("get_roll_influence") GodotMethod!(double) getRollInfluence; 65 @GodotName("get_skidinfo") GodotMethod!(double) getSkidinfo; 66 } 67 bool opEquals(in VehicleWheel other) const { return _godot_object.ptr is other._godot_object.ptr; } 68 VehicleWheel opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 69 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 70 mixin baseCasts; 71 static VehicleWheel _new() 72 { 73 static godot_class_constructor constructor; 74 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VehicleWheel"); 75 if(constructor is null) return typeof(this).init; 76 return cast(VehicleWheel)(constructor()); 77 } 78 @disable new(size_t s); 79 /** 80 81 */ 82 void setRadius(in double length) 83 { 84 checkClassBinding!(typeof(this))(); 85 ptrcall!(void)(_classBinding.setRadius, _godot_object, length); 86 } 87 /** 88 89 */ 90 double getRadius() const 91 { 92 checkClassBinding!(typeof(this))(); 93 return ptrcall!(double)(_classBinding.getRadius, _godot_object); 94 } 95 /** 96 97 */ 98 void setSuspensionRestLength(in double length) 99 { 100 checkClassBinding!(typeof(this))(); 101 ptrcall!(void)(_classBinding.setSuspensionRestLength, _godot_object, length); 102 } 103 /** 104 105 */ 106 double getSuspensionRestLength() const 107 { 108 checkClassBinding!(typeof(this))(); 109 return ptrcall!(double)(_classBinding.getSuspensionRestLength, _godot_object); 110 } 111 /** 112 113 */ 114 void setSuspensionTravel(in double length) 115 { 116 checkClassBinding!(typeof(this))(); 117 ptrcall!(void)(_classBinding.setSuspensionTravel, _godot_object, length); 118 } 119 /** 120 121 */ 122 double getSuspensionTravel() const 123 { 124 checkClassBinding!(typeof(this))(); 125 return ptrcall!(double)(_classBinding.getSuspensionTravel, _godot_object); 126 } 127 /** 128 129 */ 130 void setSuspensionStiffness(in double length) 131 { 132 checkClassBinding!(typeof(this))(); 133 ptrcall!(void)(_classBinding.setSuspensionStiffness, _godot_object, length); 134 } 135 /** 136 137 */ 138 double getSuspensionStiffness() const 139 { 140 checkClassBinding!(typeof(this))(); 141 return ptrcall!(double)(_classBinding.getSuspensionStiffness, _godot_object); 142 } 143 /** 144 145 */ 146 void setSuspensionMaxForce(in double length) 147 { 148 checkClassBinding!(typeof(this))(); 149 ptrcall!(void)(_classBinding.setSuspensionMaxForce, _godot_object, length); 150 } 151 /** 152 153 */ 154 double getSuspensionMaxForce() const 155 { 156 checkClassBinding!(typeof(this))(); 157 return ptrcall!(double)(_classBinding.getSuspensionMaxForce, _godot_object); 158 } 159 /** 160 161 */ 162 void setDampingCompression(in double length) 163 { 164 checkClassBinding!(typeof(this))(); 165 ptrcall!(void)(_classBinding.setDampingCompression, _godot_object, length); 166 } 167 /** 168 169 */ 170 double getDampingCompression() const 171 { 172 checkClassBinding!(typeof(this))(); 173 return ptrcall!(double)(_classBinding.getDampingCompression, _godot_object); 174 } 175 /** 176 177 */ 178 void setDampingRelaxation(in double length) 179 { 180 checkClassBinding!(typeof(this))(); 181 ptrcall!(void)(_classBinding.setDampingRelaxation, _godot_object, length); 182 } 183 /** 184 185 */ 186 double getDampingRelaxation() const 187 { 188 checkClassBinding!(typeof(this))(); 189 return ptrcall!(double)(_classBinding.getDampingRelaxation, _godot_object); 190 } 191 /** 192 193 */ 194 void setUseAsTraction(in bool enable) 195 { 196 checkClassBinding!(typeof(this))(); 197 ptrcall!(void)(_classBinding.setUseAsTraction, _godot_object, enable); 198 } 199 /** 200 201 */ 202 bool isUsedAsTraction() const 203 { 204 checkClassBinding!(typeof(this))(); 205 return ptrcall!(bool)(_classBinding.isUsedAsTraction, _godot_object); 206 } 207 /** 208 209 */ 210 void setUseAsSteering(in bool enable) 211 { 212 checkClassBinding!(typeof(this))(); 213 ptrcall!(void)(_classBinding.setUseAsSteering, _godot_object, enable); 214 } 215 /** 216 217 */ 218 bool isUsedAsSteering() const 219 { 220 checkClassBinding!(typeof(this))(); 221 return ptrcall!(bool)(_classBinding.isUsedAsSteering, _godot_object); 222 } 223 /** 224 225 */ 226 void setFrictionSlip(in double length) 227 { 228 checkClassBinding!(typeof(this))(); 229 ptrcall!(void)(_classBinding.setFrictionSlip, _godot_object, length); 230 } 231 /** 232 233 */ 234 double getFrictionSlip() const 235 { 236 checkClassBinding!(typeof(this))(); 237 return ptrcall!(double)(_classBinding.getFrictionSlip, _godot_object); 238 } 239 /** 240 Returns true if this wheel is in contact with a surface. 241 */ 242 bool isInContact() const 243 { 244 checkClassBinding!(typeof(this))(); 245 return ptrcall!(bool)(_classBinding.isInContact, _godot_object); 246 } 247 /** 248 249 */ 250 void setRollInfluence(in double roll_influence) 251 { 252 checkClassBinding!(typeof(this))(); 253 ptrcall!(void)(_classBinding.setRollInfluence, _godot_object, roll_influence); 254 } 255 /** 256 257 */ 258 double getRollInfluence() const 259 { 260 checkClassBinding!(typeof(this))(); 261 return ptrcall!(double)(_classBinding.getRollInfluence, _godot_object); 262 } 263 /** 264 Returns a value between 0.0 and 1.0 that indicates whether this wheel is skidding. 0.0 is not skidding, 1.0 means the wheel has lost grip. 265 */ 266 double getSkidinfo() const 267 { 268 checkClassBinding!(typeof(this))(); 269 return ptrcall!(double)(_classBinding.getSkidinfo, _godot_object); 270 } 271 /** 272 If true this wheel transfers engine force to the ground to propel the vehicle forward. 273 */ 274 @property bool useAsTraction() 275 { 276 return isUsedAsTraction(); 277 } 278 /// ditto 279 @property void useAsTraction(bool v) 280 { 281 setUseAsTraction(v); 282 } 283 /** 284 If true this wheel will be turned when the car steers. 285 */ 286 @property bool useAsSteering() 287 { 288 return isUsedAsSteering(); 289 } 290 /// ditto 291 @property void useAsSteering(bool v) 292 { 293 setUseAsSteering(v); 294 } 295 /** 296 This value effects the roll of your vehicle. If set to 0.0 for all wheels your vehicle will be prone to rolling over while a value of 1.0 will resist body roll. 297 */ 298 @property double wheelRollInfluence() 299 { 300 return getRollInfluence(); 301 } 302 /// ditto 303 @property void wheelRollInfluence(double v) 304 { 305 setRollInfluence(v); 306 } 307 /** 308 The radius of the wheel in meters. 309 */ 310 @property double wheelRadius() 311 { 312 return getRadius(); 313 } 314 /// ditto 315 @property void wheelRadius(double v) 316 { 317 setRadius(v); 318 } 319 /** 320 This is the distance in meters the wheel is lowered from its origin point. Don't set this to 0.0 and move the wheel into position, instead move the origin point of your wheel (the gizmo in Godot) to the position the wheel will take when bottoming out, then use the rest length to move the wheel down to the position it should be in when the car is in rest. 321 */ 322 @property double wheelRestLength() 323 { 324 return getSuspensionRestLength(); 325 } 326 /// ditto 327 @property void wheelRestLength(double v) 328 { 329 setSuspensionRestLength(v); 330 } 331 /** 332 This determines how much grip this wheel has. It is combined with the friction setting of the surface the wheel is in contact with. 0.0 means no grip, 1.0 is normal grip. For a drift car setup, try setting the grip of the rear wheels slightly lower than the front wheels, or use a lower value to simulate tire wear. 333 It's best to set this to 1.0 when starting out. 334 */ 335 @property double wheelFrictionSlip() 336 { 337 return getFrictionSlip(); 338 } 339 /// ditto 340 @property void wheelFrictionSlip(double v) 341 { 342 setFrictionSlip(v); 343 } 344 /** 345 This is the distance the suspension can travel. As Godot measures are in meters keep this setting relatively low. Try a value between 0.1 and 0.3 depending on the type of car . 346 */ 347 @property double suspensionTravel() 348 { 349 return getSuspensionTravel(); 350 } 351 /// ditto 352 @property void suspensionTravel(double v) 353 { 354 setSuspensionTravel(v); 355 } 356 /** 357 This value defines the stiffness of the suspension. Use a value lower than 50 for an off-road car, a value between 50 and 100 for a race car and try something around 200 for something like a Formula 1 car. 358 */ 359 @property double suspensionStiffness() 360 { 361 return getSuspensionStiffness(); 362 } 363 /// ditto 364 @property void suspensionStiffness(double v) 365 { 366 setSuspensionStiffness(v); 367 } 368 /** 369 The maximum force the spring can resist. This value should be higher than a quarter of the $(D RigidBody.mass) of the $(D VehicleBody) or the spring will not carry the weight of the vehicle. Good results are often obtained by a value that is about 3x to 4x this number. 370 */ 371 @property double suspensionMaxForce() 372 { 373 return getSuspensionMaxForce(); 374 } 375 /// ditto 376 @property void suspensionMaxForce(double v) 377 { 378 setSuspensionMaxForce(v); 379 } 380 /** 381 The damping applied to the spring when the spring is being compressed. This value should be between 0.0 (no damping) and 1.0. A value of 0.0 means the car will keep bouncing as the spring keeps its energy. A good value for this is around 0.3 for a normal car, 0.5 for a race car. 382 */ 383 @property double dampingCompression() 384 { 385 return getDampingCompression(); 386 } 387 /// ditto 388 @property void dampingCompression(double v) 389 { 390 setDampingCompression(v); 391 } 392 /** 393 The damping applied to the spring when relaxing. This value should be between 0.0 (no damping) and 1.0. This value should always be slightly higher than the $(D dampingCompression) property. For a $(D dampingCompression) value of 0.3, try a relaxation value of 0.5 394 */ 395 @property double dampingRelaxation() 396 { 397 return getDampingRelaxation(); 398 } 399 /// ditto 400 @property void dampingRelaxation(double v) 401 { 402 setDampingRelaxation(v); 403 } 404 }