-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 29 Java source files and 2 build scripts
- Loading branch information
1 parent
f75703c
commit 68b9414
Showing
31 changed files
with
2,229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Gradle script to build jolt-jni Maven artifacts | ||
|
||
plugins { | ||
id 'java-library' // to build JVM libraries | ||
} | ||
|
||
ext { | ||
group = 'com.github.stephengold' | ||
artifact = 'joltjni' | ||
version = '0.1.0' | ||
baseName = "${artifact}-${version}" // for artifacts | ||
} | ||
|
||
sourceSets.main.java { | ||
srcDir 'src/main/java' | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
tasks.withType(JavaCompile) { // Java compile-time options: | ||
options.compilerArgs << '-Xdiags:verbose' | ||
options.compilerArgs << '-Xlint:unchecked' | ||
options.deprecation = true // to provide detailed deprecation warnings | ||
options.encoding = 'UTF-8' | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// global build settings for the jolt-jni project | ||
|
||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
rootProject.name = 'jolt-jni' | ||
|
||
// no subprojects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright (c) 2024 Stephen Gold | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package com.github.stephengold.joltjni; | ||
|
||
/** | ||
* An object with mass, position, and shape that can be added to a | ||
* {@code PhysicsSystem}. Bodies may be dynamic, kinematic, or static. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class Body extends NonCopyable { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
Body(long bodyVa) { | ||
super(bodyVa); | ||
} | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Acquire the body's ID for use with {@code BodyInterface}. | ||
* | ||
* @return the value | ||
*/ | ||
public BodyId getId() { | ||
long bodyVa = va(); | ||
long bodyIdVa = getId(bodyVa); | ||
BodyId result = new BodyId(bodyIdVa); | ||
|
||
return result; | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static long getId(long bodyVa); | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/com/github/stephengold/joltjni/BodyCreationSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright (c) 2024 Stephen Gold | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package com.github.stephengold.joltjni; | ||
|
||
/** | ||
* Settings used to create a {@code Body}. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class BodyCreationSettings extends JoltPhysicsObject { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate settings for the specified shape. | ||
* | ||
* @param shape the desired shape (not null) | ||
* @param loc the desired location (not null, unaffected) | ||
* @param orient the desired orientation (not null, unaffected) | ||
* @param motionType the desired motion type (not null) | ||
* @param objLayer the ID of the desired object layer | ||
*/ | ||
public BodyCreationSettings(Shape shape, | ||
RVec3 loc, Quat orient, EMotionType motionType, int objLayer) { | ||
long shapeVa = shape.va(); | ||
int motionTypeOrdinal = motionType.ordinal(); | ||
long bodySettingsVa = createBodyCreationSettingsFromShape( | ||
shapeVa, loc.xx(), loc.yy(), loc.zz(), | ||
orient.getX(), orient.getY(), orient.getZ(), orient.getW(), | ||
motionTypeOrdinal, objLayer); | ||
setVirtualAddress(bodySettingsVa, true); | ||
} | ||
|
||
/** | ||
* Instantiate settings for the specified shape settings. | ||
* | ||
* @param shapeSettings the desired shape settings (not null) | ||
* @param loc the desired location (not null, unaffected) | ||
* @param orient the desired orientation (not null, unaffected) | ||
* @param motionType the desired motion type (not null) | ||
* @param objLayer the ID of the desired object layer | ||
*/ | ||
public BodyCreationSettings(ShapeSettings shapeSettings, | ||
RVec3 loc, Quat orient, EMotionType motionType, int objLayer) { | ||
long shapeSettingsVa = shapeSettings.va(); | ||
int motionTypeOrdinal = motionType.ordinal(); | ||
long bodySettingsVa = createBodyCreationSettingsFromShapeSettings( | ||
shapeSettingsVa, loc.xx(), loc.yy(), loc.zz(), | ||
orient.getX(), orient.getY(), orient.getZ(), orient.getW(), | ||
motionTypeOrdinal, objLayer); | ||
setVirtualAddress(bodySettingsVa, true); | ||
} | ||
// ************************************************************************* | ||
// JoltPhysicsObject methods | ||
|
||
@Override | ||
public void close() { | ||
if (ownsNativeObject()) { | ||
long settingsVa = va(); | ||
free(settingsVa); | ||
} | ||
|
||
unassignNativeObject(); | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static long createBodyCreationSettingsFromShape( | ||
long shapeVa, double locX, double locY, double locZ, | ||
float qx, float qy, float qz, float qw, | ||
int motionTypeOrdinal, int objLayer); | ||
|
||
native private static long createBodyCreationSettingsFromShapeSettings( | ||
long shapeSettingsVa, double locX, double locY, double locZ, | ||
float qx, float qy, float qz, float qw, | ||
int motionTypeOrdinal, int objLayer); | ||
|
||
native private static void free(long bodySettingsVa); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright (c) 2024 Stephen Gold | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package com.github.stephengold.joltjni; | ||
|
||
/** | ||
* Identify a particular {@code Body} to a {@code BodyInterface}. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class BodyId extends JoltPhysicsObject { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
BodyId(long bodyIdVa) { | ||
super(bodyIdVa); | ||
} | ||
} |
Oops, something went wrong.