1 /** 2 Base class for all 2D shapes. 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.shape2d; 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.resource; 24 import godot.reference; 25 /** 26 Base class for all 2D shapes. 27 28 All 2D shape types inherit from this. 29 */ 30 @GodotBaseClass struct Shape2D 31 { 32 package(godot) enum string _GODOT_internal_name = "Shape2D"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ Resource _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 GDNativeClassBinding 40 { 41 __gshared: 42 @GodotName("collide") GodotMethod!(bool, Transform2D, Shape2D, Transform2D) collide; 43 @GodotName("collide_and_get_contacts") GodotMethod!(Array, Transform2D, Shape2D, Transform2D) collideAndGetContacts; 44 @GodotName("collide_with_motion") GodotMethod!(bool, Transform2D, Vector2, Shape2D, Transform2D, Vector2) collideWithMotion; 45 @GodotName("collide_with_motion_and_get_contacts") GodotMethod!(Array, Transform2D, Vector2, Shape2D, Transform2D, Vector2) collideWithMotionAndGetContacts; 46 @GodotName("draw") GodotMethod!(void, RID, Color) draw; 47 @GodotName("get_custom_solver_bias") GodotMethod!(double) getCustomSolverBias; 48 @GodotName("set_custom_solver_bias") GodotMethod!(void, double) setCustomSolverBias; 49 } 50 /// 51 pragma(inline, true) bool opEquals(in Shape2D other) const 52 { return _godot_object.ptr is other._godot_object.ptr; } 53 /// 54 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 55 { _godot_object.ptr = n; return null; } 56 /// 57 pragma(inline, true) bool opEquals(typeof(null) n) const 58 { return _godot_object.ptr is n; } 59 /// 60 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 61 mixin baseCasts; 62 /// Construct a new instance of Shape2D. 63 /// Note: use `memnew!Shape2D` instead. 64 static Shape2D _new() 65 { 66 static godot_class_constructor constructor; 67 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Shape2D"); 68 if(constructor is null) return typeof(this).init; 69 return cast(Shape2D)(constructor()); 70 } 71 @disable new(size_t s); 72 /** 73 Returns `true` if this shape is colliding with another. 74 This method needs the transformation matrix for this shape (`local_xform`), the shape to check collisions with (`with_shape`), and the transformation matrix of that shape (`shape_xform`). 75 */ 76 bool collide(in Transform2D local_xform, Shape2D with_shape, in Transform2D shape_xform) 77 { 78 checkClassBinding!(typeof(this))(); 79 return ptrcall!(bool)(GDNativeClassBinding.collide, _godot_object, local_xform, with_shape, shape_xform); 80 } 81 /** 82 Returns a list of the points where this shape touches another. If there are no collisions the list is empty. 83 This method needs the transformation matrix for this shape (`local_xform`), the shape to check collisions with (`with_shape`), and the transformation matrix of that shape (`shape_xform`). 84 */ 85 Array collideAndGetContacts(in Transform2D local_xform, Shape2D with_shape, in Transform2D shape_xform) 86 { 87 checkClassBinding!(typeof(this))(); 88 return ptrcall!(Array)(GDNativeClassBinding.collideAndGetContacts, _godot_object, local_xform, with_shape, shape_xform); 89 } 90 /** 91 Returns whether this shape would collide with another, if a given movement was applied. 92 This method needs the transformation matrix for this shape (`local_xform`), the movement to test on this shape (`local_motion`), the shape to check collisions with (`with_shape`), the transformation matrix of that shape (`shape_xform`), and the movement to test onto the other object (`shape_motion`). 93 */ 94 bool collideWithMotion(in Transform2D local_xform, in Vector2 local_motion, Shape2D with_shape, in Transform2D shape_xform, in Vector2 shape_motion) 95 { 96 checkClassBinding!(typeof(this))(); 97 return ptrcall!(bool)(GDNativeClassBinding.collideWithMotion, _godot_object, local_xform, local_motion, with_shape, shape_xform, shape_motion); 98 } 99 /** 100 Returns a list of the points where this shape would touch another, if a given movement was applied. If there are no collisions the list is empty. 101 This method needs the transformation matrix for this shape (`local_xform`), the movement to test on this shape (`local_motion`), the shape to check collisions with (`with_shape`), the transformation matrix of that shape (`shape_xform`), and the movement to test onto the other object (`shape_motion`). 102 */ 103 Array collideWithMotionAndGetContacts(in Transform2D local_xform, in Vector2 local_motion, Shape2D with_shape, in Transform2D shape_xform, in Vector2 shape_motion) 104 { 105 checkClassBinding!(typeof(this))(); 106 return ptrcall!(Array)(GDNativeClassBinding.collideWithMotionAndGetContacts, _godot_object, local_xform, local_motion, with_shape, shape_xform, shape_motion); 107 } 108 /** 109 Draws a solid shape onto a $(D CanvasItem) with the $(D VisualServer) API filled with the specified `color`. The exact drawing method is specific for each shape and cannot be configured. 110 */ 111 void draw(in RID canvas_item, in Color color) 112 { 113 checkClassBinding!(typeof(this))(); 114 ptrcall!(void)(GDNativeClassBinding.draw, _godot_object, canvas_item, color); 115 } 116 /** 117 118 */ 119 double getCustomSolverBias() const 120 { 121 checkClassBinding!(typeof(this))(); 122 return ptrcall!(double)(GDNativeClassBinding.getCustomSolverBias, _godot_object); 123 } 124 /** 125 126 */ 127 void setCustomSolverBias(in double bias) 128 { 129 checkClassBinding!(typeof(this))(); 130 ptrcall!(void)(GDNativeClassBinding.setCustomSolverBias, _godot_object, bias); 131 } 132 /** 133 The shape's custom solver bias. 134 */ 135 @property double customSolverBias() 136 { 137 return getCustomSolverBias(); 138 } 139 /// ditto 140 @property void customSolverBias(double v) 141 { 142 setCustomSolverBias(v); 143 } 144 }