Skip to content

Commit

Permalink
add the MotionProperties class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 28, 2024
1 parent 05c07c0 commit 81fa904
Show file tree
Hide file tree
Showing 2 changed files with 360 additions and 0 deletions.
168 changes: 168 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/MotionProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
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;

/**
* Additional state for a {@code Body} that moves.
*
* @author Stephen Gold [email protected]
*/
public class MotionProperties extends JoltPhysicsObject {
// *************************************************************************
// constructors

MotionProperties(long propertiesVa) {
super(propertiesVa);
}
// *************************************************************************
// new methods exposed

/**
* Return the angular damping coefficient.
*
* @return the coefficient value
*/
public float getAngularDamping() {
long propertiesVa = va();
float result = getAngularDamping(propertiesVa);

return result;
}

/**
* Return the angular velocity.
*
* @return a new vector in physics-system coordinates
*/
public Vec3 getAngularVelocity() {
long propertiesVa = va();
float wx = getAngularVelocityX(propertiesVa);
float wy = getAngularVelocityY(propertiesVa);
float wz = getAngularVelocityZ(propertiesVa);
Vec3 result = new Vec3(wx, wy, wz);

return result;
}

/**
* Return the linear damping coefficient.
*
* @return the coefficient value
*/
public float getLinearDamping() {
long propertiesVa = va();
float result = getLinearDamping(propertiesVa);

return result;
}

/**
* Return the linear velocity.
*
* @return a new vector in physics-system coordinates
*/
public Vec3 getLinearVelocity() {
long propertiesVa = va();
float vx = getLinearVelocityX(propertiesVa);
float vy = getLinearVelocityY(propertiesVa);
float vz = getLinearVelocityZ(propertiesVa);
Vec3 result = new Vec3(vx, vy, vz);

return result;
}

/**
* Alter the angular damping.
*
* @param damping the desired coefficient value
*/
public void setAngularDamping(float damping) {
long propertiesVa = va();
setAngularDamping(propertiesVa, damping);
}

/**
* Alter the angular velocity.
*
* @param omega the desired velocity (in physics-system coordinates)
*/
public void setAngularVelocity(Vec3 omega) {
long propertiesVa = va();
float wx = omega.getX();
float wy = omega.getY();
float wz = omega.getZ();
setAngularVelocity(propertiesVa, wx, wy, wz);
}

/**
* Alter the linear damping.
*
* @param damping the desired coefficient value
*/
public void setLinearDamping(float damping) {
long propertiesVa = va();
setLinearDamping(propertiesVa, damping);
}

/**
* Alter the linear velocity.
*
* @param velocity the desired velocity (in physics-system coordinates)
*/
public void setLinearVelocity(Vec3 velocity) {
long propertiesVa = va();
float vx = velocity.getX();
float vy = velocity.getY();
float vz = velocity.getZ();
setLinearVelocity(propertiesVa, vx, vy, vz);
}
// *************************************************************************
// new methods exposed

native private static float getAngularDamping(long propertiesVa);

native private static float getAngularVelocityX(long propertiesVa);

native private static float getAngularVelocityY(long propertiesVa);

native private static float getAngularVelocityZ(long propertiesVa);

native private static float getLinearDamping(long propertiesVa);

native private static float getLinearVelocityX(long propertiesVa);

native private static float getLinearVelocityY(long propertiesVa);

native private static float getLinearVelocityZ(long propertiesVa);

native private static void setAngularDamping(
long propertiesVa, float damping);

native private static void setAngularVelocity(
long propertiesVa, float wx, float wy, float wz);

native private static void setLinearDamping(
long propertiesVa, float damping);

native private static void setLinearVelocity(
long propertiesVa, float vx, float vy, float vz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
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/Body/MotionProperties.h>
#include "auto/com_github_stephengold_joltjni_MotionProperties.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getAngularDamping
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getAngularDamping
(JNIEnv *, jclass, jlong propertiesVa) {
const MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
float result = pProperties->GetAngularDamping();
return result;
}

inline static const Vec3& getAngularVelocity(jlong propertiesVa) {
const MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
const Vec3& result = pProperties->GetAngularVelocity();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getAngularVelocityX
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getAngularVelocityX
(JNIEnv *, jclass, jlong propertiesVa) {
const Vec3& vec3 = getAngularVelocity(propertiesVa);
float result = vec3.GetX();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getAngularVelocityY
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getAngularVelocityY
(JNIEnv *, jclass, jlong propertiesVa) {
const Vec3 &vec3 = getAngularVelocity(propertiesVa);
float result = vec3.GetY();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getAngularVelocityZ
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getAngularVelocityZ
(JNIEnv *, jclass, jlong propertiesVa) {
const Vec3 &vec3 = getAngularVelocity(propertiesVa);
float result = vec3.GetZ();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getLinearDamping
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getLinearDamping
(JNIEnv *, jclass, jlong propertiesVa) {
const MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
float result = pProperties->GetLinearDamping();
return result;
}

inline static const Vec3& getLinearVelocity(jlong propertiesVa) {
const MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
const Vec3& result = pProperties->GetLinearVelocity();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getLinearVelocityX
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getLinearVelocityX
(JNIEnv *, jclass, jlong propertiesVa) {
const Vec3 &vec3 = getLinearVelocity(propertiesVa);
float result = vec3.GetX();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getLinearVelocityY
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getLinearVelocityY
(JNIEnv *, jclass, jlong propertiesVa) {
const Vec3 &vec3 = getLinearVelocity(propertiesVa);
float result = vec3.GetY();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: getLinearVelocityZ
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_MotionProperties_getLinearVelocityZ
(JNIEnv *, jclass, jlong propertiesVa) {
const Vec3 &vec3 = getLinearVelocity(propertiesVa);
float result = vec3.GetZ();
return result;
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: setAngularDamping
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_MotionProperties_setAngularDamping
(JNIEnv *, jclass, jlong propertiesVa, jfloat damping) {
MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
pProperties->SetAngularDamping(damping);
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: setAngularVelocity
* Signature: (JFFF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_MotionProperties_setAngularVelocity
(JNIEnv *, jclass, jlong propertiesVa, jfloat wx, jfloat wy, jfloat wz) {
MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
Vec3 omega(wx, wy, wz);
pProperties->SetAngularVelocity(omega);
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: setLinearDamping
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_MotionProperties_setLinearDamping
(JNIEnv *, jclass, jlong propertiesVa, jfloat damping) {
MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
pProperties->SetLinearDamping(damping);
}

/*
* Class: com_github_stephengold_joltjni_MotionProperties
* Method: setLinearVelocity
* Signature: (JFFF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_MotionProperties_setLinearVelocity
(JNIEnv *, jclass, jlong propertiesVa, jfloat vx, jfloat vy, jfloat vz) {
MotionProperties * const pProperties
= reinterpret_cast<MotionProperties *> (propertiesVa);
Vec3 velocity(vx, vy, vz);
pProperties->SetLinearVelocity(velocity);
}

0 comments on commit 81fa904

Please sign in to comment.