1 /** 2 A hinge between two 3D bodies. 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.hingejoint; 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.joint; 24 import godot.spatial; 25 import godot.node; 26 /** 27 A hinge between two 3D bodies. 28 29 Normally uses the z-axis of body A as the hinge axis, another axis can be specified when adding it manually though. 30 */ 31 @GodotBaseClass struct HingeJoint 32 { 33 enum string _GODOT_internal_name = "HingeJoint"; 34 public: 35 @nogc nothrow: 36 union { godot_object _godot_object; Joint _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_param") GodotMethod!(void, long, double) setParam; 44 @GodotName("get_param") GodotMethod!(double, long) getParam; 45 @GodotName("set_flag") GodotMethod!(void, long, bool) setFlag; 46 @GodotName("get_flag") GodotMethod!(bool, long) getFlag; 47 @GodotName("_set_upper_limit") GodotMethod!(void, double) _setUpperLimit; 48 @GodotName("_get_upper_limit") GodotMethod!(double) _getUpperLimit; 49 @GodotName("_set_lower_limit") GodotMethod!(void, double) _setLowerLimit; 50 @GodotName("_get_lower_limit") GodotMethod!(double) _getLowerLimit; 51 } 52 bool opEquals(in HingeJoint other) const { return _godot_object.ptr is other._godot_object.ptr; } 53 HingeJoint opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 54 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 55 mixin baseCasts; 56 static HingeJoint _new() 57 { 58 static godot_class_constructor constructor; 59 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("HingeJoint"); 60 if(constructor is null) return typeof(this).init; 61 return cast(HingeJoint)(constructor()); 62 } 63 @disable new(size_t s); 64 /// 65 enum Param : int 66 { 67 /** 68 The speed with which the two bodies get pulled together when they move in different directions. 69 */ 70 paramBias = 0, 71 /** 72 The maximum rotation. only active if $(D angularLimit/enable) is `true`. 73 */ 74 paramLimitUpper = 1, 75 /** 76 The minimum rotation. only active if $(D angularLimit/enable) is `true`. 77 */ 78 paramLimitLower = 2, 79 /** 80 The speed with which the rotation across the axis perpendicular to the hinge gets corrected. 81 */ 82 paramLimitBias = 3, 83 /** 84 85 */ 86 paramLimitSoftness = 4, 87 /** 88 The lower this value, the more the rotation gets slowed down. 89 */ 90 paramLimitRelaxation = 5, 91 /** 92 Target speed for the motor. 93 */ 94 paramMotorTargetVelocity = 6, 95 /** 96 Maximum acceleration for the motor. 97 */ 98 paramMotorMaxImpulse = 7, 99 /** 100 End flag of PARAM_* constants, used internally. 101 */ 102 paramMax = 8, 103 } 104 /// 105 enum Flag : int 106 { 107 /** 108 If `true` the hinges maximum and minimum rotation, defined by $(D angularLimit/lower) and $(D angularLimit/upper) has effects. 109 */ 110 flagUseLimit = 0, 111 /** 112 When activated, a motor turns the hinge. 113 */ 114 flagEnableMotor = 1, 115 /** 116 End flag of FLAG_* constants, used internally. 117 */ 118 flagMax = 2, 119 } 120 /// 121 enum Constants : int 122 { 123 paramBias = 0, 124 flagUseLimit = 0, 125 flagEnableMotor = 1, 126 paramLimitUpper = 1, 127 flagMax = 2, 128 paramLimitLower = 2, 129 paramLimitBias = 3, 130 paramLimitSoftness = 4, 131 paramLimitRelaxation = 5, 132 paramMotorTargetVelocity = 6, 133 paramMotorMaxImpulse = 7, 134 paramMax = 8, 135 } 136 /** 137 138 */ 139 void setParam(in long param, in double value) 140 { 141 checkClassBinding!(typeof(this))(); 142 ptrcall!(void)(_classBinding.setParam, _godot_object, param, value); 143 } 144 /** 145 146 */ 147 double getParam(in long param) const 148 { 149 checkClassBinding!(typeof(this))(); 150 return ptrcall!(double)(_classBinding.getParam, _godot_object, param); 151 } 152 /** 153 154 */ 155 void setFlag(in long flag, in bool enabled) 156 { 157 checkClassBinding!(typeof(this))(); 158 ptrcall!(void)(_classBinding.setFlag, _godot_object, flag, enabled); 159 } 160 /** 161 162 */ 163 bool getFlag(in long flag) const 164 { 165 checkClassBinding!(typeof(this))(); 166 return ptrcall!(bool)(_classBinding.getFlag, _godot_object, flag); 167 } 168 /** 169 170 */ 171 void _setUpperLimit(in double upper_limit) 172 { 173 Array _GODOT_args = Array.empty_array; 174 _GODOT_args.append(upper_limit); 175 String _GODOT_method_name = String("_set_upper_limit"); 176 this.callv(_GODOT_method_name, _GODOT_args); 177 } 178 /** 179 180 */ 181 double _getUpperLimit() const 182 { 183 Array _GODOT_args = Array.empty_array; 184 String _GODOT_method_name = String("_get_upper_limit"); 185 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!double); 186 } 187 /** 188 189 */ 190 void _setLowerLimit(in double lower_limit) 191 { 192 Array _GODOT_args = Array.empty_array; 193 _GODOT_args.append(lower_limit); 194 String _GODOT_method_name = String("_set_lower_limit"); 195 this.callv(_GODOT_method_name, _GODOT_args); 196 } 197 /** 198 199 */ 200 double _getLowerLimit() const 201 { 202 Array _GODOT_args = Array.empty_array; 203 String _GODOT_method_name = String("_get_lower_limit"); 204 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!double); 205 } 206 /** 207 The speed with which the two bodies get pulled together when they move in different directions. 208 */ 209 @property double paramsBias() 210 { 211 return getParam(0); 212 } 213 /// ditto 214 @property void paramsBias(double v) 215 { 216 setParam(0, v); 217 } 218 /** 219 If `true` the hinges maximum and minimum rotation, defined by $(D angularLimit/lower) and $(D angularLimit/upper) has effects. 220 */ 221 @property bool angularLimitEnable() 222 { 223 return getFlag(0); 224 } 225 /// ditto 226 @property void angularLimitEnable(bool v) 227 { 228 setFlag(0, v); 229 } 230 /** 231 The maximum rotation. only active if $(D angularLimit/enable) is `true`. 232 */ 233 @property double angularLimitUpper() 234 { 235 return _getUpperLimit(); 236 } 237 /// ditto 238 @property void angularLimitUpper(double v) 239 { 240 _setUpperLimit(v); 241 } 242 /** 243 The minimum rotation. only active if $(D angularLimit/enable) is `true`. 244 */ 245 @property double angularLimitLower() 246 { 247 return _getLowerLimit(); 248 } 249 /// ditto 250 @property void angularLimitLower(double v) 251 { 252 _setLowerLimit(v); 253 } 254 /** 255 The speed with which the rotation across the axis perpendicular to the hinge gets corrected. 256 */ 257 @property double angularLimitBias() 258 { 259 return getParam(3); 260 } 261 /// ditto 262 @property void angularLimitBias(double v) 263 { 264 setParam(3, v); 265 } 266 /** 267 268 */ 269 @property double angularLimitSoftness() 270 { 271 return getParam(4); 272 } 273 /// ditto 274 @property void angularLimitSoftness(double v) 275 { 276 setParam(4, v); 277 } 278 /** 279 The lower this value, the more the rotation gets slowed down. 280 */ 281 @property double angularLimitRelaxation() 282 { 283 return getParam(5); 284 } 285 /// ditto 286 @property void angularLimitRelaxation(double v) 287 { 288 setParam(5, v); 289 } 290 /** 291 When activated, a motor turns the hinge. 292 */ 293 @property bool motorEnable() 294 { 295 return getFlag(1); 296 } 297 /// ditto 298 @property void motorEnable(bool v) 299 { 300 setFlag(1, v); 301 } 302 /** 303 Target speed for the motor. 304 */ 305 @property double motorTargetVelocity() 306 { 307 return getParam(6); 308 } 309 /// ditto 310 @property void motorTargetVelocity(double v) 311 { 312 setParam(6, v); 313 } 314 /** 315 Maximum acceleration for the motor. 316 */ 317 @property double motorMaxImpulse() 318 { 319 return getParam(7); 320 } 321 /// ditto 322 @property void motorMaxImpulse(double v) 323 { 324 setParam(7, v); 325 } 326 }