pbox2d 0.6.0-java → 0.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +8 -0
  3. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  4. data/.travis.yml +23 -0
  5. data/CHANGELOG.md +8 -0
  6. data/README.md +7 -7
  7. data/Rakefile +1 -2
  8. data/lib/box2d.jar +0 -0
  9. data/lib/pbox2d/version.rb +1 -1
  10. data/lib/pbox2d.rb +1 -0
  11. data/pbox2d.gemspec +6 -11
  12. data/pom.rb +59 -0
  13. data/pom.xml +82 -73
  14. data/src/org/jbox2d/JBox2D.gwt.xml +12 -0
  15. data/src/org/jbox2d/callbacks/ContactAdaptor.java +27 -0
  16. data/src/org/jbox2d/callbacks/ContactFilter.java +59 -0
  17. data/src/org/jbox2d/callbacks/ContactImpulse.java +42 -0
  18. data/src/org/jbox2d/callbacks/ContactListener.java +87 -0
  19. data/src/org/jbox2d/callbacks/DebugDraw.java +297 -0
  20. data/src/org/jbox2d/callbacks/DestructionListener.java +53 -0
  21. data/src/org/jbox2d/callbacks/PairCallback.java +29 -0
  22. data/src/org/jbox2d/callbacks/ParticleDestructionListener.java +20 -0
  23. data/src/org/jbox2d/callbacks/ParticleQueryCallback.java +19 -0
  24. data/src/org/jbox2d/callbacks/ParticleRaycastCallback.java +19 -0
  25. data/src/org/jbox2d/callbacks/QueryCallback.java +45 -0
  26. data/src/org/jbox2d/callbacks/RayCastCallback.java +55 -0
  27. data/src/org/jbox2d/callbacks/TreeCallback.java +42 -0
  28. data/src/org/jbox2d/callbacks/TreeRayCastCallback.java +44 -0
  29. data/src/org/jbox2d/collision/AABB.java +338 -0
  30. data/src/org/jbox2d/collision/Collision.java +1444 -0
  31. data/src/org/jbox2d/collision/ContactID.java +106 -0
  32. data/src/org/jbox2d/collision/Distance.java +773 -0
  33. data/src/org/jbox2d/collision/DistanceInput.java +41 -0
  34. data/src/org/jbox2d/collision/DistanceOutput.java +43 -0
  35. data/src/org/jbox2d/collision/Manifold.java +116 -0
  36. data/src/org/jbox2d/collision/ManifoldPoint.java +104 -0
  37. data/src/org/jbox2d/collision/RayCastInput.java +47 -0
  38. data/src/org/jbox2d/collision/RayCastOutput.java +46 -0
  39. data/src/org/jbox2d/collision/TimeOfImpact.java +526 -0
  40. data/src/org/jbox2d/collision/WorldManifold.java +200 -0
  41. data/src/org/jbox2d/collision/broadphase/BroadPhase.java +92 -0
  42. data/src/org/jbox2d/collision/broadphase/BroadPhaseStrategy.java +88 -0
  43. data/src/org/jbox2d/collision/broadphase/DefaultBroadPhaseBuffer.java +268 -0
  44. data/src/org/jbox2d/collision/broadphase/DynamicTree.java +883 -0
  45. data/src/org/jbox2d/collision/broadphase/DynamicTreeFlatNodes.java +873 -0
  46. data/src/org/jbox2d/collision/broadphase/DynamicTreeNode.java +54 -0
  47. data/src/org/jbox2d/collision/broadphase/Pair.java +46 -0
  48. data/src/org/jbox2d/collision/shapes/ChainShape.java +264 -0
  49. data/src/org/jbox2d/collision/shapes/CircleShape.java +207 -0
  50. data/src/org/jbox2d/collision/shapes/EdgeShape.java +254 -0
  51. data/src/org/jbox2d/collision/shapes/MassData.java +105 -0
  52. data/src/org/jbox2d/collision/shapes/PolygonShape.java +718 -0
  53. data/src/org/jbox2d/collision/shapes/Shape.java +136 -0
  54. data/src/org/jbox2d/collision/shapes/ShapeType.java +32 -0
  55. data/src/org/jbox2d/common/BufferUtils.java +209 -0
  56. data/src/org/jbox2d/common/Color3f.java +88 -0
  57. data/src/org/jbox2d/common/IViewportTransform.java +133 -0
  58. data/src/org/jbox2d/common/Mat22.java +609 -0
  59. data/src/org/jbox2d/common/Mat33.java +290 -0
  60. data/src/org/jbox2d/common/MathUtils.java +335 -0
  61. data/src/org/jbox2d/common/OBBViewportTransform.java +174 -0
  62. data/src/org/jbox2d/common/PlatformMathUtils.java +46 -0
  63. data/src/org/jbox2d/common/RaycastResult.java +37 -0
  64. data/src/org/jbox2d/common/Rot.java +150 -0
  65. data/src/org/jbox2d/common/Settings.java +246 -0
  66. data/src/org/jbox2d/common/Sweep.java +116 -0
  67. data/src/org/jbox2d/common/Timer.java +46 -0
  68. data/src/org/jbox2d/common/Transform.java +203 -0
  69. data/src/org/jbox2d/common/Vec2.java +388 -0
  70. data/src/org/jbox2d/common/Vec3.java +170 -0
  71. data/src/org/jbox2d/dynamics/Body.java +1246 -0
  72. data/src/org/jbox2d/dynamics/BodyDef.java +382 -0
  73. data/src/org/jbox2d/dynamics/BodyType.java +41 -0
  74. data/src/org/jbox2d/dynamics/ContactManager.java +293 -0
  75. data/src/org/jbox2d/dynamics/Filter.java +62 -0
  76. data/src/org/jbox2d/dynamics/Fixture.java +454 -0
  77. data/src/org/jbox2d/dynamics/FixtureDef.java +214 -0
  78. data/src/org/jbox2d/dynamics/FixtureProxy.java +38 -0
  79. data/src/org/jbox2d/dynamics/Island.java +602 -0
  80. data/src/org/jbox2d/dynamics/Profile.java +97 -0
  81. data/src/org/jbox2d/dynamics/SolverData.java +33 -0
  82. data/src/org/jbox2d/dynamics/TimeStep.java +46 -0
  83. data/src/org/jbox2d/dynamics/World.java +2075 -0
  84. data/src/org/jbox2d/dynamics/contacts/ChainAndCircleContact.java +57 -0
  85. data/src/org/jbox2d/dynamics/contacts/ChainAndPolygonContact.java +57 -0
  86. data/src/org/jbox2d/dynamics/contacts/CircleContact.java +50 -0
  87. data/src/org/jbox2d/dynamics/contacts/Contact.java +365 -0
  88. data/src/org/jbox2d/dynamics/contacts/ContactCreator.java +35 -0
  89. data/src/org/jbox2d/dynamics/contacts/ContactEdge.java +56 -0
  90. data/src/org/jbox2d/dynamics/contacts/ContactPositionConstraint.java +49 -0
  91. data/src/org/jbox2d/dynamics/contacts/ContactRegister.java +31 -0
  92. data/src/org/jbox2d/dynamics/contacts/ContactSolver.java +1104 -0
  93. data/src/org/jbox2d/dynamics/contacts/ContactVelocityConstraint.java +60 -0
  94. data/src/org/jbox2d/dynamics/contacts/EdgeAndCircleContact.java +52 -0
  95. data/src/org/jbox2d/dynamics/contacts/EdgeAndPolygonContact.java +52 -0
  96. data/src/org/jbox2d/dynamics/contacts/PolygonAndCircleContact.java +51 -0
  97. data/src/org/jbox2d/dynamics/contacts/PolygonContact.java +50 -0
  98. data/src/org/jbox2d/dynamics/contacts/Position.java +31 -0
  99. data/src/org/jbox2d/dynamics/contacts/Velocity.java +31 -0
  100. data/src/org/jbox2d/dynamics/joints/ConstantVolumeJoint.java +258 -0
  101. data/src/org/jbox2d/dynamics/joints/ConstantVolumeJointDef.java +75 -0
  102. data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +356 -0
  103. data/src/org/jbox2d/dynamics/joints/DistanceJointDef.java +106 -0
  104. data/src/org/jbox2d/dynamics/joints/FrictionJoint.java +294 -0
  105. data/src/org/jbox2d/dynamics/joints/FrictionJointDef.java +78 -0
  106. data/src/org/jbox2d/dynamics/joints/GearJoint.java +520 -0
  107. data/src/org/jbox2d/dynamics/joints/GearJointDef.java +58 -0
  108. data/src/org/jbox2d/dynamics/joints/Jacobian.java +32 -0
  109. data/src/org/jbox2d/dynamics/joints/Joint.java +235 -0
  110. data/src/org/jbox2d/dynamics/joints/JointDef.java +65 -0
  111. data/src/org/jbox2d/dynamics/joints/JointEdge.java +57 -0
  112. data/src/org/jbox2d/dynamics/joints/JointType.java +28 -0
  113. data/src/org/jbox2d/dynamics/joints/LimitState.java +28 -0
  114. data/src/org/jbox2d/dynamics/joints/MotorJoint.java +339 -0
  115. data/src/org/jbox2d/dynamics/joints/MotorJointDef.java +55 -0
  116. data/src/org/jbox2d/dynamics/joints/MouseJoint.java +262 -0
  117. data/src/org/jbox2d/dynamics/joints/MouseJointDef.java +62 -0
  118. data/src/org/jbox2d/dynamics/joints/PrismaticJoint.java +808 -0
  119. data/src/org/jbox2d/dynamics/joints/PrismaticJointDef.java +120 -0
  120. data/src/org/jbox2d/dynamics/joints/PulleyJoint.java +393 -0
  121. data/src/org/jbox2d/dynamics/joints/PulleyJointDef.java +105 -0
  122. data/src/org/jbox2d/dynamics/joints/RevoluteJoint.java +554 -0
  123. data/src/org/jbox2d/dynamics/joints/RevoluteJointDef.java +137 -0
  124. data/src/org/jbox2d/dynamics/joints/RopeJoint.java +276 -0
  125. data/src/org/jbox2d/dynamics/joints/RopeJointDef.java +34 -0
  126. data/src/org/jbox2d/dynamics/joints/WeldJoint.java +424 -0
  127. data/src/org/jbox2d/dynamics/joints/WeldJointDef.java +85 -0
  128. data/src/org/jbox2d/dynamics/joints/WheelJoint.java +498 -0
  129. data/src/org/jbox2d/dynamics/joints/WheelJointDef.java +98 -0
  130. data/src/org/jbox2d/particle/ParticleBodyContact.java +17 -0
  131. data/src/org/jbox2d/particle/ParticleColor.java +52 -0
  132. data/src/org/jbox2d/particle/ParticleContact.java +14 -0
  133. data/src/org/jbox2d/particle/ParticleDef.java +24 -0
  134. data/src/org/jbox2d/particle/ParticleGroup.java +154 -0
  135. data/src/org/jbox2d/particle/ParticleGroupDef.java +62 -0
  136. data/src/org/jbox2d/particle/ParticleGroupType.java +8 -0
  137. data/src/org/jbox2d/particle/ParticleSystem.java +2172 -0
  138. data/src/org/jbox2d/particle/ParticleType.java +28 -0
  139. data/src/org/jbox2d/particle/StackQueue.java +44 -0
  140. data/src/org/jbox2d/particle/VoronoiDiagram.java +209 -0
  141. data/src/org/jbox2d/pooling/IDynamicStack.java +47 -0
  142. data/src/org/jbox2d/pooling/IOrderedStack.java +57 -0
  143. data/src/org/jbox2d/pooling/IWorldPool.java +101 -0
  144. data/src/org/jbox2d/pooling/arrays/FloatArray.java +50 -0
  145. data/src/org/jbox2d/pooling/arrays/GeneratorArray.java +33 -0
  146. data/src/org/jbox2d/pooling/arrays/IntArray.java +53 -0
  147. data/src/org/jbox2d/pooling/arrays/Vec2Array.java +57 -0
  148. data/src/org/jbox2d/pooling/normal/CircleStack.java +77 -0
  149. data/src/org/jbox2d/pooling/normal/DefaultWorldPool.java +331 -0
  150. data/src/org/jbox2d/pooling/normal/MutableStack.java +72 -0
  151. data/src/org/jbox2d/pooling/normal/OrderedStack.java +73 -0
  152. data/src/org/jbox2d/pooling/stacks/DynamicIntStack.java +60 -0
  153. metadata +161 -14
  154. data/lib/jbox2d-library-2.3.1-SNAPSHOT.jar +0 -0
