Skip to content

Commit

Permalink
add the SphereShapeSettings class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 29, 2024
1 parent c01dbd1 commit 3a03ad5
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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 construct a {@code SphereShape}.
*
* @author Stephen Gold [email protected]
*/
public class SphereShapeSettings extends ConvexShapeSettings {
// *************************************************************************
// constructors

/**
* Instantiate settings for the specified radius.
*
* @param radius the desired radius (≥0)
*/
public SphereShapeSettings(float radius) {
long settingsVa = createSphereShapeSettings(radius);
setVirtualAddress(settingsVa, true);
}
// *************************************************************************
// new methods exposed

/**
* Generate a shape from these settings.
*
* @return a new instance
*/
public Shape createShape() {
long settingsVa = va();
long shapeVa = createSphereShape(settingsVa);
SphereShape result = new SphereShape(shapeVa);

return result;
}
// *************************************************************************
// native private methods

native private static long createSphereShape(long settingsVa);

native private static long createSphereShapeSettings(float radius);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
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.
*/

/*
* Author: Stephen Gold
*/
#include <Jolt/Jolt.h>
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
#include "auto/com_github_stephengold_joltjni_SphereShapeSettings.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_SphereShapeSettings
* Method: createSphereShape
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SphereShapeSettings_createSphereShape
(JNIEnv *, jclass, jlong settingsVa) {
const SphereShapeSettings * const pSettings
= reinterpret_cast<SphereShapeSettings *> (settingsVa);
ShapeSettings::ShapeResult shapeResult = pSettings->Create();
SphereShape * const pShape = new SphereShape(*pSettings, shapeResult);
if (shapeResult.HasError()) {
// TODO
}
return reinterpret_cast<jlong> (pShape);
}

/*
* Class: com_github_stephengold_joltjni_SphereShapeSettings
* Method: createSphereShapeSettings
* Signature: (F)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SphereShapeSettings_createSphereShapeSettings
(JNIEnv *, jclass, jfloat radius) {
SphereShapeSettings * const pResult = new SphereShapeSettings(radius);
return reinterpret_cast<jlong> (pResult);
}

0 comments on commit 3a03ad5

Please sign in to comment.