1 /** 2 Base node for collision objects. 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.collisionobject; 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.spatial; 23 import godot.inputevent; 24 import godot.shape; 25 import godot.node; 26 /** 27 Base node for collision objects. 28 29 CollisionObject is the base class for physics objects. It can hold any number of collision $(D Shape)s. Each shape must be assigned to a $(I shape owner). The CollisionObject can have any number of shape owners. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the `shape_owner_*` methods. 30 */ 31 @GodotBaseClass struct CollisionObject 32 { 33 enum string _GODOT_internal_name = "CollisionObject"; 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("_input_event") GodotMethod!(void, GodotObject, InputEvent, Vector3, Vector3, long) _inputEvent; 44 @GodotName("set_ray_pickable") GodotMethod!(void, bool) setRayPickable; 45 @GodotName("is_ray_pickable") GodotMethod!(bool) isRayPickable; 46 @GodotName("set_capture_input_on_drag") GodotMethod!(void, bool) setCaptureInputOnDrag; 47 @GodotName("get_capture_input_on_drag") GodotMethod!(bool) getCaptureInputOnDrag; 48 @GodotName("get_rid") GodotMethod!(RID) getRid; 49 @GodotName("create_shape_owner") GodotMethod!(long, GodotObject) createShapeOwner; 50 @GodotName("remove_shape_owner") GodotMethod!(void, long) removeShapeOwner; 51 @GodotName("get_shape_owners") GodotMethod!(Array) getShapeOwners; 52 @GodotName("shape_owner_set_transform") GodotMethod!(void, long, Transform) shapeOwnerSetTransform; 53 @GodotName("shape_owner_get_transform") GodotMethod!(Transform, long) shapeOwnerGetTransform; 54 @GodotName("shape_owner_get_owner") GodotMethod!(GodotObject, long) shapeOwnerGetOwner; 55 @GodotName("shape_owner_set_disabled") GodotMethod!(void, long, bool) shapeOwnerSetDisabled; 56 @GodotName("is_shape_owner_disabled") GodotMethod!(bool, long) isShapeOwnerDisabled; 57 @GodotName("shape_owner_add_shape") GodotMethod!(void, long, Shape) shapeOwnerAddShape; 58 @GodotName("shape_owner_get_shape_count") GodotMethod!(long, long) shapeOwnerGetShapeCount; 59 @GodotName("shape_owner_get_shape") GodotMethod!(Shape, long, long) shapeOwnerGetShape; 60 @GodotName("shape_owner_get_shape_index") GodotMethod!(long, long, long) shapeOwnerGetShapeIndex; 61 @GodotName("shape_owner_remove_shape") GodotMethod!(void, long, long) shapeOwnerRemoveShape; 62 @GodotName("shape_owner_clear_shapes") GodotMethod!(void, long) shapeOwnerClearShapes; 63 @GodotName("shape_find_owner") GodotMethod!(long, long) shapeFindOwner; 64 } 65 bool opEquals(in CollisionObject other) const { return _godot_object.ptr is other._godot_object.ptr; } 66 CollisionObject opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 67 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 68 mixin baseCasts; 69 static CollisionObject _new() 70 { 71 static godot_class_constructor constructor; 72 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("CollisionObject"); 73 if(constructor is null) return typeof(this).init; 74 return cast(CollisionObject)(constructor()); 75 } 76 @disable new(size_t s); 77 /** 78 Accepts unhandled $(D InputEvent)s. `click_position` is the clicked location in world space and `click_normal` is the normal vector extending from the clicked surface of the $(D Shape) at `shape_idx`. Connect to the `input_event` signal to easily pick up these events. 79 */ 80 void _inputEvent(GodotObject camera, InputEvent event, in Vector3 click_position, in Vector3 click_normal, in long shape_idx) 81 { 82 Array _GODOT_args = Array.empty_array; 83 _GODOT_args.append(camera); 84 _GODOT_args.append(event); 85 _GODOT_args.append(click_position); 86 _GODOT_args.append(click_normal); 87 _GODOT_args.append(shape_idx); 88 String _GODOT_method_name = String("_input_event"); 89 this.callv(_GODOT_method_name, _GODOT_args); 90 } 91 /** 92 93 */ 94 void setRayPickable(in bool ray_pickable) 95 { 96 checkClassBinding!(typeof(this))(); 97 ptrcall!(void)(_classBinding.setRayPickable, _godot_object, ray_pickable); 98 } 99 /** 100 101 */ 102 bool isRayPickable() const 103 { 104 checkClassBinding!(typeof(this))(); 105 return ptrcall!(bool)(_classBinding.isRayPickable, _godot_object); 106 } 107 /** 108 109 */ 110 void setCaptureInputOnDrag(in bool enable) 111 { 112 checkClassBinding!(typeof(this))(); 113 ptrcall!(void)(_classBinding.setCaptureInputOnDrag, _godot_object, enable); 114 } 115 /** 116 117 */ 118 bool getCaptureInputOnDrag() const 119 { 120 checkClassBinding!(typeof(this))(); 121 return ptrcall!(bool)(_classBinding.getCaptureInputOnDrag, _godot_object); 122 } 123 /** 124 Returns the object's $(D RID). 125 */ 126 RID getRid() const 127 { 128 checkClassBinding!(typeof(this))(); 129 return ptrcall!(RID)(_classBinding.getRid, _godot_object); 130 } 131 /** 132 Creates a new shape owner for the given object. Returns `owner_id` of the new owner for future reference. 133 */ 134 long createShapeOwner(GodotObject owner) 135 { 136 checkClassBinding!(typeof(this))(); 137 return ptrcall!(long)(_classBinding.createShapeOwner, _godot_object, owner); 138 } 139 /** 140 Removes the given shape owner. 141 */ 142 void removeShapeOwner(in long owner_id) 143 { 144 checkClassBinding!(typeof(this))(); 145 ptrcall!(void)(_classBinding.removeShapeOwner, _godot_object, owner_id); 146 } 147 /** 148 Returns an $(D Array) of `owner_id` identifiers. You can use these ids in other methods that take `owner_id` as an argument. 149 */ 150 Array getShapeOwners() 151 { 152 checkClassBinding!(typeof(this))(); 153 return ptrcall!(Array)(_classBinding.getShapeOwners, _godot_object); 154 } 155 /** 156 Sets the $(D Transform) of the given shape owner. 157 */ 158 void shapeOwnerSetTransform(in long owner_id, in Transform transform) 159 { 160 checkClassBinding!(typeof(this))(); 161 ptrcall!(void)(_classBinding.shapeOwnerSetTransform, _godot_object, owner_id, transform); 162 } 163 /** 164 Returns the shape owner's $(D Transform). 165 */ 166 Transform shapeOwnerGetTransform(in long owner_id) const 167 { 168 checkClassBinding!(typeof(this))(); 169 return ptrcall!(Transform)(_classBinding.shapeOwnerGetTransform, _godot_object, owner_id); 170 } 171 /** 172 Returns the parent object of the given shape owner. 173 */ 174 GodotObject shapeOwnerGetOwner(in long owner_id) const 175 { 176 checkClassBinding!(typeof(this))(); 177 return ptrcall!(GodotObject)(_classBinding.shapeOwnerGetOwner, _godot_object, owner_id); 178 } 179 /** 180 If `true` disables the given shape owner. 181 */ 182 void shapeOwnerSetDisabled(in long owner_id, in bool disabled) 183 { 184 checkClassBinding!(typeof(this))(); 185 ptrcall!(void)(_classBinding.shapeOwnerSetDisabled, _godot_object, owner_id, disabled); 186 } 187 /** 188 If `true` the shape owner and its shapes are disabled. 189 */ 190 bool isShapeOwnerDisabled(in long owner_id) const 191 { 192 checkClassBinding!(typeof(this))(); 193 return ptrcall!(bool)(_classBinding.isShapeOwnerDisabled, _godot_object, owner_id); 194 } 195 /** 196 Adds a $(D Shape) to the shape owner. 197 */ 198 void shapeOwnerAddShape(in long owner_id, Shape shape) 199 { 200 checkClassBinding!(typeof(this))(); 201 ptrcall!(void)(_classBinding.shapeOwnerAddShape, _godot_object, owner_id, shape); 202 } 203 /** 204 Returns the number of shapes the given shape owner contains. 205 */ 206 long shapeOwnerGetShapeCount(in long owner_id) const 207 { 208 checkClassBinding!(typeof(this))(); 209 return ptrcall!(long)(_classBinding.shapeOwnerGetShapeCount, _godot_object, owner_id); 210 } 211 /** 212 Returns the $(D Shape) with the given id from the given shape owner. 213 */ 214 Ref!Shape shapeOwnerGetShape(in long owner_id, in long shape_id) const 215 { 216 checkClassBinding!(typeof(this))(); 217 return ptrcall!(Shape)(_classBinding.shapeOwnerGetShape, _godot_object, owner_id, shape_id); 218 } 219 /** 220 Returns the child index of the $(D Shape) with the given id from the given shape owner. 221 */ 222 long shapeOwnerGetShapeIndex(in long owner_id, in long shape_id) const 223 { 224 checkClassBinding!(typeof(this))(); 225 return ptrcall!(long)(_classBinding.shapeOwnerGetShapeIndex, _godot_object, owner_id, shape_id); 226 } 227 /** 228 Removes a shape from the given shape owner. 229 */ 230 void shapeOwnerRemoveShape(in long owner_id, in long shape_id) 231 { 232 checkClassBinding!(typeof(this))(); 233 ptrcall!(void)(_classBinding.shapeOwnerRemoveShape, _godot_object, owner_id, shape_id); 234 } 235 /** 236 Removes all shapes from the shape owner. 237 */ 238 void shapeOwnerClearShapes(in long owner_id) 239 { 240 checkClassBinding!(typeof(this))(); 241 ptrcall!(void)(_classBinding.shapeOwnerClearShapes, _godot_object, owner_id); 242 } 243 /** 244 Returns the `owner_id` of the given shape. 245 */ 246 long shapeFindOwner(in long shape_index) const 247 { 248 checkClassBinding!(typeof(this))(); 249 return ptrcall!(long)(_classBinding.shapeFindOwner, _godot_object, shape_index); 250 } 251 /** 252 If `true` the $(D CollisionObject)'s shapes will respond to $(D RayCast)s. Default value: `true`. 253 */ 254 @property bool inputRayPickable() 255 { 256 return isRayPickable(); 257 } 258 /// ditto 259 @property void inputRayPickable(bool v) 260 { 261 setRayPickable(v); 262 } 263 /** 264 If `true` the `CollisionObject` will continue to receive input events as the mouse is dragged across its shapes. Default value: `false`. 265 */ 266 @property bool inputCaptureOnDrag() 267 { 268 return getCaptureInputOnDrag(); 269 } 270 /// ditto 271 @property void inputCaptureOnDrag(bool v) 272 { 273 setCaptureInputOnDrag(v); 274 } 275 }