diff --git a/.github/actions/tools/bintray.sh b/.github/actions/tools/bintray.sh index 0c7d4e6ddf..4d8c8dc984 100644 --- a/.github/actions/tools/bintray.sh +++ b/.github/actions/tools/bintray.sh @@ -35,59 +35,23 @@ function bintray_createPackage { fi } -# uploadFile file destination [REPO] "content" [PACKAGE] [USER] [PASSWORD] [SRCREPO] [LICENSE] -function bintray_uploadFile { +# minio_uploadFile +# +# Upload the specified file to the specified MinIO instance. +function minio_uploadFile { file="$1" dest="$2" - - echo "Upload $file to $dest" + url="$3" + access="$4" + secret="$5" - repo="$3" - type="$4" - package="$5" + echo "Install MinIO client" + wget --quiet https://dl.min.io/client/mc/release/linux-amd64/mc + chmod +x ./mc - user="$6" - password="$7" - - srcrepo="$8" - license="$9" - publish="${10}" + echo "Add an alias for the MinIO instance to the MinIO configuration file" + ./mc alias set objects "$url" "$access" "$secret" - bintray_createPackage $repo $package $user $password $srcrepo $license - - url="https://api.bintray.com/$type/$repo/$package/$dest" - if [ "$publish" = "true" ]; then url="$url;publish=1"; fi - - curl -T "$file" -u$user:$password "$url" - -} - -function bintray_uploadAll { - path="$1" - destpath="$2" - repo="$3" - type="$4" - package="$5" - - user="$6" - password="$7" - - srcrepo="$8" - license="$9" - publish="${10}" - - cdir="$PWD" - cd "$path" - - files="`find . -type f -print`" - IFS=" -" - set -f - for f in $files; do - destfile="$destpath/${f:2}" - bintray_uploadFile $f $destfile $repo $type $package $user $password $srcrepo $license $publish - done - set +f - unset IFS - cd "$cdir" + echo "Upload $file to $url/$dest" + ./mc cp "$file" "objects/$dest" } diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f16151f3a..b48e8fa2e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,29 +1,35 @@ ###################################################################################### -# JME CI/CD +# JME CI/CD ###################################################################################### # Quick overview of what is going on in this script: # - Build natives for android -# - Build natives for linux arm -# - Build natives for windows,mac,linux x86_64 and x86 # - Merge the natives, build the engine, create the zip release, maven artifacts, javadoc and native snapshot -# - (only when there is a change in the native code) Deploy the native snapshot to bintray -# - (only when building a release) Deploy everything else to github releases, github packet registry and bintray +# - (only when native code changes) Deploy the natives snapshot to the MinIO instance +# - (only when building a release) Deploy everything else to github releases, github packet registry, Bintray, and Sonatype # - (only when building a release) Update javadoc.jmonkeyengine.org # Note: -# All the actions/upload-artifact and actions/download-artifact steps are used to pass +# All the actions/upload-artifact and actions/download-artifact steps are used to pass # stuff between jobs, github actions has some sort of storage that is local to the # running workflow, we use it to store the result of each job since the filesystem # is not maintained between jobs. ################# CONFIGURATIONS ##################################################### -# >> Configure BINTRAY RELEASE & NATIVE SNAPSHOT +# >> Configure BINTRAY RELEASE # Configure the following secrets/variables (customize the values with your own) # BINTRAY_GENERIC_REPO=riccardoblsandbox/jmonkeyengine-files # BINTRAY_MAVEN_REPO=riccardoblsandbox/jmonkeyengine # BINTRAY_USER=riccardo # BINTRAY_APIKEY=XXXXXX # BINTRAY_LICENSE="BSD 3-Clause" +# >> Configure MINIO NATIVES SNAPSHOT +# OBJECTS_KEY=XXXXXX +# >> Configure SONATYPE RELEASE +# OSSRH_PASSWORD=XXXXXX +# OSSRH_USERNAME=XXXXXX +# >> Configure SIGNING +# SIGNING_KEY=XXXXXX +# SIGNING_PASSWORD=XXXXXX # >> Configure PACKAGE REGISTRY RELEASE -# Nothing to do here, everything is autoconfigured to work with the account/org that +# Nothing to do here, everything is autoconfigured to work with the account/org that # is running the build. # >> Configure JAVADOC # JAVADOC_GHPAGES_REPO="riccardoblsandbox/javadoc.jmonkeyengine.org.git" @@ -31,7 +37,7 @@ # ssh-keygen -t rsa -b 4096 -C "actions@users.noreply.github.com" -f javadoc_deploy # Set # JAVADOC_GHPAGES_DEPLOY_PRIVKEY="......." -# In github repo -> Settings, use javadoc_deploy.pub as Deploy key with write access +# In github repo -> Settings, use javadoc_deploy.pub as Deploy key with write access ###################################################################################### # Resources: # - Github actions docs: https://help.github.com/en/articles/about-github-actions @@ -46,6 +52,7 @@ name: Build jMonkeyEngine on: push: branches: + - gsw - master - newbuild - v3.3.* @@ -54,47 +61,19 @@ on: pull_request: release: types: [published] - -jobs: - - # Builds the natives on linux arm - BuildLinuxArmNatives: - name: Build natives for linux (arm) - runs-on: ubuntu-18.04 - container: - image: riccardoblb/buildenv-jme3:linuxArm - - steps: - - name: Clone the repo - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - name: Validate the Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Build - run: | - # Build - # Note: since this is crossbuild we use the buildForPlatforms filter to tell - # the buildscript wich platforms it should build for. - ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildForPlatforms=LinuxArm,LinuxArmHF,LinuxArm64 -PbuildNativeProjects=true \ - :jme3-bullet-native:assemble - - name: Upload natives - uses: actions/upload-artifact@master - with: - name: linuxarm-natives - path: build/native +jobs: # Build the natives on android BuildAndroidNatives: name: Build natives for android runs-on: ubuntu-18.04 container: - image: riccardoblb/buildenv-jme3:android - + image: jmonkeyengine/buildenv-jme3:android + steps: - name: Clone the repo - uses: actions/checkout@v2 + uses: actions/checkout@v2 with: fetch-depth: 1 - name: Validate the Gradle wrapper @@ -102,82 +81,19 @@ jobs: - name: Build run: | ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \ - :jme3-android-native:assemble \ - :jme3-bullet-native-android:assemble - - - name: Upload natives - uses: actions/upload-artifact@master - with: - name: android-natives - path: build/native + :jme3-android-native:assemble - # Build the natives - BuildNatives: - strategy: - fail-fast: true - matrix: - os: [ubuntu-18.04,windows-2019,macOS-latest] - jdk: [8.x.x] - include: - - os: ubuntu-18.04 - osName: linux - - os: windows-2019 - osName: windows - - os: macOS-latest - osName: mac - - name: Build natives for ${{ matrix.osName }} - runs-on: ${{ matrix.os }} - steps: - - - name: Clone the repo - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - - name: Prepare java environment - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.jdk }} - architecture: x64 - - name: Validate the Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Build Natives - shell: bash - env: - OS_NAME: ${{ matrix.osName }} - run: | - # Install dependencies - if [ "$OS_NAME" = "mac" ]; - then - echo "Prepare mac" - - elif [ "$OS_NAME" = "linux" ]; - then - echo "Prepare linux" - sudo apt-get update - sudo apt-get install -y gcc-multilib g++-multilib - else - echo "Prepare windows" - fi - - # Build - ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true -Dmaven.repo.local="$PWD/dist/maven" \ - :jme3-bullet-native:build - - # Upload natives to be used later by the BuildJMonkey job - name: Upload natives uses: actions/upload-artifact@master with: - name: ${{ matrix.osName }}-natives + name: android-natives path: build/native - # Build the engine, we only deploy from ubuntu-18.04 jdk8 - BuildJMonkey: - needs: [BuildNatives,BuildAndroidNatives] + BuildJMonkey: + needs: [BuildAndroidNatives] name: Build on ${{ matrix.osName }} jdk${{ matrix.jdk }} - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: @@ -192,51 +108,28 @@ jobs: - os: windows-2019 osName: windows - os: macOS-latest - osName: mac + osName: mac - jdk: 11.x.x - deploy: false + deploy: false - steps: + steps: - name: Clone the repo uses: actions/checkout@v2 with: fetch-depth: 1 - + - name: Setup the java environment uses: actions/setup-java@v1 with: java-version: ${{ matrix.jdk }} architecture: x64 - - name: Download natives for linux - uses: actions/download-artifact@master - with: - name: linux-natives - path: build/native - - - name: Download natives for windows - uses: actions/download-artifact@master - with: - name: windows-natives - path: build/native - - - name: Download natives for mac - uses: actions/download-artifact@master - with: - name: mac-natives - path: build/native - - name: Download natives for android uses: actions/download-artifact@master with: name: android-natives path: build/native - - name: Download natives for linux (arm) - uses: actions/download-artifact@master - with: - name: linuxarm-natives - path: build/native - name: Validate the Gradle wrapper uses: gradle/wrapper-validation-action@v1 - name: Build Engine @@ -244,32 +137,45 @@ jobs: run: | # Build ./gradlew -i -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true build - + if [ "${{ matrix.deploy }}" = "true" ]; - then + then # We are going to need "zip" sudo apt-get update sudo apt-get install -y zip # Create the zip release and the javadoc ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true mergedJavadoc createZipDistribution - + # We prepare the release for deploy mkdir -p ./dist/release/ mv build/distributions/*.zip dist/release/ - - # Create the maven artifacts - mkdir -p ./dist/maven/ - ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true install -Dmaven.repo.local="$PWD/dist/maven" + + # Install maven artifacts to ./dist/maven and sign them if possible + if [ "${{ secrets.SIGNING_PASSWORD }}" = "" ]; + then + echo "Configure the following secrets to enable signing:" + echo "SIGNING_KEY, SIGNING_PASSWORD" + + ./gradlew publishMavenPublicationToDistRepository \ + -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \ + --console=plain --stacktrace + else + ./gradlew publishMavenPublicationToDistRepository \ + -PsigningKey='${{ secrets.SIGNING_KEY }}' \ + -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \ + -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \ + --console=plain --stacktrace + fi # Zip the natives into a single archive (we are going to use this to deploy native snapshots) echo "Create native zip" cdir="$PWD" cd "build/native" - zip -r "$cdir/dist/jme3-natives.zip" * + zip -r "$cdir/dist/jme3-natives.zip" * cd "$cdir" echo "Done" - fi + fi # Used later by DeploySnapshot - name: Upload merged natives @@ -278,29 +184,29 @@ jobs: with: name: natives path: dist/jme3-natives.zip - + # Upload maven artifacts to be used later by the deploy job - name: Upload maven artifacts if: matrix.deploy==true uses: actions/upload-artifact@master with: name: maven - path: dist/maven + path: dist/maven - name: Upload javadoc if: matrix.deploy==true uses: actions/upload-artifact@master with: name: javadoc - path: dist/javadoc - - # Upload release archive to be used later by the deploy job + path: dist/javadoc + + # Upload release archive to be used later by the deploy job - name: Upload release if: github.event_name == 'release' && matrix.deploy==true uses: actions/upload-artifact@master with: name: release - path: dist/release + path: dist/release # This job deploys the native snapshot. # The snapshot is downloaded when people build the engine without setting buildNativeProject @@ -321,7 +227,7 @@ jobs: then git clone --single-branch --branch "$branch" https://github.com/${GITHUB_REPOSITORY}.git . fi - + - name: Download merged natives uses: actions/download-artifact@master with: @@ -339,7 +245,7 @@ jobs: then nativeSnapshot=`cat "natives-snapshot.properties"` nativeSnapshot="${nativeSnapshot#*=}" - + # We deploy ONLY if GITHUB_SHA (the current commit hash) is newer than $nativeSnapshot if [ "`git rev-list --count $nativeSnapshot..$GITHUB_SHA`" = "0" ]; then @@ -347,12 +253,7 @@ jobs: else # We check if the native code changed. echo "Detect changes" - NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-bullet-native/)" - if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-android-native/)"; fi - if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-bullet-native-android/)"; fi - if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-bullet/)"; fi - # The bulletUrl (in gradle.properties) might have changed. - if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- gradle.properties)"; fi + NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-android-native/)" fi fi @@ -361,31 +262,28 @@ jobs: then echo "No changes, skip." else - if [ "${{ secrets.BINTRAY_GENERIC_REPO }}" = "" ]; - then - echo "Configure the following secrets to enable native snapshot deployment" - echo "BINTRAY_GENERIC_REPO, BINTRAY_USER, BINTRAY_APIKEY" + if [ "${{ secrets.OBJECTS_KEY }}" = "" ]; + then + echo "Configure the OBJECTS_KEY secret to enable natives snapshot deployment to MinIO" else - # Deploy snapshot - bintray_uploadFile dist/jme3-natives.zip \ - $GITHUB_SHA/$GITHUB_SHA/jme3-natives.zip \ - ${{ secrets.BINTRAY_GENERIC_REPO }} "content" "natives" \ - ${{ secrets.BINTRAY_USER }} \ - ${{ secrets.BINTRAY_APIKEY }} \ - "https://github.com/${GITHUB_REPOSITORY}" \ - "${{ secrets.BINTRAY_LICENSE }}" "true" - - # We reference the snapshot by writing its commit hash in natives-snapshot.properties + # Deploy natives snapshot to a MinIO instance using function in bintray.sh + minio_uploadFile dist/jme3-natives.zip \ + native-snapshots/$GITHUB_SHA/jme3-natives.zip \ + https://objects.jmonkeyengine.org \ + jmonkeyengine \ + ${{ secrets.OBJECTS_KEY }} + + # We reference the snapshot by writing its commit hash in natives-snapshot.properties echo "natives.snapshot=$GITHUB_SHA" > natives-snapshot.properties - + # We commit the updated natives-snapshot.properties git config --global user.name "Github Actions" git config --global user.email "actions@users.noreply.github.com" - + git add natives-snapshot.properties - + git commit -m "[skip ci] update natives snapshot" - + # Pull rebase from the remote repo, just in case there was a push in the meantime git pull -q --rebase @@ -394,39 +292,55 @@ jobs: # Push (git -c http.extraheader="AUTHORIZATION: basic $header" push origin "$branch" || true) - + fi fi fi # This job deploys the release - DeployRelease: + DeployRelease: needs: [BuildJMonkey] name: Deploy Release runs-on: ubuntu-18.04 if: github.event_name == 'release' - steps: - + steps: + # We need to clone everything again for uploadToMaven.sh ... - name: Clone the repo uses: actions/checkout@v2 with: fetch-depth: 1 - + # Download all the stuff... - name: Download maven artifacts uses: actions/download-artifact@master with: name: maven path: dist/maven - + - name: Download release uses: actions/download-artifact@master with: name: release - path: dist/release - - - name: Deploy to github releases + path: dist/release + + - name: Rebuild the maven artifacts and deploy them to Sonatype OSSRH + run: | + if [ "${{ secrets.OSSRH_PASSWORD }}" = "" ]; + then + echo "Configure the following secrets to enable deployment to Sonatype:" + echo "OSSRH_PASSWORD, OSSRH_USERNAME, SIGNING_KEY, SIGNING_PASSWORD" + else + ./gradlew publishMavenPublicationToOSSRHRepository \ + -PossrhPassword=${{ secrets.OSSRH_PASSWORD }} \ + -PossrhUsername=${{ secrets.OSSRH_USERNAME }} \ + -PsigningKey='${{ secrets.SIGNING_KEY }}' \ + -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \ + -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \ + --console=plain --stacktrace + fi + + - name: Deploy to GitHub Releases run: | # We need to get the release id (yeah, it's not the same as the tag) echo "${GITHUB_EVENT_PATH}" @@ -443,7 +357,7 @@ jobs: -H "Content-Type: application/zip" \ --data-binary @"$filename" \ "$url" - + - name: Deploy to bintray run: | source .github/actions/tools/uploadToMaven.sh @@ -454,22 +368,22 @@ jobs: else uploadAllToMaven dist/maven/ https://api.bintray.com/maven/${{ secrets.BINTRAY_MAVEN_REPO }} ${{ secrets.BINTRAY_USER }} ${{ secrets.BINTRAY_APIKEY }} "https://github.com/${GITHUB_REPOSITORY}" "${{ secrets.BINTRAY_LICENSE }}" fi - + # - name: Deploy to github package registry # run: | # source .github/actions/tools/uploadToMaven.sh # registry="https://maven.pkg.github.com/$GITHUB_REPOSITORY" # echo "Deploy to github package registry $registry" # uploadAllToMaven dist/maven/ $registry "token" ${{ secrets.GITHUB_TOKEN }} - + # Deploy the javadoc - DeployJavaDoc: + DeployJavaDoc: needs: [BuildJMonkey] name: Deploy Javadoc runs-on: ubuntu-18.04 if: github.event_name == 'release' - steps: - + steps: + # We are going to need a deploy key for this, since we need # to push to a different repo - name: Set ssh key @@ -484,16 +398,16 @@ jobs: branch="gh-pages" export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key" git clone --single-branch --branch "$branch" git@github.com:${{ secrets.JAVADOC_GHPAGES_REPO }} . - + # Download the javadoc in the new directory "newdoc" - name: Download javadoc uses: actions/download-artifact@master with: name: javadoc path: newdoc - + # The actual deploy - - name: Deploy to github pages + - name: Deploy to github pages run: | set -f IFS=$'\n' @@ -515,10 +429,10 @@ jobs: # if there isn't an index.txt we create one (we need this to list the versions) if [ ! -f "index.txt" ]; then echo "" > index.txt ; fi index="`cat index.txt`" - + # Check if this version is already in index.txt addNew=true - for v in $index; + for v in $index; do if [ "$v" = "$version" ]; then @@ -545,11 +459,11 @@ jobs: # Commit the changes git config --global user.name "Github Actions" git config --global user.email "actions@users.noreply.github.com" - + git add . || true git commit -m "$version" || true - branch="gh-pages" + branch="gh-pages" git push origin "$branch" --force || true fi diff --git a/LICENSE b/LICENSE index 1fb17b9ca6..38e2806108 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2020 jMonkeyEngine +Copyright (c) 2009-2021 jMonkeyEngine All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/build.gradle b/build.gradle index 90a01131cb..5cacafe9f1 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ subprojects { apply from: rootProject.file('common-android-app.gradle') } - if (!project.name.endsWith("-native") && project.name != "jme3-bullet-native-android" && enableSpotBugs != "false" ) { + if (!project.name.endsWith("-native") && enableSpotBugs != "false" ) { apply plugin: 'com.github.spotbugs' // Currently we only warn about issues and try to fix them as we go, but those aren't mission critical. @@ -137,13 +137,10 @@ task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the pro options.overview = file("javadoc-overview.html") // Note: The closures below are executed lazily. source subprojects.collect {project -> - project.sourceSets*.allJava + project.sourceSets.main.allJava // main only, exclude tests } classpath = files(subprojects.collect {project -> project.sourceSets*.compileClasspath}) - // source { - // subprojects*.sourceSets*.main*.allSource - // } classpath.from { subprojects*.configurations*.compile*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve() } diff --git a/common.gradle b/common.gradle index 2b59420c08..63761f94c4 100644 --- a/common.gradle +++ b/common.gradle @@ -5,6 +5,8 @@ apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'maven' +apply plugin: 'maven-publish' +apply plugin: 'signing' group = 'org.jmonkeyengine' version = jmeFullVersion @@ -12,6 +14,13 @@ version = jmeFullVersion sourceCompatibility = '1.8' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +if(JavaVersion.current() >= JavaVersion.VERSION_1_9) { + compileJava { + options.compilerArgs.addAll(['--release', '8']) + //Replace previous with "options.release = 8" if updated to gradle 6.6 or newer + } +} + gradle.projectsEvaluated { tasks.withType(JavaCompile) { // compile-time options: options.compilerArgs << '-Xlint:unchecked' @@ -69,6 +78,7 @@ javadoc { if (JavaVersion.current().isJava8Compatible()){ options.addStringOption('Xdoclint:none', '-quiet') } + source = sourceSets.main.allJava // main only, exclude tests } test { @@ -136,3 +146,63 @@ artifacts { archives writeFullPom.outputs.files[0] } +publishing { + publications { + maven(MavenPublication) { + artifact javadocJar + artifact sourcesJar + from components.java + pom { + description = POM_DESCRIPTION + developers { + developer { + id = 'jMonkeyEngine' + name = 'jMonkeyEngine Team' + } + } + inceptionYear = POM_INCEPTION_YEAR + licenses { + license { + distribution = POM_LICENSE_DISTRIBUTION + name = POM_LICENSE_NAME + url = POM_LICENSE_URL + } + } + name = POM_NAME + scm { + connection = POM_SCM_CONNECTION + developerConnection = POM_SCM_DEVELOPER_CONNECTION + url = POM_SCM_URL + } + url = POM_URL + } + version project.version + } + } + repositories { + maven { + name = 'Dist' + url = gradle.rootProject.projectDir.absolutePath + '/dist/maven' + } + maven { + credentials { + username = gradle.rootProject.hasProperty('ossrhUsername') ? ossrhUsername : 'Unknown user' + password = gradle.rootProject.hasProperty('ossrhPassword') ? ossrhPassword : 'Unknown password' + } + name = 'OSSRH' + url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' + } + } +} + +signing { + def signingKey = gradle.rootProject.findProperty('signingKey') + def signingPassword = gradle.rootProject.findProperty('signingPassword') + useInMemoryPgpKeys(signingKey, signingPassword) + + sign configurations.archives + sign publishing.publications.maven +} +tasks.withType(Sign) { + onlyIf { gradle.rootProject.hasProperty('signingKey') } +} diff --git a/gradle.properties b/gradle.properties index 360b7483cf..01ff175f16 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,12 +30,6 @@ enableSpotBugs=false #ndkPath=/Users/normenhansen/Documents/Code-Import/android-ndk-r7 ndkPath = /opt/android-ndk-r16b -# Path for downloading native Bullet -# 2.89+ (circa 26 April 2020, to avoid jMonkeyEngine issue #1283) -bulletUrl = https://github.com/bulletphysics/bullet3/archive/cd8cf7521cbb8b7808126a6adebd47bb83ea166a.zip -bulletFolder = bullet3-cd8cf7521cbb8b7808126a6adebd47bb83ea166a -bulletZipFile = bullet3.zip - # POM settings POM_NAME=jMonkeyEngine POM_DESCRIPTION=jMonkeyEngine is a 3-D game engine for adventurous Java developers @@ -52,4 +46,4 @@ POM_INCEPTION_YEAR=2009 bintray_user= bintray_api_key= -PREBUILD_NATIVES_URL=https://dl.bintray.com/jmonkeyengine/files/${natives.snapshot}/jme3-natives.zip +PREBUILD_NATIVES_URL=https://objects.jmonkeyengine.org/native-snapshots/${natives.snapshot}/jme3-natives.zip diff --git a/jme3-android-examples/build.gradle b/jme3-android-examples/build.gradle index 17be807ebb..741bbe7847 100644 --- a/jme3-android-examples/build.gradle +++ b/jme3-android-examples/build.gradle @@ -53,8 +53,7 @@ dependencies { compile project(':jme3-android') compile project(':jme3-android-native') compile project(':jme3-effects') - compile project(':jme3-bullet') - compile project(':jme3-bullet-native-android') + compile project(':jme3-jbullet') compile project(':jme3-networking') compile project(':jme3-niftygui') compile project(':jme3-plugins') diff --git a/jme3-android-native/.gitignore b/jme3-android-native/.gitignore index 9010f892c2..a75c2dfd25 100644 --- a/jme3-android-native/.gitignore +++ b/jme3-android-native/.gitignore @@ -1,2 +1,2 @@ -# The headers are autogenerated and nobody should try to commit them... +# The headers are autogenerated, and nobody should try to commit them. src/native/headers diff --git a/jme3-android-native/openalsoft.gradle b/jme3-android-native/openalsoft.gradle index 3c47011ae1..f9cc834080 100644 --- a/jme3-android-native/openalsoft.gradle +++ b/jme3-android-native/openalsoft.gradle @@ -1,11 +1,12 @@ -// OpenAL Soft r1.16 -String openALSoftUrl = 'https://github.com/jMonkeyEngine/openal-soft/archive/e5016f814a265ed592a88acea95cf912c4bfdf12.zip' +// OpenAL Soft r1.21.1 +// TODO: update URL to jMonkeyEngine fork once it's updated with latest kcat's changes +String openALSoftUrl = 'https://github.com/kcat/openal-soft/archive/1.21.1.zip' String openALSoftZipFile = 'OpenALSoft.zip' // OpenAL Soft directory the download is extracted into // Typically, the downloaded OpenAL Soft zip file will extract to a directory // called "openal-soft" -String openALSoftFolder = 'openal-soft-e5016f814a265ed592a88acea95cf912c4bfdf12' +String openALSoftFolder = 'openal-soft-1.21.1' //Working directories for the ndk build. String openalsoftBuildDir = "${buildDir}" + File.separator + 'openalsoft' @@ -56,7 +57,7 @@ task copyOpenALSoft(type: Copy) { into outputDir } copyOpenALSoft.dependsOn { - def openALSoftUnzipDir = new File(project.projectDir.absolutePath + File.separator + openALSoftFolder) + def openALSoftUnzipDir = new File(openalsoftBuildDir + File.separator + openALSoftFolder) // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory() if (!openALSoftUnzipDir.isDirectory()) { diff --git a/jme3-android-native/src/native/jme_decode/Android.mk b/jme3-android-native/src/native/jme_decode/Android.mk index ee1ff8e4a6..1f2a2dca2d 100644 --- a/jme3-android-native/src/native/jme_decode/Android.mk +++ b/jme3-android-native/src/native/jme_decode/Android.mk @@ -10,7 +10,7 @@ LOCAL_C_INCLUDES:= \ $(LOCAL_PATH) \ $(LOCAL_PATH)/Tremor -LOCAL_CFLAGS := -std=gnu99 -DLIMIT_TO_64kHz +LOCAL_CFLAGS := -std=gnu99 -DLIMIT_TO_64kHz -O0 LOCAL_LDLIBS := -lz -llog -Wl,-s ifeq ($(TARGET_ARCH),arm) diff --git a/jme3-android-native/src/native/jme_openalsoft/Android.mk b/jme3-android-native/src/native/jme_openalsoft/Android.mk index 23d14b3ba1..13e1547aad 100644 --- a/jme3-android-native/src/native/jme_openalsoft/Android.mk +++ b/jme3-android-native/src/native/jme_openalsoft/Android.mk @@ -1,4 +1,4 @@ -TARGET_PLATFORM := android-9 +TARGET_PLATFORM := android-19 LOCAL_PATH := $(call my-dir) @@ -7,64 +7,97 @@ include $(CLEAR_VARS) LOCAL_MODULE := openalsoftjme LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/include \ - $(LOCAL_PATH)/OpenAL32/Include $(LOCAL_PATH)/Alc + $(LOCAL_PATH)/alc $(LOCAL_PATH)/common -LOCAL_CFLAGS := -std=c99 -ffast-math -DAL_BUILD_LIBRARY -DAL_ALEXT_PROTOTYPES +LOCAL_CPP_FEATURES += exceptions + +LOCAL_CFLAGS := -ffast-math -DAL_BUILD_LIBRARY -DAL_ALEXT_PROTOTYPES -fcommon -O0 -DRESTRICT="" LOCAL_LDLIBS := -lOpenSLES -llog -Wl,-s -LOCAL_SRC_FILES := Alc/backends/opensl.c \ - Alc/backends/loopback.c \ - Alc/backends/wave.c \ - Alc/backends/base.c \ - Alc/backends/null.c \ - Alc/ALc.c \ - Alc/helpers.c \ - Alc/bs2b.c \ - Alc/alcRing.c \ - Alc/effects/chorus.c \ - Alc/effects/flanger.c \ - Alc/effects/dedicated.c \ - Alc/effects/reverb.c \ - Alc/effects/distortion.c \ - Alc/effects/autowah.c \ - Alc/effects/equalizer.c \ - Alc/effects/modulator.c \ - Alc/effects/echo.c \ - Alc/effects/compressor.c \ - Alc/effects/null.c \ - Alc/alcConfig.c \ - Alc/ALu.c \ - Alc/mixer_c.c \ - Alc/panning.c \ - Alc/hrtf.c \ - Alc/mixer.c \ - Alc/midi/soft.c \ - Alc/midi/sf2load.c \ - Alc/midi/dummy.c \ - Alc/midi/fluidsynth.c \ - Alc/midi/base.c \ - common/uintmap.c \ - common/atomic.c \ - common/threads.c \ - common/rwlock.c \ - OpenAL32/alBuffer.c \ - OpenAL32/alPreset.c \ - OpenAL32/alListener.c \ - OpenAL32/alEffect.c \ - OpenAL32/alExtension.c \ - OpenAL32/alThunk.c \ - OpenAL32/alMidi.c \ - OpenAL32/alSoundfont.c \ - OpenAL32/alFontsound.c \ - OpenAL32/alAuxEffectSlot.c \ - OpenAL32/alError.c \ - OpenAL32/alFilter.c \ - OpenAL32/alSource.c \ - OpenAL32/alState.c \ - OpenAL32/sample_cvt.c \ - com_jme3_audio_android_AndroidAL.c \ - com_jme3_audio_android_AndroidALC.c \ - com_jme3_audio_android_AndroidEFX.c +LOCAL_SRC_FILES := al/auxeffectslot.cpp \ + al/buffer.cpp \ + al/effect.cpp \ + al/effects/autowah.cpp \ + al/effects/chorus.cpp \ + al/effects/compressor.cpp \ + al/effects/convolution.cpp \ + al/effects/dedicated.cpp \ + al/effects/distortion.cpp \ + al/effects/echo.cpp \ + al/effects/equalizer.cpp \ + al/effects/fshifter.cpp \ + al/effects/modulator.cpp \ + al/effects/null.cpp \ + al/effects/pshifter.cpp \ + al/effects/reverb.cpp \ + al/effects/vmorpher.cpp \ + al/error.cpp \ + al/event.cpp \ + al/extension.cpp \ + al/filter.cpp \ + al/listener.cpp \ + al/source.cpp \ + al/state.cpp \ + alc/alc.cpp \ + alc/alconfig.cpp \ + alc/alu.cpp \ + alc/backends/base.cpp \ + alc/backends/loopback.cpp \ + alc/backends/null.cpp \ + alc/backends/opensl.cpp \ + alc/backends/wave.cpp \ + alc/bformatdec.cpp \ + alc/buffer_storage.cpp \ + alc/converter.cpp \ + alc/effects/autowah.cpp \ + alc/effects/chorus.cpp \ + alc/effects/compressor.cpp \ + alc/effects/convolution.cpp \ + alc/effects/dedicated.cpp \ + alc/effects/distortion.cpp \ + alc/effects/echo.cpp \ + alc/effects/equalizer.cpp \ + alc/effects/fshifter.cpp \ + alc/effects/modulator.cpp \ + alc/effects/null.cpp \ + alc/effects/pshifter.cpp \ + alc/effects/reverb.cpp \ + alc/effects/vmorpher.cpp \ + alc/effectslot.cpp \ + alc/helpers.cpp \ + alc/hrtf.cpp \ + alc/panning.cpp \ + alc/uiddefs.cpp \ + alc/voice.cpp \ + common/alcomplex.cpp \ + common/alfstream.cpp \ + common/almalloc.cpp \ + common/alstring.cpp \ + common/dynload.cpp \ + common/polyphase_resampler.cpp \ + common/ringbuffer.cpp \ + common/strutils.cpp \ + common/threads.cpp \ + core/ambdec.cpp \ + core/bs2b.cpp \ + core/bsinc_tables.cpp \ + core/cpu_caps.cpp \ + core/devformat.cpp \ + core/except.cpp \ + core/filters/biquad.cpp \ + core/filters/nfc.cpp \ + core/filters/splitter.cpp \ + core/fmt_traits.cpp \ + core/fpu_ctrl.cpp \ + core/logging.cpp \ + core/mastering.cpp \ + core/mixer/mixer_c.cpp \ + core/uhjfilter.cpp \ + com_jme3_audio_android_AndroidAL.c \ + com_jme3_audio_android_AndroidALC.c \ + com_jme3_audio_android_AndroidEFX.c include $(BUILD_SHARED_LIBRARY) +# Alc/mixer/hrtf_inc.c \ + diff --git a/jme3-android-native/src/native/jme_openalsoft/Application.mk b/jme3-android-native/src/native/jme_openalsoft/Application.mk index fbc028f847..d269117ddd 100644 --- a/jme3-android-native/src/native/jme_openalsoft/Application.mk +++ b/jme3-android-native/src/native/jme_openalsoft/Application.mk @@ -1,3 +1,5 @@ -APP_PLATFORM := android-9 +APP_PLATFORM := android-19 APP_OPTIM := release -APP_ABI := all \ No newline at end of file +APP_ABI := all +APP_STL := c++_static + diff --git a/jme3-android-native/src/native/jme_openalsoft/config.h b/jme3-android-native/src/native/jme_openalsoft/config.h index f9de995283..e0f5bc73e4 100644 --- a/jme3-android-native/src/native/jme_openalsoft/config.h +++ b/jme3-android-native/src/native/jme_openalsoft/config.h @@ -2,18 +2,18 @@ #define AL_API __attribute__((visibility("protected"))) #define ALC_API __attribute__((visibility("protected"))) -/* Define to the library version */ -#define ALSOFT_VERSION "1.16.0" - -#ifdef IN_IDE_PARSER -/* KDevelop's parser doesn't recognize the C99-standard restrict keyword, but - * recent versions (at least 4.5.1) do recognize GCC's __restrict. */ -#define restrict __restrict -#endif - /* Define any available alignment declaration */ #define ALIGN(x) __attribute__((aligned(x))) +/* Define a built-in call indicating an aligned data pointer */ +#define ASSUME_ALIGNED(x, y) __builtin_assume_aligned(x, y) + +/* Define if HRTF data is embedded in the library */ +/* #undef ALSOFT_EMBED_HRTF_DATA */ + +/* Define if we have the sysconf function */ +#define HAVE_SYSCONF + /* Define if we have the C11 aligned_alloc function */ /* #undef HAVE_ALIGNED_ALLOC */ @@ -23,17 +23,21 @@ /* Define if we have the _aligned_malloc function */ /* #undef HAVE__ALIGNED_MALLOC */ +/* Define if we have the proc_pidpath function */ +/* #undef HAVE_PROC_PIDPATH */ + +/* Define if we have the getopt function */ +#define HAVE_GETOPT + /* Define if we have SSE CPU extensions */ /* #undef HAVE_SSE */ /* #undef HAVE_SSE2 */ +/* #undef HAVE_SSE3 */ /* #undef HAVE_SSE4_1 */ /* Define if we have ARM Neon CPU extensions */ /* #undef HAVE_NEON */ -/* Define if we have FluidSynth support */ -/* #undef HAVE_FLUIDSYNTH */ - /* Define if we have the ALSA backend */ /* #undef HAVE_ALSA */ @@ -49,8 +53,8 @@ /* Define if we have the QSA backend */ /* #undef HAVE_QSA */ -/* Define if we have the MMDevApi backend */ -/* #undef HAVE_MMDEVAPI */ +/* Define if we have the WASAPI backend */ +/* #undef HAVE_WASAPI */ /* Define if we have the DSound backend */ /* #undef HAVE_DSOUND */ @@ -64,6 +68,9 @@ /* Define if we have the PulseAudio backend */ /* #undef HAVE_PULSEAUDIO */ +/* Define if we have the JACK backend */ +/* #undef HAVE_JACK */ + /* Define if we have the CoreAudio backend */ /* #undef HAVE_COREAUDIO */ @@ -73,15 +80,33 @@ /* Define if we have the Wave Writer backend */ #define HAVE_WAVE +/* Define if we have the SDL2 backend */ +/* #undef HAVE_SDL2 */ + /* Define if we have the stat function */ #define HAVE_STAT /* Define if we have the lrintf function */ #define HAVE_LRINTF +/* Define if we have the modff function */ +#define HAVE_MODFF + +/* Define if we have the log2f function */ +#define HAVE_LOG2F + +/* Define if we have the cbrtf function */ +#define HAVE_CBRTF + +/* Define if we have the copysignf function */ +#define HAVE_COPYSIGNF + /* Define if we have the strtof function */ /* #undef HAVE_STRTOF */ +/* Define if we have the strnlen function */ +#define HAVE_STRNLEN + /* Define if we have the __int64 type */ /* #undef HAVE___INT64 */ @@ -91,9 +116,6 @@ /* Define to the size of a long long int type */ #define SIZEOF_LONG_LONG 8 -/* Define if we have C99 variable-length array support */ -#define HAVE_C99_VLA - /* Define if we have C99 _Bool support */ #define HAVE_C99_BOOL @@ -101,10 +123,10 @@ #define HAVE_C11_STATIC_ASSERT /* Define if we have C11 _Alignas support */ -/* #undef HAVE_C11_ALIGNAS */ +#define HAVE_C11_ALIGNAS /* Define if we have C11 _Atomic support */ -/* #undef HAVE_C11_ATOMIC */ +#define HAVE_C11_ATOMIC /* Define if we have GCC's destructor attribute */ #define HAVE_GCC_DESTRUCTOR @@ -119,7 +141,7 @@ #define HAVE_STDBOOL_H /* Define if we have stdalign.h */ -/* #undef HAVE_STDALIGN_H */ +#define HAVE_STDALIGN_H /* Define if we have windows.h */ /* #undef HAVE_WINDOWS_H */ @@ -130,17 +152,11 @@ /* Define if we have pthread_np.h */ /* #undef HAVE_PTHREAD_NP_H */ -/* Define if we have alloca.h */ -/* #undef HAVE_ALLOCA_H */ - /* Define if we have malloc.h */ #define HAVE_MALLOC_H -/* Define if we have ftw.h */ -/* #undef HAVE_FTW_H */ - -/* Define if we have io.h */ -/* #undef HAVE_IO_H */ +/* Define if we have dirent.h */ +#define HAVE_DIRENT_H /* Define if we have strings.h */ #define HAVE_STRINGS_H @@ -175,24 +191,30 @@ /* Define if we have the __cpuid() intrinsic */ /* #undef HAVE_CPUID_INTRINSIC */ +/* Define if we have the _BitScanForward64() intrinsic */ +/* #undef HAVE_BITSCANFORWARD64_INTRINSIC */ + +/* Define if we have the _BitScanForward() intrinsic */ +/* #undef HAVE_BITSCANFORWARD_INTRINSIC */ + /* Define if we have _controlfp() */ /* #undef HAVE__CONTROLFP */ /* Define if we have __control87_2() */ /* #undef HAVE___CONTROL87_2 */ -/* Define if we have ftw() */ -/* #undef HAVE_FTW */ - -/* Define if we have _wfindfirst() */ -/* #undef HAVE__WFINDFIRST */ - /* Define if we have pthread_setschedparam() */ #define HAVE_PTHREAD_SETSCHEDPARAM /* Define if we have pthread_setname_np() */ #define HAVE_PTHREAD_SETNAME_NP +/* Define if pthread_setname_np() only accepts one parameter */ +/* #undef PTHREAD_SETNAME_NP_ONE_PARAM */ + +/* Define if pthread_setname_np() accepts three parameters */ +/* #undef PTHREAD_SETNAME_NP_THREE_PARAMS */ + /* Define if we have pthread_set_name_np() */ /* #undef HAVE_PTHREAD_SET_NAME_NP */ @@ -200,4 +222,4 @@ /* #undef HAVE_PTHREAD_MUTEXATTR_SETKIND_NP */ /* Define if we have pthread_mutex_timedlock() */ -/* #undef HAVE_PTHREAD_MUTEX_TIMEDLOCK */ \ No newline at end of file +/* #undef HAVE_PTHREAD_MUTEX_TIMEDLOCK */ diff --git a/jme3-android-native/src/native/jme_openalsoft/version.h b/jme3-android-native/src/native/jme_openalsoft/version.h new file mode 100644 index 0000000000..94ce874a45 --- /dev/null +++ b/jme3-android-native/src/native/jme_openalsoft/version.h @@ -0,0 +1,10 @@ +/* Define to the library version */ +#define ALSOFT_VERSION "1.21.1" +#define ALSOFT_VERSION_NUM 1,21,1,0 + +/* Define the branch being built */ +#define ALSOFT_GIT_BRANCH "HEAD" + +/* Define the hash of the head commit */ +#define ALSOFT_GIT_COMMIT_HASH "ae4eacf1" + diff --git a/jme3-bullet-native-android/build.gradle b/jme3-bullet-native-android/build.gradle deleted file mode 100644 index fecb39b39f..0000000000 --- a/jme3-bullet-native-android/build.gradle +++ /dev/null @@ -1,131 +0,0 @@ -String jmeBulletNativeProjectPath = project(":jme3-bullet-native").projectDir - -String localUnzipPath = jmeBulletNativeProjectPath -String localZipFile = jmeBulletNativeProjectPath + File.separator + bulletZipFile -String localZipFolder = jmeBulletNativeProjectPath + File.separator + bulletFolder -String bulletSrcPath = localZipFolder + File.separator + 'src' - -String jmeAndroidPath = 'src/native/android' -String jmeCppPath = jmeBulletNativeProjectPath + '/src/native/cpp' - -//Working directories for the ndk build. -String ndkWorkingPath = "${buildDir}" + '/bullet' -String jniPath = ndkWorkingPath + '/jni' -String ndkOutputPath = ndkWorkingPath + '/libs' - -//Pre-compiled libs directory -def rootPath = rootProject.projectDir.absolutePath -String bulletPreCompiledLibsDir = rootPath + File.separator + 'build' + File.separator + 'native' + File.separator + 'android' + File.separator + 'bullet' - -if (!hasProperty('mainClass')) { - ext.mainClass = '' -} - -dependencies { - compile project(':jme3-bullet') -} - -// Java source sets for IDE access and source jar bundling / mavenization -sourceSets { - main { - java { - srcDir jmeCppPath - srcDir jmeAndroidPath - } - } -} - -// Download bullet if not available -task downloadBullet(type: MyDownload) { - sourceUrl = bulletUrl - target = file(localZipFile) -} - -// Unzip bullet if not available -task unzipBullet(type: Copy) { - from zipTree(localZipFile) - into file(localUnzipPath) -} - -unzipBullet.dependsOn { - if (!file(localZipFile).exists()) { - downloadBullet - } -} - -// Copy Bullet files to jni directory -task copyBullet(type: Copy) { - from file(bulletSrcPath) - into file(jniPath) -} - -copyBullet.dependsOn { - if (!file(localZipFolder).isDirectory()) { - unzipBullet - } -} - -// Copy jME cpp native files to jni directory -task copyJmeCpp(type: Copy) { - from file(jmeCppPath) - into file(jniPath) -} - -// Copy jME android native files to jni directory -task copyJmeAndroid(type: Copy) { - from file(jmeAndroidPath) - into file(jniPath) -} - -task buildBulletNativeLib(type: Exec, dependsOn: [copyJmeAndroid, ':jme3-bullet:compileJava', copyJmeCpp, copyBullet]) { -// args 'TARGET_PLATFORM=android-9' -// println "buildBulletNativeLib ndkWorkingPath: " + ndkWorkingPath -// println "buildBulletNativeLib rootProject.ndkCommandPath: " + rootProject.ndkCommandPath - workingDir ndkWorkingPath - executable rootProject.ndkCommandPath - args "-j" + Runtime.runtime.availableProcessors() -} - -/* The following two tasks: We store a prebuilt version in the repository, so nobody has to build - * natives in order to build the engine. When building these natives however, the prebuilt libraries - * can be updated (which is what the CI does). That's what the following two tasks do - */ - -task updatePreCompiledBulletLibs(type: Copy, dependsOn: buildBulletNativeLib) { - from file(ndkOutputPath) - into file(bulletPreCompiledLibsDir) -} - -// Copy pre-compiled libs to build directory (when not building new libs) -task copyPreCompiledBulletLibs(type: Copy) { - from file(bulletPreCompiledLibsDir) - into file(ndkOutputPath) -} - -// ndkExists is a boolean from the build.gradle in the root project -// buildNativeProjects is a string set to "true" -if (ndkExists && buildNativeProjects == "true") { - // build native libs and update stored pre-compiled libs to commit - compileJava.dependsOn { updatePreCompiledBulletLibs } -} else { - // use pre-compiled native libs (not building new ones) - compileJava.dependsOn { copyPreCompiledBulletLibs } -} - -jar.into("lib") { from ndkOutputPath } - - -// Helper class to wrap ant download task -class MyDownload extends DefaultTask { - @Input - String sourceUrl - - @OutputFile - File target - - @TaskAction - void download() { - ant.get(src: sourceUrl, dest: target) - } -} - diff --git a/jme3-bullet-native-android/src/native/android/Android.mk b/jme3-bullet-native-android/src/native/android/Android.mk deleted file mode 100644 index d04478e285..0000000000 --- a/jme3-bullet-native-android/src/native/android/Android.mk +++ /dev/null @@ -1,77 +0,0 @@ -# /* -# Bullet Continuous Collision Detection and Physics Library for Android NDK -# Copyright (c) 2006-2009 Noritsuna Imamura http://www.siprop.org/ -# -# This software is provided 'as-is', without any express or implied warranty. -# In no event will the authors be held liable for any damages arising from the use of this software. -# Permission is granted to anyone to use this software for any purpose, -# including commercial applications, and to alter it and redistribute it freely, -# subject to the following restrictions: -# -# 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -# 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -# 3. This notice may not be removed or altered from any source distribution. -# */ -LOCAL_PATH:= $(call my-dir) -BULLET_PATH:= ${LOCAL_PATH}/../ - -include $(CLEAR_VARS) - -LOCAL_MODULE := bulletjme -LOCAL_C_INCLUDES := $(BULLET_PATH)/\ - $(BULLET_PATH)/BulletCollision\ - $(BULLET_PATH)/BulletCollision/BroadphaseCollision\ - $(BULLET_PATH)/BulletCollision/CollisionDispatch\ - $(BULLET_PATH)/BulletCollision/CollisionShapes\ - $(BULLET_PATH)/BulletCollision/NarrowPhaseCollision\ - $(BULLET_PATH)/BulletCollision/Gimpact\ - $(BULLET_PATH)/BulletDynamics\ - $(BULLET_PATH)/BulletDynamics/ConstraintSolver\ - $(BULLET_PATH)/BulletDynamics/Dynamics\ - $(BULLET_PATH)/BulletDynamics/Vehicle\ - $(BULLET_PATH)/BulletDynamics/Character\ - $(BULLET_PATH)/BulletMultiThreaded\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers\ - $(BULLET_PATH)/BulletMultiThreaded/SpuNarrowPhaseCollisionTask\ - $(BULLET_PATH)/BulletMultiThreaded/SpuSampleTask\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/CPU\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/DX11\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/DX11/HLSL\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/AMD\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/Apple\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/MiniCL\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/NVidia\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC\ - $(BULLET_PATH)/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10\ - $(BULLET_PATH)/LinearMath\ - $(BULLET_PATH)/BulletSoftBody\ - $(BULLET_PATH)/LinearMath\ - $(BULLET_PATH)/MiniCL\ - $(BULLET_PATH)/MiniCL/MiniCLTask\ - $(BULLET_PATH)/vectormath\ - $(BULLET_PATH)/vectormath/scalar\ - $(BULLET_PATH)/vectormath/sse\ - $(BULLET_PATH)/vectormath/neon - -#ARM mode more performant than thumb for old armeabi -ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI), armeabi)) -LOCAL_ARM_MODE := arm -endif - -#Enable neon for armv7 -ifeq ($(TARGET_ARCH_ABI),$(filter $(TARGET_ARCH_ABI), armeabi-v7a)) -LOCAL_ARM_NEON := true -endif - -LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ldl -lm -llog - -FILE_LIST := $(wildcard $(LOCAL_PATH)/*.cpp) -FILE_LIST += $(wildcard $(LOCAL_PATH)/**/*.cpp) -FILE_LIST += $(wildcard $(LOCAL_PATH)/**/**/*.cpp) -FILE_LIST := $(filter-out $(wildcard $(LOCAL_PATH)/Bullet3OpenCL/**/*.cpp), $(FILE_LIST)) -FILE_LIST := $(filter-out $(wildcard $(LOCAL_PATH)/*All.cpp), $(FILE_LIST)) -LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) - -include $(BUILD_SHARED_LIBRARY) diff --git a/jme3-bullet-native-android/src/native/android/Application.mk b/jme3-bullet-native-android/src/native/android/Application.mk deleted file mode 100644 index 6467a5a7f9..0000000000 --- a/jme3-bullet-native-android/src/native/android/Application.mk +++ /dev/null @@ -1,7 +0,0 @@ -APP_OPTIM := release -APP_ABI := all -# Used to be stlport_static, but that has been removed. -APP_STL := c++_static -APP_MODULES := bulletjme -APP_CFLAGS += -funroll-loops -Ofast - diff --git a/jme3-bullet-native/build.gradle b/jme3-bullet-native/build.gradle deleted file mode 100644 index 745630a3b8..0000000000 --- a/jme3-bullet-native/build.gradle +++ /dev/null @@ -1,276 +0,0 @@ -apply plugin: 'cpp' - -import java.nio.file.Paths - -def rootPath = rootProject.projectDir.absolutePath - -String bulletSrcPath = bulletFolder + '/src' - -if (!hasProperty('mainClass')) { - ext.mainClass = '' -} - -dependencies { - compile project(':jme3-bullet') -} -clean { dependsOn 'cleanHeaders', 'cleanUnzipped' } - -// clean up auto-generated C++ headers -task cleanHeaders(type: Delete) { - delete fileTree(dir: 'src/native/cpp', include: 'com_jme3_bullet_*.h') -} -// clean up unzipped files -task cleanUnzipped(type: Delete) { - delete bulletFolder -} -// clean up the downloaded archive -task cleanZipFile(type: Delete) { - delete bulletZipFile -} - -model { - components { - bulletjme(NativeLibrarySpec) { - - - String[] targets=[ - "Windows64", - "Windows32", - "Mac64", - "Linux64", - "Linux32", - "LinuxArm", - "LinuxArmHF", - "LinuxArm64" - ]; - - String[] filter=gradle.rootProject.ext.usePrebuildNatives==true?null:buildForPlatforms.split(","); - if(filter==null)println("No filter set. build for all"); - for(String target:targets){ - if(filter==null){ - targetPlatform(target); - }else{ - for(String f:filter){ - if(f.equals(target)){ - targetPlatform(target); - break; - } - } - } - } - - sources { - cpp { - source { - srcDir 'src/native/cpp' - srcDir bulletSrcPath - exclude 'Bullet3Collision/**' - exclude 'Bullet3Dynamics/**' - exclude 'Bullet3Geometry/**' - exclude 'Bullet3OpenCL/**' - exclude 'Bullet3Serialize/**' - include '**/*.cpp' - exclude '**/*All.cpp' - } - exportedHeaders { - srcDir 'src/native/cpp' - srcDir bulletSrcPath - exclude 'Bullet3Collision/**' - exclude 'Bullet3Dynamics/**' - exclude 'Bullet3Geometry/**' - exclude 'Bullet3OpenCL/**' - exclude 'Bullet3Serialize/**' - include '**/*.h' - } - } - } - } - } - - - toolChains { - visualCpp(VisualCpp) - gcc(Gcc) - clang(Clang) - gccArm(Gcc) { - // Fun Fact: Gradle uses gcc as linker frontend, so we don't specify ld directly here - target("LinuxArm"){ - path "/usr/bin" - cCompiler.executable = "arm-linux-gnueabi-gcc-8" - cppCompiler.executable = "arm-linux-gnueabi-g++-8" - linker.executable = "arm-linux-gnueabi-gcc-8" - assembler.executable = "arm-linux-gnueabi-as" - } - - target("LinuxArmHF"){ - path "/usr/bin" - cCompiler.executable = "arm-linux-gnueabihf-gcc-8" - cppCompiler.executable = "arm-linux-gnueabihf-g++-8" - linker.executable = "arm-linux-gnueabihf-gcc-8" - assembler.executable = "arm-linux-gnueabihf-as" - } - - target("LinuxArm64"){ - path "/usr/bin" - cCompiler.executable = "aarch64-linux-gnu-gcc-8" - cppCompiler.executable = "aarch64-linux-gnu-g++-8" - linker.executable = "aarch64-linux-gnu-gcc-8" - assembler.executable = "aarch64-linux-gnu-as" - } - } - } - - binaries { - withType(SharedLibraryBinarySpec) { - def javaHome = org.gradle.internal.jvm.Jvm.current().javaHome - def os = targetPlatform.operatingSystem.name - def arch = targetPlatform.architecture.name - def fileName = sharedLibraryFile.name - - // Gradle decided to change underscores to dashes - fix that. - arch = arch.replaceAll('-', '_') - - // For all binaries that can't be built on the current system - if (buildNativeProjects != "true") buildable = false - - if (buildable) { - cppCompiler.define('BT_NO_PROFILE') - if (toolChain in VisualCpp) { - cppCompiler.args "/I$javaHome\\include" - } else{ - cppCompiler.args '-I', "$javaHome/include" - } - - if (os == "osx") { - cppCompiler.args '-I', "$javaHome/include/darwin" - cppCompiler.args "-O3" - cppCompiler.args "-U_FORTIFY_SOURCE" - } else if (os == "linux") { - cppCompiler.args "-fvisibility=hidden" - cppCompiler.args '-I', "$javaHome/include/linux" - cppCompiler.args "-fPIC" - cppCompiler.args "-O3" - cppCompiler.args "-U_FORTIFY_SOURCE" - cppCompiler.args "-fpermissive" - linker.args "-fvisibility=hidden" - } else if (os == "windows") { - if (toolChain in Gcc) { - if (toolChain.name.startsWith('mingw')) cppCompiler.args '-I', "$projectDir/src/native/cpp/fake_win32" - else cppCompiler.args '-I', "$javaHome/include/win32" - cppCompiler.args "-fpermissive" - cppCompiler.args "-static" - cppCompiler.args "-O3" - cppCompiler.args "-U_FORTIFY_SOURCE" - linker.args "-static" - linker.args "-Wl,--exclude-all-symbols" - } else if (toolChain in VisualCpp) { - cppCompiler.args "/I$javaHome\\include\\win32" - } - cppCompiler.define('WIN32') - } - tasks.all { - dependsOn unzipBulletIfNeeded - dependsOn ':jme3-bullet:compileJava' - } - - task "copyBinaryToLibs${targetPlatform.name}"(type: Copy, dependsOn: tasks) { - from sharedLibraryFile - into "${rootPath}/build/native/bullet/native/${os}/${arch}" - } - - // Add depend on copy - jar.dependsOn("copyBinaryToLibs${targetPlatform.name}") - - } - } - withType(StaticLibraryBinarySpec) { - buildable = false - } - } - - platforms { - Windows32 { - architecture "x86" - operatingSystem "windows" - } - Windows64 { - architecture "x86_64" - operatingSystem "windows" - } - Mac64 { - architecture "x86_64" - operatingSystem "osx" - } - Linux32 { - architecture "x86" - operatingSystem "linux" - } - Linux64 { - architecture "x86_64" - operatingSystem "linux" - } - LinuxArm { - architecture "arm" - operatingSystem "linux" - } - LinuxArmHF { - architecture "armhf" - operatingSystem "linux" - } - LinuxArm64 { - architecture "aarch64" - operatingSystem "linux" - } - } -} - -// Java source sets for IDE access and source jar bundling / mavenization -sourceSets { - main { - java { - srcDir 'src/native/cpp' - } - resources { - srcDir file(Paths.get(rootPath, 'build', 'native', 'bullet')) - } - } -} - -task downloadBullet(type: MyDownload) { - sourceUrl = bulletUrl - target = file(bulletZipFile) -} - -task unzipBullet(type: Copy) { - from zipTree(bulletZipFile) - into file('.') -} - -unzipBullet.dependsOn { - if (!file(bulletZipFile).exists()) { - downloadBullet - } -} - -task unzipBulletIfNeeded { -} - -unzipBulletIfNeeded.dependsOn { - if (buildNativeProjects == "true") { - unzipBullet - } -} - -// Helper class to wrap ant download task -class MyDownload extends DefaultTask { - @Input - String sourceUrl - - @OutputFile - File target - - @TaskAction - void download() { - ant.get(src: sourceUrl, dest: target) - } -} diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp deleted file mode 100644 index 4e143cb4a6..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp +++ /dev/null @@ -1,551 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "com_jme3_bullet_PhysicsSpace.h" -#include "jmePhysicsSpace.h" -#include "jmeBulletUtil.h" - -/** - * Author: Normen Hansen - */ -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: createPhysicsSpace - * Signature: (FFFFFFI)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_PhysicsSpace_createPhysicsSpace - (JNIEnv * env, jobject object, jfloat minX, jfloat minY, jfloat minZ, - jfloat maxX, jfloat maxY, jfloat maxZ, jint broadphase, - jboolean threading) { - jmeClasses::initJavaClasses(env); - - jmePhysicsSpace* space = new jmePhysicsSpace(env, object); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space has not been created."); - return 0; - } - - space->createPhysicsSpace(minX, minY, minZ, maxX, maxY, maxZ, - broadphase, threading); - return reinterpret_cast (space); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: stepSimulation - * Signature: (JFIF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_stepSimulation - (JNIEnv * env, jobject object, jlong spaceId, jfloat tpf, jint maxSteps, - jfloat accuracy) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - space->stepSimulation(tpf, maxSteps, accuracy); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addCollisionObject - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addCollisionObject - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btCollisionObject* collisionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer(); - userPointer -> space = space; - - space->getDynamicsWorld()->addCollisionObject(collisionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: removeCollisionObject - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeCollisionObject - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btCollisionObject* collisionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - space->getDynamicsWorld()->removeCollisionObject(collisionObject); - jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer(); - userPointer -> space = NULL; - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addRigidBody - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addRigidBody - (JNIEnv * env, jobject object, jlong spaceId, jlong rigidBodyId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btRigidBody* collisionObject = reinterpret_cast (rigidBodyId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer(); - userPointer -> space = space; - space->getDynamicsWorld()->addRigidBody(collisionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: removeRigidBody - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeRigidBody - (JNIEnv * env, jobject object, jlong spaceId, jlong rigidBodyId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btRigidBody* collisionObject = reinterpret_cast (rigidBodyId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer(); - userPointer -> space = NULL; - space->getDynamicsWorld()->removeRigidBody(collisionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addCharacterObject - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addCharacterObject - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btCollisionObject* collisionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer(); - userPointer -> space = space; - space->getDynamicsWorld()->addCollisionObject(collisionObject, - btBroadphaseProxy::CharacterFilter, - btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter - ); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: removeCharacterObject - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeCharacterObject - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btCollisionObject* collisionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*) collisionObject->getUserPointer(); - userPointer -> space = NULL; - space->getDynamicsWorld()->removeCollisionObject(collisionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addAction - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addAction - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btActionInterface* actionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (actionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The action object does not exist."); - return; - } - space->getDynamicsWorld()->addAction(actionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: removeAction - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeAction - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btActionInterface* actionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (actionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The action object does not exist."); - return; - } - space->getDynamicsWorld()->removeAction(actionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addVehicle - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addVehicle - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btActionInterface* actionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (actionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The vehicle object does not exist."); - return; - } - space->getDynamicsWorld()->addVehicle(actionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: removeVehicle - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeVehicle - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btActionInterface* actionObject = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (actionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The action object does not exist."); - return; - } - space->getDynamicsWorld()->removeVehicle(actionObject); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addConstraint - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addConstraint - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btTypedConstraint* constraint = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (constraint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The constraint object does not exist."); - return; - } - space->getDynamicsWorld()->addConstraint(constraint); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: addConstraint - * Signature: (JJZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addConstraintC - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId, jboolean collision) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btTypedConstraint* constraint = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (constraint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The constraint object does not exist."); - return; - } - space->getDynamicsWorld()->addConstraint(constraint, collision); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: removeConstraint - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeConstraint - (JNIEnv * env, jobject object, jlong spaceId, jlong objectId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - btTypedConstraint* constraint = reinterpret_cast (objectId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - if (constraint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The constraint object does not exist."); - return; - } - space->getDynamicsWorld()->removeConstraint(constraint); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: setGravity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setGravity - (JNIEnv * env, jobject object, jlong spaceId, jobject vector) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - btVector3 gravity = btVector3(); - jmeBulletUtil::convert(env, vector, &gravity); - - space->getDynamicsWorld()->setGravity(gravity); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: initNativePhysics - * Signature: ()V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_initNativePhysics - (JNIEnv * env, jclass clazz) { - jmeClasses::initJavaClasses(env); - } - - /* - * Class: com_jme3_bullet_PhysicsSpace - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_finalizeNative - (JNIEnv * env, jobject object, jlong spaceId) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - if (space == NULL) { - return; - } - delete(space); - } - - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_rayTest_1native - (JNIEnv * env, jobject object, jobject from, jobject to, jlong spaceId, jobject resultlist, jint flags) { - - jmePhysicsSpace* space = reinterpret_cast (spaceId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - - struct AllRayResultCallback : public btCollisionWorld::RayResultCallback { - - AllRayResultCallback(const btVector3& rayFromWorld, const btVector3 & rayToWorld) : m_rayFromWorld(rayFromWorld), m_rayToWorld(rayToWorld) { - } - jobject resultlist; - JNIEnv* env; - btVector3 m_rayFromWorld; //used to calculate hitPointWorld from hitFraction - btVector3 m_rayToWorld; - - btVector3 m_hitNormalWorld; - btVector3 m_hitPointWorld; - - virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) { - if (normalInWorldSpace) { - m_hitNormalWorld = rayResult.m_hitNormalLocal; - } else { - m_hitNormalWorld = m_collisionObject->getWorldTransform().getBasis() * rayResult.m_hitNormalLocal; - } - m_hitPointWorld.setInterpolate3(m_rayFromWorld, m_rayToWorld, rayResult.m_hitFraction); - - jmeBulletUtil::addResult(env, resultlist, &m_hitNormalWorld, &m_hitPointWorld, rayResult.m_hitFraction, rayResult.m_collisionObject); - - return 1.f; - } - }; - - btVector3 native_to = btVector3(); - jmeBulletUtil::convert(env, to, &native_to); - - btVector3 native_from = btVector3(); - jmeBulletUtil::convert(env, from, &native_from); - - AllRayResultCallback resultCallback(native_from, native_to); - resultCallback.env = env; - resultCallback.resultlist = resultlist; - resultCallback.m_flags = flags; - space->getDynamicsWorld()->rayTest(native_from, native_to, resultCallback); - - return; - } - - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_sweepTest_1native - (JNIEnv * env, jobject object, jlong shapeId, jobject from, jobject to, jlong spaceId, jobject resultlist, jfloat allowedCcdPenetration) { - - jmePhysicsSpace* space = reinterpret_cast (spaceId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - - btCollisionShape* shape = reinterpret_cast (shapeId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The shape does not exist."); - return; - } - - struct AllConvexResultCallback : public btCollisionWorld::ConvexResultCallback { - - AllConvexResultCallback(const btTransform& convexFromWorld, const btTransform & convexToWorld) : m_convexFromWorld(convexFromWorld), m_convexToWorld(convexToWorld) { - } - jobject resultlist; - JNIEnv* env; - btTransform m_convexFromWorld; //used to calculate hitPointWorld from hitFraction - btTransform m_convexToWorld; - - btVector3 m_hitNormalWorld; - btVector3 m_hitPointWorld; - - virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& convexResult, bool normalInWorldSpace) { - if (normalInWorldSpace) { - m_hitNormalWorld = convexResult.m_hitNormalLocal; - } else { - m_hitNormalWorld = convexResult.m_hitCollisionObject->getWorldTransform().getBasis() * convexResult.m_hitNormalLocal; - } - m_hitPointWorld.setInterpolate3(m_convexFromWorld.getBasis() * m_convexFromWorld.getOrigin(), m_convexToWorld.getBasis() * m_convexToWorld.getOrigin(), convexResult.m_hitFraction); - - jmeBulletUtil::addSweepResult(env, resultlist, &m_hitNormalWorld, &m_hitPointWorld, convexResult.m_hitFraction, convexResult.m_hitCollisionObject); - - return 1.f; - } - }; - - btTransform native_to = btTransform(); - jmeBulletUtil::convert(env, to, &native_to); - - btTransform native_from = btTransform(); - jmeBulletUtil::convert(env, from, &native_from); - - btScalar native_allowed_ccd_penetration = btScalar(allowedCcdPenetration); - - AllConvexResultCallback resultCallback(native_from, native_to); - resultCallback.env = env; - resultCallback.resultlist = resultlist; - space->getDynamicsWorld()->convexSweepTest((btConvexShape *) shape, native_from, native_to, resultCallback, native_allowed_ccd_penetration); - return; - } - - JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations - (JNIEnv *env, jobject object, jlong spaceId, jint value) { - jmePhysicsSpace* space = reinterpret_cast (spaceId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The physics space does not exist."); - return; - } - - space->getDynamicsWorld()->getSolverInfo().m_numIterations = value; - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_PhysicsCollisionEvent.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_PhysicsCollisionEvent.cpp deleted file mode 100644 index 071f0d59c8..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_PhysicsCollisionEvent.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "jmeBulletUtil.h" -#include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" -#include "com_jme3_bullet_collision_PhysicsCollisionEvent.h" - -// Change to trigger build - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getAppliedImpulse - * Signature: (J)F - */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getAppliedImpulse - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_appliedImpulse; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getAppliedImpulseLateral1 - * Signature: (J)F - */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getAppliedImpulseLateral1 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_appliedImpulseLateral1; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getAppliedImpulseLateral2 - * Signature: (J)F - */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getAppliedImpulseLateral2 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_appliedImpulseLateral2; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getCombinedFriction - * Signature: (J)F - */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getCombinedFriction - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_combinedFriction; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getCombinedRestitution - * Signature: (J)F - */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getCombinedRestitution - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_combinedRestitution; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getDistance1 - * Signature: (J)F - */ -JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getDistance1 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_distance1; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getIndex0 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getIndex0 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_index0; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getIndex1 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getIndex1 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_index1; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getLateralFrictionDir1 - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getLateralFrictionDir1 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject lateralFrictionDir1) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_lateralFrictionDir1, lateralFrictionDir1); -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getLateralFrictionDir2 - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getLateralFrictionDir2 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject lateralFrictionDir2) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_lateralFrictionDir2, lateralFrictionDir2); -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: isLateralFrictionInitialized - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_isLateralFrictionInitialized - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return (mp -> m_contactPointFlags) & BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getLifeTime - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getLifeTime - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_lifeTime; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getLocalPointA - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getLocalPointA - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject localPointA) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_localPointA, localPointA); -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getLocalPointB - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getLocalPointB - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject localPointB) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_localPointB, localPointB); -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getNormalWorldOnB - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getNormalWorldOnB - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject normalWorldOnB) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_normalWorldOnB, normalWorldOnB); -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getPartId0 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getPartId0 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_partId0; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getPartId1 - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getPartId1 - (JNIEnv * env, jobject object, jlong manifoldPointObjectId) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return 0; - } - return mp -> m_partId1; -} - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getPositionWorldOnA - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getPositionWorldOnA - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject positionWorldOnA) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_positionWorldOnA, positionWorldOnA); -} - - -/* - * Class: com_jme3_bullet_collision_PhysicsCollisionEvent - * Method: getPositionWorldOnB - * Signature: (JLcom/jme3/math/Vector3f;)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionEvent_getPositionWorldOnB - (JNIEnv * env, jobject object, jlong manifoldPointObjectId, jobject positionWorldOnB) { - btManifoldPoint* mp = reinterpret_cast(manifoldPointObjectId); - if (mp == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The manifoldPoint does not exist."); - return; - } - jmeBulletUtil::convert(env, &mp -> m_positionWorldOnB, positionWorldOnB); -} diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_PhysicsCollisionObject.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_PhysicsCollisionObject.cpp deleted file mode 100644 index 15d27849ce..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_PhysicsCollisionObject.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_PhysicsCollisionObject.h" -#include "jmeBulletUtil.h" -#include "jmePhysicsSpace.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: attachCollisionShape - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_attachCollisionShape - (JNIEnv * env, jobject object, jlong objectId, jlong shapeId) { - btCollisionObject* collisionObject = reinterpret_cast(objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/IllegalStateException"); - env->ThrowNew(newExc, "The collision object does not exist."); - return; - } - btCollisionShape* collisionShape = reinterpret_cast(shapeId); - if (collisionShape == NULL) { - jclass newExc = env->FindClass("java/lang/IllegalStateException"); - env->ThrowNew(newExc, "The collision shape does not exist."); - return; - } - collisionObject->setCollisionShape(collisionShape); - } - - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_finalizeNative - (JNIEnv * env, jobject object, jlong objectId) { - btCollisionObject* collisionObject = reinterpret_cast(objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - if (collisionObject -> getUserPointer() != NULL){ - jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer(); - delete(userPointer); - } - delete(collisionObject); - } - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: initUserPointer - * Signature: (JII)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_initUserPointer - (JNIEnv *env, jobject object, jlong objectId, jint group, jint groups) { - btCollisionObject* collisionObject = reinterpret_cast(objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer(); - if (userPointer != NULL) { -// delete(userPointer); - } - userPointer = new jmeUserPointer(); - userPointer -> javaCollisionObject = env->NewWeakGlobalRef(object); - userPointer -> group = group; - userPointer -> groups = groups; - userPointer -> space = NULL; - collisionObject -> setUserPointer(userPointer); - } - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: setCollisionGroup - * Signature: (JI)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollisionGroup - (JNIEnv *env, jobject object, jlong objectId, jint group) { - btCollisionObject* collisionObject = reinterpret_cast(objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer(); - if (userPointer != NULL){ - userPointer -> group = group; - } - } - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: setCollideWithGroups - * Signature: (JI)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollideWithGroups - (JNIEnv *env, jobject object, jlong objectId, jint groups) { - btCollisionObject* collisionObject = reinterpret_cast(objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeUserPointer *userPointer = (jmeUserPointer*)collisionObject->getUserPointer(); - if (userPointer != NULL){ - userPointer -> groups = groups; - } - } - - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: getCollisionFlags - * Signature: (J)I - */ - JNIEXPORT jint JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_getCollisionFlags - (JNIEnv *env, jobject object, jlong objectId) { - btCollisionObject* collisionObject = reinterpret_cast (objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - - jint result = collisionObject->getCollisionFlags(); - return result; - } - - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: setCollisionFlags - * Signature: (JI)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_setCollisionFlags - (JNIEnv *env, jobject object, jlong objectId, jint desiredFlags) { - btCollisionObject* collisionObject = reinterpret_cast (objectId); - if (collisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - - collisionObject->setCollisionFlags(desiredFlags); - } - - /* - * Class: com_jme3_bullet_collision_PhysicsCollisionObject - * Method: getDeactivationTime - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_PhysicsCollisionObject_getDeactivationTime - (JNIEnv *env, jobject object, jlong pcoId) { - btCollisionObject *pCollisionObject - = reinterpret_cast (pcoId); - if (pCollisionObject == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - - jfloat result = pCollisionObject->getDeactivationTime(); - return result; - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_BoxCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_BoxCollisionShape.cpp deleted file mode 100644 index d5af179307..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_BoxCollisionShape.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_BoxCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_BoxCollisionShape - * Method: createShape - * Signature: (Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_BoxCollisionShape_createShape - (JNIEnv *env, jobject object, jobject halfExtents) { - jmeClasses::initJavaClasses(env); - btVector3 extents = btVector3(); - jmeBulletUtil::convert(env, halfExtents, &extents); - btBoxShape* shape = new btBoxShape(extents); - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CapsuleCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CapsuleCollisionShape.cpp deleted file mode 100644 index fd3957ba13..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CapsuleCollisionShape.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_CapsuleCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_CapsuleCollisionShape - * Method: createShape - * Signature: (IFF)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CapsuleCollisionShape_createShape - (JNIEnv * env, jobject object, jint axis, jfloat radius, jfloat height) { - jmeClasses::initJavaClasses(env); - btCollisionShape* shape; - switch(axis){ - case 0: - shape = new btCapsuleShapeX(radius, height); - break; - case 1: - shape = new btCapsuleShape(radius, height); - break; - case 2: - shape = new btCapsuleShapeZ(radius, height); - break; - } - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CollisionShape.cpp deleted file mode 100644 index bfdaa20de6..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CollisionShape.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_CollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_CollisionShape - * Method: getMargin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_collision_shapes_CollisionShape_getMargin - (JNIEnv * env, jobject object, jlong shapeId) { - btCollisionShape* shape = reinterpret_cast(shapeId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return shape->getMargin(); - } - - /* - * Class: com_jme3_bullet_collision_shapes_CollisionShape - * Method: setLocalScaling - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_CollisionShape_setLocalScaling - (JNIEnv * env, jobject object, jlong shapeId, jobject scale) { - btCollisionShape* shape = reinterpret_cast(shapeId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 scl = btVector3(); - jmeBulletUtil::convert(env, scale, &scl); - shape->setLocalScaling(scl); - } - - /* - * Class: com_jme3_bullet_collision_shapes_CollisionShape - * Method: setMargin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_CollisionShape_setMargin - (JNIEnv * env, jobject object, jlong shapeId, jfloat newMargin) { - btCollisionShape* shape = reinterpret_cast(shapeId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - shape->setMargin(newMargin); - } - - /* - * Class: com_jme3_bullet_collision_shapes_CollisionShape - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_CollisionShape_finalizeNative - (JNIEnv * env, jobject object, jlong shapeId) { - btCollisionShape* shape = reinterpret_cast(shapeId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - delete(shape); - } - - /* - * Class: com_jme3_bullet_collision_shapes_CollisionShape - * Method: isNonMoving - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_collision_shapes_CollisionShape_isNonMoving - (JNIEnv *env, jobject object, jlong shapeId) { - btCollisionShape *pShape - = reinterpret_cast (shapeId); - if (pShape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - - return pShape->isNonMoving(); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CompoundCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CompoundCollisionShape.cpp deleted file mode 100644 index c3b07f45d4..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CompoundCollisionShape.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_CompoundCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Class: com_jme3_bullet_collision_shapes_CompoundCollisionShape - * Method: createShape - * Signature: ()J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_createShape - (JNIEnv *env, jobject object) { - jmeClasses::initJavaClasses(env); - btCompoundShape* shape = new btCompoundShape(); - return reinterpret_cast(shape); - } - - /* - * Class: com_jme3_bullet_collision_shapes_CompoundCollisionShape - * Method: addChildShape - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_addChildShape - (JNIEnv *env, jobject object, jlong compoundId, jlong childId, jobject childLocation, jobject childRotation) { - btCompoundShape* shape = reinterpret_cast(compoundId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btCollisionShape* child = reinterpret_cast(childId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btMatrix3x3 mtx = btMatrix3x3(); - btTransform trans = btTransform(mtx); - jmeBulletUtil::convert(env, childLocation, &trans.getOrigin()); - jmeBulletUtil::convert(env, childRotation, &trans.getBasis()); - shape->addChildShape(trans, child); - return 0; - } - - /* - * Class: com_jme3_bullet_collision_shapes_CompoundCollisionShape - * Method: removeChildShape - * Signature: (JJ)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CompoundCollisionShape_removeChildShape - (JNIEnv * env, jobject object, jlong compoundId, jlong childId) { - btCompoundShape* shape = reinterpret_cast(compoundId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btCollisionShape* child = reinterpret_cast(childId); - if (shape == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - shape->removeChildShape(child); - return 0; - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_ConeCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_ConeCollisionShape.cpp deleted file mode 100644 index d218975b08..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_ConeCollisionShape.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_ConeCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_ConeCollisionShape - * Method: createShape - * Signature: (IFF)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_ConeCollisionShape_createShape - (JNIEnv * env, jobject object, jint axis, jfloat radius, jfloat height) { - jmeClasses::initJavaClasses(env); - btCollisionShape* shape; - switch (axis) { - case 0: - shape = new btConeShapeX(radius, height); - break; - case 1: - shape = new btConeShape(radius, height); - break; - case 2: - shape = new btConeShapeZ(radius, height); - break; - } - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CylinderCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CylinderCollisionShape.cpp deleted file mode 100644 index fbab5baf7c..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_CylinderCollisionShape.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_CylinderCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_CylinderCollisionShape - * Method: createShape - * Signature: (ILcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_CylinderCollisionShape_createShape - (JNIEnv * env, jobject object, jint axis, jobject halfExtents) { - jmeClasses::initJavaClasses(env); - btVector3 extents = btVector3(); - jmeBulletUtil::convert(env, halfExtents, &extents); - btCollisionShape* shape; - switch (axis) { - case 0: - shape = new btCylinderShapeX(extents); - break; - case 1: - shape = new btCylinderShape(extents); - break; - case 2: - shape = new btCylinderShapeZ(extents); - break; - } - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_GImpactCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_GImpactCollisionShape.cpp deleted file mode 100644 index 71a3d3742b..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_GImpactCollisionShape.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_GImpactCollisionShape.h" -#include "jmeBulletUtil.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_GImpactCollisionShape - * Method: createShape - * Signature: (J)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_GImpactCollisionShape_createShape - (JNIEnv * env, jobject object, jlong meshId) { - jmeClasses::initJavaClasses(env); - btTriangleIndexVertexArray* array = reinterpret_cast(meshId); - btGImpactMeshShape* shape = new btGImpactMeshShape(array); - shape->updateBound(); - return reinterpret_cast(shape); - } - - /* - * Class: com_jme3_bullet_collision_shapes_GImpactCollisionShape - * Method: recalcAabb - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_GImpactCollisionShape_recalcAabb - (JNIEnv *env, jobject object, jlong shapeId) { - btGImpactMeshShape *pShape - = reinterpret_cast (shapeId); - pShape->updateBound(); - } - - /* - * Class: com_jme3_bullet_collision_shapes_GImpactCollisionShape - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_GImpactCollisionShape_finalizeNative - (JNIEnv * env, jobject object, jlong meshId) { - btTriangleIndexVertexArray* array = reinterpret_cast (meshId); - delete(array); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_HeightfieldCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_HeightfieldCollisionShape.cpp deleted file mode 100644 index c217e3a2d6..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_HeightfieldCollisionShape.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_HeightfieldCollisionShape.h" -#include "jmeBulletUtil.h" -#include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_HeightfieldCollisionShape - * Method: createShape - * Signature: (II[FFFFIZ)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_HeightfieldCollisionShape_createShape - (JNIEnv * env, jobject object, jint heightStickWidth, jint heightStickLength, jobject heightfieldData, jfloat heightScale, jfloat minHeight, jfloat maxHeight, jint upAxis, jboolean flipQuadEdges) { - jmeClasses::initJavaClasses(env); - void* data = env->GetDirectBufferAddress(heightfieldData); - btHeightfieldTerrainShape* shape=new btHeightfieldTerrainShape(heightStickWidth, heightStickLength, data, heightScale, minHeight, maxHeight, upAxis, PHY_FLOAT, flipQuadEdges); - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_HullCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_HullCollisionShape.cpp deleted file mode 100644 index 604f5a0e9b..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_HullCollisionShape.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_HullCollisionShape.h" -#include "jmeBulletUtil.h" -#include "BulletCollision/CollisionShapes/btConvexHullShape.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_HullCollisionShape - * Method: createShape - * Signature: ([F)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_HullCollisionShape_createShape - (JNIEnv *env, jobject object, jobject array) { - jmeClasses::initJavaClasses(env); - float* data = (float*) env->GetDirectBufferAddress(array); - //TODO: capacity will not always be length! - int length = env->GetDirectBufferCapacity(array)/4; - btConvexHullShape* shape = new btConvexHullShape(); - for (int i = 0; i < length; i+=3) { - btVector3 vect = btVector3(data[i], - data[i + 1], - data[i + 2]); - - shape->addPoint(vect); - } - - shape->optimizeConvexHull(); - - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_MeshCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_MeshCollisionShape.cpp deleted file mode 100644 index a5eabcb3cd..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_MeshCollisionShape.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** -* Author: Normen Hansen -*/ -#include "com_jme3_bullet_collision_shapes_MeshCollisionShape.h" -#include "jmeBulletUtil.h" -#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" -#include "btBulletDynamicsCommon.h" -#include "BulletCollision/Gimpact/btGImpactShape.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_MeshCollisionShape - * Method: createShape - * Signature: (J)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_MeshCollisionShape_createShape - (JNIEnv* env, jobject object,jboolean isMemoryEfficient,jboolean buildBVH, jlong arrayId) { - jmeClasses::initJavaClasses(env); - btTriangleIndexVertexArray* array = reinterpret_cast(arrayId); - btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(array, isMemoryEfficient, buildBVH); - return reinterpret_cast(shape); - } - - JNIEXPORT jbyteArray JNICALL Java_com_jme3_bullet_collision_shapes_MeshCollisionShape_saveBVH(JNIEnv* env, jobject, jlong meshobj){ - btBvhTriangleMeshShape* mesh = reinterpret_cast(meshobj); - btOptimizedBvh* bvh = mesh->getOptimizedBvh(); - unsigned int ssize = bvh->calculateSerializeBufferSize(); - char* buffer = (char*)btAlignedAlloc(ssize, 16); - bool success = bvh->serialize(buffer, ssize, true); - if(!success){ - jclass newExc = env->FindClass("java/lang/RuntimeException"); - env->ThrowNew(newExc, "Unableto Serialize, native error reported"); - } - - jbyteArray byteArray = env->NewByteArray(ssize); - env->SetByteArrayRegion(byteArray, 0, ssize , (jbyte*) buffer); - btAlignedFree(buffer); - return byteArray; - }; - - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_MeshCollisionShape_setBVH(JNIEnv* env, jobject,jbyteArray bytearray,jlong meshobj){ - int len = env->GetArrayLength (bytearray); - void* buffer = btAlignedAlloc(len, 16); - env->GetByteArrayRegion (bytearray, 0, len, reinterpret_cast(buffer)); - - btOptimizedBvh* bhv = btOptimizedBvh::deSerializeInPlace(buffer, len, true); - btBvhTriangleMeshShape* mesh = reinterpret_cast(meshobj); - mesh->setOptimizedBvh(bhv); - return reinterpret_cast(buffer); - }; - - /* - * Class: com_jme3_bullet_collision_shapes_MeshCollisionShape - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_MeshCollisionShape_finalizeNative - (JNIEnv* env, jobject object, jlong arrayId,jlong nativeBVHBuffer){ - btTriangleIndexVertexArray* array = reinterpret_cast(arrayId); - delete(array); - if (nativeBVHBuffer > 0) { - void* buffer = reinterpret_cast(nativeBVHBuffer); - btAlignedFree(buffer); - } - } - - -#ifdef __cplusplus -} -#endif - diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_PlaneCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_PlaneCollisionShape.cpp deleted file mode 100644 index 6362516ad1..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_PlaneCollisionShape.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_PlaneCollisionShape.h" -#include "jmeBulletUtil.h" -#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_PlaneCollisionShape - * Method: createShape - * Signature: (Lcom/jme3/math/Vector3f;F)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_PlaneCollisionShape_createShape - (JNIEnv * env, jobject object, jobject normal, jfloat constant) { - jmeClasses::initJavaClasses(env); - btVector3 norm = btVector3(); - jmeBulletUtil::convert(env, normal, &norm); - btStaticPlaneShape* shape = new btStaticPlaneShape(norm, constant); - return reinterpret_cast(shape); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_SimplexCollisionShape.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_SimplexCollisionShape.cpp deleted file mode 100644 index 43a4ddf8a7..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_SimplexCollisionShape.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_collision_shapes_SimplexCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_collision_shapes_SimplexCollisionShape - * Method: createShape - * Signature: (Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2 - (JNIEnv *env, jobject object, jobject vector1) { - jmeClasses::initJavaClasses(env); - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, vector1, &vec1); - btBU_Simplex1to4* simplexShape = new btBU_Simplex1to4(vec1); - return reinterpret_cast(simplexShape); - } - - /* - * Class: com_jme3_bullet_collision_shapes_SimplexCollisionShape - * Method: createShape - * Signature: (Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2 - (JNIEnv *env, jobject object, jobject vector1, jobject vector2) { - jmeClasses::initJavaClasses(env); - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, vector1, &vec1); - btVector3 vec2 = btVector3(); - jmeBulletUtil::convert(env, vector2, &vec2); - btBU_Simplex1to4* simplexShape = new btBU_Simplex1to4(vec1, vec2); - return reinterpret_cast(simplexShape); - } - /* - * Class: com_jme3_bullet_collision_shapes_SimplexCollisionShape - * Method: createShape - * Signature: (Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2 - (JNIEnv * env, jobject object, jobject vector1, jobject vector2, jobject vector3) { - jmeClasses::initJavaClasses(env); - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, vector1, &vec1); - btVector3 vec2 = btVector3(); - jmeBulletUtil::convert(env, vector2, &vec2); - btVector3 vec3 = btVector3(); - jmeBulletUtil::convert(env, vector3, &vec3); - btBU_Simplex1to4* simplexShape = new btBU_Simplex1to4(vec1, vec2, vec3); - return reinterpret_cast(simplexShape); - } - /* - * Class: com_jme3_bullet_collision_shapes_SimplexCollisionShape - * Method: createShape - * Signature: (Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SimplexCollisionShape_createShape__Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2Lcom_jme3_math_Vector3f_2 - (JNIEnv * env, jobject object, jobject vector1, jobject vector2, jobject vector3, jobject vector4) { - jmeClasses::initJavaClasses(env); - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, vector1, &vec1); - btVector3 vec2 = btVector3(); - jmeBulletUtil::convert(env, vector2, &vec2); - btVector3 vec3 = btVector3(); - jmeBulletUtil::convert(env, vector3, &vec3); - btVector3 vec4 = btVector3(); - jmeBulletUtil::convert(env, vector4, &vec4); - btBU_Simplex1to4* simplexShape = new btBU_Simplex1to4(vec1, vec2, vec3, vec4); - return reinterpret_cast(simplexShape); - } -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_ConeJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_ConeJoint.cpp deleted file mode 100644 index 27c90e1d9d..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_ConeJoint.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_ConeJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_ConeJoint - * Method: setLimit - * Signature: (JFFF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_ConeJoint_setLimit - (JNIEnv * env, jobject object, jlong jointId, jfloat swingSpan1, jfloat swingSpan2, jfloat twistSpan) { - btConeTwistConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - //TODO: extended setLimit! - joint->setLimit(swingSpan1, swingSpan2, twistSpan); - } - - /* - * Class: com_jme3_bullet_joints_ConeJoint - * Method: setAngularOnly - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_ConeJoint_setAngularOnly - (JNIEnv * env, jobject object, jlong jointId, jboolean angularOnly) { - btConeTwistConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setAngularOnly(angularOnly); - } - - /* - * Class: com_jme3_bullet_joints_ConeJoint - * Method: createJoint - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_ConeJoint_createJoint - (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB) { - jmeClasses::initJavaClasses(env); - btRigidBody* bodyA = reinterpret_cast(bodyIdA); - btRigidBody* bodyB = reinterpret_cast(bodyIdB); - btMatrix3x3 mtx1 = btMatrix3x3(); - btMatrix3x3 mtx2 = btMatrix3x3(); - btTransform transA = btTransform(mtx1); - jmeBulletUtil::convert(env, pivotA, &transA.getOrigin()); - jmeBulletUtil::convert(env, rotA, &transA.getBasis()); - btTransform transB = btTransform(mtx2); - jmeBulletUtil::convert(env, pivotB, &transB.getOrigin()); - jmeBulletUtil::convert(env, rotB, &transB.getBasis()); - btConeTwistConstraint* joint = new btConeTwistConstraint(*bodyA, *bodyB, transA, transB); - return reinterpret_cast(joint); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_HingeJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_HingeJoint.cpp deleted file mode 100644 index 351be3ffa3..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_HingeJoint.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_HingeJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: enableMotor - * Signature: (JZFF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_enableMotor - (JNIEnv * env, jobject object, jlong jointId, jboolean enable, jfloat targetVelocity, jfloat maxMotorImpulse) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->enableAngularMotor(enable, targetVelocity, maxMotorImpulse); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: getEnableAngularMotor - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_HingeJoint_getEnableAngularMotor - (JNIEnv * env, jobject object, jlong jointId) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return joint->getEnableAngularMotor(); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: getMotorTargetVelocity - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getMotorTargetVelocity - (JNIEnv * env, jobject object, jlong jointId) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getMotorTargetVelocity(); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: getMaxMotorImpulse - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getMaxMotorImpulse - (JNIEnv * env, jobject object, jlong jointId) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getMaxMotorImpulse(); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: setLimit - * Signature: (JFF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_setLimit__JFF - (JNIEnv * env, jobject object, jlong jointId, jfloat low, jfloat high) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - return joint->setLimit(low, high); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: setLimit - * Signature: (JFFFFF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_setLimit__JFFFFF - (JNIEnv * env, jobject object, jlong jointId, jfloat low, jfloat high, jfloat softness, jfloat biasFactor, jfloat relaxationFactor) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - return joint->setLimit(low, high, softness, biasFactor, relaxationFactor); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: getUpperLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getUpperLimit - (JNIEnv * env, jobject object, jlong jointId) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getUpperLimit(); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: getLowerLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getLowerLimit - (JNIEnv * env, jobject object, jlong jointId) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getLowerLimit(); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: setAngularOnly - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_HingeJoint_setAngularOnly - (JNIEnv * env, jobject object, jlong jointId, jboolean angular) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setAngularOnly(angular); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: getHingeAngle - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_HingeJoint_getHingeAngle - (JNIEnv * env, jobject object, jlong jointId) { - btHingeConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getHingeAngle(); - } - - /* - * Class: com_jme3_bullet_joints_HingeJoint - * Method: createJoint - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_HingeJoint_createJoint - (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject axisA, jobject pivotB, jobject axisB) { - jmeClasses::initJavaClasses(env); - btRigidBody* bodyA = reinterpret_cast(bodyIdA); - btRigidBody* bodyB = reinterpret_cast(bodyIdB); - btVector3 vec1 = btVector3(); - btVector3 vec2 = btVector3(); - btVector3 vec3 = btVector3(); - btVector3 vec4 = btVector3(); - jmeBulletUtil::convert(env, pivotA, &vec1); - jmeBulletUtil::convert(env, pivotB, &vec2); - jmeBulletUtil::convert(env, axisA, &vec3); - jmeBulletUtil::convert(env, axisB, &vec4); - btHingeConstraint* joint = new btHingeConstraint(*bodyA, *bodyB, vec1, vec2, vec3, vec4); - return reinterpret_cast(joint); - } -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_PhysicsJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_PhysicsJoint.cpp deleted file mode 100644 index b00425e88c..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_PhysicsJoint.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_PhysicsJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_PhysicsJoint - * Method: getAppliedImpulse - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_PhysicsJoint_getAppliedImpulse - (JNIEnv * env, jobject object, jlong jointId) { - btTypedConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getAppliedImpulse(); - } - - /* - * Class: com_jme3_bullet_joints_PhysicsJoint - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_PhysicsJoint_finalizeNative - (JNIEnv * env, jobject object, jlong jointId) { - btTypedConstraint* joint = reinterpret_cast (jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - delete(joint); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_Point2PointJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_Point2PointJoint.cpp deleted file mode 100644 index 5284518788..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_Point2PointJoint.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_Point2PointJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: setDamping - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setDamping - (JNIEnv * env, jobject object, jlong jointId, jfloat damping) { - btPoint2PointConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->m_setting.m_damping = damping; - } - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: setImpulseClamp - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setImpulseClamp - (JNIEnv * env, jobject object, jlong jointId, jfloat clamp) { - btPoint2PointConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->m_setting.m_impulseClamp = clamp; - } - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: setTau - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setTau - (JNIEnv * env, jobject object, jlong jointId, jfloat tau) { - btPoint2PointConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->m_setting.m_tau = tau; - } - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: getDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getDamping - (JNIEnv * env, jobject object, jlong jointId) { - btPoint2PointConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->m_setting.m_damping; - } - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: getImpulseClamp - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getImpulseClamp - (JNIEnv * env, jobject object, jlong jointId) { - btPoint2PointConstraint* joint = reinterpret_cast (jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->m_setting.m_impulseClamp; - } - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: getTau - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getTau - (JNIEnv * env, jobject object, jlong jointId) { - btPoint2PointConstraint* joint = reinterpret_cast (jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->m_setting.m_tau; - } - - /* - * Class: com_jme3_bullet_joints_Point2PointJoint - * Method: createJoint - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_createJoint - (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject pivotB) { - jmeClasses::initJavaClasses(env); - btRigidBody* bodyA = reinterpret_cast(bodyIdA); - btRigidBody* bodyB = reinterpret_cast(bodyIdB); - btVector3 pivotAIn; - btVector3 pivotBIn; - jmeBulletUtil::convert(env, pivotA, &pivotAIn); - jmeBulletUtil::convert(env, pivotB, &pivotBIn); - btPoint2PointConstraint * joint = new btPoint2PointConstraint(*bodyA, *bodyB, pivotAIn, pivotBIn); - return reinterpret_cast(joint); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp deleted file mode 100644 index 24a26c0cfa..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_SixDofJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: getRotationalLimitMotor - * Signature: (JI)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofJoint_getRotationalLimitMotor - (JNIEnv * env, jobject object, jlong jointId, jint index) { - btGeneric6DofConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return reinterpret_cast(joint->getRotationalLimitMotor(index)); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: getTranslationalLimitMotor - * Signature: (J)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofJoint_getTranslationalLimitMotor - (JNIEnv * env, jobject object, jlong jointId) { - btGeneric6DofConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return reinterpret_cast(joint->getTranslationalLimitMotor()); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: setLinearUpperLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofJoint_setLinearUpperLimit - (JNIEnv * env, jobject object, jlong jointId, jobject vector) { - btGeneric6DofConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, vector, &vec); - joint->setLinearUpperLimit(vec); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: setLinearLowerLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofJoint_setLinearLowerLimit - (JNIEnv * env, jobject object, jlong jointId, jobject vector) { - btGeneric6DofConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, vector, &vec); - joint->setLinearLowerLimit(vec); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: setAngularUpperLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofJoint_setAngularUpperLimit - (JNIEnv * env, jobject object, jlong jointId, jobject vector) { - btGeneric6DofConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, vector, &vec); - joint->setAngularUpperLimit(vec); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: setAngularLowerLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofJoint_setAngularLowerLimit - (JNIEnv * env, jobject object, jlong jointId, jobject vector) { - btGeneric6DofConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, vector, &vec); - joint->setAngularLowerLimit(vec); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: createJoint - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofJoint_createJoint - (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) { - jmeClasses::initJavaClasses(env); - btRigidBody* bodyA = reinterpret_cast(bodyIdA); - btRigidBody* bodyB = reinterpret_cast(bodyIdB); - btMatrix3x3 mtx1 = btMatrix3x3(); - btMatrix3x3 mtx2 = btMatrix3x3(); - btTransform transA = btTransform(mtx1); - jmeBulletUtil::convert(env, pivotA, &transA.getOrigin()); - jmeBulletUtil::convert(env, rotA, &transA.getBasis()); - btTransform transB = btTransform(mtx2); - jmeBulletUtil::convert(env, pivotB, &transB.getOrigin()); - jmeBulletUtil::convert(env, rotB, &transB.getBasis()); - btGeneric6DofConstraint* joint = new btGeneric6DofConstraint(*bodyA, *bodyB, transA, transB, useLinearReferenceFrameA); - return reinterpret_cast(joint); - } - - /* - * Class: com_jme3_bullet_joints_SixDofJoint - * Method: getAngles - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofJoint_getAngles - (JNIEnv *env, jobject object, jlong jointId, jobject storeVector) { - btGeneric6DofConstraint *pJoint - = reinterpret_cast (jointId); - if (pJoint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - - pJoint->calculateTransforms(); - btScalar x = pJoint->getAngle(0); - btScalar y = pJoint->getAngle(1); - btScalar z = pJoint->getAngle(2); - const btVector3& angles = btVector3(x, y, z); - jmeBulletUtil::convert(env, &angles, storeVector); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofSpringJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofSpringJoint.cpp deleted file mode 100644 index da225ee2fa..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofSpringJoint.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_SixDofSpringJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Class: com_jme3_bullet_joints_SixDofSpringJoint - * Method: enableString - * Signature: (JIZ)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_enableSpring - (JNIEnv *env, jobject object, jlong jointId, jint index, jboolean onOff) { - btGeneric6DofSpringConstraint* joint = reinterpret_cast(jointId); - joint -> enableSpring(index, onOff); -} - - -/* - * Class: com_jme3_bullet_joints_SixDofSpringJoint - * Method: setStiffness - * Signature: (JIF)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setStiffness - (JNIEnv *env, jobject object, jlong jointId, jint index, jfloat stiffness) { - btGeneric6DofSpringConstraint* joint = reinterpret_cast(jointId); - joint -> setStiffness(index, stiffness); -} - -/* - * Class: com_jme3_bullet_joints_SixDofSpringJoint - * Method: setDamping - * Signature: (JIF)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setDamping - (JNIEnv *env, jobject object, jlong jointId, jint index, jfloat damping) { - btGeneric6DofSpringConstraint* joint = reinterpret_cast(jointId); - joint -> setDamping(index, damping); -} - -/* - * Class: com_jme3_bullet_joints_SixDofSpringJoint - * Method: setEquilibriumPoint - * Signature: (JIF)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__J - (JNIEnv *env, jobject object, jlong jointId) { - btGeneric6DofSpringConstraint* joint = reinterpret_cast(jointId); - joint -> setEquilibriumPoint(); -} - -/* - * Class: com_jme3_bullet_joints_SixDofSpringJoint - * Method: setEquilibriumPoint - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_setEquilibriumPoint__JI - (JNIEnv *env, jobject object, jlong jointId, jint index) { - btGeneric6DofSpringConstraint* joint = reinterpret_cast(jointId); - joint -> setEquilibriumPoint(index); -} - - - - -/* - * Class: com_jme3_bullet_joints_SixDofSpringJoint - * Method: createJoint - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J - */ -JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SixDofSpringJoint_createJoint - (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) { - jmeClasses::initJavaClasses(env); - btRigidBody* bodyA = reinterpret_cast(bodyIdA); - btRigidBody* bodyB = reinterpret_cast(bodyIdB); - btTransform transA; - jmeBulletUtil::convert(env, pivotA, &transA.getOrigin()); - jmeBulletUtil::convert(env, rotA, &transA.getBasis()); - btTransform transB; - jmeBulletUtil::convert(env, pivotB, &transB.getOrigin()); - jmeBulletUtil::convert(env, rotB, &transB.getBasis()); - - btGeneric6DofSpringConstraint* joint = new btGeneric6DofSpringConstraint(*bodyA, *bodyB, transA, transB, useLinearReferenceFrameA); - return reinterpret_cast(joint); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SliderJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SliderJoint.cpp deleted file mode 100644 index 0817d79752..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SliderJoint.cpp +++ /dev/null @@ -1,963 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_SliderJoint.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getLowerLinLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getLowerLinLimit - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getLowerLinLimit(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setLowerLinLimit - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setLowerLinLimit - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setLowerLinLimit(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getUpperLinLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getUpperLinLimit - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getUpperLinLimit(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setUpperLinLimit - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setUpperLinLimit - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setUpperLinLimit(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getLowerAngLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getLowerAngLimit - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getLowerAngLimit(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setLowerAngLimit - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setLowerAngLimit - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setLowerAngLimit(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getUpperAngLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getUpperAngLimit - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getUpperAngLimit(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setUpperAngLimit - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setUpperAngLimit - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setUpperAngLimit(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getSoftnessDirLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getSoftnessDirLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getSoftnessDirLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setSoftnessDirLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setSoftnessDirLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setSoftnessDirLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getRestitutionDirLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getRestitutionDirLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getRestitutionDirLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setRestitutionDirLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setRestitutionDirLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setRestitutionDirLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getDampingDirLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getDampingDirLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getDampingDirLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setDampingDirLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setDampingDirLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setDampingDirLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getSoftnessDirAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getSoftnessDirAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getSoftnessDirAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setSoftnessDirAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setSoftnessDirAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setSoftnessDirAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getRestitutionDirAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getRestitutionDirAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getRestitutionDirAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setRestitutionDirAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setRestitutionDirAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setRestitutionDirAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getDampingDirAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getDampingDirAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getDampingDirAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setDampingDirAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setDampingDirAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setDampingDirAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getSoftnessLimLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getSoftnessLimLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getSoftnessLimLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setSoftnessLimLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setSoftnessLimLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setSoftnessLimLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getRestitutionLimLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getRestitutionLimLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getRestitutionLimLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setRestitutionLimLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setRestitutionLimLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setRestitutionLimLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getDampingLimLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getDampingLimLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getDampingLimLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setDampingLimLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setDampingLimLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setDampingLimLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getSoftnessLimAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getSoftnessLimAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getSoftnessLimAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setSoftnessLimAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setSoftnessLimAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setSoftnessLimAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getRestitutionLimAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getRestitutionLimAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getRestitutionLimAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setRestitutionLimAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setRestitutionLimAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setRestitutionLimAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getDampingLimAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getDampingLimAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getDampingLimAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setDampingLimAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setDampingLimAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setDampingLimAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getSoftnessOrthoLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getSoftnessOrthoLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getSoftnessOrthoLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setSoftnessOrthoLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setSoftnessOrthoLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setSoftnessOrthoLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getRestitutionOrthoLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getRestitutionOrthoLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getRestitutionOrthoLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setRestitutionOrthoLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setRestitutionOrthoLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setRestitutionOrthoLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getDampingOrthoLin - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getDampingOrthoLin - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getDampingOrthoLin(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setDampingOrthoLin - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setDampingOrthoLin - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setDampingOrthoLin(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getSoftnessOrthoAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getSoftnessOrthoAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getSoftnessOrthoAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setSoftnessOrthoAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setSoftnessOrthoAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setSoftnessOrthoAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getRestitutionOrthoAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getRestitutionOrthoAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getRestitutionOrthoAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setRestitutionOrthoAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setRestitutionOrthoAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setRestitutionOrthoAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getDampingOrthoAng - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getDampingOrthoAng - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getDampingOrthoAng(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setDampingOrthoAng - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setDampingOrthoAng - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setDampingOrthoAng(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: isPoweredLinMotor - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_SliderJoint_isPoweredLinMotor - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return joint->getPoweredLinMotor(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setPoweredLinMotor - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setPoweredLinMotor - (JNIEnv * env, jobject object, jlong jointId, jboolean value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setPoweredLinMotor(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getTargetLinMotorVelocity - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getTargetLinMotorVelocity - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getTargetLinMotorVelocity(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setTargetLinMotorVelocity - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setTargetLinMotorVelocity - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setTargetLinMotorVelocity(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getMaxLinMotorForce - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getMaxLinMotorForce - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getMaxLinMotorForce(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setMaxLinMotorForce - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setMaxLinMotorForce - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setMaxLinMotorForce(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: isPoweredAngMotor - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_SliderJoint_isPoweredAngMotor - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return joint->getPoweredAngMotor(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setPoweredAngMotor - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setPoweredAngMotor - (JNIEnv * env, jobject object, jlong jointId, jboolean value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setPoweredAngMotor(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getTargetAngMotorVelocity - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getTargetAngMotorVelocity - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getTargetAngMotorVelocity(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setTargetAngMotorVelocity - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setTargetAngMotorVelocity - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setTargetAngMotorVelocity(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: getMaxAngMotorForce - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_SliderJoint_getMaxAngMotorForce - (JNIEnv * env, jobject object, jlong jointId) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return joint->getMaxAngMotorForce(); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: setMaxAngMotorForce - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SliderJoint_setMaxAngMotorForce - (JNIEnv * env, jobject object, jlong jointId, jfloat value) { - btSliderConstraint* joint = reinterpret_cast(jointId); - if (joint == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - joint->setMaxAngMotorForce(value); - } - - /* - * Class: com_jme3_bullet_joints_SliderJoint - * Method: createJoint - * Signature: (JJLcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Matrix3f;Z)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_joints_SliderJoint_createJoint - (JNIEnv * env, jobject object, jlong bodyIdA, jlong bodyIdB, jobject pivotA, jobject rotA, jobject pivotB, jobject rotB, jboolean useLinearReferenceFrameA) { - jmeClasses::initJavaClasses(env); - btRigidBody* bodyA = reinterpret_cast(bodyIdA); - btRigidBody* bodyB = reinterpret_cast(bodyIdB); - btMatrix3x3 mtx1 = btMatrix3x3(); - btMatrix3x3 mtx2 = btMatrix3x3(); - btTransform transA = btTransform(mtx1); - jmeBulletUtil::convert(env, pivotA, &transA.getOrigin()); - jmeBulletUtil::convert(env, rotA, &transA.getBasis()); - btTransform transB = btTransform(mtx2); - jmeBulletUtil::convert(env, pivotB, &transB.getOrigin()); - jmeBulletUtil::convert(env, rotB, &transB.getBasis()); - btSliderConstraint* joint = new btSliderConstraint(*bodyA, *bodyB, transA, transB, useLinearReferenceFrameA); - return reinterpret_cast(joint); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_RotationalLimitMotor.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_RotationalLimitMotor.cpp deleted file mode 100644 index 396d47ae3a..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_RotationalLimitMotor.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_motors_RotationalLimitMotor.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getLoLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getLoLimit - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_loLimit; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setLoLimit - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setLoLimit - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_loLimit = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getHiLimit - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getHiLimit - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_hiLimit; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setHiLimit - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setHiLimit - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_hiLimit = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getTargetVelocity - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getTargetVelocity - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_targetVelocity; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setTargetVelocity - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setTargetVelocity - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_targetVelocity = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getMaxMotorForce - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getMaxMotorForce - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_maxMotorForce; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setMaxMotorForce - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setMaxMotorForce - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_maxMotorForce = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getMaxLimitForce - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getMaxLimitForce - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_maxLimitForce; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setMaxLimitForce - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setMaxLimitForce - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_maxLimitForce = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getDamping - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_damping; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setDamping - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setDamping - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_damping = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getLimitSoftness - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getLimitSoftness - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_limitSoftness; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setLimitSoftness - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setLimitSoftness - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_limitSoftness = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getERP - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getERP - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_stopERP; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setERP - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setERP - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_stopERP = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: getBounce - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_getBounce - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_bounce; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setBounce - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setBounce - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_bounce = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: isEnableMotor - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_isEnableMotor - (JNIEnv *env, jobject object, jlong motorId) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return motor->m_enableMotor; - } - - /* - * Class: com_jme3_bullet_joints_motors_RotationalLimitMotor - * Method: setEnableMotor - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_RotationalLimitMotor_setEnableMotor - (JNIEnv *env, jobject object, jlong motorId, jboolean value) { - btRotationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_enableMotor = value; - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp deleted file mode 100644 index 14e66933f6..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_joints_motors_TranslationalLimitMotor.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: getLowerLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_getLowerLimit - (JNIEnv *env, jobject object, jlong motorId, jobject vector) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &motor->m_lowerLimit, vector); - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setLowerLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setLowerLimit - (JNIEnv *env, jobject object, jlong motorId, jobject vector) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, vector, &motor->m_lowerLimit); - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: getUpperLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_getUpperLimit - (JNIEnv *env, jobject object, jlong motorId, jobject vector) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &motor->m_upperLimit, vector); - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setUpperLimit - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setUpperLimit - (JNIEnv *env, jobject object, jlong motorId, jobject vector) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, vector, &motor->m_upperLimit); - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: getAccumulatedImpulse - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_getAccumulatedImpulse - (JNIEnv *env, jobject object, jlong motorId, jobject vector) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &motor->m_accumulatedImpulse, vector); - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setAccumulatedImpulse - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setAccumulatedImpulse - (JNIEnv *env, jobject object, jlong motorId, jobject vector) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, vector, &motor->m_accumulatedImpulse); - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: getLimitSoftness - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_getLimitSoftness - (JNIEnv *env, jobject object, jlong motorId) { - btTranslationalLimitMotor* motor = reinterpret_cast (motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_limitSoftness; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setLimitSoftness - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setLimitSoftness - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_limitSoftness = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: getDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_getDamping - (JNIEnv *env, jobject object, jlong motorId) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_damping; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setDamping - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setDamping - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_damping = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: getRestitution - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_getRestitution - (JNIEnv *env, jobject object, jlong motorId) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return motor->m_restitution; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setRestitution - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setRestitution - (JNIEnv *env, jobject object, jlong motorId, jfloat value) { - btTranslationalLimitMotor* motor = reinterpret_cast(motorId); - if (motor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - motor->m_restitution = value; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: setEnabled - * Signature: (JIZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setEnabled - (JNIEnv *env, jobject object, jlong motorId, jint axisIndex, jboolean newSetting) { - btTranslationalLimitMotor *pMotor - = reinterpret_cast (motorId); - if (pMotor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - - pMotor->m_enableMotor[axisIndex] = (bool)newSetting; - } - - /* - * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor - * Method: isEnabled - * Signature: (JI)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_isEnabled - (JNIEnv *env, jobject object, jlong motorId, jint axisIndex) { - btTranslationalLimitMotor *pMotor - = reinterpret_cast (motorId); - if (pMotor == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - - bool result = pMotor->m_enableMotor[axisIndex]; - return (jboolean) result; - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsCharacter.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsCharacter.cpp deleted file mode 100644 index e807d43f89..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsCharacter.cpp +++ /dev/null @@ -1,627 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ - -#include "com_jme3_bullet_objects_PhysicsCharacter.h" -#include "jmeBulletUtil.h" -#include "BulletCollision/CollisionDispatch/btGhostObject.h" -#include "BulletDynamics/Character/btKinematicCharacterController.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: createGhostObject - * Signature: ()J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_createGhostObject - (JNIEnv * env, jobject object) { - jmeClasses::initJavaClasses(env); - btPairCachingGhostObject* ghost = new btPairCachingGhostObject(); - return reinterpret_cast(ghost); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setCharacterFlags - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setCharacterFlags - (JNIEnv *env, jobject object, jlong ghostId) { - btPairCachingGhostObject* ghost = reinterpret_cast(ghostId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - ghost->setCollisionFlags(/*ghost->getCollisionFlags() |*/ btCollisionObject::CF_CHARACTER_OBJECT); - ghost->setCollisionFlags(ghost->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: createCharacterObject - * Signature: (JJF)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_createCharacterObject - (JNIEnv *env, jobject object, jlong objectId, jlong shapeId, jfloat stepHeight) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - //TODO: check convexshape! - btConvexShape* shape = reinterpret_cast(shapeId); - btKinematicCharacterController* character = new btKinematicCharacterController(ghost, shape, stepHeight); - return reinterpret_cast(character); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: warp - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_warp - (JNIEnv *env, jobject object, jlong objectId, jobject vector) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, vector, &vec); - character->warp(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setWalkDirection - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setWalkDirection - (JNIEnv *env, jobject object, jlong objectId, jobject vector) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, vector, &vec); - character->setWalkDirection(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setUp - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setUp - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - character->setUp(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setAngularVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setAngularVelocity - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - character->setAngularVelocity(vec); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getAngularVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getAngularVelocity - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 a_vel = character->getAngularVelocity(); - jmeBulletUtil::convert(env, &a_vel, value); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setLinearVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setLinearVelocity - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - character->setLinearVelocity(vec); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getLinearVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getLinearVelocity - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 l_vel = character->getLinearVelocity(); - jmeBulletUtil::convert(env, &l_vel, value); - } - - - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setFallSpeed - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setFallSpeed - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - character->setFallSpeed(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setJumpSpeed - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setJumpSpeed - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - character->setJumpSpeed(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setGravity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setGravity - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - character->setGravity(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getGravity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getGravity - (JNIEnv *env, jobject object, jlong objectId,jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 g = character->getGravity(); - jmeBulletUtil::convert(env, &g, value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setLinearDamping - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setLinearDamping - (JNIEnv *env, jobject object, jlong objectId,jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return ; - } - character->setLinearDamping(value); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getLinearDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getLinearDamping - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return character->getLinearDamping(); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setAngularDamping - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setAngularDamping - (JNIEnv *env, jobject object, jlong objectId,jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - character->setAngularDamping(value); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getAngularDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getAngularDamping - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return character->getAngularDamping(); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setStepHeight - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setStepHeight - (JNIEnv *env, jobject object, jlong objectId,jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - character->setStepHeight(value); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getStepHeight - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getStepHeight - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return character->getStepHeight(); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setMaxSlope - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setMaxSlope - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - character->setMaxSlope(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getMaxSlope - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getMaxSlope - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return character->getMaxSlope(); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setMaxPenetrationDepth - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setMaxPenetrationDepth - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - character->setMaxPenetrationDepth(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getMaxPenetrationDepth - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getMaxPenetrationDepth - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return character->getMaxPenetrationDepth(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: onGround - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_onGround - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return character->onGround(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: jump - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_jump - (JNIEnv *env, jobject object, jlong objectId,jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - character->jump(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: applyImpulse - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_applyImpulse - (JNIEnv *env, jobject object, jlong objectId,jobject value) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - character->applyImpulse(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getPhysicsLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getPhysicsLocation - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &ghost->getWorldTransform().getOrigin(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setCcdSweptSphereRadius - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setCcdSweptSphereRadius - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - ghost->setCcdSweptSphereRadius(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: setCcdMotionThreshold - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_setCcdMotionThreshold - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - ghost->setCcdMotionThreshold(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getCcdSweptSphereRadius - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getCcdSweptSphereRadius - (JNIEnv *env, jobject object, jlong objectId) { - btGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getCcdSweptSphereRadius(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getCcdMotionThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getCcdMotionThreshold - (JNIEnv *env, jobject object, jlong objectId) { - btGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getCcdMotionThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: getCcdSquareMotionThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_getCcdSquareMotionThreshold - (JNIEnv *env, jobject object, jlong objectId) { - btGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getCcdSquareMotionThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsCharacter - * Method: finalizeNativeCharacter - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsCharacter_finalizeNativeCharacter - (JNIEnv *env, jobject object, jlong objectId) { - btKinematicCharacterController* character = reinterpret_cast(objectId); - if (character == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - delete(character); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsGhostObject.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsGhostObject.cpp deleted file mode 100644 index fa38c1b639..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsGhostObject.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ - -#include - -#include "com_jme3_bullet_objects_PhysicsGhostObject.h" -#include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h" -#include "jmeBulletUtil.h" -#include "jmePhysicsSpace.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: createGhostObject - * Signature: ()J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_createGhostObject - (JNIEnv * env, jobject object) { - jmeClasses::initJavaClasses(env); - btPairCachingGhostObject* ghost = new btPairCachingGhostObject(); - return reinterpret_cast(ghost); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: setGhostFlags - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setGhostFlags - (JNIEnv *env, jobject object, jlong objectId) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - ghost->setCollisionFlags(ghost->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: setPhysicsLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setPhysicsLocation - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, value, &ghost->getWorldTransform().getOrigin()); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: setPhysicsRotation - * Signature: (JLcom/jme3/math/Matrix3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setPhysicsRotation__JLcom_jme3_math_Matrix3f_2 - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, value, &ghost->getWorldTransform().getBasis()); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: setPhysicsRotation - * Signature: (JLcom/jme3/math/Quaternion;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setPhysicsRotation__JLcom_jme3_math_Quaternion_2 - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convertQuat(env, value, &ghost->getWorldTransform().getBasis()); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getPhysicsLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysicsLocation - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &ghost->getWorldTransform().getOrigin(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getPhysicsRotation - * Signature: (JLcom/jme3/math/Quaternion;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysicsRotation - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convertQuat(env, &ghost->getWorldTransform().getBasis(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getPhysicsRotationMatrix - * Signature: (JLcom/jme3/math/Matrix3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getPhysicsRotationMatrix - (JNIEnv *env, jobject object, jlong objectId, jobject value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &ghost->getWorldTransform().getBasis(), value); - } - - class jmeGhostOverlapCallback : public btOverlapCallback { - JNIEnv* m_env; - jobject m_object; - btCollisionObject *m_ghost; - public: - jmeGhostOverlapCallback(JNIEnv *env, jobject object, btCollisionObject *ghost) - :m_env(env), - m_object(object), - m_ghost(ghost) - { - } - virtual ~jmeGhostOverlapCallback() {} - virtual bool processOverlap(btBroadphasePair& pair) - { - btCollisionObject *other; - if(pair.m_pProxy1->m_clientObject == m_ghost){ - other = (btCollisionObject *)pair.m_pProxy0->m_clientObject; - }else{ - other = (btCollisionObject *)pair.m_pProxy1->m_clientObject; - } - jmeUserPointer *up1 = (jmeUserPointer*)other -> getUserPointer(); - jobject javaCollisionObject1 = m_env->NewLocalRef(up1->javaCollisionObject); - m_env->CallVoidMethod(m_object, jmeClasses::PhysicsGhostObject_addOverlappingObject, javaCollisionObject1); - m_env->DeleteLocalRef(javaCollisionObject1); - if (m_env->ExceptionCheck()) { - m_env->Throw(m_env->ExceptionOccurred()); - return false; - } - - return false; - } - }; - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getOverlappingObjects - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getOverlappingObjects - (JNIEnv *env, jobject object, jlong objectId) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btHashedOverlappingPairCache * pc = ghost->getOverlappingPairCache(); - jmeGhostOverlapCallback cb(env, object, ghost); - pc -> processAllOverlappingPairs(&cb, NULL); - } - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getOverlappingCount - * Signature: (J)I - */ - JNIEXPORT jint JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getOverlappingCount - (JNIEnv *env, jobject object, jlong objectId) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getNumOverlappingObjects(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: setCcdSweptSphereRadius - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setCcdSweptSphereRadius - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - ghost->setCcdSweptSphereRadius(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: setCcdMotionThreshold - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_setCcdMotionThreshold - (JNIEnv *env, jobject object, jlong objectId, jfloat value) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - ghost->setCcdMotionThreshold(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getCcdSweptSphereRadius - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getCcdSweptSphereRadius - (JNIEnv *env, jobject object, jlong objectId) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getCcdSweptSphereRadius(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getCcdMotionThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getCcdMotionThreshold - (JNIEnv *env, jobject object, jlong objectId) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getCcdMotionThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsGhostObject - * Method: getCcdSquareMotionThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsGhostObject_getCcdSquareMotionThreshold - (JNIEnv *env, jobject object, jlong objectId) { - btPairCachingGhostObject* ghost = reinterpret_cast(objectId); - if (ghost == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return ghost->getCcdSquareMotionThreshold(); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp deleted file mode 100644 index 3c05e124fb..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp +++ /dev/null @@ -1,918 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_objects_PhysicsRigidBody.h" -#include "jmeBulletUtil.h" -#include "jmeMotionState.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: createRigidBody - * Signature: (FJJ)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_createRigidBody - (JNIEnv *env, jobject object, jfloat mass, jlong motionstatId, jlong shapeId) { - jmeClasses::initJavaClasses(env); - btMotionState* motionState = reinterpret_cast(motionstatId); - btCollisionShape* shape = reinterpret_cast(shapeId); - btVector3 localInertia = btVector3(); - shape->calculateLocalInertia(mass, localInertia); - btRigidBody* body = new btRigidBody(mass, motionState, shape, localInertia); - body->setUserPointer(NULL); - return reinterpret_cast(body); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: isInWorld - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_isInWorld - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return body->isInWorld(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setPhysicsLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsLocation - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - // if (body->isStaticOrKinematicObject() || !body->isInWorld()) - ((jmeMotionState*) body->getMotionState())->setKinematicLocation(env, value); - body->setCenterOfMassTransform(((jmeMotionState*) body->getMotionState())->worldTransform); - // else{ - // btMatrix3x3* mtx = &btMatrix3x3(); - // btTransform* trans = &btTransform(*mtx); - // trans->setBasis(body->getCenterOfMassTransform().getBasis()); - // jmeBulletUtil::convert(env, value, &trans->getOrigin()); - // body->setCenterOfMassTransform(*trans); - // } - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setPhysicsRotation - * Signature: (JLcom/jme3/math/Matrix3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsRotation__JLcom_jme3_math_Matrix3f_2 - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - // if (body->isStaticOrKinematicObject() || !body->isInWorld()) - ((jmeMotionState*) body->getMotionState())->setKinematicRotation(env, value); - body->setCenterOfMassTransform(((jmeMotionState*) body->getMotionState())->worldTransform); - // else{ - // btMatrix3x3* mtx = &btMatrix3x3(); - // btTransform* trans = &btTransform(*mtx); - // trans->setOrigin(body->getCenterOfMassTransform().getOrigin()); - // jmeBulletUtil::convert(env, value, &trans->getBasis()); - // body->setCenterOfMassTransform(*trans); - // } - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setPhysicsRotation - * Signature: (JLcom/jme3/math/Quaternion;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsRotation__JLcom_jme3_math_Quaternion_2 - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - // if (body->isStaticOrKinematicObject() || !body->isInWorld()) - ((jmeMotionState*) body->getMotionState())->setKinematicRotationQuat(env, value); - body->setCenterOfMassTransform(((jmeMotionState*) body->getMotionState())->worldTransform); - // else{ - // btMatrix3x3* mtx = &btMatrix3x3(); - // btTransform* trans = &btTransform(*mtx); - // trans->setOrigin(body->getCenterOfMassTransform().getOrigin()); - // jmeBulletUtil::convertQuat(env, value, &trans->getBasis()); - // body->setCenterOfMassTransform(*trans); - // } - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setInverseInertiaLocal - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setInverseInertiaLocal - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - body->setInvInertiaDiagLocal(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getInverseInertiaLocal - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getInverseInertiaLocal - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getInvInertiaDiagLocal(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getPhysicsLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsLocation - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getWorldTransform().getOrigin(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getPhysicsRotation - * Signature: (JLcom/jme3/math/Quaternion;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsRotation - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convertQuat(env, &body->getWorldTransform().getBasis(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getPhysicsRotationMatrix - * Signature: (JLcom/jme3/math/Matrix3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsRotationMatrix - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getWorldTransform().getBasis(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setKinematic - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setKinematic - (JNIEnv *env, jobject object, jlong bodyId, jboolean value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - if (value) { - body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); - body->setActivationState(DISABLE_DEACTIVATION); - } else { - body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT); - body->activate(true); - body->forceActivationState(ACTIVE_TAG); - } - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setCcdSweptSphereRadius - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setCcdSweptSphereRadius - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setCcdSweptSphereRadius(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setCcdMotionThreshold - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setCcdMotionThreshold - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setCcdMotionThreshold(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getCcdSweptSphereRadius - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getCcdSweptSphereRadius - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getCcdSweptSphereRadius(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getCcdMotionThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getCcdMotionThreshold - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getCcdMotionThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getCcdSquareMotionThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getCcdSquareMotionThreshold - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getCcdSquareMotionThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setStatic - * Signature: (JZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setStatic - (JNIEnv *env, jobject object, jlong bodyId, jboolean value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - if (value) { - body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); - } else { - body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_STATIC_OBJECT); - } - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: updateMassProps - * Signature: (JJF)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_updateMassProps - (JNIEnv *env, jobject object, jlong bodyId, jlong shapeId, jfloat mass) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btCollisionShape* shape = reinterpret_cast(shapeId); - btVector3 localInertia = btVector3(); - shape->calculateLocalInertia(mass, localInertia); - body->setMassProps(mass, localInertia); - return reinterpret_cast(body); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getGravity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getGravity - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getGravity(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setGravity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setGravity - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - body->setGravity(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getFriction - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getFriction - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getFriction(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setFriction - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setFriction - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setFriction(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setDamping - * Signature: (JFF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setDamping - (JNIEnv *env, jobject object, jlong bodyId, jfloat value1, jfloat value2) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setDamping(value1, value2); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setAngularDamping - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularDamping - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setDamping(body->getLinearDamping(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getLinearDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearDamping - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getLinearDamping(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getAngularDamping - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularDamping - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getAngularDamping(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getRestitution - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getRestitution - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getRestitution(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setRestitution - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setRestitution - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setRestitution(value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getAngularVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularVelocity - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getAngularVelocity(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setAngularVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularVelocity - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - body->setAngularVelocity(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getLinearVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearVelocity - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getLinearVelocity(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setLinearVelocity - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearVelocity - (JNIEnv *env, jobject object, jlong bodyId, jobject value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, value, &vec); - body->setLinearVelocity(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: applyForce - * Signature: (JLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyForce - (JNIEnv *env, jobject object, jlong bodyId, jobject force, jobject location) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec1 = btVector3(); - btVector3 vec2 = btVector3(); - jmeBulletUtil::convert(env, force, &vec1); - jmeBulletUtil::convert(env, location, &vec2); - body->applyForce(vec1, vec2); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: applyCentralForce - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyCentralForce - (JNIEnv *env, jobject object, jlong bodyId, jobject force) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, force, &vec1); - body->applyCentralForce(vec1); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: applyTorque - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyTorque - (JNIEnv *env, jobject object, jlong bodyId, jobject force) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, force, &vec1); - body->applyTorque(vec1); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: applyImpulse - * Signature: (JLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyImpulse - (JNIEnv *env, jobject object, jlong bodyId, jobject force, jobject location) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec1 = btVector3(); - btVector3 vec2 = btVector3(); - jmeBulletUtil::convert(env, force, &vec1); - jmeBulletUtil::convert(env, location, &vec2); - body->applyImpulse(vec1, vec2); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: applyTorqueImpulse - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_applyTorqueImpulse - (JNIEnv *env, jobject object, jlong bodyId, jobject force) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec1 = btVector3(); - jmeBulletUtil::convert(env, force, &vec1); - body->applyTorqueImpulse(vec1); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: clearForces - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_clearForces - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->clearForces(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setCollisionShape - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setCollisionShape - (JNIEnv *env, jobject object, jlong bodyId, jlong shapeId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btCollisionShape* shape = reinterpret_cast(shapeId); - body->setCollisionShape(shape); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: activate - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_activate - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->activate(false); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: isActive - * Signature: (J)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_isActive - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return body->isActive(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setSleepingThresholds - * Signature: (JFF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setSleepingThresholds - (JNIEnv *env, jobject object, jlong bodyId, jfloat linear, jfloat angular) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setSleepingThresholds(linear, angular); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setLinearSleepingThreshold - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearSleepingThreshold - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setSleepingThresholds(value, body->getAngularSleepingThreshold()); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setAngularSleepingThreshold - * Signature: (JF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularSleepingThreshold - (JNIEnv *env, jobject object, jlong bodyId, jfloat value) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - body->setSleepingThresholds(body->getLinearSleepingThreshold(), value); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getLinearSleepingThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearSleepingThreshold - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getLinearSleepingThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getAngularSleepingThreshold - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularSleepingThreshold - (JNIEnv *env, jobject object, jlong bodyId) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return body->getAngularSleepingThreshold(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getAngularFactor - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor - (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getAngularFactor(), factor); - } - - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setAngularFactor - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor - (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, factor, &vec); - body->setAngularFactor(vec); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: getLinearFactor - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearFactor - (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &body->getLinearFactor(), factor); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsRigidBody - * Method: setLinearFactor - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearFactor - (JNIEnv *env, jobject object, jlong bodyId, jobject factor) { - btRigidBody* body = reinterpret_cast(bodyId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 vec = btVector3(); - jmeBulletUtil::convert(env, factor, &vec); - body->setLinearFactor(vec); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsVehicle.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsVehicle.cpp deleted file mode 100644 index 58ceaf9daf..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsVehicle.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ - -#include "com_jme3_bullet_objects_PhysicsVehicle.h" -#include "jmeBulletUtil.h" -#include "jmePhysicsSpace.h" -#include "BulletDynamics/Vehicle/btRaycastVehicle.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: updateWheelTransform - * Signature: (JIZ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_updateWheelTransform - (JNIEnv *env, jobject object, jlong vehicleId, jint wheel, jboolean interpolated) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - vehicle->updateWheelTransform(wheel, interpolated); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: createVehicleRaycaster - * Signature: (JJ)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_createVehicleRaycaster - (JNIEnv *env, jobject object, jlong bodyId, jlong spaceId) { - //btRigidBody* body = reinterpret_cast bodyId; - jmeClasses::initJavaClasses(env); - jmePhysicsSpace *space = reinterpret_cast(spaceId); - if (space == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btDefaultVehicleRaycaster* caster = new btDefaultVehicleRaycaster(space->getDynamicsWorld()); - return reinterpret_cast(caster); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: createRaycastVehicle - * Signature: (JJ)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_createRaycastVehicle - (JNIEnv *env, jobject object, jlong objectId, jlong casterId) { - jmeClasses::initJavaClasses(env); - btRigidBody* body = reinterpret_cast(objectId); - if (body == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - body->setActivationState(DISABLE_DEACTIVATION); - btVehicleRaycaster* caster = reinterpret_cast(casterId); - if (caster == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btRaycastVehicle::btVehicleTuning tuning; - btRaycastVehicle* vehicle = new btRaycastVehicle(tuning, body, caster); - return reinterpret_cast(vehicle); - - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: setCoordinateSystem - * Signature: (JIII)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_setCoordinateSystem - (JNIEnv *env, jobject object, jlong vehicleId, jint right, jint up, jint forward) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - vehicle->setCoordinateSystem(right, up, forward); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: addWheel - * Signature: (JLcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;Lcom/jme3/math/Vector3f;FFLcom/jme3/bullet/objects/infos/VehicleTuning;Z)J - */ - JNIEXPORT jint JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_addWheel - (JNIEnv *env, jobject object, jlong vehicleId, jobject location, jobject direction, jobject axle, jfloat restLength, jfloat radius, jobject tuning, jboolean frontWheel) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - btVector3 vec1 = btVector3(); - btVector3 vec2 = btVector3(); - btVector3 vec3 = btVector3(); - jmeBulletUtil::convert(env, location, &vec1); - jmeBulletUtil::convert(env, direction, &vec2); - jmeBulletUtil::convert(env, axle, &vec3); - btRaycastVehicle::btVehicleTuning tune; - btWheelInfo* info = &vehicle->addWheel(vec1, vec2, vec3, restLength, radius, tune, frontWheel); - int idx = vehicle->getNumWheels(); - return idx-1; - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: resetSuspension - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_resetSuspension - (JNIEnv *env, jobject object, jlong vehicleId) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - vehicle->resetSuspension(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: applyEngineForce - * Signature: (JIF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_applyEngineForce - (JNIEnv *env, jobject object, jlong vehicleId, jint wheel, jfloat force) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - vehicle->applyEngineForce(force, wheel); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: steer - * Signature: (JIF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_steer - (JNIEnv *env, jobject object, jlong vehicleId, jint wheel, jfloat value) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - vehicle->setSteeringValue(value, wheel); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: brake - * Signature: (JIF)F - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_brake - (JNIEnv *env, jobject object, jlong vehicleId, jint wheel, jfloat value) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - vehicle->setBrake(value, wheel); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: getCurrentVehicleSpeedKmHour - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_getCurrentVehicleSpeedKmHour - (JNIEnv *env, jobject object, jlong vehicleId) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return vehicle->getCurrentSpeedKmHour(); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: getForwardVector - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_getForwardVector - (JNIEnv *env, jobject object, jlong vehicleId, jobject out) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - btVector3 forwardVector = vehicle->getForwardVector(); - jmeBulletUtil::convert(env, &forwardVector, out); - } - - /* - * Class: com_jme3_bullet_objects_PhysicsVehicle - * Method: finalizeNative - * Signature: (JJ)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsVehicle_finalizeNative - (JNIEnv *env, jobject object, jlong casterId, jlong vehicleId) { - btVehicleRaycaster* rayCaster = reinterpret_cast(casterId); - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - delete(vehicle); - if (rayCaster == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - delete(rayCaster); - } - -#ifdef __cplusplus -} -#endif - diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_VehicleWheel.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_VehicleWheel.cpp deleted file mode 100644 index b3d38a6733..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_VehicleWheel.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ - -#include "com_jme3_bullet_objects_VehicleWheel.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: getWheelLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getWheelLocation - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_worldTransform.getOrigin(), out); - } - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: getWheelRotation - * Signature: (JLcom/jme3/math/Matrix3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getWheelRotation - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_worldTransform.getBasis(), out); - } - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: applyInfo - * Signature: (JFFFFFFFFZF)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_applyInfo - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jfloat suspensionStiffness, jfloat wheelsDampingRelaxation, jfloat wheelsDampingCompression, jfloat frictionSlip, jfloat rollInfluence, jfloat maxSuspensionTravelCm, jfloat maxSuspensionForce, jfloat radius, jboolean frontWheel, jfloat restLength) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - vehicle->getWheelInfo(wheelIndex).m_suspensionStiffness = suspensionStiffness; - vehicle->getWheelInfo(wheelIndex).m_wheelsDampingRelaxation = wheelsDampingRelaxation; - vehicle->getWheelInfo(wheelIndex).m_wheelsDampingCompression = wheelsDampingCompression; - vehicle->getWheelInfo(wheelIndex).m_frictionSlip = frictionSlip; - vehicle->getWheelInfo(wheelIndex).m_rollInfluence = rollInfluence; - vehicle->getWheelInfo(wheelIndex).m_maxSuspensionTravelCm = maxSuspensionTravelCm; - vehicle->getWheelInfo(wheelIndex).m_maxSuspensionForce = maxSuspensionForce; - vehicle->getWheelInfo(wheelIndex).m_wheelsRadius = radius; - vehicle->getWheelInfo(wheelIndex).m_bIsFrontWheel = frontWheel; - vehicle->getWheelInfo(wheelIndex).m_suspensionRestLength1 = restLength; - - } - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: getCollisionLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getCollisionLocation - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_raycastInfo.m_contactPointWS, out); - } - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: getCollisionNormal - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getCollisionNormal - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex, jobject out) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &vehicle->getWheelInfo(wheelIndex).m_raycastInfo.m_contactNormalWS, out); - } - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: getSkidInfo - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getSkidInfo - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return vehicle->getWheelInfo(wheelIndex).m_skidInfo; - } - - /* - * Class: com_jme3_bullet_objects_VehicleWheel - * Method: getDeltaRotation - * Signature: (J)F - */ - JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_VehicleWheel_getDeltaRotation - (JNIEnv *env, jobject object, jlong vehicleId, jint wheelIndex) { - btRaycastVehicle* vehicle = reinterpret_cast(vehicleId); - if (vehicle == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return 0; - } - return vehicle->getWheelInfo(wheelIndex).m_deltaRotation; - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_infos_RigidBodyMotionState.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_infos_RigidBodyMotionState.cpp deleted file mode 100644 index 5f614f052d..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_infos_RigidBodyMotionState.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_objects_infos_RigidBodyMotionState.h" -#include "jmeBulletUtil.h" -#include "jmeMotionState.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_objects_infos_RigidBodyMotionState - * Method: createMotionState - * Signature: ()J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_createMotionState - (JNIEnv *env, jobject object) { - jmeClasses::initJavaClasses(env); - jmeMotionState* motionState = new jmeMotionState(); - return reinterpret_cast(motionState); - } - - /* - * Class: com_jme3_bullet_objects_infos_RigidBodyMotionState - * Method: applyTransform - * Signature: (JLcom/jme3/math/Vector3f;Lcom/jme3/math/Quaternion;)Z - */ - JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_applyTransform - (JNIEnv *env, jobject object, jlong stateId, jobject location, jobject rotation) { - jmeMotionState* motionState = reinterpret_cast(stateId); - if (motionState == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return false; - } - return motionState->applyTransform(env, location, rotation); - } - - /* - * Class: com_jme3_bullet_objects_infos_RigidBodyMotionState - * Method: getWorldLocation - * Signature: (JLcom/jme3/math/Vector3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_getWorldLocation - (JNIEnv *env, jobject object, jlong stateId, jobject value) { - jmeMotionState* motionState = reinterpret_cast(stateId); - if (motionState == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &motionState->worldTransform.getOrigin(), value); - } - - /* - * Class: com_jme3_bullet_objects_infos_RigidBodyMotionState - * Method: getWorldRotation - * Signature: (JLcom/jme3/math/Matrix3f;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_getWorldRotation - (JNIEnv *env, jobject object, jlong stateId, jobject value) { - jmeMotionState* motionState = reinterpret_cast(stateId); - if (motionState == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convert(env, &motionState->worldTransform.getBasis(), value); - } - - /* - * Class: com_jme3_bullet_objects_infos_RigidBodyMotionState - * Method: getWorldRotationQuat - * Signature: (JLcom/jme3/math/Quaternion;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_getWorldRotationQuat - (JNIEnv *env, jobject object, jlong stateId, jobject value) { - jmeMotionState* motionState = reinterpret_cast(stateId); - if (motionState == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - jmeBulletUtil::convertQuat(env, &motionState->worldTransform.getBasis(), value); - } - - /* - * Class: com_jme3_bullet_objects_infos_RigidBodyMotionState - * Method: finalizeNative - * Signature: (J)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_infos_RigidBodyMotionState_finalizeNative - (JNIEnv *env, jobject object, jlong stateId) { - jmeMotionState* motionState = reinterpret_cast(stateId); - if (motionState == NULL) { - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, "The native object does not exist."); - return; - } - delete(motionState); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_util_DebugShapeFactory.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_util_DebugShapeFactory.cpp deleted file mode 100644 index 0496cb07de..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_util_DebugShapeFactory.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen, CJ Hare - */ -#include "com_jme3_bullet_util_DebugShapeFactory.h" -#include "jmeBulletUtil.h" -#include "BulletCollision/CollisionShapes/btShapeHull.h" - -class DebugCallback : public btTriangleCallback, public btInternalTriangleIndexCallback { -public: - JNIEnv* env; - jobject callback; - - DebugCallback(JNIEnv* env, jobject object) { - this->env = env; - this->callback = object; - } - - virtual void internalProcessTriangleIndex(btVector3* triangle, int partId, int triangleIndex) { - processTriangle(triangle, partId, triangleIndex); - } - - virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex) { - btVector3 vertexA, vertexB, vertexC; - vertexA = triangle[0]; - vertexB = triangle[1]; - vertexC = triangle[2]; - env->CallVoidMethod(callback, jmeClasses::DebugMeshCallback_addVector, vertexA.getX(), vertexA.getY(), vertexA.getZ(), partId, triangleIndex); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -// triangle = - env->CallVoidMethod(callback, jmeClasses::DebugMeshCallback_addVector, vertexB.getX(), vertexB.getY(), vertexB.getZ(), partId, triangleIndex); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->CallVoidMethod(callback, jmeClasses::DebugMeshCallback_addVector, vertexC.getX(), vertexC.getY(), vertexC.getZ(), partId, triangleIndex); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - } -}; - -#ifdef __cplusplus -extern "C" { -#endif - - /* Inaccessible static: _00024assertionsDisabled */ - - /* - * Class: com_jme3_bullet_util_DebugShapeFactory - * Method: getVertices - * Signature: (JLcom/jme3/bullet/util/DebugMeshCallback;)V - */ - JNIEXPORT void JNICALL Java_com_jme3_bullet_util_DebugShapeFactory_getVertices - (JNIEnv *env, jclass clazz, jlong shapeId, jobject callback) { - btCollisionShape* shape = reinterpret_cast(shapeId); - if (shape->isConcave()) { - btConcaveShape* concave = reinterpret_cast(shape); - DebugCallback* clb = new DebugCallback(env, callback); - btVector3 min = btVector3(-1e30, -1e30, -1e30); - btVector3 max = btVector3(1e30, 1e30, 1e30); - concave->processAllTriangles(clb, min, max); - delete(clb); - } else if (shape->isConvex()) { - btConvexShape* convexShape = reinterpret_cast(shape); - // Check there is a hull shape to render - if (convexShape->getUserPointer() == NULL) { - // create a hull approximation - btShapeHull* hull = new btShapeHull(convexShape); - float margin = convexShape->getMargin(); - hull->buildHull(margin); - convexShape->setUserPointer(hull); - } - - btShapeHull* hull = (btShapeHull*) convexShape->getUserPointer(); - - int numberOfTriangles = hull->numTriangles(); - int numberOfFloats = 3 * 3 * numberOfTriangles; - int byteBufferSize = numberOfFloats * 4; - - // Loop variables - const unsigned int* hullIndices = hull->getIndexPointer(); - const btVector3* hullVertices = hull->getVertexPointer(); - btVector3 vertexA, vertexB, vertexC; - int index = 0; - - for (int i = 0; i < numberOfTriangles; i++) { - // Grab the data for this triangle from the hull - vertexA = hullVertices[hullIndices[index++]]; - vertexB = hullVertices[hullIndices[index++]]; - vertexC = hullVertices[hullIndices[index++]]; - - // Put the verticies into the vertex buffer - env->CallVoidMethod(callback, jmeClasses::DebugMeshCallback_addVector, vertexA.getX(), vertexA.getY(), vertexA.getZ()); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->CallVoidMethod(callback, jmeClasses::DebugMeshCallback_addVector, vertexB.getX(), vertexB.getY(), vertexB.getZ()); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->CallVoidMethod(callback, jmeClasses::DebugMeshCallback_addVector, vertexC.getX(), vertexC.getY(), vertexC.getZ()); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - } - delete hull; - convexShape->setUserPointer(NULL); - } - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_util_NativeMeshUtil.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_util_NativeMeshUtil.cpp deleted file mode 100644 index a85d2d84df..0000000000 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_util_NativeMeshUtil.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * Author: Normen Hansen - */ -#include "com_jme3_bullet_util_NativeMeshUtil.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif - - /* - * Class: com_jme3_bullet_util_NativeMeshUtil - * Method: createTriangleIndexVertexArray - * Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;IIII)J - */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_util_NativeMeshUtil_createTriangleIndexVertexArray - (JNIEnv * env, jclass cls, jobject triangleIndexBase, jobject vertexIndexBase, jint numTriangles, jint numVertices, jint vertexStride, jint triangleIndexStride) { - jmeClasses::initJavaClasses(env); - int* triangles = (int*) env->GetDirectBufferAddress(triangleIndexBase); - float* vertices = (float*) env->GetDirectBufferAddress(vertexIndexBase); - btTriangleIndexVertexArray* array = new btTriangleIndexVertexArray(numTriangles, triangles, triangleIndexStride, numVertices, vertices, vertexStride); - return reinterpret_cast(array); - } - -#ifdef __cplusplus -} -#endif diff --git a/jme3-bullet-native/src/native/cpp/fake_win32/jni_md.h b/jme3-bullet-native/src/native/cpp/fake_win32/jni_md.h deleted file mode 100644 index 2cab367e98..0000000000 --- a/jme3-bullet-native/src/native/cpp/fake_win32/jni_md.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef JNI_MD_H -#define JNI_MD_H - -#ifndef __has_attribute -#define __has_attribute(x) 0 -#endif - -#define JNIEXPORT __declspec(dllexport) -#define JNIIMPORT __declspec(dllimport) -#define JNICALL - -typedef int jint; -typedef long long jlong; -typedef signed char jbyte; - -#endif diff --git a/jme3-bullet-native/src/native/cpp/jmeBulletUtil.cpp b/jme3-bullet-native/src/native/cpp/jmeBulletUtil.cpp deleted file mode 100644 index a51bcf8339..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmeBulletUtil.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "jmeBulletUtil.h" - -/** - * Author: Normen Hansen,Empire Phoenix, Lutherion - */ -void jmeBulletUtil::convert(JNIEnv* env, jobject in, btVector3* out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - float x = env->GetFloatField(in, jmeClasses::Vector3f_x); //env->CallFloatMethod(in, jmeClasses::Vector3f_getX); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float y = env->GetFloatField(in, jmeClasses::Vector3f_y); //env->CallFloatMethod(in, jmeClasses::Vector3f_getY); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float z = env->GetFloatField(in, jmeClasses::Vector3f_z); //env->CallFloatMethod(in, jmeClasses::Vector3f_getZ); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - out->setX(x); - out->setY(y); - out->setZ(z); -} - -void jmeBulletUtil::convert(JNIEnv* env, jobject in, btQuaternion* out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - float x = env->GetFloatField(in, jmeClasses::Quaternion_x); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float y = env->GetFloatField(in, jmeClasses::Quaternion_y); //env->CallFloatMethod(in, jmeClasses::Vector3f_getY); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float z = env->GetFloatField(in, jmeClasses::Quaternion_z); //env->CallFloatMethod(in, jmeClasses::Vector3f_getZ); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - float w = env->GetFloatField(in, jmeClasses::Quaternion_w); //env->CallFloatMethod(in, jmeClasses::Vector3f_getZ); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - out->setX(x); - out->setY(y); - out->setZ(z); - out->setW(w); -} - - -void jmeBulletUtil::convert(JNIEnv* env, const btVector3* in, jobject out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - float x = in->getX(); - float y = in->getY(); - float z = in->getZ(); - env->SetFloatField(out, jmeClasses::Vector3f_x, x); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Vector3f_y, y); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Vector3f_z, z); - // env->CallObjectMethod(out, jmeClasses::Vector3f_set, x, y, z); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -} - -void jmeBulletUtil::convert(JNIEnv* env, jobject in, btMatrix3x3* out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - float m00 = env->GetFloatField(in, jmeClasses::Matrix3f_m00); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m01 = env->GetFloatField(in, jmeClasses::Matrix3f_m01); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m02 = env->GetFloatField(in, jmeClasses::Matrix3f_m02); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m10 = env->GetFloatField(in, jmeClasses::Matrix3f_m10); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m11 = env->GetFloatField(in, jmeClasses::Matrix3f_m11); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m12 = env->GetFloatField(in, jmeClasses::Matrix3f_m12); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m20 = env->GetFloatField(in, jmeClasses::Matrix3f_m20); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m21 = env->GetFloatField(in, jmeClasses::Matrix3f_m21); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float m22 = env->GetFloatField(in, jmeClasses::Matrix3f_m22); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - out->setValue(m00, m01, m02, m10, m11, m12, m20, m21, m22); -} - -void jmeBulletUtil::convert(JNIEnv* env, const btMatrix3x3* in, jobject out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - float m00 = in->getRow(0).m_floats[0]; - float m01 = in->getRow(0).m_floats[1]; - float m02 = in->getRow(0).m_floats[2]; - float m10 = in->getRow(1).m_floats[0]; - float m11 = in->getRow(1).m_floats[1]; - float m12 = in->getRow(1).m_floats[2]; - float m20 = in->getRow(2).m_floats[0]; - float m21 = in->getRow(2).m_floats[1]; - float m22 = in->getRow(2).m_floats[2]; - env->SetFloatField(out, jmeClasses::Matrix3f_m00, m00); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m01, m01); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m02, m02); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m10, m10); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m11, m11); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m12, m12); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m20, m20); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m21, m21); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Matrix3f_m22, m22); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -} - -void jmeBulletUtil::convertQuat(JNIEnv* env, jobject in, btMatrix3x3* out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - float x = env->GetFloatField(in, jmeClasses::Quaternion_x); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float y = env->GetFloatField(in, jmeClasses::Quaternion_y); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float z = env->GetFloatField(in, jmeClasses::Quaternion_z); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - float w = env->GetFloatField(in, jmeClasses::Quaternion_w); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - float norm = w * w + x * x + y * y + z * z; - float s = (norm == 1.0) ? 2.0 : (norm > 0.1) ? 2.0 / norm : 0.0; - - // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs - // will be used 2-4 times each. - float xs = x * s; - float ys = y * s; - float zs = z * s; - float xx = x * xs; - float xy = x * ys; - float xz = x * zs; - float xw = w * xs; - float yy = y * ys; - float yz = y * zs; - float yw = w * ys; - float zz = z * zs; - float zw = w * zs; - - // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here - out->setValue(1.0 - (yy + zz), (xy - zw), (xz + yw), - (xy + zw), 1 - (xx + zz), (yz - xw), - (xz - yw), (yz + xw), 1.0 - (xx + yy)); -} - -void jmeBulletUtil::convertQuat(JNIEnv* env, const btMatrix3x3* in, jobject out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - // the trace is the sum of the diagonal elements; see - // http://mathworld.wolfram.com/MatrixTrace.html - float t = in->getRow(0).m_floats[0] + in->getRow(1).m_floats[1] + in->getRow(2).m_floats[2]; - float w, x, y, z; - // we protect the division by s by ensuring that s>=1 - if (t >= 0) { // |w| >= .5 - float s = sqrt(t + 1); // |s|>=1 ... - w = 0.5f * s; - s = 0.5f / s; // so this division isn't bad - x = (in->getRow(2).m_floats[1] - in->getRow(1).m_floats[2]) * s; - y = (in->getRow(0).m_floats[2] - in->getRow(2).m_floats[0]) * s; - z = (in->getRow(1).m_floats[0] - in->getRow(0).m_floats[1]) * s; - } else if ((in->getRow(0).m_floats[0] > in->getRow(1).m_floats[1]) && (in->getRow(0).m_floats[0] > in->getRow(2).m_floats[2])) { - float s = sqrt(1.0f + in->getRow(0).m_floats[0] - in->getRow(1).m_floats[1] - in->getRow(2).m_floats[2]); // |s|>=1 - x = s * 0.5f; // |x| >= .5 - s = 0.5f / s; - y = (in->getRow(1).m_floats[0] + in->getRow(0).m_floats[1]) * s; - z = (in->getRow(0).m_floats[2] + in->getRow(2).m_floats[0]) * s; - w = (in->getRow(2).m_floats[1] - in->getRow(1).m_floats[2]) * s; - } else if (in->getRow(1).m_floats[1] > in->getRow(2).m_floats[2]) { - float s = sqrt(1.0f + in->getRow(1).m_floats[1] - in->getRow(0).m_floats[0] - in->getRow(2).m_floats[2]); // |s|>=1 - y = s * 0.5f; // |y| >= .5 - s = 0.5f / s; - x = (in->getRow(1).m_floats[0] + in->getRow(0).m_floats[1]) * s; - z = (in->getRow(2).m_floats[1] + in->getRow(1).m_floats[2]) * s; - w = (in->getRow(0).m_floats[2] - in->getRow(2).m_floats[0]) * s; - } else { - float s = sqrt(1.0f + in->getRow(2).m_floats[2] - in->getRow(0).m_floats[0] - in->getRow(1).m_floats[1]); // |s|>=1 - z = s * 0.5f; // |z| >= .5 - s = 0.5f / s; - x = (in->getRow(0).m_floats[2] + in->getRow(2).m_floats[0]) * s; - y = (in->getRow(2).m_floats[1] + in->getRow(1).m_floats[2]) * s; - w = (in->getRow(1).m_floats[0] - in->getRow(0).m_floats[1]) * s; - } - - env->SetFloatField(out, jmeClasses::Quaternion_x, x); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Quaternion_y, y); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Quaternion_z, z); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - env->SetFloatField(out, jmeClasses::Quaternion_w, w); - // env->CallObjectMethod(out, jmeClasses::Quaternion_set, x, y, z, w); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -} - -void jmeBulletUtil::addResult(JNIEnv* env, jobject resultlist, btVector3* hitnormal, btVector3* m_hitPointWorld, btScalar m_hitFraction, const btCollisionObject* hitobject) { - - jobject singleresult = env->AllocObject(jmeClasses::PhysicsRay_Class); - jobject hitnormalvec = env->AllocObject(jmeClasses::Vector3f); - - convert(env, hitnormal, hitnormalvec); - jmeUserPointer *up1 = (jmeUserPointer*) hitobject -> getUserPointer(); - - env->SetObjectField(singleresult, jmeClasses::PhysicsRay_normalInWorldSpace, hitnormalvec); - env->SetFloatField(singleresult, jmeClasses::PhysicsRay_hitfraction, m_hitFraction); - - env->SetObjectField(singleresult, jmeClasses::PhysicsRay_collisionObject, up1->javaCollisionObject); - env->CallBooleanMethod(resultlist, jmeClasses::PhysicsRay_addmethod, singleresult); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -} - - -void jmeBulletUtil::addSweepResult(JNIEnv* env, jobject resultlist, btVector3* hitnormal, btVector3* m_hitPointWorld, btScalar m_hitFraction, const btCollisionObject* hitobject) { - - jobject singleresult = env->AllocObject(jmeClasses::PhysicsSweep_Class); - jobject hitnormalvec = env->AllocObject(jmeClasses::Vector3f); - - convert(env, hitnormal, hitnormalvec); - jmeUserPointer *up1 = (jmeUserPointer*)hitobject->getUserPointer(); - - env->SetObjectField(singleresult, jmeClasses::PhysicsSweep_normalInWorldSpace, hitnormalvec); - env->SetFloatField(singleresult, jmeClasses::PhysicsSweep_hitfraction, m_hitFraction); - - env->SetObjectField(singleresult, jmeClasses::PhysicsSweep_collisionObject, up1->javaCollisionObject); - env->CallBooleanMethod(resultlist, jmeClasses::PhysicsSweep_addmethod, singleresult); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -} - -void jmeBulletUtil::convert(JNIEnv* env, jobject in, btTransform* out) { - if (in == NULL || out == NULL) { - jmeClasses::throwNPE(env); - } - - jobject translation_vec = env->CallObjectMethod(in, jmeClasses::Transform_translation); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - jobject rot_quat = env->CallObjectMethod(in, jmeClasses::Transform_rotation); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - /* - //Scale currently not supported by bullet - //@TBD: Create an assertion somewhere to avoid scale values - jobject scale_vec = env->GetObjectField(in, jmeClasses::Transform_scale); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - */ - btVector3 native_translation_vec = btVector3(); - //btVector3 native_scale_vec = btVector3(); - btQuaternion native_rot_quat = btQuaternion(); - - convert(env, translation_vec, &native_translation_vec); - //convert(env, scale_vec, native_scale_vec); - convert(env, rot_quat, &native_rot_quat); - - out->setRotation(native_rot_quat); - out->setOrigin(native_translation_vec); -} diff --git a/jme3-bullet-native/src/native/cpp/jmeBulletUtil.h b/jme3-bullet-native/src/native/cpp/jmeBulletUtil.h deleted file mode 100644 index 7d982c80ef..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmeBulletUtil.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "jmeClasses.h" -#include "btBulletDynamicsCommon.h" -#include "btBulletCollisionCommon.h" -#include "LinearMath/btVector3.h" - -/** - * Author: Normen Hansen - */ -class jmeBulletUtil{ -public: - static void convert(JNIEnv* env, jobject in, btVector3* out); - static void convert(JNIEnv* env, const btVector3* in, jobject out); - static void convert(JNIEnv* env, jobject in, btMatrix3x3* out); - static void convert(JNIEnv* env, jobject in, btQuaternion* out); - static void convert(JNIEnv* env, const btMatrix3x3* in, jobject out); - static void convertQuat(JNIEnv* env, jobject in, btMatrix3x3* out); - static void convertQuat(JNIEnv* env, const btMatrix3x3* in, jobject out); - static void convert(JNIEnv* env, jobject in, btTransform* out); - static void addResult(JNIEnv* env, jobject resultlist, btVector3* hitnormal, btVector3* m_hitPointWorld,const btScalar m_hitFraction,const btCollisionObject* hitobject); - static void addSweepResult(JNIEnv* env, jobject resultlist, btVector3* hitnormal, btVector3* m_hitPointWorld, const btScalar m_hitFraction, const btCollisionObject* hitobject); -private: - jmeBulletUtil(){}; - ~jmeBulletUtil(){}; - -}; - -class jmeUserPointer { -public: - jobject javaCollisionObject; - jint group; - jint groups; - void *space; -}; \ No newline at end of file diff --git a/jme3-bullet-native/src/native/cpp/jmeClasses.cpp b/jme3-bullet-native/src/native/cpp/jmeClasses.cpp deleted file mode 100644 index ae7784c826..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmeClasses.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "jmeClasses.h" -#include - -/** - * Author: Normen Hansen,Empire Phoenix, Lutherion - */ -//public fields -jclass jmeClasses::PhysicsSpace; -jmethodID jmeClasses::PhysicsSpace_preTick; -jmethodID jmeClasses::PhysicsSpace_postTick; -jmethodID jmeClasses::PhysicsSpace_addCollisionEvent; -jmethodID jmeClasses::PhysicsSpace_notifyCollisionGroupListeners; - -jclass jmeClasses::PhysicsGhostObject; -jmethodID jmeClasses::PhysicsGhostObject_addOverlappingObject; - -jclass jmeClasses::Vector3f; -jmethodID jmeClasses::Vector3f_set; -jmethodID jmeClasses::Vector3f_toArray; -jmethodID jmeClasses::Vector3f_getX; -jmethodID jmeClasses::Vector3f_getY; -jmethodID jmeClasses::Vector3f_getZ; -jfieldID jmeClasses::Vector3f_x; -jfieldID jmeClasses::Vector3f_y; -jfieldID jmeClasses::Vector3f_z; - -jclass jmeClasses::Quaternion; -jmethodID jmeClasses::Quaternion_set; -jmethodID jmeClasses::Quaternion_getX; -jmethodID jmeClasses::Quaternion_getY; -jmethodID jmeClasses::Quaternion_getZ; -jmethodID jmeClasses::Quaternion_getW; -jfieldID jmeClasses::Quaternion_x; -jfieldID jmeClasses::Quaternion_y; -jfieldID jmeClasses::Quaternion_z; -jfieldID jmeClasses::Quaternion_w; - -jclass jmeClasses::Matrix3f; -jmethodID jmeClasses::Matrix3f_set; -jmethodID jmeClasses::Matrix3f_get; -jfieldID jmeClasses::Matrix3f_m00; -jfieldID jmeClasses::Matrix3f_m01; -jfieldID jmeClasses::Matrix3f_m02; -jfieldID jmeClasses::Matrix3f_m10; -jfieldID jmeClasses::Matrix3f_m11; -jfieldID jmeClasses::Matrix3f_m12; -jfieldID jmeClasses::Matrix3f_m20; -jfieldID jmeClasses::Matrix3f_m21; -jfieldID jmeClasses::Matrix3f_m22; - -jclass jmeClasses::DebugMeshCallback; -jmethodID jmeClasses::DebugMeshCallback_addVector; - -jclass jmeClasses::PhysicsRay_Class; -jmethodID jmeClasses::PhysicsRay_newSingleResult; - -jfieldID jmeClasses::PhysicsRay_normalInWorldSpace; -jfieldID jmeClasses::PhysicsRay_hitfraction; -jfieldID jmeClasses::PhysicsRay_collisionObject; - -jclass jmeClasses::PhysicsRay_listresult; -jmethodID jmeClasses::PhysicsRay_addmethod; - -jclass jmeClasses::PhysicsSweep_Class; -jmethodID jmeClasses::PhysicsSweep_newSingleResult; - -jfieldID jmeClasses::PhysicsSweep_normalInWorldSpace; -jfieldID jmeClasses::PhysicsSweep_hitfraction; -jfieldID jmeClasses::PhysicsSweep_collisionObject; - -jclass jmeClasses::PhysicsSweep_listresult; -jmethodID jmeClasses::PhysicsSweep_addmethod; - - -jclass jmeClasses::Transform; -jmethodID jmeClasses::Transform_rotation; -jmethodID jmeClasses::Transform_translation; - -//private fields -//JNIEnv* jmeClasses::env; -JavaVM* jmeClasses::vm; - -void jmeClasses::initJavaClasses(JNIEnv* env) { -// if (env != NULL) { -// fprintf(stdout, "Check Java VM state\n"); -// fflush(stdout); -// int res = vm->AttachCurrentThread((void**) &jmeClasses::env, NULL); -// if (res < 0) { -// fprintf(stdout, "** ERROR: getting Java env!\n"); -// if (res == JNI_EVERSION) fprintf(stdout, "GetEnv Error because of different JNI Version!\n"); -// fflush(stdout); -// } -// return; -// } - if(PhysicsSpace!=NULL) return; - fprintf(stdout, "Bullet-Native: Initializing java classes\n"); - fflush(stdout); -// jmeClasses::env = env; - env->GetJavaVM(&vm); - - PhysicsSpace = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/PhysicsSpace")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsSpace_preTick = env->GetMethodID(PhysicsSpace, "preTick_native", "(F)V"); - PhysicsSpace_postTick = env->GetMethodID(PhysicsSpace, "postTick_native", "(F)V"); - PhysicsSpace_addCollisionEvent = env->GetMethodID(PhysicsSpace, "addCollisionEvent_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;J)V"); - PhysicsSpace_notifyCollisionGroupListeners = env->GetMethodID(PhysicsSpace, "notifyCollisionGroupListeners_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;)Z"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsGhostObject = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/objects/PhysicsGhostObject")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - PhysicsGhostObject_addOverlappingObject = env->GetMethodID(PhysicsGhostObject, "addOverlappingObject_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;)V"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - Vector3f = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Vector3f")); - Vector3f_set = env->GetMethodID(Vector3f, "set", "(FFF)Lcom/jme3/math/Vector3f;"); - Vector3f_toArray = env->GetMethodID(Vector3f, "toArray", "([F)[F"); - Vector3f_getX = env->GetMethodID(Vector3f, "getX", "()F"); - Vector3f_getY = env->GetMethodID(Vector3f, "getY", "()F"); - Vector3f_getZ = env->GetMethodID(Vector3f, "getZ", "()F"); - Vector3f_x = env->GetFieldID(Vector3f, "x", "F"); - Vector3f_y = env->GetFieldID(Vector3f, "y", "F"); - Vector3f_z = env->GetFieldID(Vector3f, "z", "F"); - - Quaternion = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Quaternion")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - Quaternion_set = env->GetMethodID(Quaternion, "set", "(FFFF)Lcom/jme3/math/Quaternion;"); - Quaternion_getW = env->GetMethodID(Quaternion, "getW", "()F"); - Quaternion_getX = env->GetMethodID(Quaternion, "getX", "()F"); - Quaternion_getY = env->GetMethodID(Quaternion, "getY", "()F"); - Quaternion_getZ = env->GetMethodID(Quaternion, "getZ", "()F"); - Quaternion_x = env->GetFieldID(Quaternion, "x", "F"); - Quaternion_y = env->GetFieldID(Quaternion, "y", "F"); - Quaternion_z = env->GetFieldID(Quaternion, "z", "F"); - Quaternion_w = env->GetFieldID(Quaternion, "w", "F"); - - Matrix3f = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Matrix3f")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - Matrix3f_set = env->GetMethodID(Matrix3f, "set", "(IIF)Lcom/jme3/math/Matrix3f;"); - Matrix3f_get = env->GetMethodID(Matrix3f, "get", "(II)F"); - Matrix3f_m00 = env->GetFieldID(Matrix3f, "m00", "F"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - Matrix3f_m01 = env->GetFieldID(Matrix3f, "m01", "F"); - Matrix3f_m02 = env->GetFieldID(Matrix3f, "m02", "F"); - Matrix3f_m10 = env->GetFieldID(Matrix3f, "m10", "F"); - Matrix3f_m11 = env->GetFieldID(Matrix3f, "m11", "F"); - Matrix3f_m12 = env->GetFieldID(Matrix3f, "m12", "F"); - Matrix3f_m20 = env->GetFieldID(Matrix3f, "m20", "F"); - Matrix3f_m21 = env->GetFieldID(Matrix3f, "m21", "F"); - Matrix3f_m22 = env->GetFieldID(Matrix3f, "m22", "F"); - - DebugMeshCallback = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/util/DebugMeshCallback")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - DebugMeshCallback_addVector = env->GetMethodID(DebugMeshCallback, "addVector", "(FFFII)V"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsRay_Class = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/collision/PhysicsRayTestResult")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsRay_newSingleResult = env->GetMethodID(PhysicsRay_Class,"","()V"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsRay_normalInWorldSpace = env->GetFieldID(PhysicsRay_Class,"hitNormalLocal","Lcom/jme3/math/Vector3f;"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - - PhysicsRay_hitfraction = env->GetFieldID(PhysicsRay_Class,"hitFraction","F"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - - PhysicsRay_collisionObject = env->GetFieldID(PhysicsRay_Class,"collisionObject","Lcom/jme3/bullet/collision/PhysicsCollisionObject;"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsRay_listresult = env->FindClass("java/util/List"); - PhysicsRay_listresult = (jclass)env->NewGlobalRef(PhysicsRay_listresult); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsRay_addmethod = env->GetMethodID(PhysicsRay_listresult,"add","(Ljava/lang/Object;)Z"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsSweep_Class = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/collision/PhysicsSweepTestResult")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; -} - - PhysicsSweep_newSingleResult = env->GetMethodID(PhysicsSweep_Class, "", "()V"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsSweep_normalInWorldSpace = env->GetFieldID(PhysicsSweep_Class, "hitNormalLocal", "Lcom/jme3/math/Vector3f;"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - - PhysicsSweep_hitfraction = env->GetFieldID(PhysicsSweep_Class, "hitFraction", "F"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - - PhysicsSweep_collisionObject = env->GetFieldID(PhysicsSweep_Class, "collisionObject", "Lcom/jme3/bullet/collision/PhysicsCollisionObject;"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsSweep_listresult = env->FindClass("java/util/List"); - PhysicsSweep_listresult = (jclass)env->NewGlobalRef(PhysicsSweep_listresult); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - PhysicsSweep_addmethod = env->GetMethodID(PhysicsSweep_listresult, "add", "(Ljava/lang/Object;)Z"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - Transform = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Transform")); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - Transform_rotation = env->GetMethodID(Transform, "getRotation", "()Lcom/jme3/math/Quaternion;"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - - Transform_translation = env->GetMethodID(Transform, "getTranslation", "()Lcom/jme3/math/Vector3f;"); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - -} - -void jmeClasses::throwNPE(JNIEnv* env) { - if (env == NULL) return; - jclass newExc = env->FindClass("java/lang/NullPointerException"); - env->ThrowNew(newExc, ""); - return; -} diff --git a/jme3-bullet-native/src/native/cpp/jmeClasses.h b/jme3-bullet-native/src/native/cpp/jmeClasses.h deleted file mode 100644 index bdead6b70d..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmeClasses.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include - -/** - * Author: Normen Hansen - */ - -class jmeClasses { -public: - static void initJavaClasses(JNIEnv* env); -// static JNIEnv* env; - static JavaVM* vm; - static jclass PhysicsSpace; - static jmethodID PhysicsSpace_preTick; - static jmethodID PhysicsSpace_postTick; - static jmethodID PhysicsSpace_addCollisionEvent; - static jclass PhysicsGhostObject; - static jmethodID PhysicsGhostObject_addOverlappingObject; - static jmethodID PhysicsSpace_notifyCollisionGroupListeners; - - static jclass Vector3f; - static jmethodID Vector3f_set; - static jmethodID Vector3f_getX; - static jmethodID Vector3f_getY; - static jmethodID Vector3f_getZ; - static jmethodID Vector3f_toArray; - static jfieldID Vector3f_x; - static jfieldID Vector3f_y; - static jfieldID Vector3f_z; - - static jclass Quaternion; - static jmethodID Quaternion_set; - static jmethodID Quaternion_getX; - static jmethodID Quaternion_getY; - static jmethodID Quaternion_getZ; - static jmethodID Quaternion_getW; - static jfieldID Quaternion_x; - static jfieldID Quaternion_y; - static jfieldID Quaternion_z; - static jfieldID Quaternion_w; - - static jclass Matrix3f; - static jmethodID Matrix3f_get; - static jmethodID Matrix3f_set; - static jfieldID Matrix3f_m00; - static jfieldID Matrix3f_m01; - static jfieldID Matrix3f_m02; - static jfieldID Matrix3f_m10; - static jfieldID Matrix3f_m11; - static jfieldID Matrix3f_m12; - static jfieldID Matrix3f_m20; - static jfieldID Matrix3f_m21; - static jfieldID Matrix3f_m22; - - static jclass PhysicsRay_Class; - static jmethodID PhysicsRay_newSingleResult; - static jfieldID PhysicsRay_normalInWorldSpace; - static jfieldID PhysicsRay_hitfraction; - static jfieldID PhysicsRay_collisionObject; - static jclass PhysicsRay_listresult; - static jmethodID PhysicsRay_addmethod; - - static jclass PhysicsSweep_Class; - static jmethodID PhysicsSweep_newSingleResult; - static jfieldID PhysicsSweep_normalInWorldSpace; - static jfieldID PhysicsSweep_hitfraction; - static jfieldID PhysicsSweep_collisionObject; - static jclass PhysicsSweep_listresult; - static jmethodID PhysicsSweep_addmethod; - - static jclass Transform; - static jmethodID Transform_rotation; - static jmethodID Transform_translation; - - static jclass DebugMeshCallback; - static jmethodID DebugMeshCallback_addVector; - - static void throwNPE(JNIEnv* env); -private: - jmeClasses(){}; - ~jmeClasses(){}; -}; \ No newline at end of file diff --git a/jme3-bullet-native/src/native/cpp/jmeMotionState.cpp b/jme3-bullet-native/src/native/cpp/jmeMotionState.cpp deleted file mode 100644 index 7c14207fe9..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmeMotionState.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "jmeMotionState.h" -#include "jmeBulletUtil.h" - -/** - * Author: Normen Hansen - */ - -jmeMotionState::jmeMotionState() { - trans = new btTransform(); - trans -> setIdentity(); - worldTransform = *trans; - dirty = true; -} - -void jmeMotionState::getWorldTransform(btTransform& worldTrans) const { - worldTrans = worldTransform; -} - -void jmeMotionState::setWorldTransform(const btTransform& worldTrans) { - worldTransform = worldTrans; - dirty = true; -} - -void jmeMotionState::setKinematicTransform(const btTransform& worldTrans) { - worldTransform = worldTrans; - dirty = true; -} - -void jmeMotionState::setKinematicLocation(JNIEnv* env, jobject location) { - jmeBulletUtil::convert(env, location, &worldTransform.getOrigin()); - dirty = true; -} - -void jmeMotionState::setKinematicRotation(JNIEnv* env, jobject rotation) { - jmeBulletUtil::convert(env, rotation, &worldTransform.getBasis()); - dirty = true; -} - -void jmeMotionState::setKinematicRotationQuat(JNIEnv* env, jobject rotation) { - jmeBulletUtil::convertQuat(env, rotation, &worldTransform.getBasis()); - dirty = true; -} - -bool jmeMotionState::applyTransform(JNIEnv* env, jobject location, jobject rotation) { - if (dirty) { - // fprintf(stdout, "Apply world translation\n"); - // fflush(stdout); - jmeBulletUtil::convert(env, &worldTransform.getOrigin(), location); - jmeBulletUtil::convertQuat(env, &worldTransform.getBasis(), rotation); - dirty = false; - return true; - } - return false; -} - -jmeMotionState::~jmeMotionState() { - free(trans); -} diff --git a/jme3-bullet-native/src/native/cpp/jmeMotionState.h b/jme3-bullet-native/src/native/cpp/jmeMotionState.h deleted file mode 100644 index d4e4d195f6..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmeMotionState.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include - -/** - * Author: Normen Hansen - */ - -#include "btBulletDynamicsCommon.h" -//#include "btBulletCollisionCommon.h" - -class jmeMotionState : public btMotionState { -private: - bool dirty; - btTransform* trans; -public: - jmeMotionState(); - virtual ~jmeMotionState(); - - btTransform worldTransform; - virtual void getWorldTransform(btTransform& worldTrans) const; - virtual void setWorldTransform(const btTransform& worldTrans); - void setKinematicTransform(const btTransform& worldTrans); - void setKinematicLocation(JNIEnv*, jobject); - void setKinematicRotation(JNIEnv*, jobject); - void setKinematicRotationQuat(JNIEnv*, jobject); - bool applyTransform(JNIEnv* env, jobject location, jobject rotation); -}; diff --git a/jme3-bullet-native/src/native/cpp/jmePhysicsSpace.cpp b/jme3-bullet-native/src/native/cpp/jmePhysicsSpace.cpp deleted file mode 100644 index 953511a713..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmePhysicsSpace.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "jmePhysicsSpace.h" -#include "jmeBulletUtil.h" - -/** - * Author: Normen Hansen - */ -jmePhysicsSpace::jmePhysicsSpace(JNIEnv* env, jobject javaSpace) { - //TODO: global ref? maybe not -> cleaning, rather callback class? - this->javaPhysicsSpace = env->NewWeakGlobalRef(javaSpace); - this->env = env; - env->GetJavaVM(&vm); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } -} - -void jmePhysicsSpace::attachThread() { -#ifdef ANDROID - vm->AttachCurrentThread((JNIEnv**) &env, NULL); -#elif defined (JNI_VERSION_1_2) - vm->AttachCurrentThread((void**) &env, NULL); -#else - vm->AttachCurrentThread(&env, NULL); -#endif -} - -JNIEnv* jmePhysicsSpace::getEnv() { - attachThread(); - return this->env; -} - -void jmePhysicsSpace::stepSimulation(jfloat tpf, jint maxSteps, jfloat accuracy) { - dynamicsWorld->stepSimulation(tpf, maxSteps, accuracy); -} - -void jmePhysicsSpace::createPhysicsSpace(jfloat minX, jfloat minY, jfloat minZ, jfloat maxX, jfloat maxY, jfloat maxZ, jint broadphaseId, jboolean threading /*unused*/) { - btCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); - - btVector3 min = btVector3(minX, minY, minZ); - btVector3 max = btVector3(maxX, maxY, maxZ); - - btBroadphaseInterface* broadphase; - - switch (broadphaseId) { - case 0: // SIMPLE - broadphase = new btSimpleBroadphase(); - break; - case 1: // AXIS_SWEEP_3 - broadphase = new btAxisSweep3(min, max); - break; - case 2: // AXIS_SWEEP_3_32 - broadphase = new bt32BitAxisSweep3(min, max); - break; - case 3: // DBVT - broadphase = new btDbvtBroadphase(); - break; - } - - btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); - btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher); - - btConstraintSolver* solver = new btSequentialImpulseConstraintSolver(); - - //create dynamics world - btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); - dynamicsWorld = world; - dynamicsWorld->setWorldUserInfo(this); - - broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback()); - dynamicsWorld->setGravity(btVector3(0, -9.81f, 0)); - - struct jmeFilterCallback : public btOverlapFilterCallback { - // return true when pairs need collision - - virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy * proxy1) const { - // bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0; - // collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask); - bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0; - collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask); - if (collides) { - btCollisionObject* co0 = (btCollisionObject*) proxy0->m_clientObject; - btCollisionObject* co1 = (btCollisionObject*) proxy1->m_clientObject; - jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer(); - jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer(); - if (up0 != NULL && up1 != NULL) { - collides = (up0->group & up1->groups) != 0 || (up1->group & up0->groups) != 0; - - if(collides){ - jmePhysicsSpace *dynamicsWorld = (jmePhysicsSpace *)up0->space; - JNIEnv* env = dynamicsWorld->getEnv(); - jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace()); - jobject javaCollisionObject0 = env->NewLocalRef(up0->javaCollisionObject); - jobject javaCollisionObject1 = env->NewLocalRef(up1->javaCollisionObject); - - jboolean notifyResult = env->CallBooleanMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_notifyCollisionGroupListeners, javaCollisionObject0, javaCollisionObject1); - - env->DeleteLocalRef(javaPhysicsSpace); - env->DeleteLocalRef(javaCollisionObject0); - env->DeleteLocalRef(javaCollisionObject1); - - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return collides; - } - - collides = (bool) notifyResult; - } - - //add some additional logic here that modified 'collides' - return collides; - } - return false; - } - return collides; - } - }; - dynamicsWorld->getPairCache()->setOverlapFilterCallback(new jmeFilterCallback()); - dynamicsWorld->setInternalTickCallback(&jmePhysicsSpace::preTickCallback, static_cast (this), true); - dynamicsWorld->setInternalTickCallback(&jmePhysicsSpace::postTickCallback, static_cast (this)); - if (gContactStartedCallback == NULL) { - gContactStartedCallback = &jmePhysicsSpace::contactStartedCallback; - } -} - -void jmePhysicsSpace::preTickCallback(btDynamicsWorld *world, btScalar timeStep) { - jmePhysicsSpace* dynamicsWorld = (jmePhysicsSpace*) world->getWorldUserInfo(); - JNIEnv* env = dynamicsWorld->getEnv(); - jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace()); - if (javaPhysicsSpace != NULL) { - env->CallVoidMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_preTick, timeStep); - env->DeleteLocalRef(javaPhysicsSpace); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - } -} - -void jmePhysicsSpace::postTickCallback(btDynamicsWorld *world, btScalar timeStep) { - jmePhysicsSpace* dynamicsWorld = (jmePhysicsSpace*) world->getWorldUserInfo(); - JNIEnv* env = dynamicsWorld->getEnv(); - jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace()); - if (javaPhysicsSpace != NULL) { - env->CallVoidMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_postTick, timeStep); - env->DeleteLocalRef(javaPhysicsSpace); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - return; - } - } -} - -void jmePhysicsSpace::contactStartedCallback(btPersistentManifold* const &pm) { - const btCollisionObject* co0 = pm->getBody0(); - const btCollisionObject* co1 = pm->getBody1(); - jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer(); - jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer(); - if (up0 != NULL) { - jmePhysicsSpace *dynamicsWorld = (jmePhysicsSpace *)up0->space; - if (dynamicsWorld != NULL) { - JNIEnv* env = dynamicsWorld->getEnv(); - jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace()); - if (javaPhysicsSpace != NULL) { - jobject javaCollisionObject0 = env->NewLocalRef(up0->javaCollisionObject); - jobject javaCollisionObject1 = env->NewLocalRef(up1->javaCollisionObject); - for(int i=0;igetNumContacts();i++){ - env->CallVoidMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_addCollisionEvent, javaCollisionObject0, javaCollisionObject1, (jlong) & pm->getContactPoint(i)); - if (env->ExceptionCheck()) { - env->Throw(env->ExceptionOccurred()); - } - } - env->DeleteLocalRef(javaPhysicsSpace); - env->DeleteLocalRef(javaCollisionObject0); - env->DeleteLocalRef(javaCollisionObject1); - } - } - } -} - -btDynamicsWorld* jmePhysicsSpace::getDynamicsWorld() { - return dynamicsWorld; -} - -jobject jmePhysicsSpace::getJavaPhysicsSpace() { - return javaPhysicsSpace; -} - -jmePhysicsSpace::~jmePhysicsSpace() { - delete(dynamicsWorld); -} diff --git a/jme3-bullet-native/src/native/cpp/jmePhysicsSpace.h b/jme3-bullet-native/src/native/cpp/jmePhysicsSpace.h deleted file mode 100644 index 72c49b23cf..0000000000 --- a/jme3-bullet-native/src/native/cpp/jmePhysicsSpace.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "btBulletDynamicsCommon.h" -#include "btBulletCollisionCommon.h" -#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" -#include "BulletCollision/CollisionDispatch/btCollisionObject.h" -#include "BulletCollision/CollisionDispatch/btGhostObject.h" -#include "BulletDynamics/Character/btKinematicCharacterController.h" -#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h" -#include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" -#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" -#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h" - -/** - * Author: Normen Hansen - */ -class jmePhysicsSpace { -private: - JNIEnv* env; - JavaVM* vm; - btDynamicsWorld* dynamicsWorld; - jobject javaPhysicsSpace; - void attachThread(); -public: - jmePhysicsSpace(){}; - ~jmePhysicsSpace(); - jmePhysicsSpace(JNIEnv*, jobject); - void stepSimulation(jfloat, jint, jfloat); - void createPhysicsSpace(jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint, jboolean); - btDynamicsWorld* getDynamicsWorld(); - jobject getJavaPhysicsSpace(); - JNIEnv* getEnv(); - static void preTickCallback(btDynamicsWorld*, btScalar); - static void postTickCallback(btDynamicsWorld*, btScalar); - static void contactStartedCallback(btPersistentManifold* const &); -}; \ No newline at end of file diff --git a/jme3-bullet/build.gradle b/jme3-bullet/build.gradle deleted file mode 100644 index 64185b3442..0000000000 --- a/jme3-bullet/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -apply plugin: 'java' - -if (!hasProperty('mainClass')) { - ext.mainClass = '' -} - -String classBuildDir = "${buildDir}" + File.separator + 'classes' -def nativeIncludes = new File(project(":jme3-bullet-native").projectDir, "src/native/cpp") - -sourceSets { - main { - java { - srcDir 'src/main/java' - srcDir 'src/common/java' - } - } -} - -dependencies { - compile project(':jme3-core') - compile project(':jme3-terrain') -} - -compileJava { - // The Android-Native Project requires the jni headers to be generated, so we do that here - options.compilerArgs += ["-h", nativeIncludes] -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java b/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java deleted file mode 100644 index 4d64c454b9..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java +++ /dev/null @@ -1,1377 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet; - -import com.jme3.app.AppTask; -import com.jme3.bullet.collision.*; -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.bullet.control.PhysicsControl; -import com.jme3.bullet.control.RigidBodyControl; -import com.jme3.bullet.joints.PhysicsJoint; -import com.jme3.bullet.objects.PhysicsCharacter; -import com.jme3.bullet.objects.PhysicsGhostObject; -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.bullet.objects.PhysicsVehicle; -import com.jme3.math.Transform; -import com.jme3.math.Vector3f; -import com.jme3.scene.Node; -import com.jme3.scene.Spatial; -import com.jme3.util.SafeArrayList; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Comparator; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Future; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A jbullet-jme physics space with its own btDynamicsWorld. - * - * @author normenhansen - */ -public class PhysicsSpace { - - /** - * message logger for this class - */ - private static final Logger logger = Logger.getLogger(PhysicsSpace.class.getName()); - /** - * index of the X axis - */ - public static final int AXIS_X = 0; - /** - * index of the Y axis - */ - public static final int AXIS_Y = 1; - /** - * index of the Z axis - */ - public static final int AXIS_Z = 2; - /** - * Bullet identifier of the physics space. The constructor sets this to a - * non-zero value. - */ - private long physicsSpaceId = 0; - /** - * first-in/first-out (FIFO) queue of physics tasks for each thread - */ - private static ThreadLocal>> pQueueTL = - new ThreadLocal>>() { - @Override - protected ConcurrentLinkedQueue> initialValue() { - return new ConcurrentLinkedQueue>(); - } - }; - /** - * first-in/first-out (FIFO) queue of physics tasks - */ - private ConcurrentLinkedQueue> pQueue = new ConcurrentLinkedQueue>(); - /** - * physics space for each thread - */ - private static ThreadLocal physicsSpaceTL = new ThreadLocal(); - /** - * copy of type of acceleration structure used - */ - private BroadphaseType broadphaseType = BroadphaseType.DBVT; -// private DiscreteDynamicsWorld dynamicsWorld = null; -// private BroadphaseInterface broadphase; -// private CollisionDispatcher dispatcher; -// private ConstraintSolver solver; -// private DefaultCollisionConfiguration collisionConfiguration; -// private Map physicsGhostNodes = new ConcurrentHashMap(); - private Map physicsGhostObjects = new ConcurrentHashMap(); - private Map physicsCharacters = new ConcurrentHashMap(); - private Map physicsBodies = new ConcurrentHashMap(); - private Map physicsJoints = new ConcurrentHashMap(); - private Map physicsVehicles = new ConcurrentHashMap(); - /** - * list of registered collision listeners - */ - final private List collisionListeners - = new SafeArrayList<>(PhysicsCollisionListener.class); - /** - * queue of collision events not yet distributed to listeners - */ - private ArrayDeque collisionEvents = new ArrayDeque(); - /** - * map from collision groups to registered group listeners - */ - private Map collisionGroupListeners = new ConcurrentHashMap(); - /** - * queue of registered tick listeners - */ - private ConcurrentLinkedQueue tickListeners = new ConcurrentLinkedQueue(); - private PhysicsCollisionEventFactory eventFactory = new PhysicsCollisionEventFactory(); - /** - * copy of minimum coordinate values when using AXIS_SWEEP broadphase - * algorithms - */ - private Vector3f worldMin = new Vector3f(-10000f, -10000f, -10000f); - /** - * copy of maximum coordinate values when using AXIS_SWEEP broadphase - * algorithms - */ - private Vector3f worldMax = new Vector3f(10000f, 10000f, 10000f); - /** - * physics time step (in seconds, >0) - */ - private float accuracy = 1f / 60f; - /** - * maximum number of physics steps per frame (≥0, default=4) - */ - private int maxSubSteps = 4; - /** - * flags used in ray tests - */ - private int rayTestFlags = 1 << 2; - /** - * copy of number of iterations used by the contact-and-constraint solver - * (default=10) - */ - private int solverNumIterations = 10; - - static { -// System.loadLibrary("bulletjme"); -// initNativePhysics(); - } - - /** - * Access the PhysicsSpace running on this thread. For parallel - * physics, this can be invoked from the OpenGL thread. - * - * @return the PhysicsSpace running on this thread - */ - public static PhysicsSpace getPhysicsSpace() { - return physicsSpaceTL.get(); - } - - /** - * Used internally - * - * @param space which physics space to simulate on this thread - */ - public static void setLocalThreadPhysicsSpace(PhysicsSpace space) { - physicsSpaceTL.set(space); - } - - /** - * Instantiate a PhysicsSpace. Must be invoked on the designated physics - * thread. - */ - public PhysicsSpace() { - this(new Vector3f(-10000f, -10000f, -10000f), new Vector3f(10000f, 10000f, 10000f), BroadphaseType.DBVT); - } - - /** - * Instantiate a PhysicsSpace. Must be invoked on the designated physics - * thread. - */ - public PhysicsSpace(BroadphaseType broadphaseType) { - this(new Vector3f(-10000f, -10000f, -10000f), new Vector3f(10000f, 10000f, 10000f), broadphaseType); - } - - /** - * Instantiate a PhysicsSpace. Must be invoked on the designated physics - * thread. - */ - public PhysicsSpace(Vector3f worldMin, Vector3f worldMax) { - this(worldMin, worldMax, BroadphaseType.AXIS_SWEEP_3); - } - - /** - * Instantiate a PhysicsSpace. Must be invoked on the designated physics - * thread. - * - * @param worldMin the desired minimum coordinates values (not null, - * unaffected, default=-10k,-10k,-10k) - * @param worldMax the desired minimum coordinates values (not null, - * unaffected, default=10k,10k,10k) - * @param broadphaseType which broadphase collision-detection algorithm to - * use (not null) - */ - public PhysicsSpace(Vector3f worldMin, Vector3f worldMax, BroadphaseType broadphaseType) { - this.worldMin.set(worldMin); - this.worldMax.set(worldMax); - this.broadphaseType = broadphaseType; - create(); - } - - /** - * Must be invoked on the designated physics thread. - */ - public void create() { - physicsSpaceId = createPhysicsSpace(worldMin.x, worldMin.y, worldMin.z, worldMax.x, worldMax.y, worldMax.z, broadphaseType.ordinal(), false); - pQueueTL.set(pQueue); - physicsSpaceTL.set(this); - -// collisionConfiguration = new DefaultCollisionConfiguration(); -// dispatcher = new CollisionDispatcher(collisionConfiguration); -// switch (broadphaseType) { -// case SIMPLE: -// broadphase = new SimpleBroadphase(); -// break; -// case AXIS_SWEEP_3: -// broadphase = new AxisSweep3(Converter.convert(worldMin), Converter.convert(worldMax)); -// break; -// case AXIS_SWEEP_3_32: -// broadphase = new AxisSweep3_32(Converter.convert(worldMin), Converter.convert(worldMax)); -// break; -// case DBVT: -// broadphase = new DbvtBroadphase(); -// break; -// } -// -// solver = new SequentialImpulseConstraintSolver(); -// -// dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); -// dynamicsWorld.setGravity(new javax.vecmath.Vector3f(0, -9.81f, 0)); -// -// broadphase.getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback()); -// GImpactCollisionAlgorithm.registerAlgorithm(dispatcher); -// -// //register filter callback for tick / collision -// setTickCallback(); -// setContactCallbacks(); -// //register filter callback for collision groups -// setOverlapFilterCallback(); - } - - private native long createPhysicsSpace(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, int broadphaseType, boolean threading); - - /** - * Callback invoked just before the physics is stepped. - *

- * This method is invoked from native code. - * - * @param timeStep the time per physics step (in seconds, ≥0) - */ - private void preTick_native(float f) { - AppTask task; - while((task=pQueue.poll())!=null){ - if(task.isCancelled())continue; - try{ - task.invoke(); - } catch (Exception ex) { - logger.log(Level.SEVERE, null, ex); - } - } - - for (Iterator it = tickListeners.iterator(); it.hasNext();) { - PhysicsTickListener physicsTickCallback = it.next(); - physicsTickCallback.prePhysicsTick(this, f); - } - } - - /** - * Callback invoked just after the physics is stepped. - *

- * This method is invoked from native code. - * - * @param timeStep the time per physics step (in seconds, ≥0) - */ - private void postTick_native(float f) { - for (Iterator it = tickListeners.iterator(); it.hasNext();) { - PhysicsTickListener physicsTickCallback = it.next(); - physicsTickCallback.physicsTick(this, f); - } - } - - /** - * This method is invoked from native code. - */ - private void addCollision_native() { - } - - private boolean needCollision_native(PhysicsCollisionObject objectA, PhysicsCollisionObject objectB) { - return false; - } - -// private void setOverlapFilterCallback() { -// OverlapFilterCallback callback = new OverlapFilterCallback() { -// -// public boolean needBroadphaseCollision(BroadphaseProxy bp, BroadphaseProxy bp1) { -// boolean collides = (bp.collisionFilterGroup & bp1.collisionFilterMask) != 0; -// if (collides) { -// collides = (bp1.collisionFilterGroup & bp.collisionFilterMask) != 0; -// } -// if (collides) { -// assert (bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject && bp1.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject); -// com.bulletphysics.collision.dispatch.CollisionObject colOb = (com.bulletphysics.collision.dispatch.CollisionObject) bp.clientObject; -// com.bulletphysics.collision.dispatch.CollisionObject colOb1 = (com.bulletphysics.collision.dispatch.CollisionObject) bp1.clientObject; -// assert (colOb.getUserPointer() != null && colOb1.getUserPointer() != null); -// PhysicsCollisionObject collisionObject = (PhysicsCollisionObject) colOb.getUserPointer(); -// PhysicsCollisionObject collisionObject1 = (PhysicsCollisionObject) colOb1.getUserPointer(); -// if ((collisionObject.getCollideWithGroups() & collisionObject1.getCollisionGroup()) > 0 -// || (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) { -// PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup()); -// PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup()); -// if (listener != null) { -// return listener.collide(collisionObject, collisionObject1); -// } else if (listener1 != null) { -// return listener1.collide(collisionObject, collisionObject1); -// } -// return true; -// } else { -// return false; -// } -// } -// return collides; -// } -// }; -// dynamicsWorld.getPairCache().setOverlapFilterCallback(callback); -// } -// private void setTickCallback() { -// final PhysicsSpace space = this; -// InternalTickCallback callback2 = new InternalTickCallback() { -// -// @Override -// public void internalTick(DynamicsWorld dw, float f) { -// //execute task list -// AppTask task = pQueue.poll(); -// task = pQueue.poll(); -// while (task != null) { -// while (task.isCancelled()) { -// task = pQueue.poll(); -// } -// try { -// task.invoke(); -// } catch (Exception ex) { -// logger.log(Level.SEVERE, null, ex); -// } -// task = pQueue.poll(); -// } -// for (Iterator it = tickListeners.iterator(); it.hasNext();) { -// PhysicsTickListener physicsTickCallback = it.next(); -// physicsTickCallback.prePhysicsTick(space, f); -// } -// } -// }; -// dynamicsWorld.setPreTickCallback(callback2); -// InternalTickCallback callback = new InternalTickCallback() { -// -// @Override -// public void internalTick(DynamicsWorld dw, float f) { -// for (Iterator it = tickListeners.iterator(); it.hasNext();) { -// PhysicsTickListener physicsTickCallback = it.next(); -// physicsTickCallback.physicsTick(space, f); -// } -// } -// }; -// dynamicsWorld.setInternalTickCallback(callback, this); -// } -// private void setContactCallbacks() { -// BulletGlobals.setContactAddedCallback(new ContactAddedCallback() { -// -// public boolean contactAdded(ManifoldPoint cp, com.bulletphysics.collision.dispatch.CollisionObject colObj0, -// int partId0, int index0, com.bulletphysics.collision.dispatch.CollisionObject colObj1, int partId1, -// int index1) { -// System.out.println("contact added"); -// return true; -// } -// }); -// -// BulletGlobals.setContactProcessedCallback(new ContactProcessedCallback() { -// -// public boolean contactProcessed(ManifoldPoint cp, Object body0, Object body1) { -// if (body0 instanceof CollisionObject && body1 instanceof CollisionObject) { -// PhysicsCollisionObject node = null, node1 = null; -// CollisionObject rBody0 = (CollisionObject) body0; -// CollisionObject rBody1 = (CollisionObject) body1; -// node = (PhysicsCollisionObject) rBody0.getUserPointer(); -// node1 = (PhysicsCollisionObject) rBody1.getUserPointer(); -// collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, cp)); -// } -// return true; -// } -// }); -// -// BulletGlobals.setContactDestroyedCallback(new ContactDestroyedCallback() { -// -// public boolean contactDestroyed(Object userPersistentData) { -// System.out.println("contact destroyed"); -// return true; -// } -// }); -// } - private void addCollisionEvent_native(PhysicsCollisionObject node, PhysicsCollisionObject node1, long manifoldPointObjectId) { -// System.out.println("addCollisionEvent:"+node.getObjectId()+" "+ node1.getObjectId()); - collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, manifoldPointObjectId)); - } - - /** - * This method is invoked from native code. - */ - private boolean notifyCollisionGroupListeners_native(PhysicsCollisionObject node, PhysicsCollisionObject node1){ - PhysicsCollisionGroupListener listener = collisionGroupListeners.get(node.getCollisionGroup()); - PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(node1.getCollisionGroup()); - boolean result = true; - - if(listener != null){ - result = listener.collide(node, node1); - } - if(listener1 != null && node.getCollisionGroup() != node1.getCollisionGroup()){ - result = listener1.collide(node, node1) && result; - } - - return result; - } - - /** - * Update this space. Invoked (by the Bullet app state) once per frame while - * the app state is attached and enabled. - * - * @param time time-per-frame multiplied by speed (in seconds, ≥0) - */ - public void update(float time) { - update(time, maxSubSteps); - } - - /** - * Simulate for the specified time interval, using no more than the - * specified number of steps. - * - * @param time the time interval (in seconds, ≥0) - * @param maxSteps the maximum number of steps (≥1) - */ - public void update(float time, int maxSteps) { -// if (getDynamicsWorld() == null) { -// return; -// } - //step simulation - stepSimulation(physicsSpaceId, time, maxSteps, accuracy); - } - - private native void stepSimulation(long space, float time, int maxSteps, float accuracy); - - /** - * Distribute each collision event to all listeners. - */ - public void distributeEvents() { - //add collision callbacks - int clistsize = collisionListeners.size(); - while( collisionEvents.isEmpty() == false ) { - PhysicsCollisionEvent physicsCollisionEvent = collisionEvents.pop(); - for(int i=0;i the task's result type - * @param callable the task to be executed - * @return a new task (not null) - */ - public static Future enqueueOnThisThread(Callable callable) { - AppTask task = new AppTask(callable); - System.out.println("created apptask"); - pQueueTL.get().add(task); - return task; - } - - /** - * Invoke the specified callable during the next physics tick. This is - * useful for applying forces. - * - * @param the return type of the callable - * @param callable which callable to invoke - * @return Future object - */ - public Future enqueue(Callable callable) { - AppTask task = new AppTask(callable); - pQueue.add(task); - return task; - } - - /** - * Add the specified object to this space. - * - * @param obj the PhysicsControl, Spatial-with-PhysicsControl, - * PhysicsCollisionObject, or PhysicsJoint to add (not null, modified) - */ - public void add(Object obj) { - if (obj instanceof PhysicsControl) { - ((PhysicsControl) obj).setPhysicsSpace(this); - } else if (obj instanceof Spatial) { - Spatial node = (Spatial) obj; - for (int i = 0; i < node.getNumControls(); i++) { - if (node.getControl(i) instanceof PhysicsControl) { - add(node.getControl(i)); - } - } - } else if (obj instanceof PhysicsCollisionObject) { - addCollisionObject((PhysicsCollisionObject) obj); - } else if (obj instanceof PhysicsJoint) { - addJoint((PhysicsJoint) obj); - } else { - throw (new UnsupportedOperationException("Cannot add this kind of object to the physics space.")); - } - } - - /** - * Add the specified collision object to this space. - * - * @param obj the PhysicsCollisionObject to add (not null, modified) - */ - public void addCollisionObject(PhysicsCollisionObject obj) { - if (obj instanceof PhysicsGhostObject) { - addGhostObject((PhysicsGhostObject) obj); - } else if (obj instanceof PhysicsRigidBody) { - addRigidBody((PhysicsRigidBody) obj); - } else if (obj instanceof PhysicsVehicle) { - addRigidBody((PhysicsVehicle) obj); - } else if (obj instanceof PhysicsCharacter) { - addCharacter((PhysicsCharacter) obj); - } - } - - /** - * Remove the specified object from this space. - * - * @param obj the PhysicsCollisionObject to add, or null (modified) - */ - public void remove(Object obj) { - if (obj == null) return; - if (obj instanceof PhysicsControl) { - ((PhysicsControl) obj).setPhysicsSpace(null); - } else if (obj instanceof Spatial) { - Spatial node = (Spatial) obj; - for (int i = 0; i < node.getNumControls(); i++) { - if (node.getControl(i) instanceof PhysicsControl) { - remove(node.getControl(i)); - } - } - } else if (obj instanceof PhysicsCollisionObject) { - removeCollisionObject((PhysicsCollisionObject) obj); - } else if (obj instanceof PhysicsJoint) { - removeJoint((PhysicsJoint) obj); - } else { - throw (new UnsupportedOperationException("Cannot remove this kind of object from the physics space.")); - } - } - - /** - * Remove the specified collision object from this space. - * - * @param obj the PhysicsControl or Spatial with PhysicsControl to remove - */ - public void removeCollisionObject(PhysicsCollisionObject obj) { - if (obj instanceof PhysicsGhostObject) { - removeGhostObject((PhysicsGhostObject) obj); - } else if (obj instanceof PhysicsRigidBody) { - removeRigidBody((PhysicsRigidBody) obj); - } else if (obj instanceof PhysicsCharacter) { - removeCharacter((PhysicsCharacter) obj); - } - } - - /** - * Add all collision objects and joints in the specified subtree of the - * scene graph to this space (e.g. after loading from disk). Note: - * recursive! - * - * @param spatial the root of the subtree (not null) - */ - public void addAll(Spatial spatial) { - add(spatial); - - if (spatial.getControl(RigidBodyControl.class) != null) { - RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); - //add joints with physicsNode as BodyA - List joints = physicsNode.getJoints(); - for (Iterator it1 = joints.iterator(); it1.hasNext();) { - PhysicsJoint physicsJoint = it1.next(); - if (physicsNode.equals(physicsJoint.getBodyA())) { - //add(physicsJoint.getBodyB()); - add(physicsJoint); - } - } - } - //recursion - if (spatial instanceof Node) { - List children = ((Node) spatial).getChildren(); - for (Iterator it = children.iterator(); it.hasNext();) { - Spatial spat = it.next(); - addAll(spat); - } - } - } - - /** - * Remove all physics controls and joints in the specified subtree of the - * scene graph from the physics space (e.g. before saving to disk) Note: - * recursive! - * - * @param spatial the root of the subtree (not null) - */ - public void removeAll(Spatial spatial) { - if (spatial.getControl(RigidBodyControl.class) != null) { - RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); - //remove joints with physicsNode as BodyA - List joints = physicsNode.getJoints(); - for (Iterator it1 = joints.iterator(); it1.hasNext();) { - PhysicsJoint physicsJoint = it1.next(); - if (physicsNode.equals(physicsJoint.getBodyA())) { - removeJoint(physicsJoint); - //remove(physicsJoint.getBodyB()); - } - } - } - - remove(spatial); - //recursion - if (spatial instanceof Node) { - List children = ((Node) spatial).getChildren(); - for (Iterator it = children.iterator(); it.hasNext();) { - Spatial spat = it.next(); - removeAll(spat); - } - } - } - - private native void addCollisionObject(long space, long id); - - private native void removeCollisionObject(long space, long id); - - private native void addRigidBody(long space, long id); - - private native void removeRigidBody(long space, long id); - - private native void addCharacterObject(long space, long id); - - private native void removeCharacterObject(long space, long id); - - private native void addAction(long space, long id); - - private native void removeAction(long space, long id); - - private native void addVehicle(long space, long id); - - private native void removeVehicle(long space, long id); - - private native void addConstraint(long space, long id); - - private native void addConstraintC(long space, long id, boolean collision); - - private native void removeConstraint(long space, long id); - - private void addGhostObject(PhysicsGhostObject node) { - if (physicsGhostObjects.containsKey(node.getObjectId())) { - logger.log(Level.WARNING, "GhostObject {0} already exists in PhysicsSpace, cannot add.", node); - return; - } - physicsGhostObjects.put(node.getObjectId(), node); - logger.log(Level.FINE, "Adding ghost object {0} to physics space.", Long.toHexString(node.getObjectId())); - addCollisionObject(physicsSpaceId, node.getObjectId()); - } - - private void removeGhostObject(PhysicsGhostObject node) { - if (!physicsGhostObjects.containsKey(node.getObjectId())) { - logger.log(Level.WARNING, "GhostObject {0} does not exist in PhysicsSpace, cannot remove.", node); - return; - } - physicsGhostObjects.remove(node.getObjectId()); - logger.log(Level.FINE, "Removing ghost object {0} from physics space.", Long.toHexString(node.getObjectId())); - removeCollisionObject(physicsSpaceId, node.getObjectId()); - } - - private void addCharacter(PhysicsCharacter node) { - if (physicsCharacters.containsKey(node.getObjectId())) { - logger.log(Level.WARNING, "Character {0} already exists in PhysicsSpace, cannot add.", node); - return; - } - physicsCharacters.put(node.getObjectId(), node); - logger.log(Level.FINE, "Adding character {0} to physics space.", Long.toHexString(node.getObjectId())); - addCharacterObject(physicsSpaceId, node.getObjectId()); - addAction(physicsSpaceId, node.getControllerId()); -// dynamicsWorld.addCollisionObject(node.getObjectId(), CollisionFilterGroups.CHARACTER_FILTER, (short) (CollisionFilterGroups.STATIC_FILTER | CollisionFilterGroups.DEFAULT_FILTER)); -// dynamicsWorld.addAction(node.getControllerId()); - } - - private void removeCharacter(PhysicsCharacter node) { - if (!physicsCharacters.containsKey(node.getObjectId())) { - logger.log(Level.WARNING, "Character {0} does not exist in PhysicsSpace, cannot remove.", node); - return; - } - physicsCharacters.remove(node.getObjectId()); - logger.log(Level.FINE, "Removing character {0} from physics space.", Long.toHexString(node.getObjectId())); - removeAction(physicsSpaceId, node.getControllerId()); - removeCharacterObject(physicsSpaceId, node.getObjectId()); -// dynamicsWorld.removeAction(node.getControllerId()); -// dynamicsWorld.removeCollisionObject(node.getObjectId()); - } - - /** - * NOTE: When a rigid body is added, its gravity gets set to that of the - * physics space. - * - * @param node the body to add (not null, not already in the space) - */ - private void addRigidBody(PhysicsRigidBody node) { - if (physicsBodies.containsKey(node.getObjectId())) { - logger.log(Level.WARNING, "RigidBody {0} already exists in PhysicsSpace, cannot add.", node); - return; - } - physicsBodies.put(node.getObjectId(), node); - - //Workaround - //It seems that adding a Kinematic RigidBody to the dynamicWorld prevents it from being non-kinematic again afterward. - //so we add it non kinematic, then set it kinematic again. - boolean kinematic = false; - if (node.isKinematic()) { - kinematic = true; - node.setKinematic(false); - } - addRigidBody(physicsSpaceId, node.getObjectId()); - if (kinematic) { - node.setKinematic(true); - } - - logger.log(Level.FINE, "Adding RigidBody {0} to physics space.", node.getObjectId()); - if (node instanceof PhysicsVehicle) { - PhysicsVehicle vehicle = (PhysicsVehicle) node; - vehicle.createVehicle(this); - long vehicleId = vehicle.getVehicleId(); - assert vehicleId != 0L; - logger.log(Level.FINE, - "Adding vehicle constraint {0} to physics space.", - Long.toHexString(vehicleId)); - physicsVehicles.put(vehicleId, vehicle); - addVehicle(physicsSpaceId, vehicleId); - } - } - - private void removeRigidBody(PhysicsRigidBody node) { - if (!physicsBodies.containsKey(node.getObjectId())) { - logger.log(Level.WARNING, "RigidBody {0} does not exist in PhysicsSpace, cannot remove.", node); - return; - } - if (node instanceof PhysicsVehicle) { - logger.log(Level.FINE, "Removing vehicle constraint {0} from physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId())); - physicsVehicles.remove(((PhysicsVehicle) node).getVehicleId()); - removeVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId()); - } - logger.log(Level.FINE, "Removing RigidBody {0} from physics space.", Long.toHexString(node.getObjectId())); - physicsBodies.remove(node.getObjectId()); - removeRigidBody(physicsSpaceId, node.getObjectId()); - } - - private void addJoint(PhysicsJoint joint) { - if (physicsJoints.containsKey(joint.getObjectId())) { - logger.log(Level.WARNING, "Joint {0} already exists in PhysicsSpace, cannot add.", joint); - return; - } - logger.log(Level.FINE, "Adding Joint {0} to physics space.", Long.toHexString(joint.getObjectId())); - physicsJoints.put(joint.getObjectId(), joint); - addConstraintC(physicsSpaceId, joint.getObjectId(), !joint.isCollisionBetweenLinkedBodys()); -// dynamicsWorld.addConstraint(joint.getObjectId(), !joint.isCollisionBetweenLinkedBodys()); - } - - private void removeJoint(PhysicsJoint joint) { - if (!physicsJoints.containsKey(joint.getObjectId())) { - logger.log(Level.WARNING, "Joint {0} does not exist in PhysicsSpace, cannot remove.", joint); - return; - } - logger.log(Level.FINE, "Removing Joint {0} from physics space.", Long.toHexString(joint.getObjectId())); - physicsJoints.remove(joint.getObjectId()); - removeConstraint(physicsSpaceId, joint.getObjectId()); -// dynamicsWorld.removeConstraint(joint.getObjectId()); - } - - /** - * Copy the list of rigid bodies that have been added to this space and not - * yet removed. - * - * @return a new list (not null) - */ - public Collection getRigidBodyList() { - return new LinkedList(physicsBodies.values()); - } - - /** - * Copy the list of ghost objects that have been added to this space and not - * yet removed. - * - * @return a new list (not null) - */ - public Collection getGhostObjectList() { - return new LinkedList(physicsGhostObjects.values()); - } - - /** - * Copy the list of physics characters that have been added to this space - * and not yet removed. - * - * @return a new list (not null) - */ - public Collection getCharacterList() { - return new LinkedList(physicsCharacters.values()); - } - - /** - * Copy the list of physics joints that have been added to this space and - * not yet removed. - * - * @return a new list (not null) - */ - public Collection getJointList() { - return new LinkedList(physicsJoints.values()); - } - - /** - * Copy the list of physics vehicles that have been added to this space and - * not yet removed. - * - * @return a new list (not null) - */ - public Collection getVehicleList() { - return new LinkedList(physicsVehicles.values()); - } - - /** - * Alter the gravitational acceleration acting on newly-added bodies. - *

- * Whenever a rigid body is added to a space, the body's gravity gets set to - * that of the space. Thus it makes sense to set the space's vector before - * adding any bodies to the space. - * - * @param gravity the desired acceleration vector (not null, unaffected) - */ - public void setGravity(Vector3f gravity) { - this.gravity.set(gravity); - setGravity(physicsSpaceId, gravity); - } - - private native void setGravity(long spaceId, Vector3f gravity); - - /** - * copy of gravity-acceleration vector (default is 9.81 in the -Y direction, - * corresponding to Earth-normal in MKS units) - */ - private final Vector3f gravity = new Vector3f(0,-9.81f,0); - /** - * Copy the gravitational acceleration acting on newly-added bodies. - * - * @param gravity storage for the result (not null, modified) - * @return acceleration (in the vector provided) - */ - public Vector3f getGravity(Vector3f gravity) { - return gravity.set(this.gravity); - } - -// /** -// * applies gravity value to all objects -// */ -// public void applyGravity() { -//// dynamicsWorld.applyGravity(); -// } -// -// /** -// * clears forces of all objects -// */ -// public void clearForces() { -//// dynamicsWorld.clearForces(); -// } -// - /** - * Register the specified tick listener with this space. - *

- * Tick listeners are notified before and after each physics step. A physics - * step is not necessarily the same as a frame; it is more influenced by the - * accuracy of the physics space. - * - * @see #setAccuracy(float) - * - * @param listener the listener to register (not null) - */ - public void addTickListener(PhysicsTickListener listener) { - tickListeners.add(listener); - } - - /** - * De-register the specified tick listener. - * - * @see #addTickListener(com.jme3.bullet.PhysicsTickListener) - * @param listener the listener to de-register (not null) - */ - public void removeTickListener(PhysicsTickListener listener) { - tickListeners.remove(listener); - } - - /** - * Register the specified collision listener with this space. - *

- * Collision listeners are notified when collisions occur in the space. - * - * @param listener the listener to register (not null, alias created) - */ - public void addCollisionListener(PhysicsCollisionListener listener) { - collisionListeners.add(listener); - } - - /** - * De-register the specified collision listener. - * - * @see - * #addCollisionListener(com.jme3.bullet.collision.PhysicsCollisionListener) - * @param listener the listener to de-register (not null) - */ - public void removeCollisionListener(PhysicsCollisionListener listener) { - collisionListeners.remove(listener); - } - - /** - * Register the specified collision-group listener with the specified - * collision group of this space. - *

- * Such a listener can disable collisions when they occur. There can be only - * one listener per collision group per space. - * - * @param listener the listener to register (not null) - * @param collisionGroup which group it should listen for (bit mask with - * exactly one bit set) - */ - public void addCollisionGroupListener(PhysicsCollisionGroupListener listener, int collisionGroup) { - collisionGroupListeners.put(collisionGroup, listener); - } - - /** - * De-register the specified collision-group listener. - * - * @see - * #addCollisionGroupListener(com.jme3.bullet.collision.PhysicsCollisionGroupListener, - * int) - * @param collisionGroup the group of the listener to de-register (bit mask - * with exactly one bit set) - */ - public void removeCollisionGroupListener(int collisionGroup) { - collisionGroupListeners.remove(collisionGroup); - } - - /** - * Perform a ray-collision test and return the results as a list of - * PhysicsRayTestResults sorted by ascending hitFraction. - * - * @param from the starting location (physics-space coordinates, not null, - * unaffected) - * @param to the ending location (in physics-space coordinates, not null, - * unaffected) - * @return a new list of results (not null) - */ - public List rayTest(Vector3f from, Vector3f to) { - List results = new ArrayList(); - rayTest(from, to, results); - - return results; - } - - /** - * Perform a ray-collision test and return the results as a list of - * PhysicsRayTestResults in arbitrary order. - * - * @param from the starting location (in physics-space coordinates, not - * null, unaffected) - * @param to the ending location (in physics-space coordinates, not null, - * unaffected) - * @return a new list of results (not null) - */ - public List rayTestRaw(Vector3f from, Vector3f to) { - List results = new ArrayList(); - rayTestRaw(from, to, results); - - return results; - } - - /** - * Alters the m_flags used in ray tests. see - * https://code.google.com/p/bullet/source/browse/trunk/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h - * for possible options. Defaults to using the faster, approximate raytest. - * - * @param flags the desired flags, ORed together (default=0x4) - */ - public void SetRayTestFlags(int flags) { - rayTestFlags = flags; - } - - /** - * Reads m_flags used in ray tests. see - * https://code.google.com/p/bullet/source/browse/trunk/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h - * for possible options. - * - * @return which flags are used - */ - public int GetRayTestFlags() { - return rayTestFlags; - } - - private static Comparator hitFractionComparator = new Comparator() { - @Override - public int compare(PhysicsRayTestResult r1, PhysicsRayTestResult r2) { - float comp = r1.getHitFraction() - r2.getHitFraction(); - return comp > 0 ? 1 : -1; - } - }; - - /** - * Perform a ray-collision test and return the results as a list of - * PhysicsRayTestResults sorted by ascending hitFraction. - * - * @param from coordinates of the starting location (in physics space, not - * null, unaffected) - * @param to coordinates of the ending location (in physics space, not null, - * unaffected) - * @param results the list to hold results (not null, modified) - * @return results - */ - public List rayTest(Vector3f from, Vector3f to, List results) { - results.clear(); - rayTest_native(from, to, physicsSpaceId, results, rayTestFlags); - - Collections.sort(results, hitFractionComparator); - return results; - } - - /** - * Perform a ray-collision test and return the results as a list of - * PhysicsRayTestResults in arbitrary order. - * - * @param from coordinates of the starting location (in physics space, not - * null, unaffected) - * @param to coordinates of the ending location (in physics space, not null, - * unaffected) - * @param results the list to hold results (not null, modified) - * @return results - */ - public List rayTestRaw(Vector3f from, Vector3f to, List results) { - results.clear(); - rayTest_native(from, to, physicsSpaceId, results, rayTestFlags); - return results; - } - - public native void rayTest_native(Vector3f from, Vector3f to, long physicsSpaceId, List results, int flags); - -// private class InternalRayListener extends CollisionWorld.RayResultCallback { -// -// private List results; -// -// public InternalRayListener(List results) { -// this.results = results; -// } -// -// @Override -// public float addSingleResult(LocalRayResult lrr, boolean bln) { -// PhysicsCollisionObject obj = (PhysicsCollisionObject) lrr.collisionObject.getUserPointer(); -// results.add(new PhysicsRayTestResult(obj, Converter.convert(lrr.hitNormalLocal), lrr.hitFraction, bln)); -// return lrr.hitFraction; -// } -// } -// -// - - - /** - * Perform a sweep-collision test and return the results as a new list. - *

- * The starting and ending locations must be at least 0.4f physics-space - * units apart. - *

- * A sweep test will miss a collision if it starts inside an object and - * sweeps away from the object's center. - * - * @param shape the shape to sweep (not null) - * @param start the starting physics-space transform (not null) - * @param end the ending physics-space transform (not null) - * @return a new list of results - */ - public List sweepTest(CollisionShape shape, Transform start, Transform end) { - List results = new LinkedList<>(); - sweepTest(shape, start, end , results); - return results; - } - - /** - * Perform a sweep-collision test and store the results in an existing list. - *

- * The starting and ending locations must be at least 0.4f physics-space - * units apart. - *

- * A sweep test will miss a collision if it starts inside an object and - * sweeps away from the object's center. - * - * @param shape the shape to sweep (not null) - * @param start the starting physics-space transform (not null) - * @param end the ending physics-space transform (not null) - * @param results the list to hold results (not null, modified) - * @return results - */ - public List sweepTest(CollisionShape shape, Transform start, Transform end, List results) { - return sweepTest(shape, start, end, results, 0.0f); - } - - public native void sweepTest_native(long shape, Transform from, Transform to, long physicsSpaceId, List results, float allowedCcdPenetration); - /** - * Perform a sweep-collision test and store the results in an existing list. - *

- * The starting and ending locations must be at least 0.4f physics-space - * units apart. - *

- * A sweep test will miss a collision if it starts inside an object and - * sweeps away from the object's center. - * - * @param shape the shape to sweep (not null) - * @param start the starting physics-space transform (not null) - * @param end the ending physics-space transform (not null) - * @param results the list to hold results (not null, modified) - * @param allowedCcdPenetration true→allow, false→disallow - * @return results - */ - public List sweepTest(CollisionShape shape, Transform start, Transform end, List results, float allowedCcdPenetration ) { - results.clear(); - sweepTest_native(shape.getObjectId(), start, end, physicsSpaceId, results, allowedCcdPenetration); - return results; - } - -/* private class InternalSweepListener extends CollisionWorld.ConvexResultCallback { - - private List results; - - public InternalSweepListener(List results) { - this.results = results; - } - - @Override - public float addSingleResult(LocalConvexResult lcr, boolean bln) { - PhysicsCollisionObject obj = (PhysicsCollisionObject) lcr.hitCollisionObject.getUserPointer(); - results.add(new PhysicsSweepTestResult(obj, Converter.convert(lcr.hitNormalLocal), lcr.hitFraction, bln)); - return lcr.hitFraction; - } - } - - */ - - /** - * Destroy this space so that a new one can be instantiated. - */ - public void destroy() { - physicsBodies.clear(); - physicsJoints.clear(); - -// dynamicsWorld.destroy(); -// dynamicsWorld = null; - } - - /** - * // * used internally // - * - * @return the dynamicsWorld // - */ - public long getSpaceId() { - return physicsSpaceId; - } - - /** - * Read the type of acceleration structure used. - * - * @return an enum value (not null) - */ - public BroadphaseType getBroadphaseType() { - return broadphaseType; - } - - /** - * Alter the type of acceleration structure used. - * - * @param broadphaseType the desired algorithm (not null) - */ - public void setBroadphaseType(BroadphaseType broadphaseType) { - this.broadphaseType = broadphaseType; - } - - /** - * Alter the maximum number of physics steps per frame. - *

- * Extra physics steps help maintain determinism when the render fps drops - * below 1/accuracy. For example a value of 2 can compensate for frame rates - * as low as 30fps, assuming the physics has an accuracy of 1/60 sec. - *

- * Setting this value too high can depress the frame rate. - * - * @param steps the desired maximum number of steps per frame (≥1, - * default=4) - */ - public void setMaxSubSteps(int steps) { - maxSubSteps = steps; - } - - /** - * Read the accuracy (time step) of the physics simulation. - * - * @return the timestep (in seconds, >0) - */ - public float getAccuracy() { - return accuracy; - } - - /** - * Alter the accuracy (time step) of the physics simulation. - *

- * In general, the smaller the time step, the more accurate (and - * compute-intensive) the simulation will be. Bullet works best with a - * time step of no more than 1/60 second. - * - * @param accuracy the desired time step (in seconds, >0, default=1/60) - */ - public void setAccuracy(float accuracy) { - this.accuracy = accuracy; - } - - /** - * Access the minimum coordinate values for this space. - * - * @return the pre-existing vector - */ - public Vector3f getWorldMin() { - return worldMin; - } - - /** - * Alter the minimum coordinate values for this space. (only affects - * AXIS_SWEEP broadphase algorithms) - * - * @param worldMin the desired minimum coordinate values (not null, - * unaffected) - */ - public void setWorldMin(Vector3f worldMin) { - this.worldMin.set(worldMin); - } - - /** - * Access the maximum coordinate values for this space. - * - * @return the pre-existing vector (not null) - */ - public Vector3f getWorldMax() { - return worldMax; - } - - /** - * only applies for AXIS_SWEEP broadphase - * - * @param worldMax - */ - public void setWorldMax(Vector3f worldMax) { - this.worldMax.set(worldMax); - } - - /** - * Alter the number of iterations used by the contact-and-constraint solver. - *

- * Use 4 for low quality, 20 for high quality. - * - * @param numIterations the desired number of iterations (≥1, default=10) - */ - public void setSolverNumIterations(int numIterations) { - this.solverNumIterations = numIterations; - setSolverNumIterations(physicsSpaceId, numIterations); - } - - /** - * Read the number of iterations used by the contact-and-constraint solver. - * - * @return the number of iterations used - */ - public int getSolverNumIterations() { - return solverNumIterations; - } - - private native void setSolverNumIterations(long physicsSpaceId, int numIterations); - - public static native void initNativePhysics(); - - /** - * Enumerate the available acceleration structures for broadphase collision - * detection. - */ - public enum BroadphaseType { - - /** - * btSimpleBroadphase: a brute-force reference implementation for - * debugging purposes - */ - SIMPLE, - /** - * btAxisSweep3: uses incremental 3-D sweep and prune, requires world - * bounds, limited to 16_384 objects - */ - AXIS_SWEEP_3, - /** - * bt32BitAxisSweep3: uses incremental 3-D sweep and prune, requires - * world bounds, limited to 65_536 objects - */ - AXIS_SWEEP_3_32, - /** - * btDbvtBroadphase: uses a fast, dynamic bounding-volume hierarchy - * based on AABB tree to allow quicker addition/removal of physics - * objects - */ - DBVT; - } - - /** - * Finalize this physics space just before it is destroyed. Should be - * invoked only by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing PhysicsSpace {0}", Long.toHexString(physicsSpaceId)); - finalizeNative(physicsSpaceId); - } - - private native void finalizeNative(long objectId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/CollisionFlag.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/CollisionFlag.java deleted file mode 100644 index 6445af53f3..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/CollisionFlag.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision; - -/** - * Named collision flags for a {@link PhysicsCollisionObject}. Values must agree - * with those in BulletCollision/CollisionDispatch/btCollisionObject.h - * - * @author Stephen Gold sgold@sonic.net - * @see PhysicsCollisionObject#getCollisionFlags(long) - */ -public class CollisionFlag { - /** - * flag for a static object - */ - final public static int STATIC_OBJECT = 0x1; - /** - * flag for a kinematic object - */ - final public static int KINEMATIC_OBJECT = 0x2; - /** - * flag for an object with no contact response, such as a PhysicsGhostObject - */ - final public static int NO_CONTACT_RESPONSE = 0x4; - /** - * flag to enable a custom material callback for per-triangle - * friction/restitution (not used by JME) - */ - final public static int CUSTOM_MATERIAL_CALLBACK = 0x8; - /** - * flag for a character object, such as a PhysicsCharacter - */ - final public static int CHARACTER_OBJECT = 0x10; - /** - * flag to disable debug visualization (not used by JME) - */ - final public static int DISABLE_VISUALIZE_OBJECT = 0x20; - /** - * flag to disable parallel/SPU processing (not used by JME) - */ - final public static int DISABLE_SPU_COLLISION_PROCESSING = 0x40; - /** - * flag not used by JME - */ - final public static int HAS_CONTACT_STIFFNESS_DAMPING = 0x80; - /** - * flag not used by JME - */ - final public static int HAS_CUSTOM_DEBUG_RENDERING_COLOR = 0x100; - /** - * flag not used by JME - */ - final public static int HAS_FRICTION_ANCHOR = 0x200; - /** - * flag not used by JME - */ - final public static int HAS_COLLISION_SOUND_TRIGGER = 0x400; -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionEvent.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionEvent.java deleted file mode 100644 index bb62760020..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionEvent.java +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision; - -import com.jme3.math.Vector3f; -import com.jme3.scene.Spatial; -import java.util.EventObject; - -/** - * Describe a collision in the physics world. - *

- * Do not retain this object, as it will be reused after the collision() method - * returns. Copy any data you need during the collide() method. - * - * @author normenhansen - */ -public class PhysicsCollisionEvent extends EventObject { - - /** - * type value to indicate a new event - */ - public static final int TYPE_ADDED = 0; - /** - * type value to indicate an event that has been added to a PhysicsSpace - * queue - */ - public static final int TYPE_PROCESSED = 1; - /** - * type value to indicate a cleaned/destroyed event - */ - public static final int TYPE_DESTROYED = 2; - /** - * type value that indicates the event's status - */ - private int type; - /** - * 1st involved object - */ - private PhysicsCollisionObject nodeA; - /** - * 2nd involved object - */ - private PhysicsCollisionObject nodeB; - /** - * Bullet identifier of the btManifoldPoint - */ - private long manifoldPointObjectId = 0; - - /** - * Instantiate a collision event. - * - * @param type event type (0=added/1=processed/2=destroyed) - * @param nodeA 1st involved object (alias created) - * @param nodeB 2nd involved object (alias created) - * @param manifoldPointObjectId Bullet identifier of the btManifoldPoint - */ - public PhysicsCollisionEvent(int type, PhysicsCollisionObject nodeA, PhysicsCollisionObject nodeB, long manifoldPointObjectId) { - super(nodeA); - this.type = type; - this.nodeA = nodeA; - this.nodeB = nodeB; - this.manifoldPointObjectId = manifoldPointObjectId; - } - - /** - * Destroy this event. - */ - public void clean() { - source = null; - this.type = 0; - this.nodeA = null; - this.nodeB = null; - this.manifoldPointObjectId = 0; - } - - /** - * Reuse this event. - * - * @param type event type (added/processed/destroyed) - * @param source 1st involved object (alias created) - * @param nodeB 2nd involved object (alias created) - * @param manifoldPointObjectId Bullet identifier - */ - public void refactor(int type, PhysicsCollisionObject source, PhysicsCollisionObject nodeB, long manifoldPointObjectId) { - this.source = source; - this.type = type; - this.nodeA = source; - this.nodeB = nodeB; - this.manifoldPointObjectId = manifoldPointObjectId; - } - - /** - * Read the type of event. - * - * @return added/processed/destroyed - */ - public int getType() { - return type; - } - - /** - * Access the user object of collision object A, provided it's a Spatial. - * - * @return the pre-existing Spatial, or null if none - */ - public Spatial getNodeA() { - if (nodeA.getUserObject() instanceof Spatial) { - return (Spatial) nodeA.getUserObject(); - } - return null; - } - - /** - * Access the user object of collision object B, provided it's a Spatial. - * - * @return the pre-existing Spatial, or null if none - */ - public Spatial getNodeB() { - if (nodeB.getUserObject() instanceof Spatial) { - return (Spatial) nodeB.getUserObject(); - } - return null; - } - - /** - * Access collision object A. - * - * @return the pre-existing object (not null) - */ - public PhysicsCollisionObject getObjectA() { - return nodeA; - } - - /** - * Access collision object B. - * - * @return the pre-existing object (not null) - */ - public PhysicsCollisionObject getObjectB() { - return nodeB; - } - - /** - * Read the collision's applied impulse. - * - * @return impulse - */ - public float getAppliedImpulse() { - return getAppliedImpulse(manifoldPointObjectId); - } - private native float getAppliedImpulse(long manifoldPointObjectId); - - /** - * Read the collision's applied lateral impulse #1. - * - * @return impulse - */ - public float getAppliedImpulseLateral1() { - return getAppliedImpulseLateral1(manifoldPointObjectId); - } - private native float getAppliedImpulseLateral1(long manifoldPointObjectId); - - /** - * Read the collision's applied lateral impulse #2. - * - * @return impulse - */ - public float getAppliedImpulseLateral2() { - return getAppliedImpulseLateral2(manifoldPointObjectId); - } - private native float getAppliedImpulseLateral2(long manifoldPointObjectId); - - /** - * Read the collision's combined friction. - * - * @return friction - */ - public float getCombinedFriction() { - return getCombinedFriction(manifoldPointObjectId); - } - private native float getCombinedFriction(long manifoldPointObjectId); - - /** - * Read the collision's combined restitution. - * - * @return restitution - */ - public float getCombinedRestitution() { - return getCombinedRestitution(manifoldPointObjectId); - } - private native float getCombinedRestitution(long manifoldPointObjectId); - - /** - * Read the collision's distance #1. - * - * @return distance - */ - public float getDistance1() { - return getDistance1(manifoldPointObjectId); - } - private native float getDistance1(long manifoldPointObjectId); - - /** - * Read the collision's index 0. - * - * @return index - */ - public int getIndex0() { - return getIndex0(manifoldPointObjectId); - } - private native int getIndex0(long manifoldPointObjectId); - - /** - * Read the collision's index 1. - * - * @return index - */ - public int getIndex1() { - return getIndex1(manifoldPointObjectId); - } - private native int getIndex1(long manifoldPointObjectId); - - /** - * Copy the collision's lateral friction direction #1. - * - * @return a new vector (not null) - */ - public Vector3f getLateralFrictionDir1() { - return getLateralFrictionDir1(new Vector3f()); - } - - /** - * Copy the collision's lateral friction direction #1. - * - * @param lateralFrictionDir1 storage for the result (not null, modified) - * @return direction vector (not null) - */ - public Vector3f getLateralFrictionDir1(Vector3f lateralFrictionDir1) { - getLateralFrictionDir1(manifoldPointObjectId, lateralFrictionDir1); - return lateralFrictionDir1; - } - private native void getLateralFrictionDir1(long manifoldPointObjectId, Vector3f lateralFrictionDir1); - - /** - * Copy the collision's lateral friction direction #2. - * - * @return a new vector - */ - public Vector3f getLateralFrictionDir2() { - return getLateralFrictionDir2(new Vector3f()); - } - - /** - * Copy the collision's lateral friction direction #2. - * - * @param lateralFrictionDir2 storage for the result (not null, modified) - * @return direction vector (not null) - */ - public Vector3f getLateralFrictionDir2(Vector3f lateralFrictionDir2) { - getLateralFrictionDir2(manifoldPointObjectId, lateralFrictionDir2); - return lateralFrictionDir2; - } - private native void getLateralFrictionDir2(long manifoldPointObjectId, Vector3f lateralFrictionDir2); - - /** - * Test whether the collision's lateral friction is initialized. - * - * @return true if initialized, otherwise false - */ - public boolean isLateralFrictionInitialized() { - return isLateralFrictionInitialized(manifoldPointObjectId); - } - private native boolean isLateralFrictionInitialized(long manifoldPointObjectId); - - /** - * Read the collision's lifetime. - * - * @return lifetime - */ - public int getLifeTime() { - return getLifeTime(manifoldPointObjectId); - } - private native int getLifeTime(long manifoldPointObjectId); - - /** - * Copy the collision's location in the local coordinates of object A. - * - * @return a new location vector (in local coordinates, not null) - */ - public Vector3f getLocalPointA() { - return getLocalPointA(new Vector3f()); - } - - /** - * Copy the collision's location in the local coordinates of object A. - * - * @param localPointA storage for the result (not null, modified) - * @return a location vector (in local coordinates, not null) - */ - public Vector3f getLocalPointA(Vector3f localPointA) { - getLocalPointA(manifoldPointObjectId, localPointA); - return localPointA; - } - private native void getLocalPointA(long manifoldPointObjectId, Vector3f localPointA); - - /** - * Copy the collision's location in the local coordinates of object B. - * - * @return a new location vector (in local coordinates, not null) - */ - public Vector3f getLocalPointB() { - return getLocalPointB(new Vector3f()); - } - - /** - * Copy the collision's location in the local coordinates of object B. - * - * @param localPointB storage for the result (not null, modified) - * @return a location vector (in local coordinates, not null) - */ - public Vector3f getLocalPointB(Vector3f localPointB) { - getLocalPointB(manifoldPointObjectId, localPointB); - return localPointB; - } - private native void getLocalPointB(long manifoldPointObjectId, Vector3f localPointB); - - /** - * Copy the collision's normal on object B. - * - * @return a new normal vector (in physics-space coordinates, not null) - */ - public Vector3f getNormalWorldOnB() { - return getNormalWorldOnB(new Vector3f()); - } - - /** - * Copy the collision's normal on object B. - * - * @param normalWorldOnB storage for the result (not null, modified) - * @return a normal vector (in physics-space coordinates, not null) - */ - public Vector3f getNormalWorldOnB(Vector3f normalWorldOnB) { - getNormalWorldOnB(manifoldPointObjectId, normalWorldOnB); - return normalWorldOnB; - } - private native void getNormalWorldOnB(long manifoldPointObjectId, Vector3f normalWorldOnB); - - /** - * Read part identifier 0. - * - * @return identifier - */ - public int getPartId0() { - return getPartId0(manifoldPointObjectId); - } - private native int getPartId0(long manifoldPointObjectId); - - /** - * Read part identifier 1. - * - * @return identifier - */ - public int getPartId1() { - return getPartId1(manifoldPointObjectId); - } - - private native int getPartId1(long manifoldPointObjectId); - - /** - * Copy the collision's location. - * - * @return a new vector (in physics-space coordinates, not null) - */ - public Vector3f getPositionWorldOnA() { - return getPositionWorldOnA(new Vector3f()); - } - - /** - * Copy the collision's location. - * - * @param positionWorldOnA storage for the result (not null, modified) - * @return a location vector (in physics-space coordinates, not null) - */ - public Vector3f getPositionWorldOnA(Vector3f positionWorldOnA) { - getPositionWorldOnA(manifoldPointObjectId, positionWorldOnA); - return positionWorldOnA; - } - private native void getPositionWorldOnA(long manifoldPointObjectId, Vector3f positionWorldOnA); - - /** - * Copy the collision's location. - * - * @return a new location vector (in physics-space coordinates, not null) - */ - public Vector3f getPositionWorldOnB() { - return getPositionWorldOnB(new Vector3f()); - } - - /** - * Copy the collision's location. - * - * @param positionWorldOnB storage for the result (not null, modified) - * @return a location vector (in physics-space coordinates, not null) - */ - public Vector3f getPositionWorldOnB(Vector3f positionWorldOnB) { - getPositionWorldOnB(manifoldPointObjectId, positionWorldOnB); - return positionWorldOnB; - } - private native void getPositionWorldOnB(long manifoldPointObjectId, Vector3f positionWorldOnB); - -// public Object getUserPersistentData() { -// return userPersistentData; -// } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionObject.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionObject.java deleted file mode 100644 index df4265be5c..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionObject.java +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision; - -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.export.*; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * The abstract base class for collision objects based on Bullet's - * btCollisionObject. - *

- * Collision objects include PhysicsCharacter, PhysicsRigidBody, and - * PhysicsGhostObject. - * - * @author normenhansen - */ -public abstract class PhysicsCollisionObject implements Savable { - - /** - * Unique identifier of the btCollisionObject. Constructors are responsible - * for setting this to a non-zero value. The id might change if the object - * gets rebuilt. - */ - protected long objectId = 0; - /** - * shape associated with this object (not null) - */ - protected CollisionShape collisionShape; - /** - * collideWithGroups bitmask that represents "no groups" - */ - public static final int COLLISION_GROUP_NONE = 0x00000000; - /** - * collisionGroup/collideWithGroups bitmask that represents group #1 - */ - public static final int COLLISION_GROUP_01 = 0x00000001; - /** - * collisionGroup/collideWithGroups bitmask that represents group #2 - */ - public static final int COLLISION_GROUP_02 = 0x00000002; - /** - * collisionGroup/collideWithGroups bitmask that represents group #3 - */ - public static final int COLLISION_GROUP_03 = 0x00000004; - /** - * collisionGroup/collideWithGroups bitmask that represents group #4 - */ - public static final int COLLISION_GROUP_04 = 0x00000008; - /** - * collisionGroup/collideWithGroups bitmask that represents group #5 - */ - public static final int COLLISION_GROUP_05 = 0x00000010; - /** - * collisionGroup/collideWithGroups bitmask that represents group #6 - */ - public static final int COLLISION_GROUP_06 = 0x00000020; - /** - * collisionGroup/collideWithGroups bitmask that represents group #7 - */ - public static final int COLLISION_GROUP_07 = 0x00000040; - /** - * collisionGroup/collideWithGroups bitmask that represents group #8 - */ - public static final int COLLISION_GROUP_08 = 0x00000080; - /** - * collisionGroup/collideWithGroups bitmask that represents group #9 - */ - public static final int COLLISION_GROUP_09 = 0x00000100; - /** - * collisionGroup/collideWithGroups bitmask that represents group #10 - */ - public static final int COLLISION_GROUP_10 = 0x00000200; - /** - * collisionGroup/collideWithGroups bitmask that represents group #11 - */ - public static final int COLLISION_GROUP_11 = 0x00000400; - /** - * collisionGroup/collideWithGroups bitmask that represents group #12 - */ - public static final int COLLISION_GROUP_12 = 0x00000800; - /** - * collisionGroup/collideWithGroups bitmask that represents group #13 - */ - public static final int COLLISION_GROUP_13 = 0x00001000; - /** - * collisionGroup/collideWithGroups bitmask that represents group #14 - */ - public static final int COLLISION_GROUP_14 = 0x00002000; - /** - * collisionGroup/collideWithGroups bitmask that represents group #15 - */ - public static final int COLLISION_GROUP_15 = 0x00004000; - /** - * collisionGroup/collideWithGroups bitmask that represents group #16 - */ - public static final int COLLISION_GROUP_16 = 0x00008000; - /** - * collision group to which this physics object belongs (default=group #1) - */ - protected int collisionGroup = 0x00000001; - /** - * collision groups with which this object can collide (default=only group - * #1) - */ - protected int collisionGroupsMask = 0x00000001; - private Object userObject; - - /** - * Apply the specified CollisionShape to this object. Note that the object - * should not be in any physics space while changing shape; the object gets - * rebuilt on the physics side. - * - * @param collisionShape the shape to apply (not null, alias created) - */ - public void setCollisionShape(CollisionShape collisionShape) { - this.collisionShape = collisionShape; - } - - /** - * Access the shape of this physics object. - * - * @return the pre-existing instance, which can then be applied to other - * physics objects (increases performance) - */ - public CollisionShape getCollisionShape() { - return collisionShape; - } - - /** - * Read the deactivation time. - * - * @return the time (in seconds) - */ - public float getDeactivationTime() { - float time = getDeactivationTime(objectId); - return time; - } - - native private float getDeactivationTime(long objectId); - - /** - * Read the collision group for this physics object. - * - * @return the collision group (bit mask with exactly one bit set) - */ - public int getCollisionGroup() { - return collisionGroup; - } - - /** - * Alter the collision group for this physics object. - *

- * Groups are represented by integer bit masks with exactly 1 bit set. - * Pre-made variables are available in PhysicsCollisionObject. By default, - * physics objects are in COLLISION_GROUP_01. - *

- * Two objects can collide only if one of them has the collisionGroup of the - * other in its collideWithGroups set. - * - * @param collisionGroup the collisionGroup to apply (bit mask with exactly - * 1 bit set) - */ - public void setCollisionGroup(int collisionGroup) { - this.collisionGroup = collisionGroup; - if (objectId != 0) { - setCollisionGroup(objectId, collisionGroup); - } - } - - /** - * Add collision groups to the set with which this object can collide. - * - * Two objects can collide only if one of them has the collisionGroup of the - * other in its collideWithGroups set. - * - * @param collisionGroup groups to add (bit mask) - */ - public void addCollideWithGroup(int collisionGroup) { - this.collisionGroupsMask = this.collisionGroupsMask | collisionGroup; - if (objectId != 0) { - setCollideWithGroups(objectId, this.collisionGroupsMask); - } - } - - /** - * Remove collision groups from the set with which this object can collide. - * - * @param collisionGroup groups to remove, ORed together (bit mask) - */ - public void removeCollideWithGroup(int collisionGroup) { - this.collisionGroupsMask = this.collisionGroupsMask & ~collisionGroup; - if (objectId != 0) { - setCollideWithGroups(this.collisionGroupsMask); - } - } - - /** - * Directly alter the collision groups with which this object can collide. - * - * @param collisionGroups desired groups, ORed together (bit mask) - */ - public void setCollideWithGroups(int collisionGroups) { - this.collisionGroupsMask = collisionGroups; - if (objectId != 0) { - setCollideWithGroups(objectId, this.collisionGroupsMask); - } - } - - /** - * Read the set of collision groups with which this object can collide. - * - * @return bit mask - */ - public int getCollideWithGroups() { - return collisionGroupsMask; - } - - /** - * Initialize the user pointer and collision-group information of this - * object. - */ - protected void initUserPointer() { - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "initUserPointer() objectId = {0}", Long.toHexString(objectId)); - initUserPointer(objectId, collisionGroup, collisionGroupsMask); - } - native void initUserPointer(long objectId, int group, int groups); - - /** - * Access the user object associated with this collision object. - * - * @return the pre-existing instance, or null if none - */ - public Object getUserObject() { - return userObject; - } - - /** - * Test whether this object responds to contact with other objects. - * - * @return true if responsive, otherwise false - */ - public boolean isContactResponse() { - int flags = getCollisionFlags(objectId); - boolean result = (flags & CollisionFlag.NO_CONTACT_RESPONSE) == 0x0; - return result; - } - - /** - * Associate a user object (such as a Spatial) with this collision object. - * - * @param userObject the object to associate with this collision object - * (alias created, may be null) - */ - public void setUserObject(Object userObject) { - this.userObject = userObject; - } - - /** - * Read the id of the btCollisionObject. - * - * @return the unique identifier (not zero) - */ - public long getObjectId(){ - return objectId; - } - - /** - * Attach the identified btCollisionShape to the identified - * btCollisionObject. Native method. - * - * @param objectId the unique identifier of the btCollisionObject (not zero) - * @param collisionShapeId the unique identifier of the btCollisionShape - * (not zero) - */ - protected native void attachCollisionShape(long objectId, long collisionShapeId); - native void setCollisionGroup(long objectId, int collisionGroup); - native void setCollideWithGroups(long objectId, int collisionGroups); - - /** - * Serialize this object, for example when saving to a J3O file. - * - * @param e exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter e) throws IOException { - OutputCapsule capsule = e.getCapsule(this); - capsule.write(collisionGroup, "collisionGroup", 0x00000001); - capsule.write(collisionGroupsMask, "collisionGroupsMask", 0x00000001); - capsule.write(collisionShape, "collisionShape", null); - } - - /** - * De-serialize this object, for example when loading from a J3O file. - * - * @param e importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter e) throws IOException { - InputCapsule capsule = e.getCapsule(this); - collisionGroup = capsule.readInt("collisionGroup", 0x00000001); - collisionGroupsMask = capsule.readInt("collisionGroupsMask", 0x00000001); - CollisionShape shape = (CollisionShape) capsule.readSavable("collisionShape", null); - collisionShape = shape; - } - - /** - * Read the collision flags of this object. Subclasses are responsible for - * cloning/reading/writing these flags. - * - * @param objectId the ID of the btCollisionObject (not zero) - * @return the collision flags (bit mask) - */ - native protected int getCollisionFlags(long objectId); - - /** - * Alter the collision flags of this object. Subclasses are responsible for - * cloning/reading/writing these flags. - * - * @param objectId the ID of the btCollisionObject (not zero) - * @param desiredFlags the desired collision flags (bit mask) - */ - native protected void setCollisionFlags(long objectId, int desiredFlags); - - /** - * Finalize this collision object just before it is destroyed. Should be - * invoked only by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing CollisionObject {0}", Long.toHexString(objectId)); - finalizeNative(objectId); - } - - /** - * Finalize the identified btCollisionObject. Native method. - * - * @param objectId the unique identifier of the btCollisionObject (not zero) - */ - protected native void finalizeNative(long objectId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsRayTestResult.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsRayTestResult.java deleted file mode 100644 index 02bf0162e6..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsRayTestResult.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision; - -import com.jme3.math.Vector3f; - -/** - * Represent the results of a Bullet ray test. - * - * @author Empire-Phoenix,normenhansen - */ -public class PhysicsRayTestResult { - - /** - * collision object that was hit - */ - private PhysicsCollisionObject collisionObject; - /** - * normal vector at the point of contact - */ - private Vector3f hitNormalLocal; - /** - * fraction of the ray's total length (from=0, to=1, ≥0, ≤1) - */ - private float hitFraction; - /** - * true→need to transform normal into world space - */ - private boolean normalInWorldSpace = true; - - /** - * A private constructor to inhibit instantiation of this class by Java. - * These results are instantiated exclusively by native code. - */ - private PhysicsRayTestResult() { - } - - /** - * Access the collision object that was hit. - * - * @return the pre-existing instance - */ - public PhysicsCollisionObject getCollisionObject() { - return collisionObject; - } - - /** - * Access the normal vector at the point of contact. - * - * @return a pre-existing unit vector (not null) - */ - public Vector3f getHitNormalLocal() { - return hitNormalLocal; - } - - /** - * Read the fraction of the ray's total length. - * - * @return fraction (from=0, to=1, ≥0, ≤1) - */ - public float getHitFraction() { - return hitFraction; - } - - /** - * Test whether the normal is in world space. - * - * @return true if in world space, otherwise false - */ - public boolean isNormalInWorldSpace() { - return normalInWorldSpace; - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsSweepTestResult.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsSweepTestResult.java deleted file mode 100644 index 9becbb1c76..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsSweepTestResult.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision; - -import com.jme3.math.Vector3f; - -/** - * Represent the results of a Bullet sweep test. - * - * @author normenhansen - */ -public class PhysicsSweepTestResult { - - /** - * collision object that was hit - */ - private PhysicsCollisionObject collisionObject; - /** - * normal vector at the point of contact - */ - private Vector3f hitNormalLocal; - /** - * fraction of the way between the transforms (from=0, to=1, ≥0, ≤1) - */ - private float hitFraction; - /** - * true→need to transform normal into world space - */ - private boolean normalInWorldSpace; - - /** - * A private constructor to inhibit instantiation of this class by Java. - * These results are instantiated exclusively by native code. - */ - public PhysicsSweepTestResult() { - } - - public PhysicsSweepTestResult(PhysicsCollisionObject collisionObject, Vector3f hitNormalLocal, float hitFraction, boolean normalInWorldSpace) { - this.collisionObject = collisionObject; - this.hitNormalLocal = hitNormalLocal; - this.hitFraction = hitFraction; - this.normalInWorldSpace = normalInWorldSpace; - } - - /** - * Access the collision object that was hit. - * - * @return the pre-existing instance - */ - public PhysicsCollisionObject getCollisionObject() { - return collisionObject; - } - - /** - * Access the normal vector at the point of contact. - * - * @return the pre-existing vector (not null) - */ - public Vector3f getHitNormalLocal() { - return hitNormalLocal; - } - - /** - * Read the fraction of fraction of the way between the transforms (from=0, - * to=1, ≥0, ≤1) - * - * @return fraction (from=0, to=1, ≥0, ≤1) - */ - public float getHitFraction() { - return hitFraction; - } - - /** - * Test whether the normal is in world space. - * - * @return true if in world space, otherwise false - */ - public boolean isNormalInWorldSpace() { - return normalInWorldSpace; - } - - /** - * Fill in the fields of this result. - * - * @param collisionObject - * @param hitNormalLocal - * @param hitFraction - * @param normalInWorldSpace - */ - public void fill(PhysicsCollisionObject collisionObject, Vector3f hitNormalLocal, float hitFraction, boolean normalInWorldSpace) { - this.collisionObject = collisionObject; - this.hitNormalLocal = hitNormalLocal; - this.hitFraction = hitFraction; - this.normalInWorldSpace = normalInWorldSpace; - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/BoxCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/BoxCollisionShape.java deleted file mode 100644 index 1f3ac4673f..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/BoxCollisionShape.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A rectangular-solid collision shape based on Bullet's btBoxShape. - * - * @author normenhansen - */ -public class BoxCollisionShape extends CollisionShape { - - /** - * copy of half-extents of the box on each local axis (not null, no negative - * component) - */ - private Vector3f halfExtents; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected BoxCollisionShape() { - } - - /** - * Instantiate a box shape with the specified half extents. - * - * @param halfExtents the desired unscaled half extents (not null, no - * negative component, alias created) - */ - public BoxCollisionShape(Vector3f halfExtents) { - this.halfExtents = halfExtents; - createShape(); - } - - /** - * Access the half extents of the box. - * - * @return the pre-existing instance (not null, no negative component) - */ - public final Vector3f getHalfExtents() { - return halfExtents; - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(halfExtents, "halfExtents", new Vector3f(1, 1, 1)); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - Vector3f halfExtents = (Vector3f) capsule.readSavable("halfExtents", new Vector3f(1, 1, 1)); - this.halfExtents = halfExtents; - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - objectId = createShape(halfExtents); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); -// cShape = new BoxShape(Converter.convert(halfExtents)); - setScale(scale); - setMargin(margin); - } - - private native long createShape(Vector3f halfExtents); - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CapsuleCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CapsuleCollisionShape.java deleted file mode 100644 index 52f2af555f..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CapsuleCollisionShape.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A capsule collision shape based on Bullet's btCapsuleShapeX, btCapsuleShape, - * or btCapsuleShapeZ. These shapes have no margin and cannot be scaled. - * - * @author normenhansen - */ -public class CapsuleCollisionShape extends CollisionShape{ - /** - * copy of height of the cylindrical portion (≥0) - */ - private float height; - /** - * copy of radius (≥0) - */ - private float radius; - /** - * copy of main (height) axis (0→X, 1→Y, 2→Z) - */ - private int axis; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected CapsuleCollisionShape() { - } - - /** - * Instantiate a Y-axis capsule shape with the specified radius and height. - * - * @param radius the desired radius (≥0) - * @param height the desired height (of the cylindrical portion) (≥0) - */ - public CapsuleCollisionShape(float radius, float height) { - this.radius=radius; - this.height=height; - this.axis=1; - createShape(); - } - - /** - * Instantiate a capsule shape around the specified main (height) axis. - * - * @param radius the desired radius (≥0) - * @param height the desired height (of the cylindrical portion) (≥0) - * @param axis which local axis: 0→X, 1→Y, 2→Z - */ - public CapsuleCollisionShape(float radius, float height, int axis) { - this.radius=radius; - this.height=height; - this.axis=axis; - createShape(); - } - - /** - * Read the radius of the capsule. - * - * @return the radius (≥0) - */ - public float getRadius() { - return radius; - } - - /** - * Read the height (of the cylindrical portion) of the capsule. - * - * @return height (≥0) - */ - public float getHeight() { - return height; - } - - /** - * Determine the main (height) axis of the capsule. - * - * @return 0 for local X, 1 for local Y, or 2 for local Z - */ - public int getAxis() { - return axis; - } - - /** - * Alter the scaling factors of this shape. Scaling is disabled - * for capsule shapes. - * - * @param scale the desired scaling factor for each local axis (not null, no - * negative component, unaffected, default=1,1,1) - */ - @Override - public void setScale(Vector3f scale) { - if (!scale.equals(Vector3f.UNIT_XYZ)) { - Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "CapsuleCollisionShape cannot be scaled"); - } - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(radius, "radius", 0.5f); - capsule.write(height, "height", 1); - capsule.write(axis, "axis", 1); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - radius = capsule.readFloat("radius", 0.5f); - height = capsule.readFloat("height", 0.5f); - axis = capsule.readInt("axis", 1); - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape(){ - objectId = createShape(axis, radius, height); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); - setScale(scale); - setMargin(margin); -// switch(axis){ -// case 0: -// objectId=new CapsuleShapeX(radius,height); -// break; -// case 1: -// objectId=new CapsuleShape(radius,height); -// break; -// case 2: -// objectId=new CapsuleShapeZ(radius,height); -// break; -// } -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - } - - private native long createShape(int axis, float radius, float height); - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java deleted file mode 100644 index 615f23499c..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CollisionShape.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.*; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * The abstract base class for collision shapes based on Bullet's - * btCollisionShape. - *

- * Collision shapes include BoxCollisionShape and CapsuleCollisionShape. As - * suggested in the Bullet manual, a single collision shape can be shared among - * multiple collision objects. - * - * @author normenhansen - */ -public abstract class CollisionShape implements Savable { - - /** - * default margin for new non-sphere/non-capsule shapes (in physics-space - * units, >0, default=0.04) - */ - private static float defaultMargin = 0.04f; - /** - * unique identifier of the btCollisionShape - *

- * Constructors are responsible for setting this to a non-zero value. After - * that, the id never changes. - */ - protected long objectId = 0; - /** - * copy of scaling factors: one for each local axis (default=1,1,1) - */ - protected Vector3f scale = new Vector3f(1, 1, 1); - /** - * copy of collision margin (in physics-space units, >0, default=0) - */ - protected float margin = defaultMargin; - - public CollisionShape() { - } - -// /** -// * used internally, not safe -// */ -// public void calculateLocalInertia(long objectId, float mass) { -// if (this.objectId == 0) { -// return; -// } -//// if (this instanceof MeshCollisionShape) { -//// vector.set(0, 0, 0); -//// } else { -// calculateLocalInertia(objectId, this.objectId, mass); -//// objectId.calculateLocalInertia(mass, vector); -//// } -// } -// -// private native void calculateLocalInertia(long objectId, long shapeId, float mass); - - /** - * Read the id of the btCollisionShape. - * - * @return the unique identifier (not zero) - */ - public long getObjectId() { - return objectId; - } - - /** - * used internally - */ - public void setObjectId(long id) { - this.objectId = id; - } - - /** - * Alter the scaling factors of this shape. CAUTION: Not all shapes can be - * scaled. - *

- * Note that if the shape is shared (between collision objects and/or - * compound shapes) changes can have unintended consequences. - * - * @param scale the desired scaling factor for each local axis (not null, no - * negative component, unaffected, default=1,1,1) - */ - public void setScale(Vector3f scale) { - this.scale.set(scale); - setLocalScaling(objectId, scale); - } - /** - * Access the scaling factors. - * - * @return the pre-existing vector (not null) - */ - public Vector3f getScale() { - return scale; - } - - /** - * Test whether this shape can be applied to a dynamic rigid body. The only - * non-moving shapes are the heightfield, mesh, and plane shapes. - * - * @return true if non-moving, false otherwise - */ - public boolean isNonMoving() { - boolean result = isNonMoving(objectId); - return result; - } - - native private boolean isNonMoving(long objectId); - - /** - * Read the collision margin for this shape. - * - * @return the margin distance (in physics-space units, ≥0) - */ - public float getMargin() { - return getMargin(objectId); - } - - private native float getMargin(long objectId); - - /** - * Alter the default margin for new shapes that are neither capsules nor - * spheres. - * - * @param margin the desired margin distance (in physics-space units, >0, - * default=0.04) - */ - public static void setDefaultMargin(float margin) { - defaultMargin = margin; - } - - /** - * Read the default margin for new shapes. - * - * @return margin the default margin distance (in physics-space units, - * >0) - */ - public static float getDefaultMargin() { - return defaultMargin; - } - - /** - * Alter the collision margin of this shape. CAUTION: Margin is applied - * differently, depending on the type of shape. Generally the collision - * margin expands the object, creating a gap. Don't set the collision margin - * to zero. - *

- * Note that if the shape is shared (between collision objects and/or - * compound shapes) changes can have unintended consequences. - * - * @param margin the desired margin distance (in physics-space units, >0, - * default=0.04) - */ - public void setMargin(float margin) { - setMargin(objectId, margin); - this.margin = margin; - } - - private native void setLocalScaling(long obectId, Vector3f scale); - - private native void setMargin(long objectId, float margin); - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(scale, "scale", new Vector3f(1, 1, 1)); - capsule.write(getMargin(), "margin", 0.0f); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - InputCapsule capsule = im.getCapsule(this); - this.scale = (Vector3f) capsule.readSavable("scale", new Vector3f(1, 1, 1)); - this.margin = capsule.readFloat("margin", 0.0f); - } - - /** - * Finalize this shape just before it is destroyed. Should be invoked only - * by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing CollisionShape {0}", Long.toHexString(objectId)); - finalizeNative(objectId); - } - - private native void finalizeNative(long objectId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java deleted file mode 100644 index 1ddcb7740f..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.bullet.collision.shapes.infos.ChildCollisionShape; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A collision shape formed by combining convex child shapes, based on Bullet's - * btCompoundShape. - * - * @author normenhansen - */ -public class CompoundCollisionShape extends CollisionShape { - - /** - * children of this shape - */ - protected ArrayList children = new ArrayList(); - - /** - * Instantiate an empty compound shape (with no children). - */ - public CompoundCollisionShape() { - objectId = createShape();//new CompoundShape(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); - } - - /** - * Add a child shape with the specified local translation. - * - * @param shape the child shape to add (not null, not a compound shape, - * alias created) - * @param location the local coordinates of the child shape's center (not - * null, unaffected) - */ - public void addChildShape(CollisionShape shape, Vector3f location) { -// Transform transA = new Transform(Converter.convert(new Matrix3f())); -// Converter.convert(location, transA.origin); -// children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); -// ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); - addChildShape(shape, location, new Matrix3f()); - } - - /** - * Add a child shape with the specified local translation and orientation. - * - * @param shape the child shape to add (not null, not a compound shape, - * alias created) - * @param location the local coordinates of the child shape's center (not - * null, unaffected) - * @param rotation the local orientation of the child shape (not null, - * unaffected) - */ - public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) { - if(shape instanceof CompoundCollisionShape){ - throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); - } -// Transform transA = new Transform(Converter.convert(rotation)); -// Converter.convert(location, transA.origin); -// Converter.convert(rotation, transA.basis); - children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape)); - addChildShape(objectId, shape.getObjectId(), location, rotation); -// ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); - } - - private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { - if(shape instanceof CompoundCollisionShape){ - throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); - } -// Transform transA = new Transform(Converter.convert(rotation)); -// Converter.convert(location, transA.origin); -// Converter.convert(rotation, transA.basis); - addChildShape(objectId, shape.getObjectId(), location, rotation); -// ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); - } - - /** - * Remove a child from this shape. - * - * @param shape the child shape to remove (not null) - */ - public void removeChildShape(CollisionShape shape) { - removeChildShape(objectId, shape.getObjectId()); -// ((CompoundShape) objectId).removeChildShape(shape.getObjectId()); - for (Iterator it = children.iterator(); it.hasNext();) { - ChildCollisionShape childCollisionShape = it.next(); - if (childCollisionShape.shape == shape) { - it.remove(); - } - } - } - - /** - * Access the list of children. - * - * @return the pre-existing list (not null) - */ - public List getChildren() { - return children; - } - - private native long createShape(); - - private native long addChildShape(long objectId, long childId, Vector3f location, Matrix3f rotation); - - private native long removeChildShape(long objectId, long childId); - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.writeSavableArrayList(children, "children", new ArrayList()); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - @SuppressWarnings("unchecked") - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - children = capsule.readSavableArrayList("children", new ArrayList()); - setScale(scale); - setMargin(margin); - loadChildren(); - } - - private void loadChildren() { - for (Iterator it = children.iterator(); it.hasNext();) { - ChildCollisionShape child = it.next(); - addChildShapeDirect(child.shape, child.location, child.rotation); - } - } - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/ConeCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/ConeCollisionShape.java deleted file mode 100644 index 914176dde5..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/ConeCollisionShape.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.bullet.PhysicsSpace; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A conical collision shape based on Bullet's btConeShapeX, btConeShape, or - * btConeShapeZ. - * - * @author normenhansen - */ -public class ConeCollisionShape extends CollisionShape { - - /** - * copy of radius (≥0) - */ - protected float radius; - /** - * copy of height (≥0) - */ - protected float height; - /** - * copy of main (height) axis (0→X, 1→Y, 2→Z) - */ - protected int axis; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected ConeCollisionShape() { - } - - /** - * Instantiate a cone shape around the specified main (height) axis. - * - * @param radius the desired radius (≥0) - * @param height the desired height (≥0) - * @param axis which local axis: 0→X, 1→Y, 2→Z - */ - public ConeCollisionShape(float radius, float height, int axis) { - this.radius = radius; - this.height = height; - this.axis = axis; - createShape(); - } - - /** - * Instantiate a cone shape oriented along the Y axis. - * - * @param radius the desired radius (≥0) - * @param height the desired height (≥0) - */ - public ConeCollisionShape(float radius, float height) { - this.radius = radius; - this.height = height; - this.axis = PhysicsSpace.AXIS_Y; - createShape(); - } - - /** - * Read the radius of the cone. - * - * @return radius (≥0) - */ - public float getRadius() { - return radius; - } - - /** - * Read the height of the cone. - * - * @return height (≥0) - */ - public float getHeight() { - return height; - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(radius, "radius", 0.5f); - capsule.write(height, "height", 0.5f); - capsule.write(axis, "axis", PhysicsSpace.AXIS_Y); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - radius = capsule.readFloat("radius", 0.5f); - height = capsule.readFloat("height", 0.5f); - axis = capsule.readInt("axis", PhysicsSpace.AXIS_Y); - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - objectId = createShape(axis, radius, height); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); -// if (axis == PhysicsSpace.AXIS_X) { -// objectId = new ConeShapeX(radius, height); -// } else if (axis == PhysicsSpace.AXIS_Y) { -// objectId = new ConeShape(radius, height); -// } else if (axis == PhysicsSpace.AXIS_Z) { -// objectId = new ConeShapeZ(radius, height); -// } -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - setScale(scale); - setMargin(margin); - } - - private native long createShape(int axis, float radius, float height); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CylinderCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CylinderCollisionShape.java deleted file mode 100644 index 7686cd3dab..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CylinderCollisionShape.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A cylindrical collision shape based on Bullet's btCylinderShapeX, new - * btCylinderShape, or btCylinderShapeZ. - * - * @author normenhansen - */ -public class CylinderCollisionShape extends CollisionShape { - - /** - * copy of half-extents of the cylinder on each local axis (not null, no - * negative component) - */ - protected Vector3f halfExtents; - /** - * copy of main (height) axis (0→X, 1→Y, 2→Z) - */ - protected int axis; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected CylinderCollisionShape() { - } - - /** - * Instantiate a Z-axis cylinder shape with the specified half extents. - * - * @param halfExtents the desired unscaled half extents (not null, no - * negative component, alias created) - */ - public CylinderCollisionShape(Vector3f halfExtents) { - this.halfExtents = halfExtents; - this.axis = 2; - createShape(); - } - - /** - * Instantiate a cylinder shape around the specified axis. - * - * @param halfExtents the desired unscaled half extents (not null, no - * negative component, alias created) - * @param axis which local axis: 0→X, 1→Y, 2→Z - */ - public CylinderCollisionShape(Vector3f halfExtents, int axis) { - this.halfExtents = halfExtents; - this.axis = axis; - createShape(); - } - - /** - * Access the half extents of the cylinder. - * - * @return the pre-existing vector (not null, no negative component) - */ - public final Vector3f getHalfExtents() { - return halfExtents; - } - - /** - * Determine the main axis of the cylinder. - * - * @return 0→X, 1→Y, 2→Z - */ - public int getAxis() { - return axis; - } - - /** - * Alter the scaling factors of this shape. Scaling is disabled - * for cylinder shapes. - * - * @param scale the desired scaling factor for each local axis (not null, no - * negative component, unaffected, default=1,1,1) - */ - @Override - public void setScale(Vector3f scale) { - if (!scale.equals(Vector3f.UNIT_XYZ)) { - Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "CylinderCollisionShape cannot be scaled"); - } - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(halfExtents, "halfExtents", new Vector3f(0.5f, 0.5f, 0.5f)); - capsule.write(axis, "axis", 1); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - halfExtents = (Vector3f) capsule.readSavable("halfExtents", new Vector3f(0.5f, 0.5f, 0.5f)); - axis = capsule.readInt("axis", 1); - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - objectId = createShape(axis, halfExtents); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); -// switch (axis) { -// case 0: -// objectId = new CylinderShapeX(Converter.convert(halfExtents)); -// break; -// case 1: -// objectId = new CylinderShape(Converter.convert(halfExtents)); -// break; -// case 2: -// objectId = new CylinderShapeZ(Converter.convert(halfExtents)); -// break; -// } -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - setScale(scale); - setMargin(margin); - } - - private native long createShape(int axis, Vector3f halfExtents); - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java deleted file mode 100644 index b2007aab68..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.bullet.util.NativeMeshUtil; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import com.jme3.scene.Mesh; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.scene.mesh.IndexBuffer; -import com.jme3.util.BufferUtils; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A mesh collision shape based on Bullet's btGImpactMeshShape. - * - * @author normenhansen - */ -public class GImpactCollisionShape extends CollisionShape { - -// protected Vector3f worldScale; - protected int numVertices, numTriangles, vertexStride, triangleIndexStride; - protected ByteBuffer triangleIndexBase, vertexBase; - /** - * Unique identifier of the Bullet mesh. The constructor sets this to a - * non-zero value. - */ - protected long meshId = 0; -// protected IndexedMesh bulletMesh; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected GImpactCollisionShape() { - } - - /** - * Instantiate a shape based on the specified JME mesh. - * - * @param mesh the Mesh to use - */ - public GImpactCollisionShape(Mesh mesh) { - createCollisionMesh(mesh); - } - - private void createCollisionMesh(Mesh mesh) { - triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4); - vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); -// triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4); -// vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4); - numVertices = mesh.getVertexCount(); - vertexStride = 12; //3 verts * 4 bytes per. - numTriangles = mesh.getTriangleCount(); - triangleIndexStride = 12; //3 index entries * 4 bytes each. - - IndexBuffer indices = mesh.getIndicesAsList(); - FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); - vertices.rewind(); - - int verticesLength = mesh.getVertexCount() * 3; - for (int i = 0; i < verticesLength; i++) { - float tempFloat = vertices.get(); - vertexBase.putFloat(tempFloat); - } - - int indicesLength = mesh.getTriangleCount() * 3; - for (int i = 0; i < indicesLength; i++) { - triangleIndexBase.putInt(indices.get(i)); - } - vertices.rewind(); - vertices.clear(); - - createShape(); - } - -// /** -// * creates a jme mesh from the collision shape, only needed for debugging -// */ -// public Mesh createJmeMesh() { -// return Converter.convert(bulletMesh); -// } - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); -// capsule.write(worldScale, "worldScale", new Vector3f(1, 1, 1)); - capsule.write(numVertices, "numVertices", 0); - capsule.write(numTriangles, "numTriangles", 0); - capsule.write(vertexStride, "vertexStride", 0); - capsule.write(triangleIndexStride, "triangleIndexStride", 0); - - capsule.write(triangleIndexBase.array(), "triangleIndexBase", new byte[0]); - capsule.write(vertexBase.array(), "vertexBase", new byte[0]); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); -// worldScale = (Vector3f) capsule.readSavable("worldScale", new Vector3f(1, 1, 1)); - numVertices = capsule.readInt("numVertices", 0); - numTriangles = capsule.readInt("numTriangles", 0); - vertexStride = capsule.readInt("vertexStride", 0); - triangleIndexStride = capsule.readInt("triangleIndexStride", 0); - - triangleIndexBase = ByteBuffer.wrap(capsule.readByteArray("triangleIndexBase", new byte[0])); - vertexBase = ByteBuffer.wrap(capsule.readByteArray("vertexBase", new byte[0])); - createShape(); - } - - /** - * Alter the scaling factors of this shape. - *

- * Note that if the shape is shared (between collision objects and/or - * compound shapes) changes can have unintended consequences. - * - * @param scale the desired scaling factor for each local axis (not null, no - * negative component, unaffected, default=(1,1,1)) - */ - @Override - public void setScale(Vector3f scale) { - super.setScale(scale); - recalcAabb(objectId); - } - - native private void recalcAabb(long shapeId); - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { -// bulletMesh = new IndexedMesh(); -// bulletMesh.numVertices = numVertices; -// bulletMesh.numTriangles = numTriangles; -// bulletMesh.vertexStride = vertexStride; -// bulletMesh.triangleIndexStride = triangleIndexStride; -// bulletMesh.triangleIndexBase = triangleIndexBase; -// bulletMesh.vertexBase = vertexBase; -// bulletMesh.triangleIndexBase = triangleIndexBase; -// TriangleIndexVertexArray tiv = new TriangleIndexVertexArray(numTriangles, triangleIndexBase, triangleIndexStride, numVertices, vertexBase, vertexStride); -// objectId = new GImpactMeshShape(tiv); -// objectId.setLocalScaling(Converter.convert(worldScale)); -// ((GImpactMeshShape)objectId).updateBound(); -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - meshId = NativeMeshUtil.createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Mesh {0}", Long.toHexString(meshId)); - objectId = createShape(meshId); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); - setScale(scale); - setMargin(margin); - } - - private native long createShape(long meshId); - - /** - * Finalize this shape just before it is destroyed. Should be invoked only - * by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing Mesh {0}", Long.toHexString(meshId)); - finalizeNative(meshId); - } - - private native void finalizeNative(long objectId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/HeightfieldCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/HeightfieldCollisionShape.java deleted file mode 100644 index 649f8612d8..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/HeightfieldCollisionShape.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.FastMath; -import com.jme3.math.Vector3f; -import com.jme3.scene.Mesh; -import com.jme3.util.BufferUtils; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A terrain collision shape based on Bullet's btHeightfieldTerrainShape. - *

- * This is much more efficient than a regular mesh, but it has a couple - * limitations: - *

    - *
  • No rotation or translation.
  • - *
  • The collision bounding box must be centered on (0,0,0) with the height - * above and below the X-Z plane being equal on either side. If not, the whole - * collision box is shifted vertically and objects won't collide properly.
  • - *
- * - * @author Brent Owens - */ -public class HeightfieldCollisionShape extends CollisionShape { - - /** - * number of rows in the heightfield (>1) - */ - protected int heightStickWidth; - /** - * number of columns in the heightfield (>1) - */ - protected int heightStickLength; - /** - * array of heightfield samples - */ - protected float[] heightfieldData; - protected float heightScale; - protected float minHeight; - protected float maxHeight; - /** - * index of the height axis (0→X, 1→Y, 2→Z) - */ - protected int upAxis; - protected boolean flipQuadEdges; - /** - * buffer for passing height data to Bullet - *

- * A Java reference must persist after createShape() completes, or else the - * buffer might get garbage collected. - */ - protected ByteBuffer bbuf; -// protected FloatBuffer fbuf; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected HeightfieldCollisionShape() { - } - - /** - * Instantiate a new shape for the specified height map. - * - * @param heightmap (not null, length≥4, length a perfect square) - */ - public HeightfieldCollisionShape(float[] heightmap) { - createCollisionHeightfield(heightmap, Vector3f.UNIT_XYZ); - } - - /** - * Instantiate a new shape for the specified height map and scale vector. - * - * @param heightmap (not null, length≥4, length a perfect square) - * @param scale (not null, no negative component, unaffected, default=1,1,1) - */ - public HeightfieldCollisionShape(float[] heightmap, Vector3f scale) { - createCollisionHeightfield(heightmap, scale); - } - - protected void createCollisionHeightfield(float[] heightmap, Vector3f worldScale) { - this.scale = worldScale; - this.heightScale = 1;//don't change away from 1, we use worldScale instead to scale - - this.heightfieldData = heightmap; - - float min = heightfieldData[0]; - float max = heightfieldData[0]; - // calculate min and max height - for (int i = 0; i < heightfieldData.length; i++) { - if (heightfieldData[i] < min) { - min = heightfieldData[i]; - } - if (heightfieldData[i] > max) { - max = heightfieldData[i]; - } - } - // we need to center the terrain collision box at 0,0,0 for BulletPhysics. And to do that we need to set the - // min and max height to be equal on either side of the y axis, otherwise it gets shifted and collision is incorrect. - if (max < 0) { - max = -min; - } else { - if (Math.abs(max) > Math.abs(min)) { - min = -max; - } else { - max = -min; - } - } - this.minHeight = min; - this.maxHeight = max; - - this.upAxis = 1; - flipQuadEdges = true; - - heightStickWidth = (int) FastMath.sqrt(heightfieldData.length); - heightStickLength = heightStickWidth; - - - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - bbuf = BufferUtils.createByteBuffer(heightfieldData.length * 4); -// fbuf = bbuf.asFloatBuffer();//FloatBuffer.wrap(heightfieldData); -// fbuf.rewind(); -// fbuf.put(heightfieldData); - for (int i = 0; i < heightfieldData.length; i++) { - float f = heightfieldData[i]; - bbuf.putFloat(f); - } -// fbuf.rewind(); - objectId = createShape(heightStickWidth, heightStickLength, bbuf, heightScale, minHeight, maxHeight, upAxis, flipQuadEdges); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); - setScale(scale); - setMargin(margin); - } - - private native long createShape(int heightStickWidth, int heightStickLength, ByteBuffer heightfieldData, float heightScale, float minHeight, float maxHeight, int upAxis, boolean flipQuadEdges); - - /** - * Does nothing. - * - * @return null - */ - public Mesh createJmeMesh() { - //TODO return Converter.convert(bulletMesh); - return null; - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(heightStickWidth, "heightStickWidth", 0); - capsule.write(heightStickLength, "heightStickLength", 0); - capsule.write(heightScale, "heightScale", 0); - capsule.write(minHeight, "minHeight", 0); - capsule.write(maxHeight, "maxHeight", 0); - capsule.write(upAxis, "upAxis", 1); - capsule.write(heightfieldData, "heightfieldData", new float[0]); - capsule.write(flipQuadEdges, "flipQuadEdges", false); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - heightStickWidth = capsule.readInt("heightStickWidth", 0); - heightStickLength = capsule.readInt("heightStickLength", 0); - heightScale = capsule.readFloat("heightScale", 0); - minHeight = capsule.readFloat("minHeight", 0); - maxHeight = capsule.readFloat("maxHeight", 0); - upAxis = capsule.readInt("upAxis", 1); - heightfieldData = capsule.readFloatArray("heightfieldData", new float[0]); - flipQuadEdges = capsule.readBoolean("flipQuadEdges", false); - createShape(); - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/HullCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/HullCollisionShape.java deleted file mode 100644 index 7e584844ba..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/HullCollisionShape.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.scene.Mesh; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.util.BufferUtils; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A convex hull collision shape based on Bullet's btConvexHullShape. - */ -public class HullCollisionShape extends CollisionShape { - - private float[] points; -// protected FloatBuffer fbuf; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected HullCollisionShape() { - } - - /** - * Instantiate a collision shape based on the specified JME mesh. For best - * performance and stability, use the mesh should have no more than 100 - * vertices. - * - * @param mesh a mesh on which to base the shape (not null, at least one - * vertex) - */ - public HullCollisionShape(Mesh mesh) { - this.points = getPoints(mesh); - createShape(); - } - - /** - * Instantiate a collision shape based on the specified array of - * coordinates. - * - * @param points an array of coordinates on which to base the shape (not - * null, not empty, length a multiple of 3) - */ - public HullCollisionShape(float[] points) { - this.points = points; - createShape(); - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(points, "points", null); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - - // for backwards compatability - Mesh mesh = (Mesh) capsule.readSavable("hullMesh", null); - if (mesh != null) { - this.points = getPoints(mesh); - } else { - this.points = capsule.readFloatArray("points", null); - - } -// fbuf = ByteBuffer.allocateDirect(points.length * 4).asFloatBuffer(); -// fbuf.put(points); -// fbuf = FloatBuffer.wrap(points).order(ByteOrder.nativeOrder()).asFloatBuffer(); - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { -// ObjectArrayList pointList = new ObjectArrayList(); -// for (int i = 0; i < points.length; i += 3) { -// pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); -// } -// objectId = new ConvexHullShape(pointList); -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - ByteBuffer bbuf=BufferUtils.createByteBuffer(points.length * 4); -// fbuf = bbuf.asFloatBuffer(); -// fbuf.rewind(); -// fbuf.put(points); - for (int i = 0; i < points.length; i++) { - float f = points[i]; - bbuf.putFloat(f); - } - bbuf.rewind(); - objectId = createShape(bbuf); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); - setScale(scale); - setMargin(margin); - } - - private native long createShape(ByteBuffer points); - - /** - * Copy the vertex positions from a JME mesh. - * - * @param mesh the mesh to read (not null) - * @return a new array (not null, length a multiple of 3) - */ - protected float[] getPoints(Mesh mesh) { - FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); - vertices.rewind(); - int components = mesh.getVertexCount() * 3; - float[] pointsArray = new float[components]; - for (int i = 0; i < components; i += 3) { - pointsArray[i] = vertices.get(); - pointsArray[i + 1] = vertices.get(); - pointsArray[i + 2] = vertices.get(); - } - return pointsArray; - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java deleted file mode 100644 index db95b8120e..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.jme3.bullet.util.NativeMeshUtil; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.scene.Mesh; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.scene.mesh.IndexBuffer; -import com.jme3.util.BufferUtils; - -/** - * A mesh collision shape based on Bullet's btBvhTriangleMeshShape. - * - * @author normenhansen - */ -public class MeshCollisionShape extends CollisionShape { - - private static final String VERTEX_BASE = "vertexBase"; - private static final String TRIANGLE_INDEX_BASE = "triangleIndexBase"; - private static final String TRIANGLE_INDEX_STRIDE = "triangleIndexStride"; - private static final String VERTEX_STRIDE = "vertexStride"; - private static final String NUM_TRIANGLES = "numTriangles"; - private static final String NUM_VERTICES = "numVertices"; - private static final String NATIVE_BVH = "nativeBvh"; - protected int numVertices, numTriangles, vertexStride, triangleIndexStride; - protected ByteBuffer triangleIndexBase, vertexBase; - /** - * Unique identifier of the Bullet mesh. The constructor sets this to a - * non-zero value. - */ - protected long meshId = 0; - protected long nativeBVHBuffer = 0; - private boolean memoryOptimized; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected MeshCollisionShape() { - } - - /** - * Instantiate a collision shape based on the specified JME mesh, optimized - * for memory usage. - * - * @param mesh the mesh on which to base the shape (not null) - */ - public MeshCollisionShape(Mesh mesh) { - this(mesh, true); - } - - /** - * Instantiate a collision shape based on the specified JME mesh. - *

- * memoryOptimized determines if optimized instead of quantized - * BVH will be used. Internally, memoryOptimized BVH is slower - * to calculate (~4x) but also smaller (~0.5x). It is preferable to use the - * memory optimized version and then serialize the resulting - * MeshCollisionshape as this will also save the generated BVH. An exception - * can be procedurally / generated collision shapes, where the generation - * time is more of a concern - * - * @param mesh the mesh on which to base the shape (not null) - * @param memoryOptimized true to generate a memory-optimized BVH, false to - * generate quantized BVH - */ - public MeshCollisionShape(final Mesh mesh, final boolean memoryOptimized) { - this.memoryOptimized = memoryOptimized; - this.createCollisionMesh(mesh); - } - - /** - * An advanced constructor. Passing false values can lead to a crash. - * Usually you don’t want to use this. Use at own risk. - *

- * This constructor bypasses all copy logic normally used, this allows for - * faster Bullet shape generation when using procedurally generated Meshes. - * - * @param indices the raw index buffer - * @param vertices the raw vertex buffer - * @param memoryOptimized use quantized BVH, uses less memory, but slower - */ - public MeshCollisionShape(ByteBuffer indices, ByteBuffer vertices, boolean memoryOptimized) { - this.triangleIndexBase = indices; - this.vertexBase = vertices; - this.numVertices = vertices.limit() / 4 / 3; - this.numTriangles = this.triangleIndexBase.limit() / 4 / 3; - this.vertexStride = 12; - this.triangleIndexStride = 12; - this.memoryOptimized = memoryOptimized; - this.createShape(null); - } - - private void createCollisionMesh(Mesh mesh) { - this.triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4); - this.vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); - this.numVertices = mesh.getVertexCount(); - this.vertexStride = 12; // 3 verts * 4 bytes per. - this.numTriangles = mesh.getTriangleCount(); - this.triangleIndexStride = 12; // 3 index entries * 4 bytes each. - - IndexBuffer indices = mesh.getIndicesAsList(); - FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); - vertices.rewind(); - - int verticesLength = mesh.getVertexCount() * 3; - for (int i = 0; i < verticesLength; i++) { - float tempFloat = vertices.get(); - vertexBase.putFloat(tempFloat); - } - - int indicesLength = mesh.getTriangleCount() * 3; - for (int i = 0; i < indicesLength; i++) { - triangleIndexBase.putInt(indices.get(i)); - } - vertices.rewind(); - vertices.clear(); - - this.createShape(null); - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(final JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(numVertices, MeshCollisionShape.NUM_VERTICES, 0); - capsule.write(numTriangles, MeshCollisionShape.NUM_TRIANGLES, 0); - capsule.write(vertexStride, MeshCollisionShape.VERTEX_STRIDE, 0); - capsule.write(triangleIndexStride, MeshCollisionShape.TRIANGLE_INDEX_STRIDE, 0); - - triangleIndexBase.position(0); - byte[] triangleIndexBasearray = new byte[triangleIndexBase.limit()]; - triangleIndexBase.get(triangleIndexBasearray); - capsule.write(triangleIndexBasearray, MeshCollisionShape.TRIANGLE_INDEX_BASE, null); - - vertexBase.position(0); - byte[] vertexBaseArray = new byte[vertexBase.limit()]; - vertexBase.get(vertexBaseArray); - capsule.write(vertexBaseArray, MeshCollisionShape.VERTEX_BASE, null); - - if (memoryOptimized) { - byte[] data = saveBVH(objectId); - capsule.write(data, MeshCollisionShape.NATIVE_BVH, null); - } - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(final JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - this.numVertices = capsule.readInt(MeshCollisionShape.NUM_VERTICES, 0); - this.numTriangles = capsule.readInt(MeshCollisionShape.NUM_TRIANGLES, 0); - this.vertexStride = capsule.readInt(MeshCollisionShape.VERTEX_STRIDE, 0); - this.triangleIndexStride = capsule.readInt(MeshCollisionShape.TRIANGLE_INDEX_STRIDE, 0); - - this.triangleIndexBase = BufferUtils.createByteBuffer(capsule.readByteArray(MeshCollisionShape.TRIANGLE_INDEX_BASE, null)); - this.vertexBase = BufferUtils.createByteBuffer(capsule.readByteArray(MeshCollisionShape.VERTEX_BASE, null)); - - byte[] nativeBvh = capsule.readByteArray(MeshCollisionShape.NATIVE_BVH, null); - memoryOptimized=nativeBvh != null; - createShape(nativeBvh); - } - - /** - * Instantiate the configured shape in Bullet. - */ - private void createShape(byte bvh[]) { - boolean buildBvh=bvh==null||bvh.length==0; - this.meshId = NativeMeshUtil.createTriangleIndexVertexArray(this.triangleIndexBase, this.vertexBase, this.numTriangles, this.numVertices, this.vertexStride, this.triangleIndexStride); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Mesh {0}", Long.toHexString(this.meshId)); - this.objectId = createShape(memoryOptimized, buildBvh, this.meshId); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(this.objectId)); - if(!buildBvh) nativeBVHBuffer = setBVH(bvh, this.objectId); - this.setScale(this.scale); - this.setMargin(this.margin); - } - - /** - * returns the pointer to the native buffer used by the in place - * de-serialized shape, must be freed when not used anymore! - */ - private native long setBVH(byte[] buffer, long objectid); - - private native byte[] saveBVH(long objectId); - - private native long createShape(boolean memoryOptimized, boolean buildBvt, long meshId); - - /** - * Finalize this shape just before it is destroyed. Should be invoked only - * by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - public void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing Mesh {0}", Long.toHexString(this.meshId)); - if (this.meshId > 0) { - this.finalizeNative(this.meshId, this.nativeBVHBuffer); - } - } - - private native void finalizeNative(long objectId, long nativeBVHBuffer); -} \ No newline at end of file diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/PlaneCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/PlaneCollisionShape.java deleted file mode 100644 index a21ced662c..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/PlaneCollisionShape.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Plane; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A planar collision shape based on Bullet's btStaticPlaneShape. - * - * @author normenhansen - */ -public class PlaneCollisionShape extends CollisionShape{ - /** - * description of the plane - */ - private Plane plane; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected PlaneCollisionShape() { - } - - /** - * Instantiate a plane shape defined by the specified plane. - * - * @param plane the desired plane (not null, alias created) - */ - public PlaneCollisionShape(Plane plane) { - this.plane = plane; - createShape(); - } - - /** - * Access the defining plane. - * - * @return the pre-existing instance (not null) - */ - public final Plane getPlane() { - return plane; - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(plane, "collisionPlane", new Plane()); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - plane = (Plane) capsule.readSavable("collisionPlane", new Plane()); - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - objectId = createShape(plane.getNormal(), plane.getConstant()); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); -// objectId = new StaticPlaneShape(Converter.convert(plane.getNormal()),plane.getConstant()); -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - setScale(scale); - setMargin(margin); - } - - private native long createShape(Vector3f normal, float constant); - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/SimplexCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/SimplexCollisionShape.java deleted file mode 100644 index 2b76ed14be..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/SimplexCollisionShape.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A simple point, line-segment, triangle, or tetrahedron collision shape based - * on Bullet's btBU_Simplex1to4. - * - * @author normenhansen - */ -public class SimplexCollisionShape extends CollisionShape { - - /** - * vertex positions - */ - private Vector3f vector1, vector2, vector3, vector4; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected SimplexCollisionShape() { - } - - /** - * Instantiate a tetrahedral collision shape based on the specified points. - * - * @param point1 the coordinates of 1st point (not null, alias created) - * @param point2 the coordinates of 2nd point (not null, alias created) - * @param point3 the coordinates of 3rd point (not null, alias created) - * @param point4 the coordinates of 4th point (not null, alias created) - */ - public SimplexCollisionShape(Vector3f point1, Vector3f point2, Vector3f point3, Vector3f point4) { - vector1 = point1; - vector2 = point2; - vector3 = point3; - vector4 = point4; - createShape(); - } - - /** - * Instantiate a triangular collision shape based on the specified points. - * - * @param point1 the coordinates of 1st point (not null, alias created) - * @param point2 the coordinates of 2nd point (not null, alias created) - * @param point3 the coordinates of 3rd point (not null, alias created) - */ - public SimplexCollisionShape(Vector3f point1, Vector3f point2, Vector3f point3) { - vector1 = point1; - vector2 = point2; - vector3 = point3; - createShape(); - } - - /** - * Instantiate a line-segment collision shape based on the specified points. - * - * @param point1 the coordinates of 1st point (not null, alias created) - * @param point2 the coordinates of 2nd point (not null, alias created) - */ - public SimplexCollisionShape(Vector3f point1, Vector3f point2) { - vector1 = point1; - vector2 = point2; - createShape(); - } - - /** - * Instantiate a point collision shape based on the specified points. - * - * @param point1 the coordinates of point (not null, alias created) - */ - public SimplexCollisionShape(Vector3f point1) { - vector1 = point1; - createShape(); - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(vector1, "simplexPoint1", null); - capsule.write(vector2, "simplexPoint2", null); - capsule.write(vector3, "simplexPoint3", null); - capsule.write(vector4, "simplexPoint4", null); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - vector1 = (Vector3f) capsule.readSavable("simplexPoint1", null); - vector2 = (Vector3f) capsule.readSavable("simplexPoint2", null); - vector3 = (Vector3f) capsule.readSavable("simplexPoint3", null); - vector4 = (Vector3f) capsule.readSavable("simplexPoint4", null); - createShape(); - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - if (vector4 != null) { - objectId = createShape(vector1, vector2, vector3, vector4); -// objectId = new BU_Simplex1to4(Converter.convert(vector1), Converter.convert(vector2), Converter.convert(vector3), Converter.convert(vector4)); - } else if (vector3 != null) { - objectId = createShape(vector1, vector2, vector3); -// objectId = new BU_Simplex1to4(Converter.convert(vector1), Converter.convert(vector2), Converter.convert(vector3)); - } else if (vector2 != null) { - objectId = createShape(vector1, vector2); -// objectId = new BU_Simplex1to4(Converter.convert(vector1), Converter.convert(vector2)); - } else { - objectId = createShape(vector1); -// objectId = new BU_Simplex1to4(Converter.convert(vector1)); - } - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - setScale(scale); - setMargin(margin); - } - - private native long createShape(Vector3f vector1); - - private native long createShape(Vector3f vector1, Vector3f vector2); - - private native long createShape(Vector3f vector1, Vector3f vector2, Vector3f vector3); - - private native long createShape(Vector3f vector1, Vector3f vector2, Vector3f vector3, Vector3f vector4); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/SphereCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/SphereCollisionShape.java deleted file mode 100644 index 665ce6f4dc..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/SphereCollisionShape.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.collision.shapes; - -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A spherical collision shape based on Bullet's btSphereShape. These shapes - * have no margin and cannot be scaled. - * - * @author normenhansen - */ -public class SphereCollisionShape extends CollisionShape { - - /** - * copy of radius (≥0) - */ - protected float radius; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected SphereCollisionShape() { - } - - /** - * Instantiate a sphere shape with the specified radius. - * - * @param radius the desired radius (≥0) - */ - public SphereCollisionShape(float radius) { - this.radius = radius; - createShape(); - } - - /** - * Read the radius of the sphere. - * - * @return the radius (≥0) - */ - public float getRadius() { - return radius; - } - - /** - * Serialize this shape, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(radius, "radius", 0.5f); - } - - /** - * De-serialize this shape, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - radius = capsule.readFloat("radius", 0.5f); - createShape(); - } - - /** - * Alter the scaling factors of this shape. Scaling is disabled - * for sphere shapes. - * - * @param scale the desired scaling factor for each local axis (not null, no - * negative component, unaffected, default=1,1,1) - */ - @Override - public void setScale(Vector3f scale) { - if (!scale.equals(Vector3f.UNIT_XYZ)) { - Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "SphereCollisionShape cannot be scaled"); - } - } - - /** - * Instantiate the configured shape in Bullet. - */ - protected void createShape() { - objectId = createShape(radius); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); -// new SphereShape(radius); -// objectId.setLocalScaling(Converter.convert(getScale())); -// objectId.setMargin(margin); - setScale(scale); // Set the scale to 1 - setMargin(margin); - } - - private native long createShape(float radius); - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java deleted file mode 100644 index ea05e9f659..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A joint based on Bullet's btConeTwistConstraint. - *

- * From the Bullet manual:
- * To create ragdolls, the cone twist constraint is very useful for limbs like - * the upper arm. It is a special point to point constraint that adds cone and - * twist axis limits. The x-axis serves as twist axis. - * - * @author normenhansen - */ -public class ConeJoint extends PhysicsJoint { - - protected Matrix3f rotA, rotB; - protected float swingSpan1 = 1e30f; - protected float swingSpan2 = 1e30f; - protected float twistSpan = 1e30f; - protected boolean angularOnly = false; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected ConeJoint() { - } - - /** - * Instantiate a ConeJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - */ - public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB) { - super(nodeA, nodeB, pivotA, pivotB); - this.rotA = new Matrix3f(); - this.rotB = new Matrix3f(); - createJoint(); - } - - /** - * Instantiate a ConeJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA local translation of the joint connection point in node A - * (not null, alias created) - * @param pivotB local translation of the joint connection point in node B - * (not null, alias created) - * @param rotA the local orientation of the connection to node A (not null, - * alias created) - * @param rotB the local orientation of the connection to node B (not null, - * alias created) - */ - public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB) { - super(nodeA, nodeB, pivotA, pivotB); - this.rotA = rotA; - this.rotB = rotB; - createJoint(); - } - - /** - * Alter the angular limits for this joint. - * - * @param swingSpan1 angle (in radians) - * @param swingSpan2 angle (in radians) - * @param twistSpan angle (in radians) - */ - public void setLimit(float swingSpan1, float swingSpan2, float twistSpan) { - this.swingSpan1 = swingSpan1; - this.swingSpan2 = swingSpan2; - this.twistSpan = twistSpan; - setLimit(objectId, swingSpan1, swingSpan2, twistSpan); - } - - private native void setLimit(long objectId, float swingSpan1, float swingSpan2, float twistSpan); - - /** - * Alter whether this joint is angular only. - * - * @param value the desired setting (default=false) - */ - public void setAngularOnly(boolean value) { - angularOnly = value; - setAngularOnly(objectId, value); - } - - private native void setAngularOnly(long objectId, boolean value); - - /** - * Serialize this joint, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(rotA, "rotA", new Matrix3f()); - capsule.write(rotB, "rotB", new Matrix3f()); - - capsule.write(angularOnly, "angularOnly", false); - capsule.write(swingSpan1, "swingSpan1", 1e30f); - capsule.write(swingSpan2, "swingSpan2", 1e30f); - capsule.write(twistSpan, "twistSpan", 1e30f); - } - - /** - * De-serialize this joint, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - this.rotA = (Matrix3f) capsule.readSavable("rotA", new Matrix3f()); - this.rotB = (Matrix3f) capsule.readSavable("rotB", new Matrix3f()); - - this.angularOnly = capsule.readBoolean("angularOnly", false); - this.swingSpan1 = capsule.readFloat("swingSpan1", 1e30f); - this.swingSpan2 = capsule.readFloat("swingSpan2", 1e30f); - this.twistSpan = capsule.readFloat("twistSpan", 1e30f); - createJoint(); - } - - /** - * Create the configured joint in Bullet. - */ - protected void createJoint() { - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - setLimit(objectId, swingSpan1, swingSpan2, twistSpan); - setAngularOnly(objectId, angularOnly); - } - - private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/HingeJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/HingeJoint.java deleted file mode 100644 index 29b9b80700..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/HingeJoint.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A joint based on Bullet's btHingeConstraint. - *

- * From the Bullet manual:
- * Hinge constraint, or revolute joint restricts two additional angular degrees - * of freedom, so the body can only rotate around one axis, the hinge axis. This - * can be useful to represent doors or wheels rotating around one axis. The user - * can specify limits and motor for the hinge. - * - * @author normenhansen - */ -public class HingeJoint extends PhysicsJoint { - - protected Vector3f axisA; - protected Vector3f axisB; - /** - * copy of the angular-only flag (default=false) - */ - protected boolean angularOnly = false; - /** - * copy of the limit's bias factor, how strictly position errors (drift) is - * corrected (default=0.3) - */ - protected float biasFactor = 0.3f; - /** - * copy of the limit's relaxation factor, the rate at which velocity errors - * are corrected (default=1) - */ - protected float relaxationFactor = 1.0f; - /** - * copy of the limit's softness, the range fraction at which velocity-error - * correction starts operating (default=0.9) - */ - protected float limitSoftness = 0.9f; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected HingeJoint() { - } - - /** - * Instantiate a HingeJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - * @param axisA the local axis of the connection to node A (not null, alias - * created) - * @param axisB the local axis of the connection to node B (not null, alias - * created) - */ - public HingeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Vector3f axisA, Vector3f axisB) { - super(nodeA, nodeB, pivotA, pivotB); - this.axisA = axisA; - this.axisB = axisB; - createJoint(); - } - - /** - * Enable or disable this joint's motor. - * - * @param enable true to enable, false to disable - * @param targetVelocity the desired target velocity - * @param maxMotorImpulse the desired maximum rotational force - */ - public void enableMotor(boolean enable, float targetVelocity, float maxMotorImpulse) { - enableMotor(objectId, enable, targetVelocity, maxMotorImpulse); - } - - private native void enableMotor(long objectId, boolean enable, float targetVelocity, float maxMotorImpulse); - - /** - * Test whether this joint's motor is enabled. - * - * @return true if enabled, otherwise false - */ - public boolean getEnableMotor() { - return getEnableAngularMotor(objectId); - } - - private native boolean getEnableAngularMotor(long objectId); - - /** - * Read the motor's target velocity. - * - * @return velocity - */ - public float getMotorTargetVelocity() { - return getMotorTargetVelocity(objectId); - } - - private native float getMotorTargetVelocity(long objectId); - - /** - * Read the motor's maximum impulse. - * - * @return impulse - */ - public float getMaxMotorImpulse() { - return getMaxMotorImpulse(objectId); - } - - private native float getMaxMotorImpulse(long objectId); - - /** - * Alter this joint's limits. - * - * @param low the desired lower limit of the hinge angle (in radians) - * @param high the desired upper limit of the joint angle (in radians) - */ - public void setLimit(float low, float high) { - setLimit(objectId, low, high); - } - - private native void setLimit(long objectId, float low, float high); - - /** - * Alter this joint's limits. If you're above the softness, velocities that - * would shoot through the actual limit are slowed down. The bias should be - * in the range of 0.2 - 0.5. - * - * @param low the desired lower limit of the hinge angle (in radians) - * @param high the desired upper limit of the joint angle (in radians) - * @param _softness the desired range fraction at which velocity-error - * correction starts operating. A softness of 0.9 means that the correction - * starts at 90% of the limit range. (default=0.9) - * @param _biasFactor the desired magnitude of the position correction, how - * strictly position errors (drift) is corrected. (default=0.3) - * @param _relaxationFactor the desired rate at which velocity errors are - * corrected. This can be seen as the strength of the limits. A low value - * will make the limits more spongy. (default=1) - */ - public void setLimit(float low, float high, float _softness, float _biasFactor, float _relaxationFactor) { - biasFactor = _biasFactor; - relaxationFactor = _relaxationFactor; - limitSoftness = _softness; - setLimit(objectId, low, high, _softness, _biasFactor, _relaxationFactor); - } - - private native void setLimit(long objectId, float low, float high, float _softness, float _biasFactor, float _relaxationFactor); - - /** - * Read the upper limit of the hinge angle. - * - * @return angle (in radians) - */ - public float getUpperLimit() { - return getUpperLimit(objectId); - } - - private native float getUpperLimit(long objectId); - - /** - * Read the lower limit of the hinge angle. - * - * @return the angle (in radians) - */ - public float getLowerLimit() { - return getLowerLimit(objectId); - } - - private native float getLowerLimit(long objectId); - - /** - * Alter the hinge translation flag. - * - * @param angularOnly true→rotate only, false→rotate and translate - * (default=false) - */ - public void setAngularOnly(boolean angularOnly) { - this.angularOnly = angularOnly; - setAngularOnly(objectId, angularOnly); - } - - private native void setAngularOnly(long objectId, boolean angularOnly); - - /** - * Read the hinge angle. - * - * @return the angle (in radians) - */ - public float getHingeAngle() { - return getHingeAngle(objectId); - } - - private native float getHingeAngle(long objectId); - - /** - * Serialize this joint, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(axisA, "axisA", new Vector3f()); - capsule.write(axisB, "axisB", new Vector3f()); - - capsule.write(angularOnly, "angularOnly", false); - - capsule.write(getLowerLimit(), "lowerLimit", 1e30f); - capsule.write(getUpperLimit(), "upperLimit", -1e30f); - - capsule.write(biasFactor, "biasFactor", 0.3f); - capsule.write(relaxationFactor, "relaxationFactor", 1f); - capsule.write(limitSoftness, "limitSoftness", 0.9f); - - capsule.write(getEnableMotor(), "enableAngularMotor", false); - capsule.write(getMotorTargetVelocity(), "targetVelocity", 0.0f); - capsule.write(getMaxMotorImpulse(), "maxMotorImpulse", 0.0f); - } - - /** - * De-serialize this joint, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - this.axisA = (Vector3f) capsule.readSavable("axisA", new Vector3f()); - this.axisB = (Vector3f) capsule.readSavable("axisB", new Vector3f()); - - this.angularOnly = capsule.readBoolean("angularOnly", false); - float lowerLimit = capsule.readFloat("lowerLimit", 1e30f); - float upperLimit = capsule.readFloat("upperLimit", -1e30f); - - this.biasFactor = capsule.readFloat("biasFactor", 0.3f); - this.relaxationFactor = capsule.readFloat("relaxationFactor", 1f); - this.limitSoftness = capsule.readFloat("limitSoftness", 0.9f); - - boolean enableAngularMotor = capsule.readBoolean("enableAngularMotor", false); - float targetVelocity = capsule.readFloat("targetVelocity", 0.0f); - float maxMotorImpulse = capsule.readFloat("maxMotorImpulse", 0.0f); - - createJoint(); - enableMotor(enableAngularMotor, targetVelocity, maxMotorImpulse); - setLimit(lowerLimit, upperLimit, limitSoftness, biasFactor, relaxationFactor); - } - - /** - * Create the configured joint in Bullet. - */ - protected void createJoint() { - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, axisA, pivotB, axisB); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - setAngularOnly(objectId, angularOnly); - } - - private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Vector3f axisA, Vector3f pivotB, Vector3f axisB); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/PhysicsJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/PhysicsJoint.java deleted file mode 100644 index f5f9edf2e4..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/PhysicsJoint.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.export.*; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * The abstract base class for physics joints based on Bullet's - * btTypedConstraint, used to connect 2 dynamic rigid bodies in the same - * physics space. - *

- * Joints include ConeJoint, HingeJoint, Point2PointJoint, and SixDofJoint. - * - * @author normenhansen - */ -public abstract class PhysicsJoint implements Savable { - - /** - * Unique identifier of the Bullet constraint. Constructors are responsible - * for setting this to a non-zero value. After that, the id never changes. - */ - protected long objectId = 0; - /** - * one of the connected rigid bodies - */ - protected PhysicsRigidBody nodeA; - /** - * the other connected rigid body - */ - protected PhysicsRigidBody nodeB; - /** - * local offset of this joint's connection point in node A - */ - protected Vector3f pivotA; - /** - * local offset of this joint's connection point in node B - */ - protected Vector3f pivotB; - protected boolean collisionBetweenLinkedBodys = true; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected PhysicsJoint() { - } - - /** - * Instantiate a PhysicsJoint. To be effective, the joint must be added to - * the physics space of the two bodies. Also, the bodies must be dynamic and - * distinct. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA local offset of the joint connection point in node A (not - * null, alias created) - * @param pivotB local offset of the joint connection point in node B (not - * null, alias created) - */ - public PhysicsJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB) { - this.nodeA = nodeA; - this.nodeB = nodeB; - this.pivotA = pivotA; - this.pivotB = pivotB; - nodeA.addJoint(this); - nodeB.addJoint(this); - } - - /** - * Read the magnitude of the applied impulse. - * - * @return impulse - */ - public float getAppliedImpulse() { - return getAppliedImpulse(objectId); - } - - private native float getAppliedImpulse(long objectId); - - /** - * Read the id of the Bullet constraint. - * - * @return the unique identifier (not zero) - */ - public long getObjectId() { - return objectId; - } - - /** - * Test whether collisions are allowed between the linked bodies. - * - * @return true if collision are allowed, otherwise false - */ - public boolean isCollisionBetweenLinkedBodys() { - return collisionBetweenLinkedBodys; - } - - /** - * Enable or disable collisions between the linked bodies. The joint must be - * removed from and added to PhysicsSpace for this change to be effective. - * - * @param collisionBetweenLinkedBodys true → allow collisions, false → prevent them - */ - public void setCollisionBetweenLinkedBodys(boolean collisionBetweenLinkedBodys) { - this.collisionBetweenLinkedBodys = collisionBetweenLinkedBodys; - } - - /** - * Access the 1st body specified in during construction. - * - * @return the pre-existing body - */ - public PhysicsRigidBody getBodyA() { - return nodeA; - } - - /** - * Access the 2nd body specified in during construction. - * - * @return the pre-existing body - */ - public PhysicsRigidBody getBodyB() { - return nodeB; - } - - /** - * Access the local offset of the joint connection point in node A. - * - * @return the pre-existing vector (not null) - */ - public Vector3f getPivotA() { - return pivotA; - } - - /** - * Access the local offset of the joint connection point in node A. - * - * @return the pre-existing vector (not null) - */ - public Vector3f getPivotB() { - return pivotB; - } - - /** - * Destroy this joint and remove it from the joint lists of its connected - * bodies. - */ - public void destroy() { - getBodyA().removeJoint(this); - getBodyB().removeJoint(this); - } - - /** - * Serialize this joint, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(nodeA, "nodeA", null); - capsule.write(nodeB, "nodeB", null); - capsule.write(pivotA, "pivotA", null); - capsule.write(pivotB, "pivotB", null); - } - - /** - * De-serialize this joint, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - InputCapsule capsule = im.getCapsule(this); - this.nodeA = ((PhysicsRigidBody) capsule.readSavable("nodeA", null)); - this.nodeB = (PhysicsRigidBody) capsule.readSavable("nodeB", null); - this.pivotA = (Vector3f) capsule.readSavable("pivotA", new Vector3f()); - this.pivotB = (Vector3f) capsule.readSavable("pivotB", new Vector3f()); - } - - /** - * Finalize this physics joint just before it is destroyed. Should be - * invoked only by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing Joint {0}", Long.toHexString(objectId)); - finalizeNative(objectId); - } - - private native void finalizeNative(long objectId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/Point2PointJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/Point2PointJoint.java deleted file mode 100644 index 4c2ddbffe9..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/Point2PointJoint.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A joint based on Bullet's btPoint2PointConstraint. - *

- * From the Bullet manual:
- * Point to point constraint limits the translation so that the local pivot - * points of 2 rigidbodies match in worldspace. A chain of rigidbodies can be - * connected using this constraint. - * - * @author normenhansen - */ -public class Point2PointJoint extends PhysicsJoint { - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected Point2PointJoint() { - } - - /** - * Instantiate a Point2PointJoint. To be effective, the joint must be added - * to a physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - */ - public Point2PointJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB) { - super(nodeA, nodeB, pivotA, pivotB); - createJoint(); - } - - /** - * Alter the joint's damping. - * - * @param value the desired viscous damping ratio (0→no damping, - * 1→critically damped, default=1) - */ - public void setDamping(float value) { - setDamping(objectId, value); - } - - private native void setDamping(long objectId, float value); - - /** - * Alter the joint's impulse clamp. - * - * @param value the desired impulse clamp value (default=0) - */ - public void setImpulseClamp(float value) { - setImpulseClamp(objectId, value); - } - - private native void setImpulseClamp(long objectId, float value); - - /** - * Alter the joint's tau value. - * - * @param value the desired tau value (default=0.3) - */ - public void setTau(float value) { - setTau(objectId, value); - } - - private native void setTau(long objectId, float value); - - /** - * Read the joint's damping ratio. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDamping() { - return getDamping(objectId); - } - - private native float getDamping(long objectId); - - /** - * Read the joint's impulse clamp. - * - * @return the clamp value - */ - public float getImpulseClamp() { - return getImpulseClamp(objectId); - } - - private native float getImpulseClamp(long objectId); - - /** - * Read the joint's tau value. - * - * @return the tau value - */ - public float getTau() { - return getTau(objectId); - } - - private native float getTau(long objectId); - - /** - * Serialize this joint, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule cap = ex.getCapsule(this); - cap.write(getDamping(), "damping", 1.0f); - cap.write(getTau(), "tau", 0.3f); - cap.write(getImpulseClamp(), "impulseClamp", 0f); - } - - /** - * De-serialize this joint, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - createJoint(); - InputCapsule cap = im.getCapsule(this); - setDamping(cap.readFloat("damping", 1.0f)); - setDamping(cap.readFloat("tau", 0.3f)); - setDamping(cap.readFloat("impulseClamp", 0f)); - } - - /** - * Create the configured joint in Bullet. - */ - protected void createJoint() { - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, pivotB); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - } - - private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Vector3f pivotB); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java deleted file mode 100644 index 6d9fb7b10b..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.joints.motors.RotationalLimitMotor; -import com.jme3.bullet.joints.motors.TranslationalLimitMotor; -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A joint based on Bullet's btGeneric6DofConstraint. - *

- * From the Bullet manual:
- * This generic constraint can emulate a variety of standard constraints, by - * configuring each of the 6 degrees of freedom (dof). The first 3 dof axis are - * linear axis, which represent translation of rigidbodies, and the latter 3 dof - * axis represent the angular motion. Each axis can be either locked, free or - * limited. On construction of a new btGeneric6DofSpring2Constraint, all axis - * are locked. Afterwards the axis can be reconfigured. Note that several - * combinations that include free and/or limited angular degrees of freedom are - * undefined. - *

- * For each axis:

    - *
  • Lowerlimit = Upperlimit → axis is locked
  • - *
  • Lowerlimit > Upperlimit → axis is free
  • - *
  • Lowerlimit < Upperlimit → axis it limited in that range
  • - *
- * - * @author normenhansen - */ -public class SixDofJoint extends PhysicsJoint { - - Matrix3f rotA, rotB; - /** - * true→limits give the allowable range of movement of frameB in frameA - * space, false→limits give the allowable range of movement of frameA - * in frameB space - */ - boolean useLinearReferenceFrameA; - LinkedList rotationalMotors = new LinkedList(); - TranslationalLimitMotor translationalMotor; - /** - * upper limits for rotation of all 3 axes - */ - Vector3f angularUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY); - /** - * lower limits for rotation of all 3 axes - */ - Vector3f angularLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY); - /** - * upper limit for translation of all 3 axes - */ - Vector3f linearUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY); - /** - * lower limits for translation of all 3 axes - */ - Vector3f linearLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY); - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected SixDofJoint() { - } - - /** - * Instantiate a SixDofJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - * @param rotA the local orientation of the connection to node A (not null, - * alias created) - * @param rotB the local orientation of the connection to node B (not null, - * alias created) - * @param useLinearReferenceFrameA true→use node A, false→use node - * B - */ - public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { - super(nodeA, nodeB, pivotA, pivotB); - this.useLinearReferenceFrameA = useLinearReferenceFrameA; - this.rotA = rotA; - this.rotB = rotB; - - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - gatherMotors(); - } - - /** - * Instantiate a SixDofJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - * @param useLinearReferenceFrameA true→use node A, false→use node - * B - */ - public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { - super(nodeA, nodeB, pivotA, pivotB); - this.useLinearReferenceFrameA = useLinearReferenceFrameA; - rotA = new Matrix3f(); - rotB = new Matrix3f(); - - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - gatherMotors(); - } - - private void gatherMotors() { - for (int i = 0; i < 3; i++) { - RotationalLimitMotor rmot = new RotationalLimitMotor(getRotationalLimitMotor(objectId, i)); - rotationalMotors.add(rmot); - } - translationalMotor = new TranslationalLimitMotor(getTranslationalLimitMotor(objectId)); - } - - native private void getAngles(long jointId, Vector3f storeVector); - - /** - * Copy the joint's rotation angles. - * - * @param storeResult storage for the result (modified if not null) - * @return the rotation angle for each local axis (in radians, either - * storeResult or a new vector, not null) - */ - public Vector3f getAngles(Vector3f storeResult) { - Vector3f result = (storeResult == null) ? new Vector3f() : storeResult; - - long constraintId = getObjectId(); - getAngles(constraintId, result); - - return result; - } - - private native long getRotationalLimitMotor(long objectId, int index); - - private native long getTranslationalLimitMotor(long objectId); - - /** - * Access the TranslationalLimitMotor of this joint, the motor which - * influences translation on all 3 axes. - * - * @return the pre-existing instance - */ - public TranslationalLimitMotor getTranslationalLimitMotor() { - return translationalMotor; - } - - /** - * Access the indexed RotationalLimitMotor of this joint, the motor which - * influences rotation around one axis. - * - * @param index the axis index of the desired motor: 0→X, 1→Y, - * 2→Z - * @return the pre-existing instance - */ - public RotationalLimitMotor getRotationalLimitMotor(int index) { - return rotationalMotors.get(index); - } - - /** - * Alter the joint's upper limits for translation of all 3 axes. - * - * @param vector the desired upper limits (not null, unaffected) - */ - public void setLinearUpperLimit(Vector3f vector) { - linearUpperLimit.set(vector); - setLinearUpperLimit(objectId, vector); - } - - private native void setLinearUpperLimit(long objctId, Vector3f vector); - - /** - * Alter the joint's lower limits for translation of all 3 axes. - * - * @param vector the desired lower limits (not null, unaffected) - */ - public void setLinearLowerLimit(Vector3f vector) { - linearLowerLimit.set(vector); - setLinearLowerLimit(objectId, vector); - } - - private native void setLinearLowerLimit(long objctId, Vector3f vector); - - /** - * Alter the joint's upper limits for rotation of all 3 axes. - * - * @param vector the desired upper limits (in radians, not null, unaffected) - */ - public void setAngularUpperLimit(Vector3f vector) { - angularUpperLimit.set(vector); - setAngularUpperLimit(objectId, vector); - } - - private native void setAngularUpperLimit(long objctId, Vector3f vector); - - /** - * Alter the joint's lower limits for rotation of all 3 axes. - * - * @param vector the desired lower limits (in radians, not null, unaffected) - */ - public void setAngularLowerLimit(Vector3f vector) { - angularLowerLimit.set(vector); - setAngularLowerLimit(objectId, vector); - } - - private native void setAngularLowerLimit(long objctId, Vector3f vector); - - native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); - - /** - * De-serialize this joint, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - gatherMotors(); - - setAngularUpperLimit((Vector3f) capsule.readSavable("angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); - setAngularLowerLimit((Vector3f) capsule.readSavable("angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); - setLinearUpperLimit((Vector3f) capsule.readSavable("linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); - setLinearLowerLimit((Vector3f) capsule.readSavable("linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); - - for (int i = 0; i < 3; i++) { - RotationalLimitMotor rotationalLimitMotor = getRotationalLimitMotor(i); - rotationalLimitMotor.setBounce(capsule.readFloat("rotMotor" + i + "_Bounce", 0.0f)); - rotationalLimitMotor.setDamping(capsule.readFloat("rotMotor" + i + "_Damping", 1.0f)); - rotationalLimitMotor.setERP(capsule.readFloat("rotMotor" + i + "_ERP", 0.5f)); - rotationalLimitMotor.setHiLimit(capsule.readFloat("rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY)); - rotationalLimitMotor.setLimitSoftness(capsule.readFloat("rotMotor" + i + "_LimitSoftness", 0.5f)); - rotationalLimitMotor.setLoLimit(capsule.readFloat("rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY)); - rotationalLimitMotor.setMaxLimitForce(capsule.readFloat("rotMotor" + i + "_MaxLimitForce", 300.0f)); - rotationalLimitMotor.setMaxMotorForce(capsule.readFloat("rotMotor" + i + "_MaxMotorForce", 0.1f)); - rotationalLimitMotor.setTargetVelocity(capsule.readFloat("rotMotor" + i + "_TargetVelocity", 0)); - rotationalLimitMotor.setEnableMotor(capsule.readBoolean("rotMotor" + i + "_EnableMotor", false)); - } - getTranslationalLimitMotor().setAccumulatedImpulse((Vector3f) capsule.readSavable("transMotor_AccumulatedImpulse", Vector3f.ZERO)); - getTranslationalLimitMotor().setDamping(capsule.readFloat("transMotor_Damping", 1.0f)); - getTranslationalLimitMotor().setLimitSoftness(capsule.readFloat("transMotor_LimitSoftness", 0.7f)); - getTranslationalLimitMotor().setLowerLimit((Vector3f) capsule.readSavable("transMotor_LowerLimit", Vector3f.ZERO)); - getTranslationalLimitMotor().setRestitution(capsule.readFloat("transMotor_Restitution", 0.5f)); - getTranslationalLimitMotor().setUpperLimit((Vector3f) capsule.readSavable("transMotor_UpperLimit", Vector3f.ZERO)); - - for (int axisIndex = 0; axisIndex < 3; ++axisIndex) { - translationalMotor.setEnabled(axisIndex, capsule.readBoolean( - "transMotor_Enable" + axisIndex, false)); - } - } - - /** - * Serialize this joint, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(angularUpperLimit, "angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY)); - capsule.write(angularLowerLimit, "angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY)); - capsule.write(linearUpperLimit, "linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY)); - capsule.write(linearLowerLimit, "linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY)); - int i = 0; - for (Iterator it = rotationalMotors.iterator(); it.hasNext();) { - RotationalLimitMotor rotationalLimitMotor = it.next(); - capsule.write(rotationalLimitMotor.getBounce(), "rotMotor" + i + "_Bounce", 0.0f); - capsule.write(rotationalLimitMotor.getDamping(), "rotMotor" + i + "_Damping", 1.0f); - capsule.write(rotationalLimitMotor.getERP(), "rotMotor" + i + "_ERP", 0.5f); - capsule.write(rotationalLimitMotor.getHiLimit(), "rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY); - capsule.write(rotationalLimitMotor.getLimitSoftness(), "rotMotor" + i + "_LimitSoftness", 0.5f); - capsule.write(rotationalLimitMotor.getLoLimit(), "rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY); - capsule.write(rotationalLimitMotor.getMaxLimitForce(), "rotMotor" + i + "_MaxLimitForce", 300.0f); - capsule.write(rotationalLimitMotor.getMaxMotorForce(), "rotMotor" + i + "_MaxMotorForce", 0.1f); - capsule.write(rotationalLimitMotor.getTargetVelocity(), "rotMotor" + i + "_TargetVelocity", 0); - capsule.write(rotationalLimitMotor.isEnableMotor(), "rotMotor" + i + "_EnableMotor", false); - i++; - } - capsule.write(getTranslationalLimitMotor().getAccumulatedImpulse(), "transMotor_AccumulatedImpulse", Vector3f.ZERO); - capsule.write(getTranslationalLimitMotor().getDamping(), "transMotor_Damping", 1.0f); - capsule.write(getTranslationalLimitMotor().getLimitSoftness(), "transMotor_LimitSoftness", 0.7f); - capsule.write(getTranslationalLimitMotor().getLowerLimit(), "transMotor_LowerLimit", Vector3f.ZERO); - capsule.write(getTranslationalLimitMotor().getRestitution(), "transMotor_Restitution", 0.5f); - capsule.write(getTranslationalLimitMotor().getUpperLimit(), "transMotor_UpperLimit", Vector3f.ZERO); - - for (int axisIndex = 0; axisIndex < 3; ++axisIndex) { - capsule.write(translationalMotor.isEnabled(axisIndex), - "transMotor_Enable" + axisIndex, false); - } - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java deleted file mode 100644 index a9479d1e7f..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.math.Matrix3f; -import com.jme3.math.Vector3f; - -/** - * A 6 degree-of-freedom joint based on Bullet's btGeneric6DofSpringConstraint. - *

- * From the Bullet manual:
- * This generic constraint can emulate a variety of standard constraints, by - * configuring each of the 6 degrees of freedom (dof). The first 3 dof axis are - * linear axis, which represent translation of rigidbodies, and the latter 3 dof - * axis represent the angular motion. Each axis can be either locked, free or - * limited. On construction of a new btGeneric6DofSpring2Constraint, all axis - * are locked. Afterwards the axis can be reconfigured. Note that several - * combinations that include free and/or limited angular degrees of freedom are - * undefined. - *

- * For each axis:

    - *
  • Lowerlimit = Upperlimit → axis is locked
  • - *
  • Lowerlimit > Upperlimit → axis is free
  • - *
  • Lowerlimit < Upperlimit → axis it limited in that range
  • - *
- * - * @author normenhansen - */ -public class SixDofSpringJoint extends SixDofJoint { - - final boolean springEnabled[] = new boolean[6]; - final float equilibriumPoint[] = new float[6]; - final float springStiffness[] = new float[6]; - final float springDamping[] = new float[6]; // between 0 and 1 (1 == no damping) - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - public SixDofSpringJoint() { - } - - /** - * Instantiate a SixDofSpringJoint. To be effective, the joint must be added - * to a physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - * @param rotA the local orientation of the connection to node A (not - * null, alias created) - * @param rotB the local orientation of the connection to node B (not - * null, alias created) - * @param useLinearReferenceFrameA true→use node A, false→use node - * B - */ - public SixDofSpringJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { - super(nodeA, nodeB, pivotA, pivotB, rotA, rotB, useLinearReferenceFrameA); - } - - /** - * Enable or disable the spring for the indexed degree of freedom. - * - * @param index which degree of freedom (≥0, <6) - * @param onOff true → enable, false → disable - */ - public void enableSpring(int index, boolean onOff) { - enableSpring(objectId, index, onOff); - } - native void enableSpring(long objctId, int index, boolean onOff); - - /** - * Alter the spring stiffness for the indexed degree of freedom. - * - * @param index which degree of freedom (≥0, <6) - * @param stiffness the desired stiffness - */ - public void setStiffness(int index, float stiffness) { - setStiffness(objectId, index, stiffness); - } - native void setStiffness(long objctId, int index, float stiffness); - - /** - * Alter the damping for the indexed degree of freedom. - * - * @param index which degree of freedom (≥0, <6) - * @param damping the desired viscous damping ratio (0→no damping, - * 1→critically damped, default=1) - */ - public void setDamping(int index, float damping) { - setDamping(objectId, index, damping); - - } - native void setDamping(long objctId, int index, float damping); - /** - * Alter the equilibrium points for all degrees of freedom, based on the - * current constraint position/orientation. - */ - public void setEquilibriumPoint() { // set the current constraint position/orientation as an equilibrium point for all DOF - setEquilibriumPoint(objectId); - } - native void setEquilibriumPoint(long objctId); - /** - * Alter the equilibrium point of the indexed degree of freedom, based on - * the current constraint position/orientation. - * - * @param index which degree of freedom (≥0, <6) - */ - public void setEquilibriumPoint(int index){ // set the current constraint position/orientation as an equilibrium point for given DOF - setEquilibriumPoint(objectId, index); - } - native void setEquilibriumPoint(long objctId, int index); - @Override - native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java deleted file mode 100644 index 8fa93dd131..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java +++ /dev/null @@ -1,888 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints; - -import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A slider joint based on Bullet's btSliderConstraint. - *

- * From the Bullet manual:
- * The slider constraint allows the body to rotate around one axis and translate - * along this axis. - * - * @author normenhansen - */ -public class SliderJoint extends PhysicsJoint { - - protected Matrix3f rotA, rotB; - protected boolean useLinearReferenceFrameA; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected SliderJoint() { - } - - /** - * Instantiate a SliderJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - * @param rotA the local orientation of the connection to node A (not null, alias created) - * @param rotB the local orientation of the connection to node B (not null, alias created) - * @param useLinearReferenceFrameA true→use node A, false→use node - * B - */ - public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { - super(nodeA, nodeB, pivotA, pivotB); - this.rotA = rotA; - this.rotB = rotB; - this.useLinearReferenceFrameA = useLinearReferenceFrameA; - createJoint(); - } - - /** - * Instantiate a SliderJoint. To be effective, the joint must be added to a - * physics space. - * - * @param nodeA the 1st body connected by the joint (not null, alias - * created) - * @param nodeB the 2nd body connected by the joint (not null, alias - * created) - * @param pivotA the local offset of the connection point in node A (not - * null, alias created) - * @param pivotB the local offset of the connection point in node B (not - * null, alias created) - * @param useLinearReferenceFrameA true→use node A, false→use node - * B - */ - public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { - super(nodeA, nodeB, pivotA, pivotB); - this.rotA = new Matrix3f(); - this.rotB = new Matrix3f(); - this.useLinearReferenceFrameA = useLinearReferenceFrameA; - createJoint(); - } - - /** - * Read the joint's lower limit for on-axis translation. - * - * @return the lower limit - */ - public float getLowerLinLimit() { - return getLowerLinLimit(objectId); - } - - private native float getLowerLinLimit(long objectId); - - /** - * Alter the joint's lower limit for on-axis translation. - * - * @param lowerLinLimit the desired lower limit (default=-1) - */ - public void setLowerLinLimit(float lowerLinLimit) { - setLowerLinLimit(objectId, lowerLinLimit); - } - - private native void setLowerLinLimit(long objectId, float value); - - /** - * Read the joint's upper limit for on-axis translation. - * - * @return the upper limit - */ - public float getUpperLinLimit() { - return getUpperLinLimit(objectId); - } - - private native float getUpperLinLimit(long objectId); - - /** - * Alter the joint's upper limit for on-axis translation. - * - * @param upperLinLimit the desired upper limit (default=1) - */ - public void setUpperLinLimit(float upperLinLimit) { - setUpperLinLimit(objectId, upperLinLimit); - } - - private native void setUpperLinLimit(long objectId, float value); - - /** - * Read the joint's lower limit for on-axis rotation. - * - * @return the lower limit angle (in radians) - */ - public float getLowerAngLimit() { - return getLowerAngLimit(objectId); - } - - private native float getLowerAngLimit(long objectId); - - /** - * Alter the joint's lower limit for on-axis rotation. - * - * @param lowerAngLimit the desired lower limit angle (in radians, - * default=0) - */ - public void setLowerAngLimit(float lowerAngLimit) { - setLowerAngLimit(objectId, lowerAngLimit); - } - - private native void setLowerAngLimit(long objectId, float value); - - /** - * Read the joint's upper limit for on-axis rotation. - * - * @return the upper limit angle (in radians) - */ - public float getUpperAngLimit() { - return getUpperAngLimit(objectId); - } - - private native float getUpperAngLimit(long objectId); - - /** - * Alter the joint's upper limit for on-axis rotation. - * - * @param upperAngLimit the desired upper limit angle (in radians, - * default=0) - */ - public void setUpperAngLimit(float upperAngLimit) { - setUpperAngLimit(objectId, upperAngLimit); - } - - private native void setUpperAngLimit(long objectId, float value); - - /** - * Read the joint's softness for on-axis translation between the limits. - * - * @return the softness - */ - public float getSoftnessDirLin() { - return getSoftnessDirLin(objectId); - } - - private native float getSoftnessDirLin(long objectId); - - /** - * Alter the joint's softness for on-axis translation between the limits. - * - * @param softnessDirLin the desired softness (default=1) - */ - public void setSoftnessDirLin(float softnessDirLin) { - setSoftnessDirLin(objectId, softnessDirLin); - } - - private native void setSoftnessDirLin(long objectId, float value); - - /** - * Read the joint's restitution for on-axis translation between the limits. - * - * @return the restitution (bounce) factor - */ - public float getRestitutionDirLin() { - return getRestitutionDirLin(objectId); - } - - private native float getRestitutionDirLin(long objectId); - - /** - * Alter the joint's restitution for on-axis translation between the limits. - * - * @param restitutionDirLin the desired restitution (bounce) factor - * (default=0.7) - */ - public void setRestitutionDirLin(float restitutionDirLin) { - setRestitutionDirLin(objectId, restitutionDirLin); - } - - private native void setRestitutionDirLin(long objectId, float value); - - /** - * Read the joint's damping for on-axis translation between the limits. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDampingDirLin() { - return getDampingDirLin(objectId); - } - - private native float getDampingDirLin(long objectId); - - /** - * Alter the joint's damping for on-axis translation between the limits. - * - * @param dampingDirLin the desired viscous damping ratio (0→no - * damping, 1→critically damped, default=0) - */ - public void setDampingDirLin(float dampingDirLin) { - setDampingDirLin(objectId, dampingDirLin); - } - - private native void setDampingDirLin(long objectId, float value); - - /** - * Read the joint's softness for on-axis rotation between the limits. - * - * @return the softness - */ - public float getSoftnessDirAng() { - return getSoftnessDirAng(objectId); - } - - private native float getSoftnessDirAng(long objectId); - - /** - * Alter the joint's softness for on-axis rotation between the limits. - * - * @param softnessDirAng the desired softness (default=1) - */ - public void setSoftnessDirAng(float softnessDirAng) { - setSoftnessDirAng(objectId, softnessDirAng); - } - - private native void setSoftnessDirAng(long objectId, float value); - - /** - * Read the joint's restitution for on-axis rotation between the limits. - * - * @return the restitution (bounce) factor - */ - public float getRestitutionDirAng() { - return getRestitutionDirAng(objectId); - } - - private native float getRestitutionDirAng(long objectId); - - /** - * Alter the joint's restitution for on-axis rotation between the limits. - * - * @param restitutionDirAng the desired restitution (bounce) factor - * (default=0.7) - */ - public void setRestitutionDirAng(float restitutionDirAng) { - setRestitutionDirAng(objectId, restitutionDirAng); - } - - private native void setRestitutionDirAng(long objectId, float value); - - /** - * Read the joint's damping for on-axis rotation between the limits. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDampingDirAng() { - return getDampingDirAng(objectId); - } - - private native float getDampingDirAng(long objectId); - - /** - * Alter the joint's damping for on-axis rotation between the limits. - * - * @param dampingDirAng the desired viscous damping ratio (0→no - * damping, 1→critically damped, default=0) - */ - public void setDampingDirAng(float dampingDirAng) { - setDampingDirAng(objectId, dampingDirAng); - } - - private native void setDampingDirAng(long objectId, float value); - - /** - * Read the joint's softness for on-axis translation hitting the limits. - * - * @return the softness - */ - public float getSoftnessLimLin() { - return getSoftnessLimLin(objectId); - } - - private native float getSoftnessLimLin(long objectId); - - /** - * Alter the joint's softness for on-axis translation hitting the limits. - * - * @param softnessLimLin the desired softness (default=1) - */ - public void setSoftnessLimLin(float softnessLimLin) { - setSoftnessLimLin(objectId, softnessLimLin); - } - - private native void setSoftnessLimLin(long objectId, float value); - - /** - * Read the joint's restitution for on-axis translation hitting the limits. - * - * @return the restitution (bounce) factor - */ - public float getRestitutionLimLin() { - return getRestitutionLimLin(objectId); - } - - private native float getRestitutionLimLin(long objectId); - - /** - * Alter the joint's restitution for on-axis translation hitting the limits. - * - * @param restitutionLimLin the desired restitution (bounce) factor - * (default=0.7) - */ - public void setRestitutionLimLin(float restitutionLimLin) { - setRestitutionLimLin(objectId, restitutionLimLin); - } - - private native void setRestitutionLimLin(long objectId, float value); - - /** - * Read the joint's damping for on-axis translation hitting the limits. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDampingLimLin() { - return getDampingLimLin(objectId); - } - - private native float getDampingLimLin(long objectId); - - /** - * Alter the joint's damping for on-axis translation hitting the limits. - * - * @param dampingLimLin the desired viscous damping ratio (0→no - * damping, 1→critically damped, default=1) - */ - public void setDampingLimLin(float dampingLimLin) { - setDampingLimLin(objectId, dampingLimLin); - } - - private native void setDampingLimLin(long objectId, float value); - - /** - * Read the joint's softness for on-axis rotation hitting the limits. - * - * @return the softness - */ - public float getSoftnessLimAng() { - return getSoftnessLimAng(objectId); - } - - private native float getSoftnessLimAng(long objectId); - - /** - * Alter the joint's softness for on-axis rotation hitting the limits. - * - * @param softnessLimAng the desired softness (default=1) - */ - public void setSoftnessLimAng(float softnessLimAng) { - setSoftnessLimAng(objectId, softnessLimAng); - } - - private native void setSoftnessLimAng(long objectId, float value); - - /** - * Read the joint's restitution for on-axis rotation hitting the limits. - * - * @return the restitution (bounce) factor - */ - public float getRestitutionLimAng() { - return getRestitutionLimAng(objectId); - } - - private native float getRestitutionLimAng(long objectId); - - /** - * Alter the joint's restitution for on-axis rotation hitting the limits. - * - * @param restitutionLimAng the desired restitution (bounce) factor - * (default=0.7) - */ - public void setRestitutionLimAng(float restitutionLimAng) { - setRestitutionLimAng(objectId, restitutionLimAng); - } - - private native void setRestitutionLimAng(long objectId, float value); - - /** - * Read the joint's damping for on-axis rotation hitting the limits. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDampingLimAng() { - return getDampingLimAng(objectId); - } - - private native float getDampingLimAng(long objectId); - - /** - * Alter the joint's damping for on-axis rotation hitting the limits. - * - * @param dampingLimAng the desired viscous damping ratio (0→no - * damping, 1→critically damped, default=1) - */ - public void setDampingLimAng(float dampingLimAng) { - setDampingLimAng(objectId, dampingLimAng); - } - - private native void setDampingLimAng(long objectId, float value); - - /** - * Read the joint's softness for off-axis translation. - * - * @return the softness - */ - public float getSoftnessOrthoLin() { - return getSoftnessOrthoLin(objectId); - } - - private native float getSoftnessOrthoLin(long objectId); - - /** - * Alter the joint's softness for off-axis translation. - * - * @param softnessOrthoLin the desired softness (default=1) - */ - public void setSoftnessOrthoLin(float softnessOrthoLin) { - setSoftnessOrthoLin(objectId, softnessOrthoLin); - } - - private native void setSoftnessOrthoLin(long objectId, float value); - - /** - * Read the joint's restitution for off-axis translation. - * - * @return the restitution (bounce) factor - */ - public float getRestitutionOrthoLin() { - return getRestitutionOrthoLin(objectId); - } - - private native float getRestitutionOrthoLin(long objectId); - - /** - * Alter the joint's restitution for off-axis translation. - * - * @param restitutionOrthoLin the desired restitution (bounce) factor - * (default=0.7) - */ - public void setRestitutionOrthoLin(float restitutionOrthoLin) { - setRestitutionOrthoLin(objectId, restitutionOrthoLin); - } - - private native void setRestitutionOrthoLin(long objectId, float value); - - /** - * Read the joint's damping for off-axis translation. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDampingOrthoLin() { - return getDampingOrthoLin(objectId); - } - - private native float getDampingOrthoLin(long objectId); - - /** - * Alter the joint's damping for off-axis translation. - * - * @param dampingOrthoLin the desired viscous damping ratio (0→no - * damping, 1→critically damped, default=1) - */ - public void setDampingOrthoLin(float dampingOrthoLin) { - setDampingOrthoLin(objectId, dampingOrthoLin); - } - - private native void setDampingOrthoLin(long objectId, float value); - - /** - * Read the joint's softness for off-axis rotation. - * - * @return the softness - */ - public float getSoftnessOrthoAng() { - return getSoftnessOrthoAng(objectId); - } - - private native float getSoftnessOrthoAng(long objectId); - - /** - * Alter the joint's softness for off-axis rotation. - * - * @param softnessOrthoAng the desired softness (default=1) - */ - public void setSoftnessOrthoAng(float softnessOrthoAng) { - setSoftnessOrthoAng(objectId, softnessOrthoAng); - } - - private native void setSoftnessOrthoAng(long objectId, float value); - - /** - * Read the joint's restitution for off-axis rotation. - * - * @return the restitution (bounce) factor - */ - public float getRestitutionOrthoAng() { - return getRestitutionOrthoAng(objectId); - } - - private native float getRestitutionOrthoAng(long objectId); - - /** - * Alter the joint's restitution for off-axis rotation. - * - * @param restitutionOrthoAng the desired restitution (bounce) factor - * (default=0.7) - */ - public void setRestitutionOrthoAng(float restitutionOrthoAng) { - setRestitutionOrthoAng(objectId, restitutionOrthoAng); - } - - private native void setRestitutionOrthoAng(long objectId, float value); - - /** - * Read the joint's damping for off-axis rotation. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDampingOrthoAng() { - return getDampingOrthoAng(objectId); - } - - private native float getDampingOrthoAng(long objectId); - - /** - * Alter the joint's damping for off-axis rotation. - * - * @param dampingOrthoAng the desired viscous damping ratio (0→no - * damping, 1→critically damped, default=1) - */ - public void setDampingOrthoAng(float dampingOrthoAng) { - setDampingOrthoAng(objectId, dampingOrthoAng); - } - - private native void setDampingOrthoAng(long objectId, float value); - - /** - * Test whether the translation motor is powered. - * - * @return true if powered, otherwise false - */ - public boolean isPoweredLinMotor() { - return isPoweredLinMotor(objectId); - } - - private native boolean isPoweredLinMotor(long objectId); - - /** - * Alter whether the translation motor is powered. - * - * @param poweredLinMotor true to power the motor, false to de-power it - * (default=false) - */ - public void setPoweredLinMotor(boolean poweredLinMotor) { - setPoweredLinMotor(objectId, poweredLinMotor); - } - - private native void setPoweredLinMotor(long objectId, boolean value); - - /** - * Read the velocity target of the translation motor. - * - * @return the velocity target - */ - public float getTargetLinMotorVelocity() { - return getTargetLinMotorVelocity(objectId); - } - - private native float getTargetLinMotorVelocity(long objectId); - - /** - * Alter the velocity target of the translation motor. - * - * @param targetLinMotorVelocity the desired velocity target (default=0) - */ - public void setTargetLinMotorVelocity(float targetLinMotorVelocity) { - setTargetLinMotorVelocity(objectId, targetLinMotorVelocity); - } - - private native void setTargetLinMotorVelocity(long objectId, float value); - - /** - * Read the maximum force of the translation motor. - * - * @return the maximum force - */ - public float getMaxLinMotorForce() { - return getMaxLinMotorForce(objectId); - } - - private native float getMaxLinMotorForce(long objectId); - - /** - * Alter the maximum force of the translation motor. - * - * @param maxLinMotorForce the desired maximum force (default=0) - */ - public void setMaxLinMotorForce(float maxLinMotorForce) { - setMaxLinMotorForce(objectId, maxLinMotorForce); - } - - private native void setMaxLinMotorForce(long objectId, float value); - - /** - * Test whether the rotation motor is powered. - * - * @return true if powered, otherwise false - */ - public boolean isPoweredAngMotor() { - return isPoweredAngMotor(objectId); - } - - private native boolean isPoweredAngMotor(long objectId); - - /** - * Alter whether the rotation motor is powered. - * - * @param poweredAngMotor true to power the motor, false to de-power it - * (default=false) - */ - public void setPoweredAngMotor(boolean poweredAngMotor) { - setPoweredAngMotor(objectId, poweredAngMotor); - } - - private native void setPoweredAngMotor(long objectId, boolean value); - - /** - * Read the velocity target of the rotation motor. - * - * @return the velocity target (in radians per second) - */ - public float getTargetAngMotorVelocity() { - return getTargetAngMotorVelocity(objectId); - } - - private native float getTargetAngMotorVelocity(long objectId); - - /** - * Alter the velocity target of the rotation motor. - * - * @param targetAngMotorVelocity the desired velocity target (in radians per - * second, default=0) - */ - public void setTargetAngMotorVelocity(float targetAngMotorVelocity) { - setTargetAngMotorVelocity(objectId, targetAngMotorVelocity); - } - - private native void setTargetAngMotorVelocity(long objectId, float value); - - /** - * Read the maximum force of the rotation motor. - * - * @return the maximum force - */ - public float getMaxAngMotorForce() { - return getMaxAngMotorForce(objectId); - } - - private native float getMaxAngMotorForce(long objectId); - - /** - * Alter the maximum force of the rotation motor. - * - * @param maxAngMotorForce the desired maximum force (default=0) - */ - public void setMaxAngMotorForce(float maxAngMotorForce) { - setMaxAngMotorForce(objectId, maxAngMotorForce); - } - - private native void setMaxAngMotorForce(long objectId, float value); - - /** - * Serialize this joint, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - super.write(ex); - OutputCapsule capsule = ex.getCapsule(this); - //TODO: standard values.. - capsule.write(getDampingDirAng(), "dampingDirAng", 0f); - capsule.write(getDampingDirLin(), "dampingDirLin", 0f); - capsule.write(getDampingLimAng(), "dampingLimAng", 0f); - capsule.write(getDampingLimLin(), "dampingLimLin", 0f); - capsule.write(getDampingOrthoAng(), "dampingOrthoAng", 0f); - capsule.write(getDampingOrthoLin(), "dampingOrthoLin", 0f); - capsule.write(getLowerAngLimit(), "lowerAngLimit", 0f); - capsule.write(getLowerLinLimit(), "lowerLinLimit", 0f); - capsule.write(getMaxAngMotorForce(), "maxAngMotorForce", 0f); - capsule.write(getMaxLinMotorForce(), "maxLinMotorForce", 0f); - capsule.write(isPoweredAngMotor(), "poweredAngMotor", false); - capsule.write(isPoweredLinMotor(), "poweredLinMotor", false); - capsule.write(getRestitutionDirAng(), "restitutionDirAng", 0f); - capsule.write(getRestitutionDirLin(), "restitutionDirLin", 0f); - capsule.write(getRestitutionLimAng(), "restitutionLimAng", 0f); - capsule.write(getRestitutionLimLin(), "restitutionLimLin", 0f); - capsule.write(getRestitutionOrthoAng(), "restitutionOrthoAng", 0f); - capsule.write(getRestitutionOrthoLin(), "restitutionOrthoLin", 0f); - - capsule.write(getSoftnessDirAng(), "softnessDirAng", 0f); - capsule.write(getSoftnessDirLin(), "softnessDirLin", 0f); - capsule.write(getSoftnessLimAng(), "softnessLimAng", 0f); - capsule.write(getSoftnessLimLin(), "softnessLimLin", 0f); - capsule.write(getSoftnessOrthoAng(), "softnessOrthoAng", 0f); - capsule.write(getSoftnessOrthoLin(), "softnessOrthoLin", 0f); - - capsule.write(getTargetAngMotorVelocity(), "targetAngMotorVelicoty", 0f); - capsule.write(getTargetLinMotorVelocity(), "targetLinMotorVelicoty", 0f); - - capsule.write(getUpperAngLimit(), "upperAngLimit", 0f); - capsule.write(getUpperLinLimit(), "upperLinLimit", 0f); - - capsule.write(useLinearReferenceFrameA, "useLinearReferenceFrameA", false); - } - - /** - * De-serialize this joint, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - super.read(im); - InputCapsule capsule = im.getCapsule(this); - float dampingDirAng = capsule.readFloat("dampingDirAng", 0f); - float dampingDirLin = capsule.readFloat("dampingDirLin", 0f); - float dampingLimAng = capsule.readFloat("dampingLimAng", 0f); - float dampingLimLin = capsule.readFloat("dampingLimLin", 0f); - float dampingOrthoAng = capsule.readFloat("dampingOrthoAng", 0f); - float dampingOrthoLin = capsule.readFloat("dampingOrthoLin", 0f); - float lowerAngLimit = capsule.readFloat("lowerAngLimit", 0f); - float lowerLinLimit = capsule.readFloat("lowerLinLimit", 0f); - float maxAngMotorForce = capsule.readFloat("maxAngMotorForce", 0f); - float maxLinMotorForce = capsule.readFloat("maxLinMotorForce", 0f); - boolean poweredAngMotor = capsule.readBoolean("poweredAngMotor", false); - boolean poweredLinMotor = capsule.readBoolean("poweredLinMotor", false); - float restitutionDirAng = capsule.readFloat("restitutionDirAng", 0f); - float restitutionDirLin = capsule.readFloat("restitutionDirLin", 0f); - float restitutionLimAng = capsule.readFloat("restitutionLimAng", 0f); - float restitutionLimLin = capsule.readFloat("restitutionLimLin", 0f); - float restitutionOrthoAng = capsule.readFloat("restitutionOrthoAng", 0f); - float restitutionOrthoLin = capsule.readFloat("restitutionOrthoLin", 0f); - - float softnessDirAng = capsule.readFloat("softnessDirAng", 0f); - float softnessDirLin = capsule.readFloat("softnessDirLin", 0f); - float softnessLimAng = capsule.readFloat("softnessLimAng", 0f); - float softnessLimLin = capsule.readFloat("softnessLimLin", 0f); - float softnessOrthoAng = capsule.readFloat("softnessOrthoAng", 0f); - float softnessOrthoLin = capsule.readFloat("softnessOrthoLin", 0f); - - float targetAngMotorVelicoty = capsule.readFloat("targetAngMotorVelicoty", 0f); - float targetLinMotorVelicoty = capsule.readFloat("targetLinMotorVelicoty", 0f); - - float upperAngLimit = capsule.readFloat("upperAngLimit", 0f); - float upperLinLimit = capsule.readFloat("upperLinLimit", 0f); - - useLinearReferenceFrameA = capsule.readBoolean("useLinearReferenceFrameA", false); - - createJoint(); - - setDampingDirAng(dampingDirAng); - setDampingDirLin(dampingDirLin); - setDampingLimAng(dampingLimAng); - setDampingLimLin(dampingLimLin); - setDampingOrthoAng(dampingOrthoAng); - setDampingOrthoLin(dampingOrthoLin); - setLowerAngLimit(lowerAngLimit); - setLowerLinLimit(lowerLinLimit); - setMaxAngMotorForce(maxAngMotorForce); - setMaxLinMotorForce(maxLinMotorForce); - setPoweredAngMotor(poweredAngMotor); - setPoweredLinMotor(poweredLinMotor); - setRestitutionDirAng(restitutionDirAng); - setRestitutionDirLin(restitutionDirLin); - setRestitutionLimAng(restitutionLimAng); - setRestitutionLimLin(restitutionLimLin); - setRestitutionOrthoAng(restitutionOrthoAng); - setRestitutionOrthoLin(restitutionOrthoLin); - - setSoftnessDirAng(softnessDirAng); - setSoftnessDirLin(softnessDirLin); - setSoftnessLimAng(softnessLimAng); - setSoftnessLimLin(softnessLimLin); - setSoftnessOrthoAng(softnessOrthoAng); - setSoftnessOrthoLin(softnessOrthoLin); - - setTargetAngMotorVelocity(targetAngMotorVelicoty); - setTargetLinMotorVelocity(targetLinMotorVelicoty); - - setUpperAngLimit(upperAngLimit); - setUpperLinLimit(upperLinLimit); - } - - /** - * Instantiate the configured constraint in Bullet. - */ - protected void createJoint() { - objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); - // = new SliderConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); - } - - private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/RotationalLimitMotor.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/RotationalLimitMotor.java deleted file mode 100644 index 88db32aba6..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/RotationalLimitMotor.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints.motors; - -/** - * A motor based on Bullet's btRotationalLimitMotor. Motors are used to drive - * joints. - * - * @author normenhansen - */ -public class RotationalLimitMotor { - - /** - * Unique identifier of the btRotationalLimitMotor. The constructor sets - * this to a non-zero value. - */ - private long motorId = 0; - - /** - * Instantiate a motor for the identified btRotationalLimitMotor. - * - * @param motor the unique identifier (not zero) - */ - public RotationalLimitMotor(long motor) { - this.motorId = motor; - } - - /** - * Read the id of the btRotationalLimitMotor. - * - * @return the identifier of the btRotationalLimitMotor (not zero) - */ - public long getMotor() { - return motorId; - } - - /** - * Read this motor's constraint lower limit. - * - * @return the limit value - */ - public float getLoLimit() { - return getLoLimit(motorId); - } - - private native float getLoLimit(long motorId); - - /** - * Alter this motor's constraint lower limit. - * - * @param loLimit the desired limit value - */ - public void setLoLimit(float loLimit) { - setLoLimit(motorId, loLimit); - } - - private native void setLoLimit(long motorId, float loLimit); - - /** - * Read this motor's constraint upper limit. - * - * @return the limit value - */ - public float getHiLimit() { - return getHiLimit(motorId); - } - - private native float getHiLimit(long motorId); - - /** - * Alter this motor's constraint upper limit. - * - * @param hiLimit the desired limit value - */ - public void setHiLimit(float hiLimit) { - setHiLimit(motorId, hiLimit); - } - - private native void setHiLimit(long motorId, float hiLimit); - - /** - * Read this motor's target velocity. - * - * @return the target velocity (in radians per second) - */ - public float getTargetVelocity() { - return getTargetVelocity(motorId); - } - - private native float getTargetVelocity(long motorId); - - /** - * Alter this motor's target velocity. - * - * @param targetVelocity the desired target velocity (in radians per second) - */ - public void setTargetVelocity(float targetVelocity) { - setTargetVelocity(motorId, targetVelocity); - } - - private native void setTargetVelocity(long motorId, float targetVelocity); - - /** - * Read this motor's maximum force. - * - * @return the maximum force - */ - public float getMaxMotorForce() { - return getMaxMotorForce(motorId); - } - - private native float getMaxMotorForce(long motorId); - - /** - * Alter this motor's maximum force. - * - * @param maxMotorForce the desired maximum force on the motor - */ - public void setMaxMotorForce(float maxMotorForce) { - setMaxMotorForce(motorId, maxMotorForce); - } - - private native void setMaxMotorForce(long motorId, float maxMotorForce); - - /** - * Read the limit's maximum force. - * - * @return the maximum force on the limit - */ - public float getMaxLimitForce() { - return getMaxLimitForce(motorId); - } - - private native float getMaxLimitForce(long motorId); - - /** - * Alter the limit's maximum force. - * - * @param maxLimitForce the desired maximum force on the limit - */ - public void setMaxLimitForce(float maxLimitForce) { - setMaxLimitForce(motorId, maxLimitForce); - } - - private native void setMaxLimitForce(long motorId, float maxLimitForce); - - /** - * Read this motor's damping. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDamping() { - return getDamping(motorId); - } - - private native float getDamping(long motorId); - - /** - * Alter this motor's damping. - * - * @param damping the desired viscous damping ratio (0→no damping, - * 1→critically damped, default=1) - */ - public void setDamping(float damping) { - setDamping(motorId, damping); - } - - private native void setDamping(long motorId, float damping); - - /** - * Read this motor's limit softness. - * - * @return the limit softness - */ - public float getLimitSoftness() { - return getLimitSoftness(motorId); - } - - private native float getLimitSoftness(long motorId); - - /** - * Alter this motor's limit softness. - * - * @param limitSoftness the desired limit softness - */ - public void setLimitSoftness(float limitSoftness) { - setLimitSoftness(motorId, limitSoftness); - } - - private native void setLimitSoftness(long motorId, float limitSoftness); - - /** - * Read this motor's error tolerance at limits. - * - * @return the error tolerance (>0) - */ - public float getERP() { - return getERP(motorId); - } - - private native float getERP(long motorId); - - /** - * Alter this motor's error tolerance at limits. - * - * @param ERP the desired error tolerance (>0) - */ - public void setERP(float ERP) { - setERP(motorId, ERP); - } - - private native void setERP(long motorId, float ERP); - - /** - * Read this motor's bounce. - * - * @return the bounce (restitution factor) - */ - public float getBounce() { - return getBounce(motorId); - } - - private native float getBounce(long motorId); - - /** - * Alter this motor's bounce. - * - * @param bounce the desired bounce (restitution factor) - */ - public void setBounce(float bounce) { - setBounce(motorId, bounce); - } - - private native void setBounce(long motorId, float limitSoftness); - - /** - * Test whether this motor is enabled. - * - * @return true if enabled, otherwise false - */ - public boolean isEnableMotor() { - return isEnableMotor(motorId); - } - - private native boolean isEnableMotor(long motorId); - - /** - * Enable or disable this motor. - * - * @param enableMotor true→enable, false→disable - */ - public void setEnableMotor(boolean enableMotor) { - setEnableMotor(motorId, enableMotor); - } - - private native void setEnableMotor(long motorId, boolean enableMotor); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java deleted file mode 100644 index 4fbf0cb896..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.joints.motors; - -import com.jme3.math.Vector3f; - -/** - * A motor based on Bullet's btTranslationalLimitMotor. Motors are used to drive - * joints. - * - * @author normenhansen - */ -public class TranslationalLimitMotor { - - /** - * Unique identifier of the btTranslationalLimitMotor. The constructor sets - * this to a non-zero value. After that, the id never changes. - */ - private long motorId = 0; - - /** - * Instantiate a motor for the identified btTranslationalLimitMotor. - * - * @param motor the unique identifier (not zero) - */ - public TranslationalLimitMotor(long motor) { - this.motorId = motor; - } - - /** - * Read the id of the btTranslationalLimitMotor. - * - * @return the unique identifier (not zero) - */ - public long getMotor() { - return motorId; - } - - /** - * Copy this motor's constraint lower limits. - * - * @return a new vector (not null) - */ - public Vector3f getLowerLimit() { - Vector3f vec = new Vector3f(); - getLowerLimit(motorId, vec); - return vec; - } - - private native void getLowerLimit(long motorId, Vector3f vector); - - /** - * Alter the constraint lower limits. - * - * @param lowerLimit (unaffected, not null) - */ - public void setLowerLimit(Vector3f lowerLimit) { - setLowerLimit(motorId, lowerLimit); - } - - private native void setLowerLimit(long motorId, Vector3f vector); - - /** - * Copy this motor's constraint upper limits. - * - * @return a new vector (not null) - */ - public Vector3f getUpperLimit() { - Vector3f vec = new Vector3f(); - getUpperLimit(motorId, vec); - return vec; - } - - private native void getUpperLimit(long motorId, Vector3f vector); - - /** - * Alter the constraint upper limits. - * - * @param upperLimit (unaffected, not null) - */ - public void setUpperLimit(Vector3f upperLimit) { - setUpperLimit(motorId, upperLimit); - } - - private native void setUpperLimit(long motorId, Vector3f vector); - - /** - * Copy the accumulated impulse. - * - * @return a new vector (not null) - */ - public Vector3f getAccumulatedImpulse() { - Vector3f vec = new Vector3f(); - getAccumulatedImpulse(motorId, vec); - return vec; - } - - private native void getAccumulatedImpulse(long motorId, Vector3f vector); - - /** - * Alter the accumulated impulse. - * - * @param accumulatedImpulse the desired vector (not null, unaffected) - */ - public void setAccumulatedImpulse(Vector3f accumulatedImpulse) { - setAccumulatedImpulse(motorId, accumulatedImpulse); - } - - private native void setAccumulatedImpulse(long motorId, Vector3f vector); - - /** - * Read this motor's limit softness. - * - * @return the softness - */ - public float getLimitSoftness() { - return getLimitSoftness(motorId); - } - - private native float getLimitSoftness(long motorId); - - /** - * Alter the limit softness. - * - * @param limitSoftness the desired limit softness (default=0.5) - */ - public void setLimitSoftness(float limitSoftness) { - setLimitSoftness(motorId, limitSoftness); - } - - private native void setLimitSoftness(long motorId, float limitSoftness); - - /** - * Read this motor's damping. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getDamping() { - return getDamping(motorId); - } - - private native float getDamping(long motorId); - - /** - * Alter this motor's damping. - * - * @param damping the desired viscous damping ratio (0→no damping, - * 1→critically damped, default=1) - */ - public void setDamping(float damping) { - setDamping(motorId, damping); - } - - private native void setDamping(long motorId, float damping); - - /** - * Read this motor's restitution. - * - * @return the restitution (bounce) factor - */ - public float getRestitution() { - return getRestitution(motorId); - } - - private native float getRestitution(long motorId); - - /** - * Alter this motor's restitution. - * - * @param restitution the desired restitution (bounce) factor - */ - public void setRestitution(float restitution) { - setRestitution(motorId, restitution); - } - - private native void setRestitution(long motorId, float restitution); - - /** - * Enable or disable the indexed axis. - * - * @param axisIndex which axis: 0→X, 1→Y, 2→Z - * @param enableMotor true→enable, false→disable (default=false) - */ - public void setEnabled(int axisIndex, boolean enableMotor) { - setEnabled(motorId, axisIndex, enableMotor); - } - - native private void setEnabled(long motorId, int axisIndex, - boolean enableMotor); - - /** - * Test whether the indexed axis is enabled. - * - * @param axisIndex which axis: 0→X, 1→Y, 2→Z - * @return true if enabled, otherwise false - */ - public boolean isEnabled(int axisIndex) { - boolean result = isEnabled(motorId, axisIndex); - return result; - } - - native private boolean isEnabled(long motorId, int axisIndex); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java deleted file mode 100644 index 0dda1b636c..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java +++ /dev/null @@ -1,711 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects; - -import com.jme3.bullet.collision.CollisionFlag; -import com.jme3.bullet.collision.PhysicsCollisionObject; -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A collision object for simplified character simulation, based on Bullet's - * btKinematicCharacterController. - * - * @author normenhansen - */ -public class PhysicsCharacter extends PhysicsCollisionObject { - /** - * Unique identifier of btKinematicCharacterController (as opposed to its - * collision object, which is a ghost). Constructors are responsible for - * setting this to a non-zero value. The id might change if the character - * gets rebuilt. - */ - protected long characterId = 0; - protected float stepHeight; - protected Vector3f walkDirection = new Vector3f(); - protected float fallSpeed = 55.0f; - protected float jumpSpeed = 10.0f; - protected int upAxis = 1; - protected boolean locationDirty = false; - //TEMP VARIABLES - protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected PhysicsCharacter() { - } - - /** - * Instantiate a character with the specified collision shape and step - * height. - * - * @param shape the desired shape (not null, alias created) - * @param stepHeight the quantization size for vertical movement - */ - public PhysicsCharacter(CollisionShape shape, float stepHeight) { - this.collisionShape = shape; -// if (shape instanceof MeshCollisionShape || shape instanceof CompoundCollisionShape) { -// throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh or compound collision shapes")); -// } - this.stepHeight = stepHeight; - buildObject(); - /* - * The default gravity for a Bullet btKinematicCharacterController - * is (0,0,-29.4), which makes no sense for JME. - * So override the default. - */ - setGravity(new Vector3f(0f, -29.4f, 0f)); - } - - /** - * Create the configured character in Bullet. - */ - protected void buildObject() { - if (objectId == 0) { - objectId = createGhostObject(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Creating GhostObject {0}", Long.toHexString(objectId)); - initUserPointer(); - } - setCharacterFlags(objectId); - attachCollisionShape(objectId, collisionShape.getObjectId()); - if (characterId != 0) { - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Clearing Character {0}", Long.toHexString(objectId)); - finalizeNativeCharacter(characterId); - } - characterId = createCharacterObject(objectId, collisionShape.getObjectId(), stepHeight); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Creating Character {0}", Long.toHexString(characterId)); - } - - private native long createGhostObject(); - - private native void setCharacterFlags(long objectId); - - private native long createCharacterObject(long objectId, long shapeId, float stepHeight); - - /** - * Directly alter the location of this character's center of mass. - * - * @param location the desired physics location (not null, unaffected) - */ - public void warp(Vector3f location) { - warp(characterId, location); - } - - private native void warp(long characterId, Vector3f location); - - /** - * Alter the walk offset. The offset will continue to be applied until - * altered again. - * - * @param vec the desired position increment for each physics tick (not - * null, unaffected) - */ - public void setWalkDirection(Vector3f vec) { - walkDirection.set(vec); - setWalkDirection(characterId, vec); - } - - private native void setWalkDirection(long characterId, Vector3f vec); - - /** - * Access the walk offset. - * - * @return the pre-existing instance - */ - public Vector3f getWalkDirection() { - return walkDirection; - } - - /** - * @deprecated Deprecated in bullet 2.86.1 use setUp(Vector3f) instead - * @param axis which axis: 0→X, 1→Y, 2→Z - */ - @Deprecated - public void setUpAxis(int axis) { - switch (axis) { - case 0: - setUp(Vector3f.UNIT_X); - break; - case 1: - setUp(Vector3f.UNIT_Y); - break; - case 2: - setUp(Vector3f.UNIT_Z); - break; - default: - throw new IllegalArgumentException("Invalid axis, not in range [0, 2]"); - } - } - - /** - * Alter this character's "up" direction. - * - * @param axis the desired direction (not null, not zero, unaffected) - */ - public void setUp(Vector3f axis) { - setUp(characterId, axis); - } - - private native void setUp(long characterId, Vector3f axis); - - /** - * Alter this character's angular velocity. - * - * @param v the desired angular velocity vector (not null, unaffected) - */ - - public void setAngularVelocity(Vector3f v){ - setAngularVelocity(characterId,v); - } - - private native void setAngularVelocity(long characterId, Vector3f v); - - /** - * Copy this character's angular velocity. - * - * @param out storage for the result (modified if not null) - * @return the velocity vector (either the provided storage or a new vector, - * not null) - */ - public Vector3f getAngularVelocity(Vector3f out){ - if(out==null)out=new Vector3f(); - getAngularVelocity(characterId,out); - return out; - } - - private native void getAngularVelocity(long characterId, Vector3f out); - - - /** - * Alter the linear velocity of this character's center of mass. - * - * @param v the desired velocity vector (not null) - */ - public void setLinearVelocity(Vector3f v){ - setLinearVelocity(characterId,v); - } - - private native void setLinearVelocity(long characterId, Vector3f v); - - /** - * Copy the linear velocity of this character's center of mass. - * - * @param out storage for the result (modified if not null) - * @return a vector (either the provided storage or a new vector, not null) - */ - public Vector3f getLinearVelocity(Vector3f out){ - if(out==null)out=new Vector3f(); - getLinearVelocity(characterId,out); - return out; - } - - private native void getLinearVelocity(long characterId, Vector3f out); - - - /** - * Read the index of the "up" axis. - * - * @return which axis: 0→X, 1→Y, 2→Z - */ - public int getUpAxis() { - return upAxis; - } - - /** - * Alter this character's fall speed. - * - * @param fallSpeed the desired speed (default=55) - */ - public void setFallSpeed(float fallSpeed) { - this.fallSpeed = fallSpeed; - setFallSpeed(characterId, fallSpeed); - } - - private native void setFallSpeed(long characterId, float fallSpeed); - - /** - * Read this character's fall speed. - * - * @return speed - */ - public float getFallSpeed() { - return fallSpeed; - } - - /** - * Alter this character's jump speed. - * - * @param jumpSpeed the desired speed (default=10) - */ - public void setJumpSpeed(float jumpSpeed) { - this.jumpSpeed = jumpSpeed; - setJumpSpeed(characterId, jumpSpeed); - } - - private native void setJumpSpeed(long characterId, float jumpSpeed); - - /** - * Read this character's jump speed. - * - * @return speed - */ - public float getJumpSpeed() { - return jumpSpeed; - } - - /** - * @deprecated Deprecated in bullet 2.86.1. Use setGravity(Vector3f) - * instead. - * @param value the desired downward (-Y) component of the acceleration - * (typically positive) - */ - @Deprecated - public void setGravity(float value) { - setGravity(new Vector3f(0, -value, 0)); - } - - /** - * Alter this character's gravitational acceleration. - * - * @param value the desired acceleration vector (not null, unaffected) - */ - public void setGravity(Vector3f value) { - setGravity(characterId, value); - } - - private native void setGravity(long characterId, Vector3f gravity); - - /** - * @deprecated Deprecated in bullet 2.86.1. Use getGravity(Vector3f) - * instead. - * @return the downward (-Y) component of the acceleration (typically - * positive) - */ - @Deprecated - public float getGravity() { - return -getGravity(null).y; - } - - /** - * Copy this character's gravitational acceleration. - * - * @param out storage for the result (modified if not null) - * @return the acceleration vector (either the provided storage or a new - * vector, not null) - */ - public Vector3f getGravity(Vector3f out) { - if(out==null)out=new Vector3f(); - getGravity(characterId,out); - return out; - } - - private native void getGravity(long characterId,Vector3f out); - - - /** - * Read this character's linear damping. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getLinearDamping(){ - return getLinearDamping(characterId); - } - - private native float getLinearDamping(long characterId); - - /** - * Alter this character's linear damping. - * - * @param v the desired viscous damping ratio (0→no damping, - * 1→critically damped) - */ - - public void setLinearDamping(float v ){ - setLinearDamping(characterId,v ); - } - - private native void setLinearDamping(long characterId,float v); - - - /** - * Read this character's angular damping. - * - * @return the viscous damping ratio (0→no damping, 1→critically - * damped) - */ - public float getAngularDamping(){ - return getAngularDamping(characterId); - } - - private native float getAngularDamping(long characterId); - - /** - * Alter this character's angular damping. - * - * @param v the desired viscous damping ratio (0→no damping, - * 1→critically damped, default=0) - */ - public void setAngularDamping(float v ){ - setAngularDamping(characterId,v ); - } - - private native void setAngularDamping(long characterId,float v); - - - /** - * Read this character's step height. - * - * @return the height (in physics-space units) - */ - public float getStepHeight(){ - return getStepHeight(characterId); - } - - private native float getStepHeight(long characterId); - - /** - * Alter this character's step height. - * - * @param v the desired height (in physics-space units) - */ - public void setStepHeight(float v ){ - setStepHeight(characterId,v ); - } - - private native void setStepHeight(long characterId,float v); - - - /** - * Read this character's maximum penetration depth. - * - * @return the depth (in physics-space units) - */ - public float getMaxPenetrationDepth(){ - return getMaxPenetrationDepth(characterId); - } - - private native float getMaxPenetrationDepth(long characterId); - - /** - * Alter this character's maximum penetration depth. - * - * @param v the desired depth (in physics-space units) - */ - public void setMaxPenetrationDepth(float v ){ - setMaxPenetrationDepth(characterId,v ); - } - - private native void setMaxPenetrationDepth(long characterId,float v); - - - - - - /** - * Alter this character's maximum slope angle. - * - * @param slopeRadians the desired angle (in radians) - */ - public void setMaxSlope(float slopeRadians) { - setMaxSlope(characterId, slopeRadians); - } - - private native void setMaxSlope(long characterId, float slopeRadians); - - /** - * Read this character's maximum slope angle. - * - * @return the angle (in radians) - */ - public float getMaxSlope() { - return getMaxSlope(characterId); - } - - private native float getMaxSlope(long characterId); - - /** - * Enable/disable this character's contact response. - * - * @param responsive true to respond to contacts, false to ignore them - * (default=true) - */ - public void setContactResponse(boolean responsive) { - int flags = getCollisionFlags(objectId); - if (responsive) { - flags &= ~CollisionFlag.NO_CONTACT_RESPONSE; - } else { - flags |= CollisionFlag.NO_CONTACT_RESPONSE; - } - setCollisionFlags(objectId, flags); - } - - /** - * Test whether this character is on the ground. - * - * @return true if on the ground, otherwise false - */ - public boolean onGround() { - return onGround(characterId); - } - - private native boolean onGround(long characterId); - - /** - * @deprecated Deprecated in bullet 2.86.1. Use jump(Vector3f) instead. - */ - @Deprecated - public void jump() { - jump(Vector3f.ZERO); - /* - * The zero vector is treated as a special case - * by Bullet's btKinematicCharacterController::jump(), - * causing the character to jump in its "up" direction - * with the pre-set speed. - */ - } - - /** - * Jump in the specified direction. - * - * @param dir desired jump direction (not null, unaffected) - */ - public void jump(Vector3f dir) { - jump(characterId,dir); - } - - private native void jump(long characterId,Vector3f v); - - /** - * Apply the specified CollisionShape to this character. Note that the - * character should not be in any physics space while changing shape; the - * character gets rebuilt on the physics side. - * - * @param collisionShape the shape to apply (not null, alias created) - */ - @Override - public void setCollisionShape(CollisionShape collisionShape) { -// if (!(collisionShape.getObjectId() instanceof ConvexShape)) { -// throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); -// } - super.setCollisionShape(collisionShape); - if (objectId == 0) { - buildObject(); - } else { - attachCollisionShape(objectId, collisionShape.getObjectId()); - } - } - - /** - * Directly alter this character's location. (Same as - * {@link #warp(com.jme3.math.Vector3f)}).) - * - * @param location the desired location (not null, unaffected) - */ - public void setPhysicsLocation(Vector3f location) { - warp(location); - } - - /** - * Copy the location of this character's center of mass. - * - * @param trans storage for the result (modified if not null) - * @return the location vector (either the provided storage or a new vector, - * not null) - */ - public Vector3f getPhysicsLocation(Vector3f trans) { - if (trans == null) { - trans = new Vector3f(); - } - getPhysicsLocation(objectId, trans); - return trans; - } - - private native void getPhysicsLocation(long objectId, Vector3f vec); - - /** - * Copy the location of this character's center of mass. - * - * @return a new location vector (not null) - */ - public Vector3f getPhysicsLocation() { - return getPhysicsLocation(null); - } - - /** - * Alter this character's continuous collision detection (CCD) swept sphere - * radius. - * - * @param radius (≥0, default=0) - */ - public void setCcdSweptSphereRadius(float radius) { - setCcdSweptSphereRadius(objectId, radius); - } - - private native void setCcdSweptSphereRadius(long objectId, float radius); - - /** - * Alter the amount of motion required to activate continuous collision - * detection (CCD). - *

- * This addresses the issue of fast objects passing through other objects - * with no collision detected. - * - * @param threshold the desired threshold velocity (>0) or zero to - * disable CCD (default=0) - */ - public void setCcdMotionThreshold(float threshold) { - setCcdMotionThreshold(objectId, threshold); - } - - private native void setCcdMotionThreshold(long objectId, float threshold); - - /** - * Read the radius of the sphere used for continuous collision detection - * (CCD). - * - * @return radius (≥0) - */ - public float getCcdSweptSphereRadius() { - return getCcdSweptSphereRadius(objectId); - } - - private native float getCcdSweptSphereRadius(long objectId); - - /** - * Calculate this character's continuous collision detection (CCD) motion - * threshold. - * - * @return the threshold velocity (≥0) - */ - public float getCcdMotionThreshold() { - return getCcdMotionThreshold(objectId); - } - - private native float getCcdMotionThreshold(long objectId); - - /** - * Calculate the square of this character's continuous collision detection - * (CCD) motion threshold. - * - * @return the threshold velocity squared (≥0) - */ - public float getCcdSquareMotionThreshold() { - return getCcdSquareMotionThreshold(objectId); - } - - private native float getCcdSquareMotionThreshold(long objectId); - - /** - * used internally - * - * @return the Bullet id - */ - public long getControllerId() { - return characterId; - } - - /** - * Has no effect. - */ - public void destroy() { - } - - /** - * Serialize this character, for example when saving to a J3O file. - * - * @param e exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter e) throws IOException { - super.write(e); - OutputCapsule capsule = e.getCapsule(this); - capsule.write(stepHeight, "stepHeight", 1.0f); - capsule.write(getGravity(), "gravity", 9.8f * 3); - capsule.write(getMaxSlope(), "maxSlope", 1.0f); - capsule.write(fallSpeed, "fallSpeed", 55.0f); - capsule.write(jumpSpeed, "jumpSpeed", 10.0f); - capsule.write(upAxis, "upAxis", 1); - capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); - capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); - capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - } - - /** - * De-serialize this character from the specified importer, for example when - * loading from a J3O file. - * - * @param e importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter e) throws IOException { - super.read(e); - InputCapsule capsule = e.getCapsule(this); - stepHeight = capsule.readFloat("stepHeight", 1.0f); - buildObject(); - setGravity(capsule.readFloat("gravity", 9.8f * 3)); - setMaxSlope(capsule.readFloat("maxSlope", 1.0f)); - setFallSpeed(capsule.readFloat("fallSpeed", 55.0f)); - setJumpSpeed(capsule.readFloat("jumpSpeed", 10.0f)); - setUpAxis(capsule.readInt("upAxis", 1)); - setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); - setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); - setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - } - - /** - * Finalize this physics character just before it is destroyed. Should be - * invoked only by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - finalizeNativeCharacter(characterId); - } - - private native void finalizeNativeCharacter(long characterId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java deleted file mode 100644 index f3efc7366d..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects; - -import com.jme3.bullet.collision.PhysicsCollisionObject; -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; -import com.jme3.scene.Spatial; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A collision object for intangibles, based on Bullet's - * btPairCachingGhostObject. This is useful for creating a character controller, - * collision sensors/triggers, explosions etc. - *

- * From Bullet manual:
- * btGhostObject is a special btCollisionObject, useful for fast localized - * collision queries. - * - * @author normenhansen - */ -public class PhysicsGhostObject extends PhysicsCollisionObject { - - protected boolean locationDirty = false; - protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); - private List overlappingObjects = new LinkedList(); - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected PhysicsGhostObject() { - } - - /** - * Instantiate an object with the specified collision shape. - * - * @param shape the desired shape (not null, alias created) - */ - public PhysicsGhostObject(CollisionShape shape) { - collisionShape = shape; - buildObject(); - } - - public PhysicsGhostObject(Spatial child, CollisionShape shape) { - collisionShape = shape; - buildObject(); - } - - /** - * Create the configured object in Bullet. - */ - protected void buildObject() { - if (objectId == 0) { -// gObject = new PairCachingGhostObject(); - objectId = createGhostObject(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Ghost Object {0}", Long.toHexString(objectId)); - setGhostFlags(objectId); - initUserPointer(); - } -// if (gObject == null) { -// gObject = new PairCachingGhostObject(); -// gObject.setCollisionFlags(gObject.getCollisionFlags() | CollisionFlags.NO_CONTACT_RESPONSE); -// } - attachCollisionShape(objectId, collisionShape.getObjectId()); - } - - private native long createGhostObject(); - - private native void setGhostFlags(long objectId); - - /** - * Apply the specified CollisionShape to this object. Note that the object - * should not be in any physics space while changing shape; the object gets - * rebuilt on the physics side. - * - * @param collisionShape the shape to apply (not null, alias created) - */ - @Override - public void setCollisionShape(CollisionShape collisionShape) { - super.setCollisionShape(collisionShape); - if (objectId == 0) { - buildObject(); - } else { - attachCollisionShape(objectId, collisionShape.getObjectId()); - } - } - - /** - * Directly alter the location of this object's center. - * - * @param location the desired location (in physics-space coordinates, not - * null, unaffected) - */ - public void setPhysicsLocation(Vector3f location) { - setPhysicsLocation(objectId, location); - } - - private native void setPhysicsLocation(long objectId, Vector3f location); - - /** - * Directly alter this object's orientation. - * - * @param rotation the desired orientation (a rotation matrix in - * physics-space coordinates, not null, unaffected) - */ - public void setPhysicsRotation(Matrix3f rotation) { - setPhysicsRotation(objectId, rotation); - } - - private native void setPhysicsRotation(long objectId, Matrix3f rotation); - - /** - * Directly alter this object's orientation. - * - * @param rotation the desired orientation (quaternion, not null, - * unaffected) - */ - public void setPhysicsRotation(Quaternion rotation) { - setPhysicsRotation(objectId, rotation); - } - - private native void setPhysicsRotation(long objectId, Quaternion rotation); - - /** - * Copy the location of this object's center. - * - * @param trans storage for the result (modified if not null) - * @return a location vector (in physics-space coordinates, either - * the provided storage or a new vector, not null) - */ - public Vector3f getPhysicsLocation(Vector3f trans) { - if (trans == null) { - trans = new Vector3f(); - } - getPhysicsLocation(objectId, trans); - return trans; - } - - private native void getPhysicsLocation(long objectId, Vector3f vector); - - /** - * Copy this object's orientation to a quaternion. - * - * @param rot storage for the result (modified if not null) - * @return an orientation (in physics-space coordinates, either the provided - * storage or a new quaternion, not null) - */ - public Quaternion getPhysicsRotation(Quaternion rot) { - if (rot == null) { - rot = new Quaternion(); - } - getPhysicsRotation(objectId, rot); - return rot; - } - - private native void getPhysicsRotation(long objectId, Quaternion rot); - - /** - * Copy this object's orientation to a matrix. - * - * @param rot storage for the result (modified if not null) - * @return an orientation (in physics-space coordinates, either the provided - * storage or a new matrix, not null) - */ - public Matrix3f getPhysicsRotationMatrix(Matrix3f rot) { - if (rot == null) { - rot = new Matrix3f(); - } - getPhysicsRotationMatrix(objectId, rot); - return rot; - } - - private native void getPhysicsRotationMatrix(long objectId, Matrix3f rot); - - /** - * Copy the location of this object's center. - * - * @return a new location vector (not null) - */ - public Vector3f getPhysicsLocation() { - Vector3f vec = new Vector3f(); - getPhysicsLocation(objectId, vec); - return vec; - } - - /** - * Copy this object's orientation to a quaternion. - * - * @return a new quaternion (not null) - */ - public Quaternion getPhysicsRotation() { - Quaternion quat = new Quaternion(); - getPhysicsRotation(objectId, quat); - return quat; - } - - /** - * Copy this object's orientation to a matrix. - * - * @return a new matrix (not null) - */ - public Matrix3f getPhysicsRotationMatrix() { - Matrix3f mtx = new Matrix3f(); - getPhysicsRotationMatrix(objectId, mtx); - return mtx; - } - - /** - * used internally - */ -// public PairCachingGhostObject getObjectId() { -// return gObject; -// } - /** - * Has no effect. - */ - public void destroy() { - } - - /** - * Access a list of overlapping objects. - * - * @return an internal list which may get reused (not null) - */ - public List getOverlappingObjects() { - overlappingObjects.clear(); - getOverlappingObjects(objectId); -// for (com.bulletphysics.collision.dispatch.CollisionObject collObj : gObject.getOverlappingPairs()) { -// overlappingObjects.add((PhysicsCollisionObject) collObj.getUserPointer()); -// } - return overlappingObjects; - } - - protected native void getOverlappingObjects(long objectId); - - /** - * This method is invoked from native code. - * - * @param co the collision object to add - */ - private void addOverlappingObject_native(PhysicsCollisionObject co) { - overlappingObjects.add(co); - } - - /** - * Count how many collision objects this object overlaps. - * - * @return count (≥0) - */ - public int getOverlappingCount() { - return getOverlappingCount(objectId); - } - - private native int getOverlappingCount(long objectId); - - /** - * Access an overlapping collision object by its position in the list. - * - * @param index which list position (≥0, <count) - * @return the pre-existing object - */ - public PhysicsCollisionObject getOverlapping(int index) { - return overlappingObjects.get(index); - } - - /** - * Alter the continuous collision detection (CCD) swept sphere radius for - * this object. - * - * @param radius (≥0) - */ - public void setCcdSweptSphereRadius(float radius) { - setCcdSweptSphereRadius(objectId, radius); - } - - private native void setCcdSweptSphereRadius(long objectId, float radius); - - /** - * Alter the amount of motion required to trigger continuous collision - * detection (CCD). - *

- * This addresses the issue of fast objects passing through other objects - * with no collision detected. - * - * @param threshold the desired threshold value (squared velocity, >0) or - * zero to disable CCD (default=0) - */ - public void setCcdMotionThreshold(float threshold) { - setCcdMotionThreshold(objectId, threshold); - } - - private native void setCcdMotionThreshold(long objectId, float threshold); - - /** - * Read the radius of the sphere used for continuous collision detection - * (CCD). - * - * @return radius (≥0) - */ - public float getCcdSweptSphereRadius() { - return getCcdSweptSphereRadius(objectId); - } - - private native float getCcdSweptSphereRadius(long objectId); - - /** - * Read the continuous collision detection (CCD) motion threshold for this - * object. - * - * @return threshold value (squared velocity, ≥0) - */ - public float getCcdMotionThreshold() { - return getCcdMotionThreshold(objectId); - } - - private native float getCcdMotionThreshold(long objectId); - - /** - * Read the CCD square motion threshold for this object. - * - * @return threshold value (≥0) - */ - public float getCcdSquareMotionThreshold() { - return getCcdSquareMotionThreshold(objectId); - } - - private native float getCcdSquareMotionThreshold(long objectId); - - /** - * Serialize this object, for example when saving to a J3O file. - * - * @param e exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter e) throws IOException { - super.write(e); - OutputCapsule capsule = e.getCapsule(this); - capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); - capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); - capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); - } - - /** - * De-serialize this object from the specified importer, for example when - * loading from a J3O file. - * - * @param e importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter e) throws IOException { - super.read(e); - InputCapsule capsule = e.getCapsule(this); - buildObject(); - setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - setPhysicsRotation(((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()))); - setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); - setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java deleted file mode 100644 index 88acc608c6..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ /dev/null @@ -1,1081 +0,0 @@ -/* - * Copyright (c) 2009-2020 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects; - -import com.jme3.bullet.PhysicsSpace; -import com.jme3.bullet.collision.CollisionFlag; -import com.jme3.bullet.collision.PhysicsCollisionObject; -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.bullet.collision.shapes.MeshCollisionShape; -import com.jme3.bullet.joints.PhysicsJoint; -import com.jme3.bullet.objects.infos.RigidBodyMotionState; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A collision object for a rigid body, based on Bullet's btRigidBody. - * - * @author normenhansen - */ -public class PhysicsRigidBody extends PhysicsCollisionObject { - /** - * motion state - */ - protected RigidBodyMotionState motionState = new RigidBodyMotionState(); - /** - * copy of mass (>0) of a dynamic body, or 0 for a static body - * (default=1) - */ - protected float mass = 1.0f; - /** - * copy of kinematic flag: true→set kinematic mode (spatial controls - * body), false→dynamic/static mode (body controls spatial) - * (default=false) - */ - protected boolean kinematic = false; - /** - * joint list - */ - protected ArrayList joints = new ArrayList(4); - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected PhysicsRigidBody() { - } - - /** - * Instantiate a dynamic body with mass=1 and the specified collision shape. - * - * @param shape the desired shape (not null, alias created) - */ - public PhysicsRigidBody(CollisionShape shape) { - collisionShape = shape; - rebuildRigidBody(); - } - - /** - * Instantiate a body with the specified collision shape and mass. - * - * @param shape the desired shape (not null, alias created) - * @param mass if 0, a static body is created; otherwise a dynamic body is - * created (≥0) - */ - public PhysicsRigidBody(CollisionShape shape, float mass) { - collisionShape = shape; - this.mass = mass; - rebuildRigidBody(); - } - - /** - * Build/rebuild this body after parameters have changed. - */ - protected void rebuildRigidBody() { - boolean removed = false; - if (collisionShape instanceof MeshCollisionShape && mass != 0) { - throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); - } - if (objectId != 0) { - if (isInWorld(objectId)) { - PhysicsSpace.getPhysicsSpace().remove(this); - removed = true; - } - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Clearing RigidBody {0}", Long.toHexString(objectId)); - finalizeNative(objectId); - } - preRebuild(); - objectId = createRigidBody(mass, motionState.getObjectId(), collisionShape.getObjectId()); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created RigidBody {0}", Long.toHexString(objectId)); - postRebuild(); - if (removed) { - PhysicsSpace.getPhysicsSpace().add(this); - } - } - - /** - * For use by subclasses. - */ - protected void preRebuild() { - } - - private native long createRigidBody(float mass, long motionStateId, long collisionShapeId); - - /** - * For use by subclasses. - */ - protected void postRebuild() { - if (mass == 0.0f) { - setStatic(objectId, true); - } else { - setStatic(objectId, false); - } - initUserPointer(); - } - - /** - * Access this body's motion state. - * - * @return the pre-existing instance - */ - public RigidBodyMotionState getMotionState() { - return motionState; - } - - /** - * Test whether this body is in a physics space. - * - * @return true→in a space, false→not in a space - */ - public boolean isInWorld() { - return isInWorld(objectId); - } - - private native boolean isInWorld(long objectId); - - /** - * Directly alter the location of this body's center of mass. - * - * @param location the desired location (not null, unaffected) - */ - public void setPhysicsLocation(Vector3f location) { - setPhysicsLocation(objectId, location); - } - - private native void setPhysicsLocation(long objectId, Vector3f location); - - /** - * Directly alter this body's orientation. - * - * @param rotation the desired orientation (rotation matrix, not null, - * unaffected) - */ - public void setPhysicsRotation(Matrix3f rotation) { - setPhysicsRotation(objectId, rotation); - } - - private native void setPhysicsRotation(long objectId, Matrix3f rotation); - - /** - * Directly alter this body's orientation. - * - * @param rotation the desired orientation (quaternion, in physics-space - * coordinates, not null, unaffected) - */ - public void setPhysicsRotation(Quaternion rotation) { - setPhysicsRotation(objectId, rotation); - } - - private native void setPhysicsRotation(long objectId, Quaternion rotation); - - /** - * Copy the location of this body's center of mass. - * - * @param trans storage for the result (modified if not null) - * @return the location (in physics-space coordinates, either the provided - * storage or a new vector, not null) - */ - public Vector3f getPhysicsLocation(Vector3f trans) { - if (trans == null) { - trans = new Vector3f(); - } - getPhysicsLocation(objectId, trans); - return trans; - } - - private native void getPhysicsLocation(long objectId, Vector3f vector); - - /** - * Copy this body's orientation to a quaternion. - * - * @param rot storage for the result (modified if not null) - * @return the orientation (either the provided storage or a new quaternion, - * not null) - */ - public Quaternion getPhysicsRotation(Quaternion rot) { - if (rot == null) { - rot = new Quaternion(); - } - getPhysicsRotation(objectId, rot); - return rot; - } - - /** - * Alter the principal components of the local inertia tensor. - * - * @param gravity (not null, unaffected) - */ - public void setInverseInertiaLocal(Vector3f gravity) { - setInverseInertiaLocal(objectId, gravity); - } - private native void setInverseInertiaLocal(long objectId, Vector3f gravity); - - /** - * Copy the principal components of the local inverse inertia tensor. - * - * @param trans storage for the result (modified if not null) - * @return a vector (either the provided storage or a new vector, not null) - */ - public Vector3f getInverseInertiaLocal(Vector3f trans) { - if (trans == null) { - trans = new Vector3f(); - } - getInverseInertiaLocal(objectId, trans); - return trans; - } - - private native void getInverseInertiaLocal(long objectId, Vector3f vector); - - private native void getPhysicsRotation(long objectId, Quaternion rot); - - /** - * Copy this body's orientation to a matrix. - * - * @param rot storage for the result (modified if not null) - * @return the orientation (in physics-space coordinates, either the - * provided storage or a new matrix, not null) - */ - public Matrix3f getPhysicsRotationMatrix(Matrix3f rot) { - if (rot == null) { - rot = new Matrix3f(); - } - getPhysicsRotationMatrix(objectId, rot); - return rot; - } - - private native void getPhysicsRotationMatrix(long objectId, Matrix3f rot); - - /** - * Copy the location of this body's center of mass. - * - * @return a new location vector (not null) - */ - public Vector3f getPhysicsLocation() { - Vector3f vec = new Vector3f(); - getPhysicsLocation(objectId, vec); - return vec; - } - - /** - * Copy this body's orientation to a quaternion. - * - * @return a new quaternion (not null) - */ - public Quaternion getPhysicsRotation() { - Quaternion quat = new Quaternion(); - getPhysicsRotation(objectId, quat); - return quat; - } - - /** - * Copy this body's orientation to a matrix. - * - * @return a new matrix (not null) - */ - public Matrix3f getPhysicsRotationMatrix() { - Matrix3f mtx = new Matrix3f(); - getPhysicsRotationMatrix(objectId, mtx); - return mtx; - } - -// /** -// * Gets the physics object location -// * @param location the location of the actual physics object is stored in this Vector3f -// */ -// public Vector3f getInterpolatedPhysicsLocation(Vector3f location) { -// if (location == null) { -// location = new Vector3f(); -// } -// rBody.getInterpolationWorldTransform(tempTrans); -// return Converter.convert(tempTrans.origin, location); -// } -// -// /** -// * Gets the physics object rotation -// * @param rotation the rotation of the actual physics object is stored in this Matrix3f -// */ -// public Matrix3f getInterpolatedPhysicsRotation(Matrix3f rotation) { -// if (rotation == null) { -// rotation = new Matrix3f(); -// } -// rBody.getInterpolationWorldTransform(tempTrans); -// return Converter.convert(tempTrans.basis, rotation); -// } - /** - * Put this body into kinematic mode or take it out of kinematic mode. - *

- * In kinematic mode, the body is not influenced by physics but can affect - * other physics objects. Its kinetic force is calculated based on its - * movement and weight. - * - * @param kinematic true→set kinematic mode, false→set - * dynamic/static mode (default=false) - */ - public void setKinematic(boolean kinematic) { - this.kinematic = kinematic; - setKinematic(objectId, kinematic); - } - - private native void setKinematic(long objectId, boolean kinematic); - - /** - * Test whether this body is in kinematic mode. - *

- * In kinematic mode, the body is not influenced by physics but can affect - * other physics objects. Its kinetic force is calculated based on its - * movement and weight. - * - * @return true if in kinematic mode, otherwise false (dynamic/static mode) - */ - public boolean isKinematic() { - return kinematic; - } - - /** - * Enable/disable this body's contact response. - * - * @param responsive true to respond to contacts, false to ignore them - * (default=true) - */ - public void setContactResponse(boolean responsive) { - int flags = getCollisionFlags(objectId); - if (responsive) { - flags &= ~CollisionFlag.NO_CONTACT_RESPONSE; - } else { - flags |= CollisionFlag.NO_CONTACT_RESPONSE; - } - setCollisionFlags(objectId, flags); - } - - /** - * Alter the radius of the swept sphere used for continuous collision - * detection (CCD). - * - * @param radius the desired radius (≥0, default=0) - */ - public void setCcdSweptSphereRadius(float radius) { - setCcdSweptSphereRadius(objectId, radius); - } - - private native void setCcdSweptSphereRadius(long objectId, float radius); - - /** - * Alter the amount of motion required to activate continuous collision - * detection (CCD). - *

- * This addresses the issue of fast objects passing through other objects - * with no collision detected. - * - * @param threshold the desired threshold velocity (>0) or zero to - * disable CCD (default=0) - */ - public void setCcdMotionThreshold(float threshold) { - setCcdMotionThreshold(objectId, threshold); - } - - private native void setCcdMotionThreshold(long objectId, float threshold); - - /** - * Read the radius of the swept sphere used for continuous collision - * detection (CCD). - * - * @return radius (≥0) - */ - public float getCcdSweptSphereRadius() { - return getCcdSweptSphereRadius(objectId); - } - - private native float getCcdSweptSphereRadius(long objectId); - - /** - * Calculate this body's continuous collision detection (CCD) motion - * threshold. - * - * @return the threshold velocity (≥0) - */ - public float getCcdMotionThreshold() { - return getCcdMotionThreshold(objectId); - } - - private native float getCcdMotionThreshold(long objectId); - - /** - * Calculate the square of this body's continuous collision detection (CCD) - * motion threshold. - * - * @return the threshold velocity squared (≥0) - */ - public float getCcdSquareMotionThreshold() { - return getCcdSquareMotionThreshold(objectId); - } - - private native float getCcdSquareMotionThreshold(long objectId); - - /** - * Read this body's mass. - * - * @return the mass (>0) or zero for a static body - */ - public float getMass() { - return mass; - } - - /** - * Alter this body's mass. Bodies with mass=0 are static. For dynamic - * bodies, it is best to keep the mass around 1. - * - * @param mass the desired mass (>0) or 0 for a static body (default=1) - */ - public void setMass(float mass) { - this.mass = mass; - if (collisionShape instanceof MeshCollisionShape && mass != 0) { - throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); - } - if (objectId != 0) { - if (collisionShape != null) { - updateMassProps(objectId, collisionShape.getObjectId(), mass); - } - if (mass == 0.0f) { - setStatic(objectId, true); - } else { - setStatic(objectId, false); - } - } - } - - private native void setStatic(long objectId, boolean state); - - private native long updateMassProps(long objectId, long collisionShapeId, float mass); - - /** - * Copy this body's gravitational acceleration. - * - * @return a new acceleration vector (in physics-space coordinates, not - * null) - */ - public Vector3f getGravity() { - return getGravity(null); - } - - /** - * Copy this body's gravitational acceleration. - * - * @param gravity storage for the result (modified if not null) - * @return an acceleration vector (in physics-space coordinates, either the - * provided storage or a new vector, not null) - */ - public Vector3f getGravity(Vector3f gravity) { - if (gravity == null) { - gravity = new Vector3f(); - } - getGravity(objectId, gravity); - return gravity; - } - - private native void getGravity(long objectId, Vector3f gravity); - - /** - * Alter this body's gravitational acceleration. - *

- * Invoke this after adding the body to a PhysicsSpace. Adding a body to a - * PhysicsSpace alters its gravity. - * - * @param gravity the desired acceleration vector (not null, unaffected) - */ - public void setGravity(Vector3f gravity) { - setGravity(objectId, gravity); - } - private native void setGravity(long objectId, Vector3f gravity); - - /** - * Read this body's friction. - * - * @return friction value - */ - public float getFriction() { - return getFriction(objectId); - } - - private native float getFriction(long objectId); - - /** - * Alter this body's friction. - * - * @param friction the desired friction value (default=0.5) - */ - public void setFriction(float friction) { - setFriction(objectId, friction); - } - - private native void setFriction(long objectId, float friction); - - /** - * Alter this body's damping. - * - * @param linearDamping the desired linear damping value (default=0) - * @param angularDamping the desired angular damping value (default=0) - */ - public void setDamping(float linearDamping, float angularDamping) { - setDamping(objectId, linearDamping, angularDamping); - } - - private native void setDamping(long objectId, float linearDamping, float angularDamping); - -// private native void setRestitution(long objectId, float factor); -// -// public void setLinearDamping(float linearDamping) { -// constructionInfo.linearDamping = linearDamping; -// rBody.setDamping(linearDamping, constructionInfo.angularDamping); -// } -// -// private native void setRestitution(long objectId, float factor); -// - /** - * Alter this body's linear damping. - * - * @param linearDamping the desired linear damping value (default=0) - */ - public void setLinearDamping(float linearDamping) { - setDamping(objectId, linearDamping, getAngularDamping()); - } - - /** - * Alter this body's angular damping. - * - * @param angularDamping the desired angular damping value (default=0) - */ - public void setAngularDamping(float angularDamping) { - setAngularDamping(objectId, angularDamping); - } - private native void setAngularDamping(long objectId, float factor); - - /** - * Read this body's linear damping. - * - * @return damping value - */ - public float getLinearDamping() { - return getLinearDamping(objectId); - } - - private native float getLinearDamping(long objectId); - - /** - * Read this body's angular damping. - * - * @return damping value - */ - public float getAngularDamping() { - return getAngularDamping(objectId); - } - - private native float getAngularDamping(long objectId); - - /** - * Read this body's restitution (bounciness). - * - * @return restitution value - */ - public float getRestitution() { - return getRestitution(objectId); - } - - private native float getRestitution(long objectId); - - /** - * Alter this body's restitution (bounciness). For best performance, set - * restitution=0. - * - * @param restitution the desired value (default=0) - */ - public void setRestitution(float restitution) { - setRestitution(objectId, restitution); - } - - private native void setRestitution(long objectId, float factor); - - /** - * Copy this body's angular velocity. - * - * @return a new velocity vector (in physics-space coordinates, not null) - */ - public Vector3f getAngularVelocity() { - Vector3f vec = new Vector3f(); - getAngularVelocity(objectId, vec); - return vec; - } - - private native void getAngularVelocity(long objectId, Vector3f vec); - - /** - * Copy this body's angular velocity. - * - * @param vec storage for the result (in physics-space coordinates, not - * null, modified) - */ - public void getAngularVelocity(Vector3f vec) { - getAngularVelocity(objectId, vec); - } - - /** - * Alter this body's angular velocity. - * - * @param vec the desired angular velocity vector (not null, unaffected) - */ - public void setAngularVelocity(Vector3f vec) { - setAngularVelocity(objectId, vec); - activate(); - } - - private native void setAngularVelocity(long objectId, Vector3f vec); - - /** - * Copy the linear velocity of this body's center of mass. - * - * @return a new velocity vector (in physics-space coordinates, not null) - */ - public Vector3f getLinearVelocity() { - Vector3f vec = new Vector3f(); - getLinearVelocity(objectId, vec); - return vec; - } - - private native void getLinearVelocity(long objectId, Vector3f vec); - - /** - * Copy the linear velocity of this body's center of mass. - * - * @param vec storage for the result (in physics-space coordinates, not - * null, modified) - */ - public void getLinearVelocity(Vector3f vec) { - getLinearVelocity(objectId, vec); - } - - /** - * Alter the linear velocity of this body's center of mass. - * - * @param vec the desired velocity vector (not null) - */ - public void setLinearVelocity(Vector3f vec) { - setLinearVelocity(objectId, vec); - activate(); - } - - private native void setLinearVelocity(long objectId, Vector3f vec); - - /** - * Apply a force to the PhysicsRigidBody. Effective only if the next physics - * update steps the physics space. - *

- * To apply an impulse, use applyImpulse, use applyContinuousForce to apply - * continuous force. - * - * @param force the force (not null, unaffected) - * @param location the location of the force - */ - public void applyForce(Vector3f force, Vector3f location) { - applyForce(objectId, force, location); - activate(); - } - - private native void applyForce(long objectId, Vector3f force, Vector3f location); - - /** - * Apply a force to the PhysicsRigidBody. Effective only if the next physics - * update steps the physics space. - *

- * To apply an impulse, use - * {@link #applyImpulse(com.jme3.math.Vector3f, com.jme3.math.Vector3f)}. - * - * @param force the force (not null, unaffected) - */ - public void applyCentralForce(Vector3f force) { - applyCentralForce(objectId, force); - activate(); - } - - private native void applyCentralForce(long objectId, Vector3f force); - - /** - * Apply a force to the PhysicsRigidBody. Effective only if the next physics - * update steps the physics space. - *

- * To apply an impulse, use - * {@link #applyImpulse(com.jme3.math.Vector3f, com.jme3.math.Vector3f)}. - * - * @param torque the torque (not null, unaffected) - */ - public void applyTorque(Vector3f torque) { - applyTorque(objectId, torque); - activate(); - } - - private native void applyTorque(long objectId, Vector3f vec); - - /** - * Apply an impulse to the body the next physics update. - * - * @param impulse applied impulse (not null, unaffected) - * @param rel_pos location relative to object (not null, unaffected) - */ - public void applyImpulse(Vector3f impulse, Vector3f rel_pos) { - applyImpulse(objectId, impulse, rel_pos); - activate(); - } - - private native void applyImpulse(long objectId, Vector3f impulse, Vector3f rel_pos); - - /** - * Apply a torque impulse to the body in the next physics update. - * - * @param vec the torque to apply - */ - public void applyTorqueImpulse(Vector3f vec) { - applyTorqueImpulse(objectId, vec); - activate(); - } - - private native void applyTorqueImpulse(long objectId, Vector3f vec); - - /** - * Clear all forces acting on this body. - */ - public void clearForces() { - clearForces(objectId); - } - - private native void clearForces(long objectId); - - /** - * Apply the specified CollisionShape to this body. - *

- * Note that the body should not be in any physics space while changing - * shape; the body gets rebuilt on the physics side. - * - * @param collisionShape the shape to apply (not null, alias created) - */ - @Override - public void setCollisionShape(CollisionShape collisionShape) { - super.setCollisionShape(collisionShape); - if (collisionShape instanceof MeshCollisionShape && mass != 0) { - throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); - } - if (objectId == 0) { - rebuildRigidBody(); - } else { - setCollisionShape(objectId, collisionShape.getObjectId()); - updateMassProps(objectId, collisionShape.getObjectId(), mass); - } - } - - private native void setCollisionShape(long objectId, long collisionShapeId); - - /** - * Reactivates this body if it has been deactivated due to lack of motion. - */ - public void activate() { - activate(objectId); - } - - private native void activate(long objectId); - - /** - * Test whether this body has been deactivated due to lack of motion. - * - * @return true if still active, false if deactivated - */ - public boolean isActive() { - return isActive(objectId); - } - - private native boolean isActive(long objectId); - - /** - * Alter this body's sleeping thresholds. - *

- * These thresholds determine when the body can be deactivated to save - * resources. Low values keep the body active when it barely moves. - * - * @param linear the desired linear sleeping threshold (≥0, default=0.8) - * @param angular the desired angular sleeping threshold (≥0, default=1) - */ - public void setSleepingThresholds(float linear, float angular) { - setSleepingThresholds(objectId, linear, angular); - } - - private native void setSleepingThresholds(long objectId, float linear, float angular); - - /** - * Alter this body's linear sleeping threshold. - * - * @param linearSleepingThreshold the desired threshold (≥0, default=0.8) - */ - public void setLinearSleepingThreshold(float linearSleepingThreshold) { - setLinearSleepingThreshold(objectId, linearSleepingThreshold); - } - - private native void setLinearSleepingThreshold(long objectId, float linearSleepingThreshold); - - /** - * Alter this body's angular sleeping threshold. - * - * @param angularSleepingThreshold the desired threshold (≥0, default=1) - */ - public void setAngularSleepingThreshold(float angularSleepingThreshold) { - setAngularSleepingThreshold(objectId, angularSleepingThreshold); - } - - private native void setAngularSleepingThreshold(long objectId, float angularSleepingThreshold); - - /** - * Read this body's linear sleeping threshold. - * - * @return the linear sleeping threshold (≥0) - */ - public float getLinearSleepingThreshold() { - return getLinearSleepingThreshold(objectId); - } - - private native float getLinearSleepingThreshold(long objectId); - - /** - * Read this body's angular sleeping threshold. - * - * @return the angular sleeping threshold (≥0) - */ - public float getAngularSleepingThreshold() { - return getAngularSleepingThreshold(objectId); - } - - private native float getAngularSleepingThreshold(long objectId); - - /** - * Read this body's angular factor for the X axis. - * - * @return the angular factor - */ - public float getAngularFactor() { - return getAngularFactor(null).getX(); - } - - /** - * Copy this body's angular factors. - * - * @param store storage for the result (modified if not null) - * @return the angular factor for each axis (either the provided storage or - * new vector, not null) - */ - public Vector3f getAngularFactor(Vector3f store) { - // Done this way to prevent breaking the API. - if (store == null) { - store = new Vector3f(); - } - getAngularFactor(objectId, store); - return store; - } - - private native void getAngularFactor(long objectId, Vector3f vec); - - /** - * Alter this body's angular factor. - * - * @param factor the desired angular factor for all axes (not null, - * unaffected, default=1) - */ - public void setAngularFactor(float factor) { - setAngularFactor(objectId, new Vector3f(factor, factor, factor)); - } - - /** - * Alter this body's angular factors. - * - * @param factor the desired angular factor for each axis (not null, - * unaffected, default=(1,1,1)) - */ - public void setAngularFactor(Vector3f factor) { - setAngularFactor(objectId, factor); - } - - private native void setAngularFactor(long objectId, Vector3f factor); - - /** - * Copy this body's linear factors. - * - * @return the linear factor for each axis (not null) - */ - public Vector3f getLinearFactor() { - Vector3f vec = new Vector3f(); - getLinearFactor(objectId, vec); - return vec; - } - - private native void getLinearFactor(long objectId, Vector3f vec); - - /** - * Alter this body's linear factors. - * - * @param factor the desired linear factor for each axis (not null, - * unaffected, default=(1,1,1)) - */ - public void setLinearFactor(Vector3f factor) { - setLinearFactor(objectId, factor); - } - - private native void setLinearFactor(long objectId, Vector3f factor); - - - /** - * Do not invoke directly! Joints are added automatically when created. - * - * @param joint the joint to add (not null) - */ - public void addJoint(PhysicsJoint joint) { - if (!joints.contains(joint)) { - joints.add(joint); - } - } - - /** - * Do not invoke directly! Joints are removed automatically when destroyed. - * - * @param joint the joint to remove (not null) - */ - public void removeJoint(PhysicsJoint joint) { - joints.remove(joint); - } - - /** - * Access the list of joints connected with this body. - *

- * This list is only filled when the PhysicsRigidBody is added to a physics - * space. - * - * @return the pre-existing list (not null) - */ - public List getJoints() { - return joints; - } - - /** - * Serialize this body, for example when saving to a J3O file. - * - * @param e exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter e) throws IOException { - super.write(e); - OutputCapsule capsule = e.getCapsule(this); - - capsule.write(getMass(), "mass", 1.0f); - - capsule.write(getGravity(), "gravity", Vector3f.ZERO); - capsule.write(isContactResponse(), "contactResponse", true); - capsule.write(getFriction(), "friction", 0.5f); - capsule.write(getRestitution(), "restitution", 0); - Vector3f angularFactor = getAngularFactor(null); - if (angularFactor.x == angularFactor.y && angularFactor.y == angularFactor.z) { - capsule.write(getAngularFactor(), "angularFactor", 1); - } else { - capsule.write(getAngularFactor(null), "angularFactor", Vector3f.UNIT_XYZ); - capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ); - } - capsule.write(kinematic, "kinematic", false); - - capsule.write(getLinearDamping(), "linearDamping", 0); - capsule.write(getAngularDamping(), "angularDamping", 0); - capsule.write(getLinearSleepingThreshold(), "linearSleepingThreshold", 0.8f); - capsule.write(getAngularSleepingThreshold(), "angularSleepingThreshold", 1.0f); - - capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); - capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); - - capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); - capsule.write(getLinearVelocity(), "linearVelocity", null); - capsule.write(getAngularVelocity(), "angularVelocity", null); - - capsule.writeSavableArrayList(joints, "joints", null); - } - - /** - * De-serialize this body, for example when loading from a J3O file. - * - * @param e importer (not null) - * @throws IOException from importer - */ - @Override - @SuppressWarnings("unchecked") - public void read(JmeImporter e) throws IOException { - super.read(e); - - InputCapsule capsule = e.getCapsule(this); - float mass = capsule.readFloat("mass", 1.0f); - this.mass = mass; - rebuildRigidBody(); - setGravity((Vector3f) capsule.readSavable("gravity", Vector3f.ZERO.clone())); - setContactResponse(capsule.readBoolean("contactResponse", true)); - setFriction(capsule.readFloat("friction", 0.5f)); - setKinematic(capsule.readBoolean("kinematic", false)); - - setRestitution(capsule.readFloat("restitution", 0)); - Vector3f angularFactor = (Vector3f) capsule.readSavable("angularFactor", null); - if(angularFactor == null) { - setAngularFactor(capsule.readFloat("angularFactor", 1)); - } else { - setAngularFactor(angularFactor); - setLinearFactor((Vector3f) capsule.readSavable("linearFactor", Vector3f.UNIT_XYZ.clone())); - } - setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0)); - setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f)); - setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); - setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); - - setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - setPhysicsRotation((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f())); - setLinearVelocity((Vector3f) capsule.readSavable("linearVelocity", new Vector3f())); - setAngularVelocity((Vector3f) capsule.readSavable("angularVelocity", new Vector3f())); - - joints = capsule.readSavableArrayList("joints", null); - } -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsVehicle.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsVehicle.java deleted file mode 100644 index 54e6236d4e..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsVehicle.java +++ /dev/null @@ -1,695 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects; - -import com.jme3.bullet.PhysicsSpace; -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.bullet.objects.infos.VehicleTuning; -import com.jme3.export.InputCapsule; -import com.jme3.export.JmeExporter; -import com.jme3.export.JmeImporter; -import com.jme3.export.OutputCapsule; -import com.jme3.math.Vector3f; -import com.jme3.scene.Spatial; -import java.io.IOException; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A collision object for simplified vehicle simulation based on Bullet's - * btRaycastVehicle. - *

- * From Bullet manual:
- * For arcade style vehicle simulations, it is recommended to use the simplified - * Bullet vehicle model as provided in btRaycastVehicle. Instead of simulation - * each wheel and chassis as separate rigid bodies, connected by constraints, it - * uses a simplified model. This simplified model has many benefits, and is - * widely used in commercial driving games. - *

- * The entire vehicle is represented as a single rigidbody, the chassis. The - * collision detection of the wheels is approximated by ray casts, and the tire - * friction is a basic anisotropic friction model. - * - * @author normenhansen - */ -public class PhysicsVehicle extends PhysicsRigidBody { - - /** - * Unique identifier of the btRaycastVehicle. The constructor sets this to a - * non-zero value. - */ - protected long vehicleId = 0; - /** - * Unique identifier of the ray caster. - */ - protected long rayCasterId = 0; - /** - * tuning parameters applied when a wheel is created - */ - protected VehicleTuning tuning = new VehicleTuning(); - /** - * list of wheels - */ - protected ArrayList wheels = new ArrayList(); - /** - * physics space where this vehicle is added, or null if none - */ - protected PhysicsSpace physicsSpace; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected PhysicsVehicle() { - } - - /** - * Instantiate a vehicle with the specified collision shape and mass=1. - * - * @param shape the desired shape (not null, alias created) - */ - public PhysicsVehicle(CollisionShape shape) { - super(shape); - } - - /** - * Instantiate a vehicle with the specified collision shape and mass. - * - * @param shape the desired shape (not null, alias created) - * @param mass (>0) - */ - public PhysicsVehicle(CollisionShape shape, float mass) { - super(shape, mass); - } - - /** - * used internally - */ - public void updateWheels() { - if (vehicleId != 0) { - for (int i = 0; i < wheels.size(); i++) { - updateWheelTransform(vehicleId, i, true); - wheels.get(i).updatePhysicsState(); - } - } - } - - private native void updateWheelTransform(long vehicleId, int wheel, boolean interpolated); - - /** - * used internally - */ - public void applyWheelTransforms() { - if (wheels != null) { - for (int i = 0; i < wheels.size(); i++) { - wheels.get(i).applyWheelTransform(); - } - } - } - - @Override - protected void postRebuild() { - super.postRebuild(); - motionState.setVehicle(this); - createVehicle(physicsSpace); - } - - /** - * Used internally, creates the actual vehicle constraint when vehicle is - * added to physics space. - * - * @param space which physics space - */ - public void createVehicle(PhysicsSpace space) { - physicsSpace = space; - if (space == null) { - return; - } - if (space.getSpaceId() == 0) { - throw new IllegalStateException("Physics space is not initialized!"); - } - if (rayCasterId != 0) { - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Clearing RayCaster {0}", Long.toHexString(rayCasterId)); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Clearing Vehicle {0}", Long.toHexString(vehicleId)); - finalizeNative(rayCasterId, vehicleId); - } - rayCasterId = createVehicleRaycaster(objectId, space.getSpaceId()); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created RayCaster {0}", Long.toHexString(rayCasterId)); - vehicleId = createRaycastVehicle(objectId, rayCasterId); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Vehicle {0}", Long.toHexString(vehicleId)); - setCoordinateSystem(vehicleId, 0, 1, 2); - for (VehicleWheel wheel : wheels) { - wheel.setVehicleId(vehicleId, addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel())); - } - } - - private native long createVehicleRaycaster(long objectId, long physicsSpaceId); - - private native long createRaycastVehicle(long objectId, long rayCasterId); - - private native void setCoordinateSystem(long objectId, int a, int b, int c); - - private native int addWheel(long objectId, Vector3f location, Vector3f direction, Vector3f axle, float restLength, float radius, VehicleTuning tuning, boolean frontWheel); - - /** - * Add a wheel to this vehicle. - * - * @param connectionPoint the location where the suspension connects to the - * chassis (in chassis coordinates, not null, unaffected) - * @param direction the suspension direction (in chassis coordinates, not - * null, unaffected, typically down/0,-1,0) - * @param axle the axis direction (in chassis coordinates, not null, - * unaffected, typically -1,0,0) - * @param suspensionRestLength the rest length of the suspension (in - * physics-space units) - * @param wheelRadius the wheel radius (in physics-space units, >0) - * @param isFrontWheel true→front (steering) wheel, - * false→non-front wheel - * @return a new VehicleWheel for access (not null) - */ - public VehicleWheel addWheel(Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) { - return addWheel(null, connectionPoint, direction, axle, suspensionRestLength, wheelRadius, isFrontWheel); - } - - /** - * Add a wheel to this vehicle - * - * @param spat the associated spatial, or null if none - * @param connectionPoint the location where the suspension connects to the - * chassis (in chassis coordinates, not null, unaffected) - * @param direction the suspension direction (in chassis coordinates, not - * null, unaffected, typically down/0,-1,0) - * @param axle the axis direction (in chassis coordinates, not null, - * unaffected, typically -1,0,0) - * @param suspensionRestLength the rest length of the suspension (in - * physics-space units) - * @param wheelRadius the wheel radius (in physics-space units, >0) - * @param isFrontWheel true→front (steering) wheel, - * false→non-front wheel - * @return a new VehicleWheel for access (not null) - */ - public VehicleWheel addWheel(Spatial spat, Vector3f connectionPoint, Vector3f direction, Vector3f axle, float suspensionRestLength, float wheelRadius, boolean isFrontWheel) { - VehicleWheel wheel = null; - if (spat == null) { - wheel = new VehicleWheel(connectionPoint, direction, axle, suspensionRestLength, wheelRadius, isFrontWheel); - } else { - wheel = new VehicleWheel(spat, connectionPoint, direction, axle, suspensionRestLength, wheelRadius, isFrontWheel); - } - wheel.setFrictionSlip(tuning.frictionSlip); - wheel.setMaxSuspensionTravelCm(tuning.maxSuspensionTravelCm); - wheel.setSuspensionStiffness(tuning.suspensionStiffness); - wheel.setWheelsDampingCompression(tuning.suspensionCompression); - wheel.setWheelsDampingRelaxation(tuning.suspensionDamping); - wheel.setMaxSuspensionForce(tuning.maxSuspensionForce); - wheels.add(wheel); - if (vehicleId != 0) { - wheel.setVehicleId(vehicleId, addWheel(vehicleId, wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), tuning, wheel.isFrontWheel())); - } - return wheel; - } - - /** - * Remove a wheel. - * - * @param wheel the index of the wheel to remove (≥0) - */ - public void removeWheel(int wheel) { - wheels.remove(wheel); - rebuildRigidBody(); -// updateDebugShape(); - } - - /** - * Access the indexed wheel of this vehicle. - * - * @param wheel the index of the wheel to access (≥0, <count) - * @return the pre-existing instance - */ - public VehicleWheel getWheel(int wheel) { - return wheels.get(wheel); - } - - /** - * Read the number of wheels on this vehicle. - * - * @return count (≥0) - */ - public int getNumWheels() { - return wheels.size(); - } - - /** - * Read the initial friction for new wheels. - * - * @return the coefficient of friction between tyre and ground - * (0.8→realistic car, 10000→kart racer) - */ - public float getFrictionSlip() { - return tuning.frictionSlip; - } - - /** - * Alter the initial friction for new wheels. Effective only before adding - * wheels. After adding a wheel, use {@link #setFrictionSlip(int, float)}. - *

- * For better handling, increase the friction. - * - * @param frictionSlip the desired coefficient of friction between tyre and - * ground (0.8→realistic car, 10000→kart racer, default=10.5) - */ - public void setFrictionSlip(float frictionSlip) { - tuning.frictionSlip = frictionSlip; - } - - /** - * Alter the friction of the indexed wheel. - *

- * For better handling, increase the friction. - * - * @param wheel the index of the wheel to modify (≥0) - * @param frictionSlip the desired coefficient of friction between tyre and - * ground (0.8→realistic car, 10000→kart racer) - */ - public void setFrictionSlip(int wheel, float frictionSlip) { - wheels.get(wheel).setFrictionSlip(frictionSlip); - } - - /** - * Alter the roll influence of the indexed wheel. - *

- * The roll-influence factor reduces (or magnifies) any torque contributed - * by the wheel that would tend to cause the vehicle to roll over. This is a - * bit of a hack, but it's quite effective. - *

- * If the friction between the tyres and the ground is too high, you may - * reduce this factor to prevent the vehicle from rolling over. You should - * also try lowering the vehicle's center of mass. - * - * @param wheel the index of the wheel to modify (≥0) - * @param rollInfluence the desired roll-influence factor (0→no roll - * torque, 1→realistic behavior, default=1) - */ - public void setRollInfluence(int wheel, float rollInfluence) { - wheels.get(wheel).setRollInfluence(rollInfluence); - } - - /** - * Read the initial maximum suspension travel distance for new wheels. - * - * @return the maximum distance the suspension can be compressed (in - * centimeters) - */ - public float getMaxSuspensionTravelCm() { - return tuning.maxSuspensionTravelCm; - } - - /** - * Alter the initial maximum suspension travel distance for new wheels. - * Effective only before adding wheels. After adding a wheel, use - * {@link #setMaxSuspensionTravelCm(int, float)}. - * - * @param maxSuspensionTravelCm the desired maximum distance the suspension - * can be compressed (in centimeters, default=500) - */ - public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm) { - tuning.maxSuspensionTravelCm = maxSuspensionTravelCm; - } - - /** - * Alter the maximum suspension travel distance for the indexed wheel. - * - * @param wheel the index of the wheel to modify (≥0) - * @param maxSuspensionTravelCm the desired maximum distance the suspension - * can be compressed (in centimeters) - */ - public void setMaxSuspensionTravelCm(int wheel, float maxSuspensionTravelCm) { - wheels.get(wheel).setMaxSuspensionTravelCm(maxSuspensionTravelCm); - } - - /** - * Read the initial maximum suspension force for new wheels. - * - * @return the maximum force per wheel - */ - public float getMaxSuspensionForce() { - return tuning.maxSuspensionForce; - } - - /** - * Alter the initial maximum suspension force for new wheels. Effective only - * before adding wheels. After adding a wheel, use - * {@link #setMaxSuspensionForce(int, float)}. - *

- * If the suspension cannot handle the vehicle's weight, increase this - * limit. - * - * @param maxSuspensionForce the desired maximum force per wheel - * (default=6000) - */ - public void setMaxSuspensionForce(float maxSuspensionForce) { - tuning.maxSuspensionForce = maxSuspensionForce; - } - - /** - * Alter the maximum suspension force for the specified wheel. - *

- * If the suspension cannot handle the vehicle's weight, increase this - * limit. - * - * @param wheel the index of the wheel to modify (≥0) - * @param maxSuspensionForce the desired maximum force per wheel - * (default=6000) - */ - public void setMaxSuspensionForce(int wheel, float maxSuspensionForce) { - wheels.get(wheel).setMaxSuspensionForce(maxSuspensionForce); - } - - /** - * Read the initial damping (when the suspension is compressed) for new - * wheels. - * - * @return the damping coefficient - */ - public float getSuspensionCompression() { - return tuning.suspensionCompression; - } - - /** - * Alter the initial damping (when the suspension is compressed) for new - * wheels. Effective only before adding wheels. After adding a wheel, use - * {@link #setSuspensionCompression(int, float)}. - *

- * Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the - * damping ratio: - *

- * k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and - * 0.3 are good values - * - * @param suspensionCompression the desired damping coefficient - * (default=0.83) - */ - public void setSuspensionCompression(float suspensionCompression) { - tuning.suspensionCompression = suspensionCompression; - } - - /** - * Alter the damping (when the suspension is compressed) for the indexed - * wheel. - *

- * Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the - * damping ratio: - *

- * k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and - * 0.3 are good values - * - * @param wheel the index of the wheel to modify (≥0) - * @param suspensionCompression the desired damping coefficient - */ - public void setSuspensionCompression(int wheel, float suspensionCompression) { - wheels.get(wheel).setWheelsDampingCompression(suspensionCompression); - } - - /** - * Read the initial damping (when the suspension is expanded) for new - * wheels. - * - * @return the damping coefficient - */ - public float getSuspensionDamping() { - return tuning.suspensionDamping; - } - - /** - * Alter the initial damping (when the suspension is expanded) for new - * wheels. Effective only before adding wheels. After adding a wheel, use - * {@link #setSuspensionCompression(int, float)}. - *

- * Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the - * damping ratio: - *

- * k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and - * 0.3 are good values - * - * @param suspensionDamping the desired damping coefficient (default=0.88) - */ - public void setSuspensionDamping(float suspensionDamping) { - tuning.suspensionDamping = suspensionDamping; - } - - /** - * Alter the damping (when the suspension is expanded) for the indexed - * wheel. - *

- * Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the - * damping ratio: - *

- * k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and - * 0.3 are good values - * - * @param wheel the index of the wheel to modify (≥0) - * @param suspensionDamping the desired damping coefficient - */ - public void setSuspensionDamping(int wheel, float suspensionDamping) { - wheels.get(wheel).setWheelsDampingRelaxation(suspensionDamping); - } - - /** - * Read the initial suspension stiffness for new wheels. - * - * @return the stiffness constant (10→off-road buggy, 50→sports - * car, 200→Formula-1 race car) - */ - public float getSuspensionStiffness() { - return tuning.suspensionStiffness; - } - - /** - * Alter the initial suspension stiffness for new wheels. Effective only - * before adding wheels. After adding a wheel, use - * {@link #setSuspensionStiffness(int, float)}. - * - * @param suspensionStiffness the desired stiffness coefficient - * (10→off-road buggy, 50→sports car, 200→Formula-1 race car, - * default=5.88) - */ - public void setSuspensionStiffness(float suspensionStiffness) { - tuning.suspensionStiffness = suspensionStiffness; - } - - /** - * Alter the suspension stiffness of the indexed wheel. - * - * @param wheel the index of the wheel to modify (≥0) - * @param suspensionStiffness the desired stiffness coefficient - * (10→off-road buggy, 50→sports car, 200→Formula-1 race car, - * default=5.88) - */ - public void setSuspensionStiffness(int wheel, float suspensionStiffness) { - wheels.get(wheel).setSuspensionStiffness(suspensionStiffness); - } - - /** - * Reset this vehicle's suspension. - */ - public void resetSuspension() { - resetSuspension(vehicleId); - } - - private native void resetSuspension(long vehicleId); - - /** - * Apply the specified engine force to all wheels. Works continuously. - * - * @param force the desired amount of force - */ - public void accelerate(float force) { - for (int i = 0; i < wheels.size(); i++) { - accelerate(i, force); - } - } - - /** - * Apply the given engine force to the indexed wheel. Works continuously. - * - * @param wheel the index of the wheel to apply the force to (≥0) - * @param force the desired amount of force - */ - public void accelerate(int wheel, float force) { - applyEngineForce(vehicleId, wheel, force); - - } - - private native void applyEngineForce(long vehicleId, int wheel, float force); - - /** - * Alter the steering angle of all front wheels. - * - * @param value the desired steering angle (in radians, 0=straight) - */ - public void steer(float value) { - for (int i = 0; i < wheels.size(); i++) { - if (getWheel(i).isFrontWheel()) { - steer(i, value); - } - } - } - - /** - * Alter the steering angle of the indexed wheel. - * - * @param wheel the index of the wheel to steer (≥0) - * @param value the desired steering angle (in radians, 0=straight) - */ - public void steer(int wheel, float value) { - steer(vehicleId, wheel, value); - } - - private native void steer(long vehicleId, int wheel, float value); - - /** - * Apply the given brake force to all wheels. Works continuously. - * - * @param force the desired amount of force - */ - public void brake(float force) { - for (int i = 0; i < wheels.size(); i++) { - brake(i, force); - } - } - - /** - * Apply the given brake force to the indexed wheel. Works continuously. - * - * @param wheel the index of the wheel to apply the force to (≥0) - * @param force the desired amount of force - */ - public void brake(int wheel, float force) { - brake(vehicleId, wheel, force); - } - - private native void brake(long vehicleId, int wheel, float force); - - /** - * Read the vehicle's speed in km/h. - * - * @return speed (in kilometers per hour) - */ - public float getCurrentVehicleSpeedKmHour() { - return getCurrentVehicleSpeedKmHour(vehicleId); - } - - private native float getCurrentVehicleSpeedKmHour(long vehicleId); - - /** - * Copy the vehicle's forward direction. - * - * @param vector storage for the result (modified if not null) - * @return a direction vector (in physics-space coordinates, either the - * provided storage or a new vector, not null) - */ - public Vector3f getForwardVector(Vector3f vector) { - if (vector == null) { - vector = new Vector3f(); - } - getForwardVector(vehicleId, vector); - return vector; - } - - private native void getForwardVector(long objectId, Vector3f vector); - - /** - * used internally - * - * @return the unique identifier - */ - public long getVehicleId() { - return vehicleId; - } - - /** - * De-serialize this vehicle, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - @SuppressWarnings("unchecked") - public void read(JmeImporter im) throws IOException { - InputCapsule capsule = im.getCapsule(this); - tuning = new VehicleTuning(); - tuning.frictionSlip = capsule.readFloat("frictionSlip", 10.5f); - tuning.maxSuspensionTravelCm = capsule.readFloat("maxSuspensionTravelCm", 500f); - tuning.maxSuspensionForce = capsule.readFloat("maxSuspensionForce", 6000f); - tuning.suspensionCompression = capsule.readFloat("suspensionCompression", 0.83f); - tuning.suspensionDamping = capsule.readFloat("suspensionDamping", 0.88f); - tuning.suspensionStiffness = capsule.readFloat("suspensionStiffness", 5.88f); - wheels = capsule.readSavableArrayList("wheelsList", new ArrayList()); - motionState.setVehicle(this); - super.read(im); - } - - /** - * Serialize this vehicle, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(tuning.frictionSlip, "frictionSlip", 10.5f); - capsule.write(tuning.maxSuspensionTravelCm, "maxSuspensionTravelCm", 500f); - capsule.write(tuning.maxSuspensionForce, "maxSuspensionForce", 6000f); - capsule.write(tuning.suspensionCompression, "suspensionCompression", 0.83f); - capsule.write(tuning.suspensionDamping, "suspensionDamping", 0.88f); - capsule.write(tuning.suspensionStiffness, "suspensionStiffness", 5.88f); - capsule.writeSavableArrayList(wheels, "wheelsList", new ArrayList()); - super.write(ex); - } - - /** - * Finalize this vehicle just before it is destroyed. Should be invoked only - * by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing RayCaster {0}", Long.toHexString(rayCasterId)); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing Vehicle {0}", Long.toHexString(vehicleId)); - finalizeNative(rayCasterId, vehicleId); - } - - private native void finalizeNative(long rayCaster, long vehicle); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java deleted file mode 100644 index 9091559586..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java +++ /dev/null @@ -1,713 +0,0 @@ -/* - * Copyright (c) 2009-2019 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects; - -import com.jme3.bullet.collision.PhysicsCollisionObject; -import com.jme3.export.*; -import com.jme3.math.Matrix3f; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; -import com.jme3.scene.Spatial; -import java.io.IOException; - -/** - * Information about one wheel of a PhysicsVehicle. - * - * @author normenhansen - */ -public class VehicleWheel implements Savable { - - /** - * unique identifier of the btRaycastVehicle - */ - protected long wheelId = 0; - /** - * 0-origin index among the vehicle's wheels (≥0) - */ - protected int wheelIndex = 0; - /** - * copy of wheel type: true→front (steering) wheel, - * false→non-front wheel - */ - protected boolean frontWheel; - /** - * location where the suspension connects to the chassis (in chassis - * coordinates) - */ - protected Vector3f location = new Vector3f(); - /** - * suspension direction (in chassis coordinates, typically down/0,-1,0) - */ - protected Vector3f direction = new Vector3f(); - /** - * axis direction (in chassis coordinates, typically to the right/-1,0,0) - */ - protected Vector3f axle = new Vector3f(); - /** - * copy of suspension stiffness constant (10→off-road buggy, - * 50→sports car, 200→Formula-1 race car, default=20) - */ - protected float suspensionStiffness = 20.0f; - /** - * copy of suspension damping when expanded (0→no damping, default=2.3) - */ - protected float wheelsDampingRelaxation = 2.3f; - /** - * copy of suspension damping when compressed (0→no damping, - * default=4.4) - */ - protected float wheelsDampingCompression = 4.4f; - /** - * copy of coefficient of friction between tyre and ground - * (0.8→realistic car, 10000→kart racer, default=10.5) - */ - protected float frictionSlip = 10.5f; - /** - * copy of roll-influence factor (0→no roll torque, 1→realistic - * behavior, default=1) - */ - protected float rollInfluence = 1.0f; - /** - * copy of maximum suspension travel distance (in centimeters, default=500) - */ - protected float maxSuspensionTravelCm = 500f; - /** - * copy of maximum force exerted by the suspension (default=6000) - */ - protected float maxSuspensionForce = 6000f; - /** - * copy of wheel radius (in physics-space units, >0) - */ - protected float radius = 0.5f; - /** - * copy of rest length of the suspension (in physics-space units) - */ - protected float restLength = 1f; - /** - * wheel location in physics-space coordinates - */ - protected Vector3f wheelWorldLocation = new Vector3f(); - /** - * wheel orientation in physics-space coordinates - */ - protected Quaternion wheelWorldRotation = new Quaternion(); - /** - * associated spatial, or null if none - */ - protected Spatial wheelSpatial; - protected Matrix3f tmp_Matrix = new com.jme3.math.Matrix3f(); - protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); - /** - * true → physics coordinates match local transform, false → - * physics coordinates match world transform - */ - private boolean applyLocal = false; - - /** - * No-argument constructor needed by SavableClassUtil. Do not invoke - * directly! - */ - protected VehicleWheel() { - } - - /** - * Instantiate a wheel. - * - * @param spat the associated spatial, or null if none - * @param location the location where the suspension connects to the chassis - * (in chassis coordinates, not null, unaffected) - * @param direction the suspension direction (in chassis coordinates, not - * null, unaffected, typically down/0,-1,0) - * @param axle the axis direction (in chassis coordinates, not null, - * unaffected, typically right/-1,0,0) - * @param restLength the rest length of the suspension (in physics-space - * units) - * @param radius the wheel's radius (in physics-space units, ≥0) - * @param frontWheel true→front (steering) wheel, false→non-front - * wheel - */ - public VehicleWheel(Spatial spat, Vector3f location, Vector3f direction, Vector3f axle, - float restLength, float radius, boolean frontWheel) { - this(location, direction, axle, restLength, radius, frontWheel); - wheelSpatial = spat; - } - - /** - * Instantiate a wheel without an associated spatial. - * - * @param location the location where the suspension connects to the chassis - * (in chassis coordinates, not null, unaffected) - * @param direction the suspension direction (in chassis coordinates, not - * null, unaffected, typically down/0,-1,0) - * @param axle the axis direction (in chassis coordinates, not null, - * unaffected, typically right/-1,0,0) - * @param restLength the rest length of the suspension (in physics-space - * units) - * @param radius the wheel's radius (in physics-space units, ≥0) - * @param frontWheel true→front (steering) wheel, false→non-front - * wheel - */ - public VehicleWheel(Vector3f location, Vector3f direction, Vector3f axle, - float restLength, float radius, boolean frontWheel) { - this.location.set(location); - this.direction.set(direction); - this.axle.set(axle); - this.frontWheel = frontWheel; - this.restLength = restLength; - this.radius = radius; - } - - /** - * Update this wheel's location and orientation in physics space. - */ - public void updatePhysicsState() { - getWheelLocation(wheelId, wheelIndex, wheelWorldLocation); - getWheelRotation(wheelId, wheelIndex, tmp_Matrix); - wheelWorldRotation.fromRotationMatrix(tmp_Matrix); - } - - private native void getWheelLocation(long vehicleId, int wheelId, Vector3f location); - - private native void getWheelRotation(long vehicleId, int wheelId, Matrix3f location); - - /** - * Apply this wheel's physics location and orientation to its associated - * spatial, if any. - */ - public void applyWheelTransform() { - if (wheelSpatial == null) { - return; - } - Quaternion localRotationQuat = wheelSpatial.getLocalRotation(); - Vector3f localLocation = wheelSpatial.getLocalTranslation(); - if (!applyLocal && wheelSpatial.getParent() != null) { - localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation()); - localLocation.divideLocal(wheelSpatial.getParent().getWorldScale()); - tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); - - localRotationQuat.set(wheelWorldRotation); - tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat); - - wheelSpatial.setLocalTranslation(localLocation); - wheelSpatial.setLocalRotation(localRotationQuat); - } else { - wheelSpatial.setLocalTranslation(wheelWorldLocation); - wheelSpatial.setLocalRotation(wheelWorldRotation); - } - } - - /** - * Read the id of the btRaycastVehicle. - * - * @return the unique identifier (not zero) - */ - public long getWheelId() { - return wheelId; - } - - /** - * Assign this wheel to a vehicle. - * - * @param vehicleId the id of the btRaycastVehicle (not zero) - * @param wheelIndex index among the vehicle's wheels (≥0) - */ - public void setVehicleId(long vehicleId, int wheelIndex) { - this.wheelId = vehicleId; - this.wheelIndex = wheelIndex; - applyInfo(); - } - - /** - * Test whether this wheel is a front wheel. - * - * @return true if front wheel, otherwise false - */ - public boolean isFrontWheel() { - return frontWheel; - } - - /** - * Alter whether this wheel is a front (steering) wheel. - * - * @param frontWheel true→front wheel, false→non-front wheel - */ - public void setFrontWheel(boolean frontWheel) { - this.frontWheel = frontWheel; - applyInfo(); - } - - /** - * Access the location where the suspension connects to the chassis. - * - * @return the pre-existing location vector (in chassis coordinates, not - * null) - */ - public Vector3f getLocation() { - return location; - } - - /** - * Access this wheel's suspension direction. - * - * @return the pre-existing direction vector (in chassis coordinates, not - * null) - */ - public Vector3f getDirection() { - return direction; - } - - /** - * Access this wheel's axle direction. - * - * @return the pre-existing direction vector (not null) - */ - public Vector3f getAxle() { - return axle; - } - - /** - * Read the stiffness constant for this wheel's suspension. - * - * @return the stiffness constant - */ - public float getSuspensionStiffness() { - return suspensionStiffness; - } - - /** - * Alter the stiffness constant for this wheel's suspension. - * - * @param suspensionStiffness the desired stiffness constant - * (10→off-road buggy, 50→sports car, 200→Formula-1 race car, - * default=20) - */ - public void setSuspensionStiffness(float suspensionStiffness) { - this.suspensionStiffness = suspensionStiffness; - applyInfo(); - } - - /** - * Read this wheel's damping when the suspension is expanded. - * - * @return the damping - */ - public float getWheelsDampingRelaxation() { - return wheelsDampingRelaxation; - } - - /** - * Alter this wheel's damping when the suspension is expanded. - *

- * Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the - * damping ratio: - *

- * k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and - * 0.3 are good values - * - * @param wheelsDampingRelaxation the desired damping (default=2.3) - */ - public void setWheelsDampingRelaxation(float wheelsDampingRelaxation) { - this.wheelsDampingRelaxation = wheelsDampingRelaxation; - applyInfo(); - } - - /** - * Read this wheel's damping when the suspension is compressed. - * - * @return the damping - */ - public float getWheelsDampingCompression() { - return wheelsDampingCompression; - } - - /** - * Alter this wheel's damping when the suspension is compressed. - *

- * Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the - * damping ratio: - *

- * k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and - * 0.3 are good values - * - * @param wheelsDampingCompression the desired damping (default=4.4) - */ - public void setWheelsDampingCompression(float wheelsDampingCompression) { - this.wheelsDampingCompression = wheelsDampingCompression; - applyInfo(); - } - - /** - * Read the friction between this wheel's tyre and the ground. - * - * @return the coefficient of friction - */ - public float getFrictionSlip() { - return frictionSlip; - } - - /** - * Alter the friction between this wheel's tyre and the ground. - *

- * Should be about 0.8 for realistic cars, but can increased for better - * handling. Set large (10000.0) for kart racers. - * - * @param frictionSlip the desired coefficient of friction (default=10.5) - */ - public void setFrictionSlip(float frictionSlip) { - this.frictionSlip = frictionSlip; - applyInfo(); - } - - /** - * Read this wheel's roll influence. - * - * @return the roll-influence factor - */ - public float getRollInfluence() { - return rollInfluence; - } - - /** - * Alter this wheel's roll influence. - *

- * The roll-influence factor reduces (or magnifies) the torque contributed - * by this wheel that tends to cause the vehicle to roll over. This is a bit - * of a hack, but it's quite effective. - *

- * If the friction between the tyres and the ground is too high, you may - * reduce this factor to prevent the vehicle from rolling over. You should - * also try lowering the vehicle's centre of mass. - * - * @param rollInfluence the desired roll-influence factor (0→no roll - * torque, 1→realistic behaviour, default=1) - */ - public void setRollInfluence(float rollInfluence) { - this.rollInfluence = rollInfluence; - applyInfo(); - } - - /** - * Read the travel distance for this wheel's suspension. - * - * @return the maximum travel distance (in centimeters) - */ - public float getMaxSuspensionTravelCm() { - return maxSuspensionTravelCm; - } - - /** - * Alter the travel distance for this wheel's suspension. - * - * @param maxSuspensionTravelCm the desired maximum travel distance (in - * centimetres, default=500) - */ - public void setMaxSuspensionTravelCm(float maxSuspensionTravelCm) { - this.maxSuspensionTravelCm = maxSuspensionTravelCm; - applyInfo(); - } - - /** - * Read the maximum force exerted by this wheel's suspension. - * - * @return the maximum force - */ - public float getMaxSuspensionForce() { - return maxSuspensionForce; - } - - /** - * Alter the maximum force exerted by this wheel's suspension. - *

- * Increase this if your suspension cannot handle the weight of your - * vehicle. - * - * @param maxSuspensionForce the desired maximum force (default=6000) - */ - public void setMaxSuspensionForce(float maxSuspensionForce) { - this.maxSuspensionForce = maxSuspensionForce; - applyInfo(); - } - - private void applyInfo() { - if (wheelId == 0) { - return; - } - applyInfo(wheelId, wheelIndex, suspensionStiffness, wheelsDampingRelaxation, wheelsDampingCompression, frictionSlip, rollInfluence, maxSuspensionTravelCm, maxSuspensionForce, radius, frontWheel, restLength); - } - - private native void applyInfo(long wheelId, int wheelIndex, - float suspensionStiffness, - float wheelsDampingRelaxation, - float wheelsDampingCompression, - float frictionSlip, - float rollInfluence, - float maxSuspensionTravelCm, - float maxSuspensionForce, - float wheelsRadius, - boolean frontWheel, - float suspensionRestLength); - - /** - * Read the radius of this wheel. - * - * @return the radius (in physics-space units, ≥0) - */ - public float getRadius() { - return radius; - } - - /** - * Alter the radius of this wheel. - * - * @param radius the desired radius (in physics-space units, ≥0, - * default=0.5) - */ - public void setRadius(float radius) { - this.radius = radius; - applyInfo(); - } - - /** - * Read the rest length of this wheel. - * - * @return the length - */ - public float getRestLength() { - return restLength; - } - - /** - * Alter the rest length of the suspension of this wheel. - * - * @param restLength the desired length (default=1) - */ - public void setRestLength(float restLength) { - this.restLength = restLength; - applyInfo(); - } - - /** - * returns the object this wheel is in contact with or null if no contact - * @return the PhysicsCollisionObject (PhysicsRigidBody, PhysicsGhostObject) - */ - public PhysicsCollisionObject getGroundObject() { -// if (wheelInfo.raycastInfo.groundObject == null) { -// return null; -// } else if (wheelInfo.raycastInfo.groundObject instanceof RigidBody) { -// System.out.println("RigidBody"); -// return (PhysicsRigidBody) ((RigidBody) wheelInfo.raycastInfo.groundObject).getUserPointer(); -// } else { - return null; -// } - } - - /** - * Copy the location where the wheel touches the ground. - * - * @param vec storage for the result (not null, modified) - * @return a new location vector (in physics-space coordinates, not null) - */ - public Vector3f getCollisionLocation(Vector3f vec) { - getCollisionLocation(wheelId, wheelIndex, vec); - return vec; - } - - private native void getCollisionLocation(long wheelId, int wheelIndex, Vector3f vec); - - /** - * Copy the location where the wheel collides with the ground. - * - * @return a new location vector (in physics-space coordinates) - */ - public Vector3f getCollisionLocation() { - Vector3f vec = new Vector3f(); - getCollisionLocation(wheelId, wheelIndex, vec); - return vec; - } - - /** - * Copy the normal where the wheel touches the ground. - * - * @param vec storage for the result (not null, modified) - * @return a unit vector (in physics-space coordinates, not null) - */ - public Vector3f getCollisionNormal(Vector3f vec) { - getCollisionNormal(wheelId, wheelIndex, vec); - return vec; - } - - private native void getCollisionNormal(long wheelId, int wheelIndex, Vector3f vec); - - /** - * Copy the normal where the wheel touches the ground. - * - * @return a new unit vector (in physics-space coordinates, not null) - */ - public Vector3f getCollisionNormal() { - Vector3f vec = new Vector3f(); - getCollisionNormal(wheelId, wheelIndex, vec); - return vec; - } - - /** - * Calculate to what extent the wheel is skidding (for skid sounds/smoke - * etc.) - * - * @return the relative amount of traction (0→wheel is sliding, - * 1→wheel has full traction) - */ - public float getSkidInfo() { - return getSkidInfo(wheelId, wheelIndex); - } - - public native float getSkidInfo(long wheelId, int wheelIndex); - - /** - * Calculate how much this wheel has turned since the last physics step. - * - * @return the rotation angle (in radians) - */ - public float getDeltaRotation() { - return getDeltaRotation(wheelId, wheelIndex); - } - - public native float getDeltaRotation(long wheelId, int wheelIndex); - - /** - * De-serialize this wheel, for example when loading from a J3O file. - * - * @param im importer (not null) - * @throws IOException from importer - */ - @Override - public void read(JmeImporter im) throws IOException { - InputCapsule capsule = im.getCapsule(this); - wheelSpatial = (Spatial) capsule.readSavable("wheelSpatial", null); - frontWheel = capsule.readBoolean("frontWheel", false); - location = (Vector3f) capsule.readSavable("wheelLocation", new Vector3f()); - direction = (Vector3f) capsule.readSavable("wheelDirection", new Vector3f()); - axle = (Vector3f) capsule.readSavable("wheelAxle", new Vector3f()); - suspensionStiffness = capsule.readFloat("suspensionStiffness", 20.0f); - wheelsDampingRelaxation = capsule.readFloat("wheelsDampingRelaxation", 2.3f); - wheelsDampingCompression = capsule.readFloat("wheelsDampingCompression", 4.4f); - frictionSlip = capsule.readFloat("frictionSlip", 10.5f); - rollInfluence = capsule.readFloat("rollInfluence", 1.0f); - maxSuspensionTravelCm = capsule.readFloat("maxSuspensionTravelCm", 500f); - maxSuspensionForce = capsule.readFloat("maxSuspensionForce", 6000f); - radius = capsule.readFloat("wheelRadius", 0.5f); - restLength = capsule.readFloat("restLength", 1f); - } - - /** - * Serialize this wheel, for example when saving to a J3O file. - * - * @param ex exporter (not null) - * @throws IOException from exporter - */ - @Override - public void write(JmeExporter ex) throws IOException { - OutputCapsule capsule = ex.getCapsule(this); - capsule.write(wheelSpatial, "wheelSpatial", null); - capsule.write(frontWheel, "frontWheel", false); - capsule.write(location, "wheelLocation", new Vector3f()); - capsule.write(direction, "wheelDirection", new Vector3f()); - capsule.write(axle, "wheelAxle", new Vector3f()); - capsule.write(suspensionStiffness, "suspensionStiffness", 20.0f); - capsule.write(wheelsDampingRelaxation, "wheelsDampingRelaxation", 2.3f); - capsule.write(wheelsDampingCompression, "wheelsDampingCompression", 4.4f); - capsule.write(frictionSlip, "frictionSlip", 10.5f); - capsule.write(rollInfluence, "rollInfluence", 1.0f); - capsule.write(maxSuspensionTravelCm, "maxSuspensionTravelCm", 500f); - capsule.write(maxSuspensionForce, "maxSuspensionForce", 6000f); - capsule.write(radius, "wheelRadius", 0.5f); - capsule.write(restLength, "restLength", 1f); - } - - /** - * Access the spatial associated with this wheel. - * - * @return the pre-existing instance, or null - */ - public Spatial getWheelSpatial() { - return wheelSpatial; - } - - /** - * Alter which spatial is associated with this wheel. - * - * @param wheelSpatial the desired spatial, or null for none - */ - public void setWheelSpatial(Spatial wheelSpatial) { - this.wheelSpatial = wheelSpatial; - } - - /** - * Test whether physics coordinates should match the local transform of the - * Spatial. - * - * @return true if matching local transform, false if matching world - * transform - */ - public boolean isApplyLocal() { - return applyLocal; - } - - /** - * Alter whether physics coordinates should match the local transform of the - * Spatial. - * - * @param applyLocal true→match local transform, false→match world - * transform (default=false) - */ - public void setApplyLocal(boolean applyLocal) { - this.applyLocal = applyLocal; - } - - /** - * Copy this wheel's physics-space orientation to the specified quaternion. - * - * @param store storage for the result (not null, modified) - */ - public void getWheelWorldRotation(final Quaternion store) { - store.set(this.wheelWorldRotation); - } - - /** - * Copy this wheel's physics-space location to the specified vector. - * - * @param store storage for the result (not null, modified) - */ - public void getWheelWorldLocation(final Vector3f store) { - store.set(this.wheelWorldLocation); - } - -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java deleted file mode 100644 index bee3bf78df..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects.infos; - -import com.jme3.bullet.objects.PhysicsVehicle; -import com.jme3.math.Matrix3f; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; -import com.jme3.scene.Spatial; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * The motion state (transform) of a rigid body, with thread-safe access. - * - * @author normenhansen - */ -public class RigidBodyMotionState { - long motionStateId = 0; - private Vector3f worldLocation = new Vector3f(); - private Matrix3f worldRotation = new Matrix3f(); - private Quaternion worldRotationQuat = new Quaternion(); - private Quaternion tmp_inverseWorldRotation = new Quaternion(); - private PhysicsVehicle vehicle; - /** - * true → physics coordinates match local transform, false → - * physics coordinates match world transform - */ - private boolean applyPhysicsLocal = false; -// protected LinkedList listeners = new LinkedList(); - - /** - * Instantiate a motion state. - */ - public RigidBodyMotionState() { - this.motionStateId = createMotionState(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created MotionState {0}", Long.toHexString(motionStateId)); - } - - private native long createMotionState(); - - /** - * If the motion state has been updated, apply the new transform to the - * specified spatial. - * - * @param spatial where to apply the physics transform (not null, modified) - * @return true if changed - */ - public boolean applyTransform(Spatial spatial) { - Vector3f localLocation = spatial.getLocalTranslation(); - Quaternion localRotationQuat = spatial.getLocalRotation(); - boolean physicsLocationDirty = applyTransform(motionStateId, localLocation, localRotationQuat); - if (!physicsLocationDirty) { - return false; - } - if (!applyPhysicsLocal && spatial.getParent() != null) { - localLocation.subtractLocal(spatial.getParent().getWorldTranslation()); - localLocation.divideLocal(spatial.getParent().getWorldScale()); - tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation); - -// localRotationQuat.set(worldRotationQuat); - tmp_inverseWorldRotation.mult(localRotationQuat, localRotationQuat); - - spatial.setLocalTranslation(localLocation); - spatial.setLocalRotation(localRotationQuat); - } else { - spatial.setLocalTranslation(localLocation); - spatial.setLocalRotation(localRotationQuat); -// spatial.setLocalTranslation(worldLocation); -// spatial.setLocalRotation(worldRotationQuat); - } - if (vehicle != null) { - vehicle.updateWheels(); - } - return true; - } - - private native boolean applyTransform(long stateId, Vector3f location, Quaternion rotation); - - /** - * Copy the location from this motion state. - * - * @return the pre-existing location vector (in physics-space coordinates, - * not null) - */ - public Vector3f getWorldLocation() { - getWorldLocation(motionStateId, worldLocation); - return worldLocation; - } - - private native void getWorldLocation(long stateId, Vector3f vec); - - /** - * Read the rotation of this motion state (as a matrix). - * - * @return the pre-existing rotation matrix (in physics-space coordinates, - * not null) - */ - public Matrix3f getWorldRotation() { - getWorldRotation(motionStateId, worldRotation); - return worldRotation; - } - - private native void getWorldRotation(long stateId, Matrix3f vec); - - /** - * Read the rotation of this motion state (as a quaternion). - * - * @return the pre-existing instance (in physics-space coordinates, not - * null) - */ - public Quaternion getWorldRotationQuat() { - getWorldRotationQuat(motionStateId, worldRotationQuat); - return worldRotationQuat; - } - - private native void getWorldRotationQuat(long stateId, Quaternion vec); - - /** - * @param vehicle which vehicle will use this motion state - */ - public void setVehicle(PhysicsVehicle vehicle) { - this.vehicle = vehicle; - } - - /** - * Test whether physics-space coordinates should match the spatial's local - * coordinates. - * - * @return true if matching local coordinates, false if matching world - * coordinates - */ - public boolean isApplyPhysicsLocal() { - return applyPhysicsLocal; - } - - /** - * Alter whether physics-space coordinates should match the spatial's local - * coordinates. - * - * @param applyPhysicsLocal true→match local coordinates, - * false→match world coordinates (default=false) - */ - public void setApplyPhysicsLocal(boolean applyPhysicsLocal) { - this.applyPhysicsLocal = applyPhysicsLocal; - } - - /** - * Read the unique id of the native object. - * - * @return id (not zero) - */ - public long getObjectId(){ - return motionStateId; - } -// public void addMotionStateListener(PhysicsMotionStateListener listener){ -// listeners.add(listener); -// } -// -// public void removeMotionStateListener(PhysicsMotionStateListener listener){ -// listeners.remove(listener); -// } - - /** - * Finalize this motion state just before it is destroyed. Should be invoked - * only by a subclass or by the garbage collector. - * - * @throws Throwable ignored by the garbage collector - */ - @Override - protected void finalize() throws Throwable { - super.finalize(); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing MotionState {0}", Long.toHexString(motionStateId)); - finalizeNative(motionStateId); - } - - private native void finalizeNative(long objectId); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/VehicleTuning.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/VehicleTuning.java deleted file mode 100644 index 3a6dabbc7b..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/VehicleTuning.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.objects.infos; - -/** - * Typical tuning parameters for a PhysicsVehicle. - * - * @author normenhansen - */ -public class VehicleTuning { - /** - * suspension stiffness constant (10→off-road buggy, 50→sports - * car, 200→Formula-1 race car, default=5.88) - */ - public float suspensionStiffness = 5.88f; - /** - * suspension damping when compressed (0→no damping, default=0.83) - */ - public float suspensionCompression = 0.83f; - /** - * suspension damping when expanded (0→no damping, default=0.88) - */ - public float suspensionDamping = 0.88f; - /** - * maximum suspension travel distance (in centimeters, default=500) - */ - public float maxSuspensionTravelCm = 500f; - /** - * maximum force exerted by each wheel's suspension (default=6000) - */ - public float maxSuspensionForce = 6000f; - /** - * coefficient of friction between tyres and ground (0.8→realistic car, - * 10000→kart racer, default=10.5) - */ - public float frictionSlip = 10.5f; -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java b/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java deleted file mode 100644 index d56440911a..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.util; - -import com.jme3.bullet.collision.shapes.CollisionShape; -import com.jme3.bullet.collision.shapes.CompoundCollisionShape; -import com.jme3.bullet.collision.shapes.infos.ChildCollisionShape; -import com.jme3.math.Matrix3f; -import com.jme3.scene.Geometry; -import com.jme3.scene.Mesh; -import com.jme3.scene.Node; -import com.jme3.scene.Spatial; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.util.TempVars; -import java.util.Iterator; -import java.util.List; - -/** - * A utility class to generate debug spatials from Bullet collision shapes. - * - * @author CJ Hare, normenhansen - */ -public class DebugShapeFactory { - - /** The maximum corner for the aabb used for triangles to include in ConcaveShape processing.*/ -// private static final Vector3f aabbMax = new Vector3f(1e30f, 1e30f, 1e30f); - /** The minimum corner for the aabb used for triangles to include in ConcaveShape processing.*/ -// private static final Vector3f aabbMin = new Vector3f(-1e30f, -1e30f, -1e30f); - - /** - * Create a debug spatial from the specified collision shape. - *

- * This is mostly used internally. To attach a debug shape to a physics - * object, call attachDebugShape(AssetManager manager); on it. - * - * @param collisionShape the shape to visualize (may be null, unaffected) - * @return a new tree of geometries, or null - */ - public static Spatial getDebugShape(CollisionShape collisionShape) { - if (collisionShape == null) { - return null; - } - Spatial debugShape; - if (collisionShape instanceof CompoundCollisionShape) { - CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape; - List children = shape.getChildren(); - Node node = new Node("DebugShapeNode"); - for (Iterator it = children.iterator(); it.hasNext();) { - ChildCollisionShape childCollisionShape = it.next(); - CollisionShape ccollisionShape = childCollisionShape.shape; - Geometry geometry = createDebugShape(ccollisionShape); - - // apply translation - geometry.setLocalTranslation(childCollisionShape.location); - - // apply rotation - TempVars vars = TempVars.get(); - Matrix3f tempRot = vars.tempMat3; - - tempRot.set(geometry.getLocalRotation()); - childCollisionShape.rotation.mult(tempRot, tempRot); - geometry.setLocalRotation(tempRot); - - vars.release(); - - node.attachChild(geometry); - } - debugShape = node; - } else { - debugShape = createDebugShape(collisionShape); - } - if (debugShape == null) { - return null; - } - debugShape.updateGeometricState(); - return debugShape; - } - - /** - * Create a geometry for visualizing the specified shape. - * - * @param shape (not null, unaffected) - * @return a new geometry (not null) - */ - private static Geometry createDebugShape(CollisionShape shape) { - Geometry geom = new Geometry(); - geom.setMesh(DebugShapeFactory.getDebugMesh(shape)); -// geom.setLocalScale(shape.getScale()); - geom.updateModelBound(); - return geom; - } - - /** - * Create a mesh for visualizing the specified shape. - * - * @param shape (not null, unaffected) - * @return a new mesh (not null) - */ - public static Mesh getDebugMesh(CollisionShape shape) { - Mesh mesh = new Mesh(); - DebugMeshCallback callback = new DebugMeshCallback(); - long id = shape.getObjectId(); - getVertices(id, callback); - - mesh.setBuffer(Type.Position, 3, callback.getVertices()); - mesh.getFloatBuffer(Type.Position).clear(); - return mesh; - } - - private static native void getVertices(long shapeId, DebugMeshCallback buffer); -} diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/util/NativeMeshUtil.java b/jme3-bullet/src/main/java/com/jme3/bullet/util/NativeMeshUtil.java deleted file mode 100644 index caf172c821..0000000000 --- a/jme3-bullet/src/main/java/com/jme3/bullet/util/NativeMeshUtil.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2009-2018 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.bullet.util; - -import com.jme3.scene.Mesh; -import com.jme3.scene.VertexBuffer.Type; -import com.jme3.scene.mesh.IndexBuffer; -import com.jme3.util.BufferUtils; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; - -/** - * A utility class for interfacing with Native Bullet. - * - * @author normenhansen - */ -public class NativeMeshUtil { - - /** - * Pass a mesh to Native Bullet. - * - * @param mesh the JME mesh to pass (not null) - * @return the unique identifier of the resulting btTriangleIndexVertexArray - * (not 0) - */ - public static long getTriangleIndexVertexArray(Mesh mesh){ - ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4); - ByteBuffer vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); - int numVertices = mesh.getVertexCount(); - int vertexStride = 12; //3 verts * 4 bytes each - int numTriangles = mesh.getTriangleCount(); - int triangleIndexStride = 12; //3 index entries * 4 bytes each - - IndexBuffer indices = mesh.getIndicesAsList(); - FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); - vertices.rewind(); - - int verticesLength = mesh.getVertexCount() * 3; - for (int i = 0; i < verticesLength; i++) { - float tempFloat = vertices.get(); - vertexBase.putFloat(tempFloat); - } - - int indicesLength = mesh.getTriangleCount() * 3; - for (int i = 0; i < indicesLength; i++) { - triangleIndexBase.putInt(indices.get(i)); - } - vertices.rewind(); - vertices.clear(); - - return createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride); - } - - /** - * Instantiate a btTriangleIndexVertexArray. Native method. - * - * @param triangleIndexBase index buffer (not null) - * @param vertexBase vertex buffer (not null) - * @param numTraingles the number of triangles in the mesh (≥0) - * @param numVertices the number of vertices in the mesh (≥0) - * @param vertextStride (in bytes, >0) - * @param triangleIndexStride (in bytes, >0) - * @return the unique identifier of the resulting btTriangleIndexVertexArray - * (not 0) - */ - public static native long createTriangleIndexVertexArray(ByteBuffer triangleIndexBase, ByteBuffer vertexBase, int numTraingles, int numVertices, int vertextStride, int triangleIndexStride); - -} diff --git a/jme3-core/src/main/java/com/jme3/anim/Joint.java b/jme3-core/src/main/java/com/jme3/anim/Joint.java index f534797d29..eefa4797f3 100644 --- a/jme3-core/src/main/java/com/jme3/anim/Joint.java +++ b/jme3-core/src/main/java/com/jme3/anim/Joint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -342,6 +342,7 @@ public void cloneFields(Cloner cloner, Object original) { this.attachedNode = cloner.clone(attachedNode); this.targetGeometry = cloner.clone(targetGeometry); this.localTransform = cloner.clone(localTransform); + this.initialTransform = cloner.clone(initialTransform); this.inverseModelBindMatrix = cloner.clone(inverseModelBindMatrix); } diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java index 60947d7eac..d643598848 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -615,7 +615,7 @@ private BoundingVolume merge(float temp_radius, Vector3f temp_center, if (rCenter == null) { rVal.setCenter(rCenter = new Vector3f()); } - if (length > RADIUS_EPSILON) { + if (length > RADIUS_EPSILON && Float.isFinite(length)) { float coeff = (length + radiusDiff) / (2.0f * length); rCenter.set(center.addLocal(diff.multLocal(coeff))); } else { diff --git a/jme3-core/src/main/java/com/jme3/environment/EnvironmentCamera.java b/jme3-core/src/main/java/com/jme3/environment/EnvironmentCamera.java index 92163d398c..4966c001c9 100644 --- a/jme3-core/src/main/java/com/jme3/environment/EnvironmentCamera.java +++ b/jme3-core/src/main/java/com/jme3/environment/EnvironmentCamera.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2019 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -196,6 +196,24 @@ public void render(final RenderManager renderManager) { jobs.remove(0); } + /** + * Alter the background color of an initialized EnvironmentCamera. + * + * @param bgColor the desired color (not null, unaffected, default is the + * background color of the application's default viewport) + */ + public void setBackGroundColor(ColorRGBA bgColor) { + if (!isInitialized()) { + throw new IllegalStateException( + "The EnvironmentCamera is uninitialized."); + } + + backGroundColor.set(bgColor); + for (int i = 0; i < 6; ++i) { + viewports[i].setBackgroundColor(bgColor); + } + } + /** * Gets the size of environment cameras. * @@ -260,7 +278,7 @@ public ViewPort[] getViewPorts(){ @Override protected void initialize(Application app) { - this.backGroundColor = app.getViewPort().getBackgroundColor(); + this.backGroundColor = app.getViewPort().getBackgroundColor().clone(); final Camera[] cameras = new Camera[6]; final Texture2D[] textures = new Texture2D[6]; diff --git a/jme3-core/src/main/java/com/jme3/input/controls/TouchTrigger.java b/jme3-core/src/main/java/com/jme3/input/controls/TouchTrigger.java index eae9f78b55..9e0c22a8eb 100644 --- a/jme3-core/src/main/java/com/jme3/input/controls/TouchTrigger.java +++ b/jme3-core/src/main/java/com/jme3/input/controls/TouchTrigger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -58,9 +58,8 @@ public String getName() { } public static int touchHash(int keyCode) { - assert keyCode >= 0 && keyCode <= 255 : - "unexpected keyCode: " + keyCode; - return 0xfedcba98 + keyCode; + int result = 0xfedcba98 + keyCode; + return result; } @Override diff --git a/jme3-core/src/main/java/com/jme3/math/Vector3f.java b/jme3-core/src/main/java/com/jme3/math/Vector3f.java index c1d52b40a2..4a954f4887 100644 --- a/jme3-core/src/main/java/com/jme3/math/Vector3f.java +++ b/jme3-core/src/main/java/com/jme3/math/Vector3f.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -435,7 +435,18 @@ public boolean isUnitVector() { * @return the length or magnitude of the vector. */ public float length() { - return FastMath.sqrt(lengthSquared()); + /* + * Use double-precision arithmetic to reduce the chance of overflow + * (when lengthSquared > Float.MAX_VALUE) or underflow (when + * lengthSquared is < Float.MIN_VALUE). + */ + double xx = x; + double yy = y; + double zz = z; + double lengthSquared = xx * xx + yy * yy + zz * zz; + float result = (float) Math.sqrt(lengthSquared); + + return result; } /** @@ -470,7 +481,18 @@ public float distanceSquared(Vector3f v) { * @return the distance between the two vectors. */ public float distance(Vector3f v) { - return FastMath.sqrt(distanceSquared(v)); + /* + * Use double-precision arithmetic to reduce the chance of overflow + * (when distanceSquared > Float.MAX_VALUE) or underflow (when + * distanceSquared is < Float.MIN_VALUE). + */ + double dx = x - v.x; + double dy = y - v.y; + double dz = z - v.z; + double distanceSquared = dx * dx + dy * dy + dz * dz; + float result = (float) Math.sqrt(distanceSquared); + + return result; } /** diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java index 9f7c5ac309..3202af5628 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java @@ -195,6 +195,7 @@ public interface GL { public static final int GL_VERTEX_SHADER = 0x8B31; public static final int GL_ZERO = 0x0; public static final int GL_UNPACK_ROW_LENGTH = 0x0CF2; + public static final int GL_FRAMEBUFFER_BINDING = 0x8CA6; public void resetStats(); @@ -1300,4 +1301,4 @@ public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int * @param height the viewport height. */ public void glViewport(int x, int y, int width, int height); -} \ No newline at end of file +} diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index fed5800a9d..95b2ce7f1d 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -91,6 +91,7 @@ public final class GLRenderer implements Renderer { private final EnumMap limits = new EnumMap(Limits.class); private FrameBuffer mainFbOverride = null; + private int defaultFBO = 0; private final Statistics statistics = new Statistics(); private int vpX, vpY, vpW, vpH; private int clipX, clipY, clipW, clipH; @@ -630,6 +631,16 @@ public void initialize() { gl2.glEnable(GL2.GL_POINT_SPRITE); } } + + IntBuffer tmp = BufferUtils.createIntBuffer(16); + gl.glGetInteger(GL.GL_FRAMEBUFFER_BINDING, tmp); + tmp.rewind(); + int fbOnLoad = tmp.get(); + if(fbOnLoad > 0) + { + // Overriding default FB to fbOnLoad. Mostly iOS fix for scene processors and filters + defaultFBO = fbOnLoad; + } } @Override @@ -1856,10 +1867,10 @@ public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) { private void bindFrameBuffer(FrameBuffer fb) { if (fb == null) { - if (context.boundFBO != 0) { - glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, 0); + if (context.boundFBO != defaultFBO) { + glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, defaultFBO); statistics.onFrameBufferUse(null, true); - context.boundFBO = 0; + context.boundFBO = defaultFBO; context.boundFB = null; } } else { diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java index 96463c3240..29ff8050c7 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/IndexBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -77,7 +77,7 @@ public static IndexBuffer createIndexBuffer(int vertexCount, if (vertexCount < 128) { // TODO: could be vertexCount <= 256 ByteBuffer buffer = BufferUtils.createByteBuffer(indexCount); - int maxIndexValue = vertexCount - 1; + int maxIndexValue = Math.max(0, vertexCount - 1); result = new IndexByteBuffer(buffer, maxIndexValue); } else if (vertexCount < 65536) { // TODO: could be <= 65536 diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_SphereCollisionShape.cpp b/jme3-core/src/test/java/com/jme3/anim/JointCloneTest.java similarity index 69% rename from jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_SphereCollisionShape.cpp rename to jme3-core/src/test/java/com/jme3/anim/JointCloneTest.java index e161ed9bff..6ec094d8b6 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_collision_shapes_SphereCollisionShape.cpp +++ b/jme3-core/src/test/java/com/jme3/anim/JointCloneTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,29 +29,31 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package com.jme3.anim; + +import com.jme3.util.clone.Cloner; +import org.junit.Assert; +import org.junit.Test; /** - * Author: Normen Hansen + * Test cloning a Joint. + * + * @author Stephen Gold */ -#include "com_jme3_bullet_collision_shapes_SphereCollisionShape.h" -#include "jmeBulletUtil.h" - -#ifdef __cplusplus -extern "C" { -#endif +public class JointCloneTest { - /* - * Class: com_jme3_bullet_collision_shapes_SphereCollisionShape - * Method: createShape - * Signature: (F)J + /** + * Make sure the initial transform gets cloned. This was issue 1469 at + * Github. */ - JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_SphereCollisionShape_createShape - (JNIEnv *env, jobject object, jfloat radius) { - jmeClasses::initJavaClasses(env); - btSphereShape* shape=new btSphereShape(radius); - return reinterpret_cast(shape); - } + @Test + public void testInitialTransform() { + Joint testJoint = new Joint("testJoint"); + Assert.assertTrue(testJoint.getInitialTransform().isIdentity()); + + Joint clone = Cloner.deepClone(testJoint); + clone.getInitialTransform().setScale(2f); -#ifdef __cplusplus + Assert.assertTrue(testJoint.getInitialTransform().isIdentity()); + } } -#endif diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionEventFactory.java b/jme3-core/src/test/java/com/jme3/bounding/TestBoundingSphere.java similarity index 60% rename from jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionEventFactory.java rename to jme3-core/src/test/java/com/jme3/bounding/TestBoundingSphere.java index d8eb118797..7f75ec6550 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/PhysicsCollisionEventFactory.java +++ b/jme3-core/src/test/java/com/jme3/bounding/TestBoundingSphere.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,40 +29,38 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.jme3.bullet.collision; +package com.jme3.bounding; -import java.util.concurrent.ConcurrentLinkedQueue; +import com.jme3.math.Vector3f; +import org.junit.Assert; +import org.junit.Test; /** + * Test cases for the BoundingSphere class. * - * @author normenhansen + * @author Stephen Gold */ -public class PhysicsCollisionEventFactory { - - private ConcurrentLinkedQueue eventBuffer = new ConcurrentLinkedQueue(); +public class TestBoundingSphere { /** - * Obtain an unused event. - * - * @return an event (not null) + * Verify that an infinite bounding sphere can be merged with a very + * eccentric bounding box without producing NaNs. This was issue #1459 at + * GitHub. */ - public PhysicsCollisionEvent getEvent(int type, PhysicsCollisionObject source, PhysicsCollisionObject nodeB, long manifoldPointObjectId) { - PhysicsCollisionEvent event = eventBuffer.poll(); - if (event == null) { - event = new PhysicsCollisionEvent(type, source, nodeB, manifoldPointObjectId); - }else{ - event.refactor(type, source, nodeB, manifoldPointObjectId); - } - return event; - } + @Test + public void testIssue1459() { + Vector3f boxCenter = new Vector3f(-92f, 3.3194322e29f, 674.89886f); + BoundingBox boundingBox = new BoundingBox(boxCenter, + 1.0685959f, 3.3194322e29f, 2.705017f); - /** - * Recycle the specified event. - * - * @param event - */ - public void recycle(PhysicsCollisionEvent event) { - event.clean(); - eventBuffer.add(event); + Vector3f sphCenter = new Vector3f(0f, 0f, 0f); + float radius = Float.POSITIVE_INFINITY; + BoundingSphere boundingSphere = new BoundingSphere(radius, sphCenter); + + boundingSphere.mergeLocal(boundingBox); + + Vector3f copyCenter = new Vector3f(); + boundingSphere.getCenter(copyCenter); + Assert.assertTrue(Vector3f.isValidVector(copyCenter)); } } diff --git a/jme3-core/src/test/java/com/jme3/math/Vector3fTest.java b/jme3-core/src/test/java/com/jme3/math/Vector3fTest.java index 136f634745..c03719746e 100644 --- a/jme3-core/src/test/java/com/jme3/math/Vector3fTest.java +++ b/jme3-core/src/test/java/com/jme3/math/Vector3fTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2015 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -235,12 +235,16 @@ public void testCrossLocal() { assertEquals(-0.0f, retval.z, 0.0f); } + /** + * Verify that distance() doesn't always overflow when distanceSquared > + * Float.MAX_VALUE . + */ @Test public void testDistance() { final Vector3f target = new Vector3f(3.86405e+18f, 3.02146e+23f, 0.171875f); final Vector3f v = new Vector3f(-2.0f, -1.61503e+19f, 0.171875f); - - assertEquals(Float.POSITIVE_INFINITY, target.distance(v), 0.0f); + + assertEquals(3.0216215e23f, target.distance(v), 0f); } @Test @@ -540,11 +544,21 @@ public void testIsValidVector() { @Test public void testLength() { - assertEquals(0.0f, new Vector3f(1.88079e-37f, 0.0f, 1.55077e-36f).length(), 0.0f); + /* + * avoid underflow when lengthSquared is < Float.MIN_VALUE + */ + assertEquals(1.5621336e-36f, + new Vector3f(1.88079e-37f, 0.0f, 1.55077e-36f).length(), 0f); + assertEquals(Float.NaN, new Vector3f(Float.NaN, 0.0f, 1.55077e-36f).length(), 0.0f); assertEquals(Float.POSITIVE_INFINITY, new Vector3f(Float.POSITIVE_INFINITY, 0.0f, 1.0f).length(), 0.0f); + assertEquals(4.0124f, new Vector3f(1.9f, 3.2f, 1.5f).length(), 0.001f); - assertEquals(Float.POSITIVE_INFINITY, new Vector3f(1.8e37f, 1.8e37f, 1.5e36f).length(), 0.0f); + /* + * avoid overflow when lengthSquared > Float.MAX_VALUE + */ + assertEquals(2.5499999e37f, + new Vector3f(1.8e37f, 1.8e37f, 1.5e36f).length(), 0.0f); } @Test diff --git a/jme3-core/src/test/java/com/jme3/scene/PhantomTrianglesTest.java b/jme3-core/src/test/java/com/jme3/scene/PhantomTrianglesTest.java index 91f190e9dd..8f885c53e2 100644 --- a/jme3-core/src/test/java/com/jme3/scene/PhantomTrianglesTest.java +++ b/jme3-core/src/test/java/com/jme3/scene/PhantomTrianglesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 jMonkeyEngine + * Copyright (c) 2017-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,8 @@ import com.jme3.math.Ray; import com.jme3.math.Vector3f; import com.jme3.scene.shape.Quad; +import com.jme3.system.JmeSystem; +import com.jme3.system.MockJmeSystemDelegate; import org.junit.Test; /** @@ -114,6 +116,7 @@ void createWhiteLines() { @Test public void testPhantomTriangles() { + JmeSystem.setSystemDelegate(new MockJmeSystemDelegate()); assetManager = new DesktopAssetManager(); assetManager.registerLocator(null, ClasspathLocator.class); assetManager.registerLoader(J3MLoader.class, "j3m", "j3md"); diff --git a/jme3-examples/build.gradle b/jme3-examples/build.gradle index af9ec627f3..e7d42e8643 100644 --- a/jme3-examples/build.gradle +++ b/jme3-examples/build.gradle @@ -21,12 +21,7 @@ dependencies { compile project(':jme3-core') compile project(':jme3-desktop') compile project(':jme3-effects') - - // EITHER use jme3-bullet + jme3-bullet-native OR ELSE jme3-jbullet - compile project(':jme3-bullet') - compile project(':jme3-bullet-native') -// compile project(':jme3-jbullet') - + compile project(':jme3-jbullet') compile project(':jme3-jogg') compile project(':jme3-lwjgl') // compile project(':jme3-lwjgl3') @@ -58,9 +53,7 @@ jar.doFirst{ } } -task dist (dependsOn: ['build', ':jme3-bullet:jar', ':jme3-android:jar', \ - ':jme3-android-native:jar', ':jme3-bullet-native-android:jar', \ - ':jme3-bullet-native:jar']) { +task dist (dependsOn: ['build', ':jme3-android:jar', ':jme3-android-native:jar']) { doLast { // Copy all dependencies to ../dist/lib, remove versions from jar files configurations.compile.resolvedConfiguration.resolvedArtifacts.each { artifact -> @@ -80,18 +73,6 @@ task dist (dependsOn: ['build', ':jme3-bullet:jar', ':jme3-android:jar', \ rename { "jMonkeyEngine3.jar" } } - // Copy bullet packages, remove version - copy { - from project(':jme3-bullet').jar.archivePath - into '../dist/opt/native-bullet' - rename {project(':jme3-bullet').name+".jar"} - } - copy { - from project(':jme3-bullet-native').jar.archivePath - into '../dist/opt/native-bullet' - rename {project(':jme3-bullet-native').name+".jar"} - } - // Copy android packages, remove version copy { from project(':jme3-android').jar.archivePath @@ -103,10 +84,5 @@ task dist (dependsOn: ['build', ':jme3-bullet:jar', ':jme3-android:jar', \ into '../dist/opt/android' rename {project(':jme3-android-native').name+".jar"} } - copy { - from project(':jme3-bullet-native-android').jar.archivePath - into '../dist/opt/native-bullet' - rename {project(':jme3-bullet-native-android').name+".jar"} - } } } diff --git a/jme3-examples/gradle.properties b/jme3-examples/gradle.properties index 6f09931209..5b85c3b85b 100644 --- a/jme3-examples/gradle.properties +++ b/jme3-examples/gradle.properties @@ -1,5 +1,5 @@ -# When running this project we don't need javadoc to be built. -buildJavaDoc = false - # We want assertions, because this is the test project. assertions = true + +# Build javadoc per Github issue #1366 +buildJavaDoc = true \ No newline at end of file diff --git a/jme3-examples/src/main/java/jme3test/bullet/PhysicsTestHelper.java b/jme3-examples/src/main/java/jme3test/bullet/PhysicsTestHelper.java index 610e230495..372edca20c 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/PhysicsTestHelper.java +++ b/jme3-examples/src/main/java/jme3test/bullet/PhysicsTestHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -260,7 +260,7 @@ public void onAction(String name, boolean keyPressed, float tpf) { * @param assetManager for loading assets * @param floorDimensions width/depth of the "floor" (X/Z) * @param position sets the floor's local translation - * @return + * @return a new Geometry */ public static Geometry createGImpactTestFloor(AssetManager assetManager, float floorDimensions, Vector3f position) { Geometry floor = createTestFloor(assetManager, floorDimensions, position, ColorRGBA.Red); @@ -277,7 +277,7 @@ public static Geometry createGImpactTestFloor(AssetManager assetManager, float f * @param assetManager for loading assets * @param floorDimensions width/depth of the "floor" (X/Z) * @param position sets the floor's local translation - * @return + * @return a new Geometry */ public static Geometry createMeshTestFloor(AssetManager assetManager, float floorDimensions, Vector3f position) { Geometry floor = createTestFloor(assetManager, floorDimensions, position, new ColorRGBA(0.5f, 0.5f, 0.9f, 1)); diff --git a/jme3-ios/build.gradle b/jme3-ios/build.gradle index bc93216107..8eb91e0bc5 100644 --- a/jme3-ios/build.gradle +++ b/jme3-ios/build.gradle @@ -2,6 +2,9 @@ if (!hasProperty('mainClass')) { ext.mainClass = '' } +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + dependencies { compile project(':jme3-core') compile project(':jme3-plugins') diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java index 39f20a41a0..5de9d77500 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java @@ -33,8 +33,11 @@ import com.jme3.renderer.RendererException; import com.jme3.renderer.opengl.GL; +import com.jme3.renderer.opengl.GL2; +import com.jme3.renderer.opengl.GLES_30; import com.jme3.renderer.opengl.GLExt; import com.jme3.renderer.opengl.GLFbo; +import com.jme3.util.BufferUtils; import java.nio.Buffer; import java.nio.BufferOverflowException; import java.nio.ByteBuffer; @@ -43,13 +46,14 @@ import java.nio.ShortBuffer; /** - * Implements OpenGL ES 2.0 for iOS. + * Implements OpenGL ES 2.0 and 3.0 for iOS. * - * @author Kirill Vainer + * @author Kirill Vainer, Jesus Oliver */ -public class IosGL implements GL, GLExt, GLFbo { +public class IosGL implements GL, GL2, GLES_30, GLExt, GLFbo { private final int[] temp_array = new int[16]; + private final IntBuffer tmpBuff = BufferUtils.createIntBuffer(1); @Override public void resetStats() { @@ -129,7 +133,7 @@ public void glAttachShader(int program, int shader) { @Override public void glBeginQuery(int target, int query) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glBeginQuery(target, query); } @Override @@ -314,7 +318,7 @@ public void glEnableVertexAttribArray(int index) { @Override public void glEndQuery(int target) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glEndQuery(target); } @Override @@ -333,7 +337,7 @@ public void glGenTextures(IntBuffer textures) { @Override public void glGenQueries(int num, IntBuffer buff) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glGenQueries(num, buff); } @Override @@ -343,9 +347,7 @@ public int glGetAttribLocation(int program, String name) { @Override public void glGetBoolean(int pname, ByteBuffer params) { - // TODO: fix me!!! - // JmeIosGLES.glGetBoolean(pname, params); - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glGetBoolean(pname, params); } @Override @@ -374,12 +376,14 @@ public String glGetProgramInfoLog(int program, int maxLength) { @Override public long glGetQueryObjectui64(int query, int pname) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glGetQueryObjectuiv(query, pname, temp_array); + return temp_array[0]; } @Override public int glGetQueryObjectiv(int query, int pname) { - throw new UnsupportedOperationException("Today is not a good day for this"); + JmeIosGLES.glGetQueryiv(query, pname, temp_array); + return temp_array[0]; } @Override @@ -406,11 +410,11 @@ public int glGetUniformLocation(int program, String name) { @Override public boolean glIsEnabled(int cap) { - // TODO: fix me!!! + // kept this always returning true for compatibility if (cap == GLExt.GL_MULTISAMPLE_ARB) { return true; } else { - throw new UnsupportedOperationException(); + return JmeIosGLES.glIsEnabled(cap); } } @@ -454,25 +458,22 @@ public void glShaderSource(int shader, String[] string, IntBuffer length) { @Override public void glStencilFuncSeparate(int face, int func, int ref, int mask) { - // TODO: fix me!!! - // JmeIosGLES.glStencilFuncSeparate(face, func, ref, mask); + JmeIosGLES.glStencilFuncSeparate(face, func, ref, mask); } @Override public void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass) { - // TODO: fix me!!! - // JmeIosGLES.glStencilOpSeparate(face, sfail, dpfail, dppass); + JmeIosGLES.glStencilOpSeparate(face, sfail, dpfail, dppass); } @Override public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data) { - JmeIosGLES.glTexImage2D(target, level, format, width, height, 0, format, type, data); + JmeIosGLES.glTexImage2D(target, level, internalFormat, width, height, 0, format, type, data); } @Override public void glTexParameterf(int target, int pname, float param) { - // TODO: fix me!!! - // JmeIosGLES.glTexParameterf(target, pname, param); + JmeIosGLES.glTexParameterf(target, pname, param); } @Override @@ -583,7 +584,7 @@ public void glViewport(int x, int y, int width, int height) { @Override public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { - throw new UnsupportedOperationException("FBO blit not available on iOS"); + JmeIosGLES.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); } @Override @@ -598,17 +599,17 @@ public void glBufferSubData(int target, long offset, IntBuffer data) { @Override public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount) { - throw new UnsupportedOperationException("Instancing not available on iOS"); + JmeIosGLES.glDrawArraysInstanced(mode, first, count, primcount); } @Override public void glDrawBuffers(IntBuffer bufs) { - throw new UnsupportedOperationException("MRT not available on iOS"); + JmeIosGLES.glDrawBuffers(getLimitBytes(bufs), bufs); } @Override public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount) { - throw new UnsupportedOperationException("Instancing not available on iOS"); + JmeIosGLES.glDrawElementsInstanced(mode, indices_count, type, indices_buffer_offset, primcount); } @Override @@ -628,7 +629,7 @@ public void glTexImage2DMultisample(int target, int samples, int internalformat, @Override public void glVertexAttribDivisorARB(int index, int divisor) { - throw new UnsupportedOperationException("Instancing not available on iOS"); + JmeIosGLES.glVertexAttribDivisor(index, divisor); } @Override @@ -717,6 +718,59 @@ public Object glFenceSync(int condition, int flags) { @Override public void glFramebufferTextureLayerEXT(int target, int attachment, int texture, int level, int layer) { - throw new UnsupportedOperationException("OpenGL ES 2 does not support texture arrays"); + JmeIosGLES.glFramebufferTextureLayer(target, attachment, texture, level, layer); + } + + // New methods from GL2 interface which are supported in GLES30 + @Override + public void glAlphaFunc(int func, float ref) { + } + + @Override + public void glPointSize(float size) { + } + + @Override + public void glPolygonMode(int face, int mode) { + } + + // Wrapper to DrawBuffers as there's no DrawBuffer method in GLES + @Override + public void glDrawBuffer(int mode) { + ((Buffer)tmpBuff).clear(); + tmpBuff.put(0, mode); + tmpBuff.rewind(); + glDrawBuffers(tmpBuff); } + + @Override + public void glReadBuffer(int mode) { + JmeIosGLES.glReadBuffer(mode); + } + + @Override + public void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, + int border, ByteBuffer data) { + JmeIosGLES.glCompressedTexImage3D(target, level, internalFormat, width, height, depth, border, getLimitBytes(data), data); + } + + @Override + public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, + int height, int depth, int format, ByteBuffer data) { + JmeIosGLES.glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, getLimitBytes(data), data); + } + + @Override + public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border, + int format, int type, ByteBuffer data) { + JmeIosGLES.glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data); + } + + @Override + public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, + int depth, int format, int type, ByteBuffer data) { + JmeIosGLES.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data); + } + + } diff --git a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java index 2a2eee5b5a..347babbbd4 100644 --- a/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java +++ b/jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java @@ -3,14 +3,15 @@ import com.jme3.renderer.RendererException; import java.nio.Buffer; +import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.util.logging.Logger; /** - * The iOS GLES interface iOS alternative to Android's GLES20 class + * The iOS GLES interface iOS alternative to Android's GLES20 and GLES30 classes * - * @author Kostyantyn Hushchyn + * @author Kostyantyn Hushchyn, Jesus Oliver */ public class JmeIosGLES { private static final Logger logger = Logger.getLogger(JmeIosGLES.class.getName()); @@ -184,6 +185,7 @@ public class JmeIosGLES { public static native void glGenTextures(int n, int[] textures, int offset); public static native void glGenerateMipmap(int target); public static native int glGetAttribLocation(int program, String name); + public static native void glGetBoolean(int pname, ByteBuffer params); public static native int glGetError(); public static native void glGetFramebufferAttachmentParameteriv(int target, int attachment, int pname, int[] params, int offset); public static native void glGetIntegerv (int pname, int[] params, int offset); @@ -193,6 +195,7 @@ public class JmeIosGLES { public static native void glGetShaderiv(int shader, int pname, int[] params, int offset); public static native String glGetString(int name); public static native int glGetUniformLocation(int program, String name); + public static native boolean glIsEnabled(int cap); public static native boolean glIsFramebuffer(int framebuffer); public static native boolean glIsRenderbuffer(int renderbuffer); public static native void glLineWidth(float width); @@ -204,8 +207,11 @@ public class JmeIosGLES { public static native void glRenderbufferStorage(int target, int internalformat, int width, int height); public static native void glScissor(int x, int y, int width, int height); public static native void glShaderSource(int shader, String string); + public static native void glStencilFuncSeparate(int face, int func, int ref, int mask); + public static native void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass); public static native void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels); public static native void glTexParameteri(int target, int pname, int param); + public static native void glTexParameterf(int target, int pname, float param); public static native void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels); public static native void glUniform1f(int location, float x); public static native void glUniform1fv(int location, int count, FloatBuffer v); @@ -232,7 +238,31 @@ public class JmeIosGLES { public static native void glVertexAttribPointer2(int indx, int size, int type, boolean normalized, int stride, int offset); public static native void glViewport(int x, int y, int width, int height); + // New methods for GLES3 + public static native void glBeginQuery(int target, int query); + public static native void glEndQuery(int target); + public static native void glGenQueries(int num, IntBuffer buff); + public static native void glGetQueryObjectuiv(int query, int pname, int[] params); + public static native void glGetQueryiv(int query, int pname, int[] params); + public static native void glBlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter); + public static native void glDrawArraysInstanced(int mode, int first, int count, int primcount); + public static native void glDrawBuffers(int size, IntBuffer data); //TODO: use buffer or intbuffer? + public static native void glDrawElementsInstanced(int mode, int indices_count, int type, long indices_buffer_offset, int primcount); + public static native void glVertexAttribDivisor(int index, int divisor); + public static native void glFramebufferTextureLayer(int target, int attachment, int texture, int level, int layer); + + // New methods from GL2 interface which are supported in GLES30 + public static native void glReadBuffer(int mode); + public static native void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, + int border, int size, ByteBuffer data); + public static native void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, + int height, int depth, int format, int size, ByteBuffer data); + public static native void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border, + int format, int type, ByteBuffer data); + public static native void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, + int depth, int format, int type, ByteBuffer data); + public static void checkGLError() { if (!ENABLE_ERROR_CHECKING) { return; @@ -271,4 +301,4 @@ public static String gluErrorString(int error) { } */ -} \ No newline at end of file +} diff --git a/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainQuad.java b/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainQuad.java index 7eba10f403..6d447911dd 100644 --- a/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainQuad.java +++ b/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainQuad.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2020 jMonkeyEngine + * Copyright (c) 2009-2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -1734,6 +1734,7 @@ public void read(JmeImporter e) throws IOException { offsetAmount = c.readFloat("offsetAmount", 0); quadrant = c.readInt("quadrant", 0); totalSize = c.readInt("totalSize", 0); + patchSize = c.readInt("patchSize", 0); //lodCalculator = (LodCalculator) c.readSavable("lodCalculator", createDefaultLodCalculator()); //lodCalculatorFactory = (LodCalculatorFactory) c.readSavable("lodCalculatorFactory", null); @@ -1750,6 +1751,7 @@ public void write(JmeExporter e) throws IOException { OutputCapsule c = e.getCapsule(this); c.write(size, "size", 0); c.write(totalSize, "totalSize", 0); + c.write(patchSize, "patchSize", 0); c.write(stepScale, "stepScale", null); c.write(offset, "offset", new Vector2f(0,0)); c.write(offsetAmount, "offsetAmount", 0); diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugMeshCallback.java b/jme3-terrain/src/test/java/com/jme3/terrain/TestTerrainExporting.java similarity index 55% rename from jme3-bullet/src/main/java/com/jme3/bullet/util/DebugMeshCallback.java rename to jme3-terrain/src/test/java/com/jme3/terrain/TestTerrainExporting.java index f0bc3c45f3..7dceb63b0e 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugMeshCallback.java +++ b/jme3-terrain/src/test/java/com/jme3/terrain/TestTerrainExporting.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2021 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,44 +29,43 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.jme3.bullet.util; -import com.jme3.math.Vector3f; -import com.jme3.util.BufferUtils; -import java.nio.FloatBuffer; -import java.util.ArrayList; +package com.jme3.terrain; + +import com.jme3.export.binary.BinaryExporter; +import com.jme3.math.FastMath; +import com.jme3.terrain.collision.BaseAWTTest; +import com.jme3.terrain.geomipmap.TerrainQuad; +import com.jme3.terrain.heightmap.AbstractHeightMap; +import com.jme3.terrain.heightmap.ImageBasedHeightMap; +import com.jme3.texture.Texture; +import org.junit.Assert; +import org.junit.Test; /** + * Test saving/loading terrain. * - * @author normenhansen + * @author Ali-RS */ -public class DebugMeshCallback { - - private ArrayList list = new ArrayList(); +public class TestTerrainExporting extends BaseAWTTest { /** - * Add a vertex to the mesh under construction. - *

- * This method is invoked from native code. - * - * @param x local X coordinate of new vertex - * @param y local Y coordinate of new vertex - * @param z local Z coordinate of new vertex - * @param part ignored - * @param index ignored + * Test saving/loading a TerrainQuad. */ - public void addVector(float x, float y, float z, int part, int index) { - list.add(new Vector3f(x, y, z)); - } + @Test + public void testTerrainExporting() { + + Texture heightMapImage = getAssetManager().loadTexture("Textures/Terrain/splat/mountains512.png"); + AbstractHeightMap map = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); + map.load(); - public FloatBuffer getVertices() { - FloatBuffer buf = BufferUtils.createFloatBuffer(list.size() * 3); - for (int i = 0; i < list.size(); i++) { - Vector3f vector3f = list.get(i); - buf.put(vector3f.x); - buf.put(vector3f.y); - buf.put(vector3f.z); - } - return buf; + TerrainQuad terrain = new TerrainQuad("Terrain", 65, 513, map.getHeightMap()); + + TerrainQuad saveAndLoad = BinaryExporter.saveAndLoad(getAssetManager(), terrain); + + Assert.assertEquals(513, saveAndLoad.getTotalSize()); + Assert.assertEquals(65, saveAndLoad.getPatchSize()); + Assert.assertArrayEquals(terrain.getHeightMap(), saveAndLoad.getHeightMap(), FastMath.ZERO_TOLERANCE); } + } diff --git a/natives-snapshot.properties b/natives-snapshot.properties index dff06ec8a9..3d0c83a796 100644 --- a/natives-snapshot.properties +++ b/natives-snapshot.properties @@ -1 +1 @@ -natives.snapshot=5d00bb3fff5a0188c87ed998319547e5ffa9ef3a +natives.snapshot=8c4d52360c71e6061499337f87344d78a34ffc56 diff --git a/settings.gradle b/settings.gradle index fd51b5c410..78341dfa85 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,9 +26,6 @@ include 'jme3-android' include 'jme3-ios' //native builds -include 'jme3-bullet' //java -include 'jme3-bullet-native' //cpp -include 'jme3-bullet-native-android' //cpp include 'jme3-android-native' //cpp // Test Data project