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.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.spatial; 24 import godot.inputevent; 25 import godot.shape; 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 package(godot) 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 GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("_input_event") GodotMethod!(void, GodotObject, InputEvent, Vector3, Vector3, long) _inputEvent; 44 @GodotName("_shape_changed") GodotMethod!(void, Shape) _shapeChanged; 45 @GodotName("_update_debug_shapes") GodotMethod!(void) _updateDebugShapes; 46 @GodotName("create_shape_owner") GodotMethod!(long, GodotObject) createShapeOwner; 47 @GodotName("get_capture_input_on_drag") GodotMethod!(bool) getCaptureInputOnDrag; 48 @GodotName("get_rid") GodotMethod!(RID) getRid; 49 @GodotName("get_shape_owners") GodotMethod!(Array) getShapeOwners; 50 @GodotName("is_ray_pickable") GodotMethod!(bool) isRayPickable; 51 @GodotName("is_shape_owner_disabled") GodotMethod!(bool, long) isShapeOwnerDisabled; 52 @GodotName("remove_shape_owner") GodotMethod!(void, long) removeShapeOwner; 53 @GodotName("set_capture_input_on_drag") GodotMethod!(void, bool) setCaptureInputOnDrag; 54 @GodotName("set_ray_pickable") GodotMethod!(void, bool) setRayPickable; 55 @GodotName("shape_find_owner") GodotMethod!(long, long) shapeFindOwner; 56 @GodotName("shape_owner_add_shape") GodotMethod!(void, long, Shape) shapeOwnerAddShape; 57 @GodotName("shape_owner_clear_shapes") GodotMethod!(void, long) shapeOwnerClearShapes; 58 @GodotName("shape_owner_get_owner") GodotMethod!(GodotObject, long) shapeOwnerGetOwner; 59 @GodotName("shape_owner_get_shape") GodotMethod!(Shape, long, long) shapeOwnerGetShape; 60 @GodotName("shape_owner_get_shape_count") GodotMethod!(long, long) shapeOwnerGetShapeCount; 61 @GodotName("shape_owner_get_shape_index") GodotMethod!(long, long, long) shapeOwnerGetShapeIndex; 62 @GodotName("shape_owner_get_transform") GodotMethod!(Transform, long) shapeOwnerGetTransform; 63 @GodotName("shape_owner_remove_shape") GodotMethod!(void, long, long) shapeOwnerRemoveShape; 64 @GodotName("shape_owner_set_disabled") GodotMethod!(void, long, bool) shapeOwnerSetDisabled; 65 @GodotName("shape_owner_set_transform") GodotMethod!(void, long, Transform) shapeOwnerSetTransform; 66 } 67 /// 68 pragma(inline, true) bool opEquals(in CollisionObject other) const 69 { return _godot_object.ptr is other._godot_object.ptr; } 70 /// 71 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 72 { _godot_object.ptr = n; return null; } 73 /// 74 pragma(inline, true) bool opEquals(typeof(null) n) const 75 { return _godot_object.ptr is n; } 76 /// 77 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 78 mixin baseCasts; 79 /// Construct a new instance of CollisionObject. 80 /// Note: use `memnew!CollisionObject` instead. 81 static CollisionObject _new() 82 { 83 static godot_class_constructor constructor; 84 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("CollisionObject"); 85 if(constructor is null) return typeof(this).init; 86 return cast(CollisionObject)(constructor()); 87 } 88 @disable new(size_t s); 89 /** 90 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. 91 */ 92 void _inputEvent(GodotObject camera, InputEvent event, in Vector3 click_position, in Vector3 click_normal, in long shape_idx) 93 { 94 Array _GODOT_args = Array.make(); 95 _GODOT_args.append(camera); 96 _GODOT_args.append(event); 97 _GODOT_args.append(click_position); 98 _GODOT_args.append(click_normal); 99 _GODOT_args.append(shape_idx); 100 String _GODOT_method_name = String("_input_event"); 101 this.callv(_GODOT_method_name, _GODOT_args); 102 } 103 /** 104 105 */ 106 void _shapeChanged(Shape shape) 107 { 108 Array _GODOT_args = Array.make(); 109 _GODOT_args.append(shape); 110 String _GODOT_method_name = String("_shape_changed"); 111 this.callv(_GODOT_method_name, _GODOT_args); 112 } 113 /** 114 115 */ 116 void _updateDebugShapes() 117 { 118 Array _GODOT_args = Array.make(); 119 String _GODOT_method_name = String("_update_debug_shapes"); 120 this.callv(_GODOT_method_name, _GODOT_args); 121 } 122 /** 123 Creates a new shape owner for the given object. Returns `owner_id` of the new owner for future reference. 124 */ 125 long createShapeOwner(GodotObject owner) 126 { 127 checkClassBinding!(typeof(this))(); 128 return ptrcall!(long)(GDNativeClassBinding.createShapeOwner, _godot_object, owner); 129 } 130 /** 131 132 */ 133 bool getCaptureInputOnDrag() const 134 { 135 checkClassBinding!(typeof(this))(); 136 return ptrcall!(bool)(GDNativeClassBinding.getCaptureInputOnDrag, _godot_object); 137 } 138 /** 139 Returns the object's $(D RID). 140 */ 141 RID getRid() const 142 { 143 checkClassBinding!(typeof(this))(); 144 return ptrcall!(RID)(GDNativeClassBinding.getRid, _godot_object); 145 } 146 /** 147 Returns an $(D Array) of `owner_id` identifiers. You can use these ids in other methods that take `owner_id` as an argument. 148 */ 149 Array getShapeOwners() 150 { 151 checkClassBinding!(typeof(this))(); 152 return ptrcall!(Array)(GDNativeClassBinding.getShapeOwners, _godot_object); 153 } 154 /** 155 156 */ 157 bool isRayPickable() const 158 { 159 checkClassBinding!(typeof(this))(); 160 return ptrcall!(bool)(GDNativeClassBinding.isRayPickable, _godot_object); 161 } 162 /** 163 If `true`, the shape owner and its shapes are disabled. 164 */ 165 bool isShapeOwnerDisabled(in long owner_id) const 166 { 167 checkClassBinding!(typeof(this))(); 168 return ptrcall!(bool)(GDNativeClassBinding.isShapeOwnerDisabled, _godot_object, owner_id); 169 } 170 /** 171 Removes the given shape owner. 172 */ 173 void removeShapeOwner(in long owner_id) 174 { 175 checkClassBinding!(typeof(this))(); 176 ptrcall!(void)(GDNativeClassBinding.removeShapeOwner, _godot_object, owner_id); 177 } 178 /** 179 180 */ 181 void setCaptureInputOnDrag(in bool enable) 182 { 183 checkClassBinding!(typeof(this))(); 184 ptrcall!(void)(GDNativeClassBinding.setCaptureInputOnDrag, _godot_object, enable); 185 } 186 /** 187 188 */ 189 void setRayPickable(in bool ray_pickable) 190 { 191 checkClassBinding!(typeof(this))(); 192 ptrcall!(void)(GDNativeClassBinding.setRayPickable, _godot_object, ray_pickable); 193 } 194 /** 195 Returns the `owner_id` of the given shape. 196 */ 197 long shapeFindOwner(in long shape_index) const 198 { 199 checkClassBinding!(typeof(this))(); 200 return ptrcall!(long)(GDNativeClassBinding.shapeFindOwner, _godot_object, shape_index); 201 } 202 /** 203 Adds a $(D Shape) to the shape owner. 204 */ 205 void shapeOwnerAddShape(in long owner_id, Shape shape) 206 { 207 checkClassBinding!(typeof(this))(); 208 ptrcall!(void)(GDNativeClassBinding.shapeOwnerAddShape, _godot_object, owner_id, shape); 209 } 210 /** 211 Removes all shapes from the shape owner. 212 */ 213 void shapeOwnerClearShapes(in long owner_id) 214 { 215 checkClassBinding!(typeof(this))(); 216 ptrcall!(void)(GDNativeClassBinding.shapeOwnerClearShapes, _godot_object, owner_id); 217 } 218 /** 219 Returns the parent object of the given shape owner. 220 */ 221 GodotObject shapeOwnerGetOwner(in long owner_id) const 222 { 223 checkClassBinding!(typeof(this))(); 224 return ptrcall!(GodotObject)(GDNativeClassBinding.shapeOwnerGetOwner, _godot_object, owner_id); 225 } 226 /** 227 Returns the $(D Shape) with the given id from the given shape owner. 228 */ 229 Ref!Shape shapeOwnerGetShape(in long owner_id, in long shape_id) const 230 { 231 checkClassBinding!(typeof(this))(); 232 return ptrcall!(Shape)(GDNativeClassBinding.shapeOwnerGetShape, _godot_object, owner_id, shape_id); 233 } 234 /** 235 Returns the number of shapes the given shape owner contains. 236 */ 237 long shapeOwnerGetShapeCount(in long owner_id) const 238 { 239 checkClassBinding!(typeof(this))(); 240 return ptrcall!(long)(GDNativeClassBinding.shapeOwnerGetShapeCount, _godot_object, owner_id); 241 } 242 /** 243 Returns the child index of the $(D Shape) with the given id from the given shape owner. 244 */ 245 long shapeOwnerGetShapeIndex(in long owner_id, in long shape_id) const 246 { 247 checkClassBinding!(typeof(this))(); 248 return ptrcall!(long)(GDNativeClassBinding.shapeOwnerGetShapeIndex, _godot_object, owner_id, shape_id); 249 } 250 /** 251 Returns the shape owner's $(D Transform). 252 */ 253 Transform shapeOwnerGetTransform(in long owner_id) const 254 { 255 checkClassBinding!(typeof(this))(); 256 return ptrcall!(Transform)(GDNativeClassBinding.shapeOwnerGetTransform, _godot_object, owner_id); 257 } 258 /** 259 Removes a shape from the given shape owner. 260 */ 261 void shapeOwnerRemoveShape(in long owner_id, in long shape_id) 262 { 263 checkClassBinding!(typeof(this))(); 264 ptrcall!(void)(GDNativeClassBinding.shapeOwnerRemoveShape, _godot_object, owner_id, shape_id); 265 } 266 /** 267 If `true`, disables the given shape owner. 268 */ 269 void shapeOwnerSetDisabled(in long owner_id, in bool disabled) 270 { 271 checkClassBinding!(typeof(this))(); 272 ptrcall!(void)(GDNativeClassBinding.shapeOwnerSetDisabled, _godot_object, owner_id, disabled); 273 } 274 /** 275 Sets the $(D Transform) of the given shape owner. 276 */ 277 void shapeOwnerSetTransform(in long owner_id, in Transform transform) 278 { 279 checkClassBinding!(typeof(this))(); 280 ptrcall!(void)(GDNativeClassBinding.shapeOwnerSetTransform, _godot_object, owner_id, transform); 281 } 282 /** 283 If `true`, the $(D CollisionObject) will continue to receive input events as the mouse is dragged across its shapes. 284 */ 285 @property bool inputCaptureOnDrag() 286 { 287 return getCaptureInputOnDrag(); 288 } 289 /// ditto 290 @property void inputCaptureOnDrag(bool v) 291 { 292 setCaptureInputOnDrag(v); 293 } 294 /** 295 If `true`, the $(D CollisionObject)'s shapes will respond to $(D RayCast)s. 296 */ 297 @property bool inputRayPickable() 298 { 299 return isRayPickable(); 300 } 301 /// ditto 302 @property void inputRayPickable(bool v) 303 { 304 setRayPickable(v); 305 } 306 }