• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 %module btCollisionObject
2 
3 %typemap(javainterfaces) btCollisionObject %{
4 	com.badlogic.gdx.utils.Disposable
5 %}
6 
7 %rename(internalSetCollisionShape) btCollisionObject::setCollisionShape;
8 %javamethodmodifiers btCollisionObject::setCollisionShape "private";
9 %rename(internalGetCollisionShape) btCollisionObject::getCollisionShape;
10 %javamethodmodifiers btCollisionObject::getCollisionShape "private";
11 
12 %typemap(javaout) 	btCollisionObject *, const btCollisionObject *, btCollisionObject * const & {
13 	return btCollisionObject.getInstance($jnicall, $owner);
14 }
15 
16 %typemap(javaout) 	btCollisionObject, const btCollisionObject, btCollisionObject & {
17 	return btCollisionObject.getInstance($jnicall, $owner);
18 }
19 
20 %typemap(javadirectorin) btCollisionObject *, const btCollisionObject *, btCollisionObject * const &	"btCollisionObject.getInstance($1, false)"
21 
22 %typemap(javacode) btCollisionObject %{
23 	/** Provides direct access to the instances this wrapper managed. */
24 	public final static com.badlogic.gdx.utils.LongMap<btCollisionObject> instances = new com.badlogic.gdx.utils.LongMap<btCollisionObject>();
25 
26 	/** @return The existing instance for the specified pointer, or null if the instance doesn't exist */
getInstance(final long swigCPtr)27 	public static btCollisionObject getInstance(final long swigCPtr) {
28 		return swigCPtr == 0 ? null : instances.get(swigCPtr);
29 	}
30 
31 	/** @return The existing instance for the specified pointer, or a newly created instance if the instance didn't exist */
getInstance(final long swigCPtr,boolean owner)32 	public static btCollisionObject getInstance(final long swigCPtr, boolean owner) {
33 		if (swigCPtr == 0)
34 			return null;
35 		btCollisionObject result = instances.get(swigCPtr);
36 		if (result == null)
37 			result = new btCollisionObject(swigCPtr, owner);
38 		return result;
39 	}
40 
41 	/** Add the instance to the managed instances.
42 	 * You should avoid using this method. This method is intended for internal purposes only. */
addInstance(final btCollisionObject obj)43 	public static void addInstance(final btCollisionObject obj) {
44 		instances.put(getCPtr(obj), obj);
45 	}
46 
47 	/** Remove the instance to the managed instances.
48 	 * Be careful using this method. This method is intended for internal purposes only. */
removeInstance(final btCollisionObject obj)49 	public static void removeInstance(final btCollisionObject obj) {
50 		instances.remove(getCPtr(obj));
51 	}
52 
53 	protected GdxCollisionObjectBridge gdxBridge;
54 	protected int userValue;
55 	protected int contactCallbackFlag = 1;
56 	protected int contactCallbackFilter;
57 	protected btCollisionShape collisionShape;
58 
59 	/** User definable data, not used by Bullet itself. */
60 	public Object userData;
61 
62 	@Override
construct()63 	protected void construct() {
64 		super.construct();
65 		gdxBridge = new GdxCollisionObjectBridge();
66 		internalSetGdxBridge(gdxBridge);
67 		addInstance(this);
68 	}
69 
70 	@Override
dispose()71 	public void dispose() {
72 		if (swigCPtr != 0)
73 			removeInstance(this);
74 		if (gdxBridge != null)
75 			gdxBridge.dispose();
76 		gdxBridge = null;
77 		if (collisionShape != null)
78 			collisionShape.release();
79 		collisionShape = null;
80 		super.dispose();
81 	}
82 
83 	/** @return A user definable value set using {@link #setUserValue(int)}, intended to quickly identify the collision object */
getUserValue()84 	public int getUserValue() {
85 		return userValue;
86 	}
87 
88 	/** @param value A user definable value which allows you to quickly identify this collision object. Some frequently called
89 	 * methods rather return this value than the collision object itself to minimize JNI overhead. */
setUserValue(int value)90 	public void setUserValue(int value) {
91 		gdxBridge.setUserValue(userValue = value);
92 	}
93 
94 	/** @return The flag (defaults to 1) used to filter contact callbacks with this object */
getContactCallbackFlag()95 	public int getContactCallbackFlag() {
96 		return contactCallbackFlag;
97 	}
98 
99 	/** @param flag The new flag used to filter contact callbacks with this object */
setContactCallbackFlag(int flag)100 	public void setContactCallbackFlag(int flag) {
101 		gdxBridge.setContactCallbackFlag(contactCallbackFlag = flag);
102 	}
103 
104 	/** @return The filter (default to 0) that is used to match the flag of the other object for a contact callback to be triggered */
getContactCallbackFilter()105 	public int getContactCallbackFilter() {
106 		return contactCallbackFilter;
107 	}
108 
109 	/** @param filter The new filter that is used to match the flag of the other object for a contact callback to be triggered */
setContactCallbackFilter(int filter)110 	public void setContactCallbackFilter(int filter) {
111 		gdxBridge.setContactCallbackFilter(contactCallbackFilter = filter);
112 	}
113 
setCollisionShape(btCollisionShape shape)114 	public void setCollisionShape(btCollisionShape shape) {
115 		refCollisionShape(shape);
116 		internalSetCollisionShape(shape);
117 	}
118 
refCollisionShape(btCollisionShape shape)119 	protected void refCollisionShape(btCollisionShape shape) {
120 		if (collisionShape == shape)
121 			return;
122 		if (collisionShape != null)
123 			collisionShape.release();
124 		collisionShape = shape;
125 		collisionShape.obtain();
126 	}
127 
getCollisionShape()128 	public btCollisionShape getCollisionShape() {
129 		return collisionShape;
130 	}
131 %}
132 
133 %{
134 #include <BulletCollision/CollisionDispatch/btCollisionObject.h>
135 #include <gdx/collision/GdxCollisionObjectBridge.h>
136 %}
137 %include "BulletCollision/CollisionDispatch/btCollisionObject.h"
138 %include "gdx/collision/GdxCollisionObjectBridge.h"
139 
140 %javamethodmodifiers btCollisionObject::internalSetGdxBridge "private";
141 %javamethodmodifiers btCollisionObject::internalGetGdxBridge "private";
142 
143 %extend btCollisionObject {
internalSetGdxBridge(GdxCollisionObjectBridge * bridge)144 	void internalSetGdxBridge(GdxCollisionObjectBridge *bridge) {
145 		$self->setUserPointer(bridge);
146 	}
147 
internalGetGdxBridge()148 	GdxCollisionObjectBridge *internalGetGdxBridge() {
149 		return (GdxCollisionObjectBridge *)($self->getUserPointer());
150 	}
151 
getAnisotropicFriction(btVector3 & out)152 	void getAnisotropicFriction(btVector3 & out) {
153 		out = $self->getAnisotropicFriction();
154 	}
155 
getWorldTransform(btTransform & out)156     void getWorldTransform(btTransform & out) {
157 		out = $self->getWorldTransform();
158 	}
159 
getInterpolationWorldTransform(btTransform & out)160     void getInterpolationWorldTransform(btTransform & out) {
161 		out = $self->getInterpolationWorldTransform();
162 	}
163 
getInterpolationLinearVelocity(btVector3 & out)164 	void getInterpolationLinearVelocity(btVector3 & out) {
165 		out = $self->getInterpolationLinearVelocity();
166 	}
167 
getInterpolationAngularVelocity(btVector3 & out)168 	void getInterpolationAngularVelocity(btVector3 & out) {
169 		out = $self->getInterpolationAngularVelocity();
170 	}
171 };