Skip to content

Commit 2f11e17

Browse files
committed
add the SoftBodyManifold class
1 parent 32a996e commit 2f11e17

File tree

3 files changed

+397
-0
lines changed

3 files changed

+397
-0
lines changed

Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ $(N)/glue/s/SkeletonPoseDrawSettings.cpp \
215215
$(N)/glue/s/SliderConstraint.cpp \
216216
$(N)/glue/s/SliderConstraintSettings.cpp \
217217
$(N)/glue/s/SoftBodyCreationSettings.cpp \
218+
$(N)/glue/s/SoftBodyManifold.cpp \
218219
$(N)/glue/s/SoftBodyMotionProperties.cpp \
219220
$(N)/glue/s/SoftBodySharedSettings.cpp \
220221
$(N)/glue/s/SoftBodyVertex.cpp \
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
Copyright (c) 2025 Stephen Gold
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
package com.github.stephengold.joltjni;
23+
24+
/**
25+
* The vertices of a soft body that are colliding with other bodies.
26+
*
27+
* @author Stephen Gold [email protected]
28+
*/
29+
final public class SoftBodyManifold extends JoltPhysicsObject {
30+
// *************************************************************************
31+
// constructors
32+
33+
/**
34+
* Instantiate a manifold with the specified native object assigned but not
35+
* owned.
36+
* <p>
37+
* For use in custom contact listeners.
38+
*
39+
* @param manifoldVa the virtual address of the native object to assign (not
40+
* zero)
41+
*/
42+
public SoftBodyManifold(long manifoldVa) {
43+
setVirtualAddress(manifoldVa);
44+
}
45+
// *************************************************************************
46+
// new methods exposed
47+
48+
/**
49+
* Copy the ID of the body with which the specified vertex collided.
50+
*
51+
* @param vertex the vertex to query (not null, unaffected)
52+
* @return a new object
53+
*/
54+
public BodyId getContactBodyId(SoftBodyVertex vertex) {
55+
long manifoldVa = va();
56+
long vertexVa = vertex.va();
57+
long idVa = getContactBodyId(manifoldVa, vertexVa);
58+
BodyId result = new BodyId(idVa, true);
59+
60+
return result;
61+
}
62+
63+
/**
64+
* Copy the contact normal direction for the specified vertex.
65+
*
66+
* @param vertex the vertex to query (not null, unaffected)
67+
* @return a new vector
68+
*/
69+
public Vec3 getContactNormal(SoftBodyVertex vertex) {
70+
long manifoldVa = va();
71+
long vertexVa = vertex.va();
72+
float nx = getLocalContactNormalX(manifoldVa, vertexVa);
73+
float ny = getLocalContactNormalY(manifoldVa, vertexVa);
74+
float nz = getLocalContactNormalZ(manifoldVa, vertexVa);
75+
Vec3 result = new Vec3(nx, ny, nz);
76+
77+
return result;
78+
}
79+
80+
/**
81+
* Copy the location of the contact point for the specified vertex.
82+
*
83+
* @param vertex the vertex to query (not null, unaffected)
84+
* @return a new location vector (in local coordinates)
85+
*/
86+
public Vec3 getLocalContactPoint(SoftBodyVertex vertex) {
87+
long manifoldVa = va();
88+
long vertexVa = vertex.va();
89+
float x = getLocalContactPointX(manifoldVa, vertexVa);
90+
float y = getLocalContactPointY(manifoldVa, vertexVa);
91+
float z = getLocalContactPointZ(manifoldVa, vertexVa);
92+
Vec3 result = new Vec3(x, y, z);
93+
94+
return result;
95+
}
96+
97+
/**
98+
* Count how many sensors are in contact with the soft body.
99+
*
100+
* @return the count (&ge;0)
101+
*/
102+
public int getNumSensorContacts() {
103+
long manifoldVa = va();
104+
int result = getNumSensorContacts(manifoldVa);
105+
106+
return result;
107+
}
108+
109+
/**
110+
* Return the ID of the specified sensor contact.
111+
*
112+
* @param index among the sensor contacts (&ge;0)
113+
* @return a new object
114+
*/
115+
public BodyId getSensorContactBodyId(int index) {
116+
long manifoldVa = va();
117+
long idVa = getSensorContactBodyId(manifoldVa, index);
118+
BodyId result = new BodyId(idVa, true);
119+
120+
return result;
121+
}
122+
123+
/**
124+
* Enumerate all vertices of the soft body.
125+
*
126+
* @return a new array of new JVM objects with pre-existing native objects
127+
* assigned
128+
*/
129+
public SoftBodyVertex[] getVertices() {
130+
long manifoldVa = va();
131+
int numVertices = countVertices(manifoldVa);
132+
SoftBodyVertex[] result = new SoftBodyVertex[numVertices];
133+
for (int i = 0; i < numVertices; ++i) {
134+
long vertexVa = getVertex(manifoldVa, i);
135+
result[i] = new SoftBodyVertex(this, vertexVa);
136+
}
137+
138+
return result;
139+
}
140+
141+
/**
142+
* Test whether the specified vertex collided with something in this update.
143+
*
144+
* @param vertex the vertex to query (not null, unaffected)
145+
* @return {@code true} if it collided, otherwise {@code false}
146+
*/
147+
public boolean hasContact(SoftBodyVertex vertex) {
148+
long manifoldVa = va();
149+
long vertexVa = vertex.va();
150+
boolean result = hasContact(manifoldVa, vertexVa);
151+
152+
return result;
153+
}
154+
// *************************************************************************
155+
// native private methods
156+
157+
native private static int countVertices(long manifoldVa);
158+
159+
native private static long getContactBodyId(long manifoldVa, long vertexVa);
160+
161+
native private static float getLocalContactNormalX(
162+
long manifoldVa, long vertexVa);
163+
164+
native private static float getLocalContactNormalY(
165+
long manifoldVa, long vertexVa);
166+
167+
native private static float getLocalContactNormalZ(
168+
long manifoldVa, long vertexVa);
169+
170+
native private static float getLocalContactPointX(
171+
long manifoldVa, long vertexVa);
172+
173+
native private static float getLocalContactPointY(
174+
long manifoldVa, long vertexVa);
175+
176+
native private static float getLocalContactPointZ(
177+
long manifoldVa, long vertexVa);
178+
179+
native private static int getNumSensorContacts(long manifoldVa);
180+
181+
native private static long getSensorContactBodyId(
182+
long manifoldVa, int index);
183+
184+
native private static long getVertex(long manifoldVa, int index);
185+
186+
native private static boolean hasContact(long manifoldVa, long vertexVa);
187+
}

0 commit comments

Comments
 (0)