@@ -0,0 +1,136 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.collision.shapes;
25
+
26
+ import org.jbox2d.collision.AABB;
27
+ import org.jbox2d.collision.RayCastInput;
28
+ import org.jbox2d.collision.RayCastOutput;
29
+ import org.jbox2d.common.Transform;
30
+ import org.jbox2d.common.Vec2;
31
+
32
+ /**
33
+ * A shape is used for collision detection. You can create a shape however you like. Shapes used for
34
+ * simulation in World are created automatically when a Fixture is created. Shapes may encapsulate a
35
+ * one or more child shapes.
36
+ */
37
+ public abstract class Shape {
38
+
39
+ public final ShapeType m_type;
40
+ public float m_radius;
41
+
42
+ public Shape(ShapeType type) {
43
+ this.m_type = type;
44
+ }
45
+
46
+ /**
47
+ * Get the type of this shape. You can use this to down cast to the concrete shape.
48
+ *
49
+ * @return the shape type.
50
+ */
51
+ public ShapeType getType() {
52
+ return m_type;
53
+ }
54
+
55
+ /**
56
+ * The radius of the underlying shape. This can refer to different things depending on the shape
57
+ * implementation
58
+ *
59
+ * @return
60
+ */
61
+ public float getRadius() {
62
+ return m_radius;
63
+ }
64
+
65
+ /**
66
+ * Sets the radius of the underlying shape. This can refer to different things depending on the
67
+ * implementation
68
+ *
69
+ * @param radius
70
+ */
71
+ public void setRadius(float radius) {
72
+ this.m_radius = radius;
73
+ }
74
+
75
+ /**
76
+ * Get the number of child primitives
77
+ *
78
+ * @return
79
+ */
80
+ public abstract int getChildCount();
81
+
82
+ /**
83
+ * Test a point for containment in this shape. This only works for convex shapes.
84
+ *
85
+ * @param xf the shape world transform.
86
+ * @param p a point in world coordinates.
87
+ * @return
88
+ */
89
+ public abstract boolean testPoint(final Transform xf, final Vec2 p);
90
+
91
+ /**
92
+ * Cast a ray against a child shape.
93
+ *
94
+ * @param output
95
+ * @param input
96
+ * @param transform
97
+ * @param childIndex
98
+ * @return if hit
99
+ */
100
+ public abstract boolean raycast(RayCastOutput output, RayCastInput input, Transform transform,
101
+ int childIndex);
102
+
103
+
104
+ /**
105
+ * Given a transform, compute the associated axis aligned bounding box for a child shape.
106
+ *
107
+ * @param aabb returns the axis aligned box.
108
+ * @param xf the world transform of the shape.
109
+ * @param childIndex
110
+ */
111
+ public abstract void computeAABB(final AABB aabb, final Transform xf, int childIndex);
112
+
113
+ /**
114
+ * Compute the mass properties of this shape using its dimensions and density. The inertia tensor
115
+ * is computed about the local origin.
116
+ *
117
+ * @param massData returns the mass data for this shape.
118
+ * @param density the density in kilograms per meter squared.
119
+ */
120
+ public abstract void computeMass(final MassData massData, final float density);
121
+
122
+ /**
123
+ * Compute the distance from the current shape to the specified point. This only works for convex
124
+ * shapes.
125
+ *
126
+ * @param xf the shape world transform.
127
+ * @param p a point in world coordinates.
128
+ * @param childIndex
129
+ * @param normalOut returns the direction in which the distance increases.
130
+ * @return distance returns the distance from the current shape.
131
+ */
132
+ public abstract float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut);
133
+
134
+ @Override
135
+ public abstract Shape clone();
136
+ }
@@ -0,0 +1,32 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.collision.shapes;
25
+
26
+ /**
27
+ * Types of shapes
28
+ * @author Daniel
29
+ */
30
+ public enum ShapeType {
31
+ CIRCLE, EDGE, POLYGON, CHAIN
32
+ }
@@ -0,0 +1,209 @@
1
+ package org.jbox2d.common;
2
+
3
+ import java.lang.reflect.Array;
4
+
5
+ public class BufferUtils {
6
+
7
+ /**
8
+ * Reallocate a buffer.
9
+ *
10
+ * @param <T>
11
+ * @param klass
12
+ * @param oldBuffer
13
+ * @param oldCapacity
14
+ * @param newCapacity
15
+ * @return
16
+ */
17
+ public static <T> T[] reallocateBuffer(Class<T> klass, T[] oldBuffer, int oldCapacity,
18
+ int newCapacity) {
19
+ assert (newCapacity > oldCapacity);
20
+ @SuppressWarnings("unchecked")
21
+ T[] newBuffer = (T[]) Array.newInstance(klass, newCapacity);
22
+ if (oldBuffer != null) {
23
+ System.arraycopy(oldBuffer, 0, newBuffer, 0, oldCapacity);
24
+ }
25
+ for (int i = oldCapacity; i < newCapacity; i++) {
26
+ try {
27
+ newBuffer[i] = klass.newInstance();
28
+ } catch (InstantiationException | IllegalAccessException e) {
29
+ throw new RuntimeException(e);
30
+ }
31
+ }
32
+ return newBuffer;
33
+ }
34
+
35
+ /**
36
+ * Reallocate a buffer.
37
+ *
38
+ * @param oldBuffer
39
+ * @param oldCapacity
40
+ * @param newCapacity
41
+ * @return
42
+ */
43
+ public static int[] reallocateBuffer(int[] oldBuffer, int oldCapacity, int newCapacity) {
44
+ assert (newCapacity > oldCapacity);
45
+ int[] newBuffer = new int[newCapacity];
46
+ if (oldBuffer != null) {
47
+ System.arraycopy(oldBuffer, 0, newBuffer, 0, oldCapacity);
48
+ }
49
+ return newBuffer;
50
+ }
51
+
52
+ /**
53
+ * Reallocate a buffer.
54
+ *
55
+ * @param oldBuffer
56
+ * @param oldCapacity
57
+ * @param newCapacity
58
+ * @return
59
+ */
60
+ public static float[] reallocateBuffer(float[] oldBuffer, int oldCapacity, int newCapacity) {
61
+ assert (newCapacity > oldCapacity);
62
+ float[] newBuffer = new float[newCapacity];
63
+ if (oldBuffer != null) {
64
+ System.arraycopy(oldBuffer, 0, newBuffer, 0, oldCapacity);
65
+ }
66
+ return newBuffer;
67
+ }
68
+
69
+ /**
70
+ * Reallocate a buffer. A 'deferred' buffer is reallocated only if it is not
71
+ * NULL. If 'userSuppliedCapacity' is not zero, buffer is user supplied and
72
+ * must be kept.
73
+ *
74
+ * @param <T>
75
+ * @param klass
76
+ * @param buffer
77
+ * @param userSuppliedCapacity
78
+ * @param oldCapacity
79
+ * @param newCapacity
80
+ * @param deferred
81
+ * @return
82
+ */
83
+ public static <T> T[] reallocateBuffer(Class<T> klass, T[] buffer, int userSuppliedCapacity,
84
+ int oldCapacity, int newCapacity, boolean deferred) {
85
+ assert (newCapacity > oldCapacity);
86
+ assert (userSuppliedCapacity == 0 || newCapacity <= userSuppliedCapacity);
87
+ if ((!deferred || buffer != null) && userSuppliedCapacity == 0) {
88
+ buffer = reallocateBuffer(klass, buffer, oldCapacity, newCapacity);
89
+ }
90
+ return buffer;
91
+ }
92
+
93
+ /**
94
+ * Reallocate an int buffer. A 'deferred' buffer is reallocated only if it
95
+ * is not NULL. If 'userSuppliedCapacity' is not zero, buffer is user
96
+ * supplied and must be kept.
97
+ *
98
+ * @param buffer
99
+ * @param userSuppliedCapacity
100
+ * @param oldCapacity
101
+ * @param newCapacity
102
+ * @param deferred
103
+ * @return
104
+ */
105
+ public static int[] reallocateBuffer(int[] buffer, int userSuppliedCapacity, int oldCapacity,
106
+ int newCapacity, boolean deferred) {
107
+ assert (newCapacity > oldCapacity);
108
+ assert (userSuppliedCapacity == 0 || newCapacity <= userSuppliedCapacity);
109
+ if ((!deferred || buffer != null) && userSuppliedCapacity == 0) {
110
+ buffer = reallocateBuffer(buffer, oldCapacity, newCapacity);
111
+ }
112
+ return buffer;
113
+ }
114
+
115
+ /**
116
+ * Reallocate a float buffer. A 'deferred' buffer is reallocated only if it
117
+ * is not NULL. If 'userSuppliedCapacity' is not zero, buffer is user
118
+ * supplied and must be kept.
119
+ *
120
+ * @param buffer
121
+ * @param userSuppliedCapacity
122
+ * @param oldCapacity
123
+ * @param newCapacity
124
+ * @param deferred
125
+ * @return
126
+ */
127
+ public static float[] reallocateBuffer(float[] buffer, int userSuppliedCapacity, int oldCapacity,
128
+ int newCapacity, boolean deferred) {
129
+ assert (newCapacity > oldCapacity);
130
+ assert (userSuppliedCapacity == 0 || newCapacity <= userSuppliedCapacity);
131
+ if ((!deferred || buffer != null) && userSuppliedCapacity == 0) {
132
+ buffer = reallocateBuffer(buffer, oldCapacity, newCapacity);
133
+ }
134
+ return buffer;
135
+ }
136
+
137
+ /**
138
+ * Rotate an array, see std::rotate
139
+ *
140
+ * @param <T>
141
+ * @param ray
142
+ * @param first
143
+ * @param new_first
144
+ * @param last
145
+ */
146
+ public static <T> void rotate(T[] ray, int first, int new_first, int last) {
147
+ int next = new_first;
148
+ while (next != first) {
149
+ T temp = ray[first];
150
+ ray[first] = ray[next];
151
+ ray[next] = temp;
152
+ first++;
153
+ next++;
154
+ if (next == last) {
155
+ next = new_first;
156
+ } else if (first == new_first) {
157
+ new_first = next;
158
+ }
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Rotate an array, see std::rotate
164
+ *
165
+ * @param ray
166
+ * @param first
167
+ * @param new_first
168
+ * @param last
169
+ */
170
+ public static void rotate(int[] ray, int first, int new_first, int last) {
171
+ int next = new_first;
172
+ while (next != first) {
173
+ int temp = ray[first];
174
+ ray[first] = ray[next];
175
+ ray[next] = temp;
176
+ first++;
177
+ next++;
178
+ if (next == last) {
179
+ next = new_first;
180
+ } else if (first == new_first) {
181
+ new_first = next;
182
+ }
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Rotate an array, see std::rotate
188
+ *
189
+ * @param ray
190
+ * @param first
191
+ * @param new_first
192
+ * @param last
193
+ */
194
+ public static void rotate(float[] ray, int first, int new_first, int last) {
195
+ int next = new_first;
196
+ while (next != first) {
197
+ float temp = ray[first];
198
+ ray[first] = ray[next];
199
+ ray[next] = temp;
200
+ first++;
201
+ next++;
202
+ if (next == last) {
203
+ next = new_first;
204
+ } else if (first == new_first) {
205
+ new_first = next;
206
+ }
207
+ }
208
+ }
209
+ }
@@ -0,0 +1,88 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ /*
25
+ * JBox2D - A Java Port of Erin Catto's Box2D
26
+ *
27
+ * JBox2D homepage: http://jbox2d.sourceforge.net/
28
+ * Box2D homepage: http://www.box2d.org
29
+ *
30
+ * This software is provided 'as-is', without any express or implied
31
+ * warranty. In no event will the authors be held liable for any damages
32
+ * arising from the use of this software.
33
+ *
34
+ * Permission is granted to anyone to use this software for any purpose,
35
+ * including commercial applications, and to alter it and redistribute it
36
+ * freely, subject to the following restrictions:
37
+ *
38
+ * 1. The origin of this software must not be misrepresented; you must not
39
+ * claim that you wrote the original software. If you use this software
40
+ * in a product, an acknowledgment in the product documentation would be
41
+ * appreciated but is not required.
42
+ * 2. Altered source versions must be plainly marked as such, and must not be
43
+ * misrepresented as being the original software.
44
+ * 3. This notice may not be removed or altered from any source distribution.
45
+ */
46
+
47
+ package org.jbox2d.common;
48
+
49
+ // updated to rev 100
50
+ /**
51
+ * Similar to javax.vecmath.Color3f holder
52
+ * @author ewjordan
53
+ *
54
+ */
55
+ public class Color3f {
56
+
57
+ public static final Color3f WHITE = new Color3f(1, 1, 1);
58
+ public static final Color3f BLACK = new Color3f(0, 0, 0);
59
+ public static final Color3f BLUE = new Color3f(0, 0, 1);
60
+ public static final Color3f GREEN = new Color3f(0, 1, 0);
61
+ public static final Color3f RED = new Color3f(1, 0, 0);
62
+
63
+ public float x;
64
+ public float y;
65
+ public float z;
66
+
67
+
68
+ public Color3f(){
69
+ x = y = z = 0;
70
+ }
71
+ public Color3f(float r, float g, float b) {
72
+ x = r;
73
+ y = g;
74
+ z = b;
75
+ }
76
+
77
+ public void set(float r, float g, float b){
78
+ x = r;
79
+ y = g;
80
+ z = b;
81
+ }
82
+
83
+ public void set(Color3f argColor){
84
+ x = argColor.x;
85
+ y = argColor.y;
86
+ z = argColor.z;
87
+ }
88
+ }
@@ -0,0 +1,133 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.common;
25
+
26
+ /**
27
+ * This is the viewport transform used from drawing. Use yFlip if you are drawing from the top-left
28
+ * corner.
29
+ *
30
+ * @author Daniel
31
+ */
32
+ public interface IViewportTransform {
33
+
34
+ /**
35
+ * @return if the transform flips the y axis
36
+ */
37
+ boolean isYFlip();
38
+
39
+ /**
40
+ * @param yFlip if we flip the y axis when transforming
41
+ */
42
+ void setYFlip(boolean yFlip);
43
+
44
+ /**
45
+ * This is the half-width and half-height. This should be the actual half-width and half-height,
46
+ * not anything transformed or scaled. Not a copy.
47
+ * @return
48
+ */
49
+ Vec2 getExtents();
50
+
51
+ /**
52
+ * This sets the half-width and half-height. This should be the actual half-width and half-height,
53
+ * not anything transformed or scaled.
54
+ * @param extents
55
+ */
56
+ void setExtents(Vec2 extents);
57
+
58
+ /**
59
+ * This sets the half-width and half-height of the viewport. This should be the actual half-width
60
+ * and half-height, not anything transformed or scaled.
61
+ * @param halfWidth
62
+ * @param halfHeight
63
+ */
64
+ void setExtents(float halfWidth, float halfHeight);
65
+
66
+ /**
67
+ * center of the viewport. Not a copy.
68
+ * @return
69
+ */
70
+ Vec2 getCenter();
71
+
72
+ /**
73
+ * sets the center of the viewport.
74
+ * @param pos
75
+ */
76
+ void setCenter(Vec2 pos);
77
+
78
+ /**
79
+ * sets the center of the viewport.
80
+ * @param x
81
+ * @param y
82
+ */
83
+ void setCenter(float x, float y);
84
+
85
+ /**
86
+ * Sets the transform's center to the given x and y coordinates, and using the given scale.
87
+ * @param x
88
+ * @param y
89
+ * @param scale
90
+ */
91
+ void setCamera(float x, float y, float scale);
92
+
93
+ /**
94
+ * Transforms the given directional vector by the viewport transform (not positional)
95
+ * @param world
96
+ * @param screen
97
+ */
98
+ void getWorldVectorToScreen(Vec2 world, Vec2 screen);
99
+
100
+
101
+ /**
102
+ * Transforms the given directional screen vector back to the world direction.
103
+ * @param screen
104
+ * @param world
105
+ */
106
+ void getScreenVectorToWorld(Vec2 screen, Vec2 world);
107
+
108
+ Mat22 getMat22Representation();
109
+
110
+
111
+ /**
112
+ * takes the world coordinate (world) puts the corresponding screen coordinate in screen. It
113
+ * should be safe to give the same object as both parameters.
114
+ * @param world
115
+ * @param screen
116
+ */
117
+ void getWorldToScreen(Vec2 world, Vec2 screen);
118
+
119
+
120
+ /**
121
+ * takes the screen coordinates (screen) and puts the corresponding world coordinates in world. It
122
+ * should be safe to give the same object as both parameters.
123
+ * @param screen
124
+ * @param world
125
+ */
126
+ void getScreenToWorld(Vec2 screen, Vec2 world);
127
+
128
+ /**
129
+ * Multiplies the viewport transform by the given Mat22
130
+ * @param transform
131
+ */
132
+ void mulByTransform(Mat22 transform);
133
+ }