1 /**
2 Physics body that simulates the behavior of a car.
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.vehiclebody;
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.rigidbody;
25 import godot.physicsbody;
26 import godot.collisionobject;
27 import godot.spatial;
28 import godot.node;
29 /**
30 Physics body that simulates the behavior of a car.
31 
32 This node implements all the physics logic needed to simulate a car. It is based on the raycast vehicle system commonly found in physics engines. You will need to add a $(D CollisionShape) for the main body of your vehicle and add $(D VehicleWheel) nodes for the wheels. You should also add a $(D MeshInstance) to this node for the 3D model of your car but this model should not include meshes for the wheels. You should control the vehicle by using the $(D brake), $(D engineForce), and $(D steering) properties and not change the position or orientation of this node directly.
33 $(B Note:) The origin point of your VehicleBody will determine the center of gravity of your vehicle so it is better to keep this low and move the $(D CollisionShape) and $(D MeshInstance) upwards.
34 $(B Note:) This class has known issues and isn't designed to provide realistic 3D vehicle physics. If you want advanced vehicle physics, you will probably have to write your own physics integration using another $(D PhysicsBody) class.
35 */
36 @GodotBaseClass struct VehicleBody
37 {
38 	package(godot) enum string _GODOT_internal_name = "VehicleBody";
39 public:
40 @nogc nothrow:
41 	union { /** */ godot_object _godot_object; /** */ RigidBody _GODOT_base; }
42 	alias _GODOT_base this;
43 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
44 	package(godot) __gshared bool _classBindingInitialized = false;
45 	package(godot) static struct GDNativeClassBinding
46 	{
47 		__gshared:
48 		@GodotName("get_brake") GodotMethod!(double) getBrake;
49 		@GodotName("get_engine_force") GodotMethod!(double) getEngineForce;
50 		@GodotName("get_steering") GodotMethod!(double) getSteering;
51 		@GodotName("set_brake") GodotMethod!(void, double) setBrake;
52 		@GodotName("set_engine_force") GodotMethod!(void, double) setEngineForce;
53 		@GodotName("set_steering") GodotMethod!(void, double) setSteering;
54 	}
55 	/// 
56 	pragma(inline, true) bool opEquals(in VehicleBody other) const
57 	{ return _godot_object.ptr is other._godot_object.ptr; }
58 	/// 
59 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
60 	{ _godot_object.ptr = n; return null; }
61 	/// 
62 	pragma(inline, true) bool opEquals(typeof(null) n) const
63 	{ return _godot_object.ptr is n; }
64 	/// 
65 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
66 	mixin baseCasts;
67 	/// Construct a new instance of VehicleBody.
68 	/// Note: use `memnew!VehicleBody` instead.
69 	static VehicleBody _new()
70 	{
71 		static godot_class_constructor constructor;
72 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VehicleBody");
73 		if(constructor is null) return typeof(this).init;
74 		return cast(VehicleBody)(constructor());
75 	}
76 	@disable new(size_t s);
77 	/**
78 	
79 	*/
80 	double getBrake() const
81 	{
82 		checkClassBinding!(typeof(this))();
83 		return ptrcall!(double)(GDNativeClassBinding.getBrake, _godot_object);
84 	}
85 	/**
86 	
87 	*/
88 	double getEngineForce() const
89 	{
90 		checkClassBinding!(typeof(this))();
91 		return ptrcall!(double)(GDNativeClassBinding.getEngineForce, _godot_object);
92 	}
93 	/**
94 	
95 	*/
96 	double getSteering() const
97 	{
98 		checkClassBinding!(typeof(this))();
99 		return ptrcall!(double)(GDNativeClassBinding.getSteering, _godot_object);
100 	}
101 	/**
102 	
103 	*/
104 	void setBrake(in double brake)
105 	{
106 		checkClassBinding!(typeof(this))();
107 		ptrcall!(void)(GDNativeClassBinding.setBrake, _godot_object, brake);
108 	}
109 	/**
110 	
111 	*/
112 	void setEngineForce(in double engine_force)
113 	{
114 		checkClassBinding!(typeof(this))();
115 		ptrcall!(void)(GDNativeClassBinding.setEngineForce, _godot_object, engine_force);
116 	}
117 	/**
118 	
119 	*/
120 	void setSteering(in double steering)
121 	{
122 		checkClassBinding!(typeof(this))();
123 		ptrcall!(void)(GDNativeClassBinding.setSteering, _godot_object, steering);
124 	}
125 	/**
126 	Slows down the vehicle by applying a braking force. The vehicle is only slowed down if the wheels are in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the $(D RigidBody.mass) of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking.
127 	*/
128 	@property double brake()
129 	{
130 		return getBrake();
131 	}
132 	/// ditto
133 	@property void brake(double v)
134 	{
135 		setBrake(v);
136 	}
137 	/**
138 	Accelerates the vehicle by applying an engine force. The vehicle is only speed up if the wheels that have $(D VehicleWheel.useAsTraction) set to `true` and are in contact with a surface. The $(D RigidBody.mass) of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 50 range for acceleration.
139 	$(B Note:) The simulation does not take the effect of gears into account, you will need to add logic for this if you wish to simulate gears.
140 	A negative value will result in the vehicle reversing.
141 	*/
142 	@property double engineForce()
143 	{
144 		return getEngineForce();
145 	}
146 	/// ditto
147 	@property void engineForce(double v)
148 	{
149 		setEngineForce(v);
150 	}
151 	/**
152 	The steering angle for the vehicle. Setting this to a non-zero value will result in the vehicle turning when it's moving. Wheels that have $(D VehicleWheel.useAsSteering) set to `true` will automatically be rotated.
153 	*/
154 	@property double steering()
155 	{
156 		return getSteering();
157 	}
158 	/// ditto
159 	@property void steering(double v)
160 	{
161 		setSteering(v);
162 	}
163 }