Compare commits

...

77 Commits

Author SHA1 Message Date
Stephen Gold
1a05e3fc5f make TestMorph (in jme3-examples) more user-friendly 2020-04-25 17:08:39 -07:00
Github Actions
c303c899b9 [skip ci] update natives snapshot 2020-04-26 00:00:18 +00:00
Stephen Gold
9f026b41ca enable the main.yml workflow for v3.3 branch 2020-04-25 16:42:14 -07:00
Stephen Gold
d785a03ec1 update jmeVersion to 3.3.1 in gradle.properties 2020-04-25 10:58:10 -07:00
Stephen Gold
618e890ddb Fix issue 1360: ArmatureDebugAppState causes OpenGLException 2020-04-24 11:27:47 -07:00
Stephen Gold
1284671d6f T key had to be pressed 2x before worked in jme3test.terrain (4 files) 2020-04-24 11:27:36 -07:00
Stephen Gold
d5339a1ec0 improve initial camera orientations in jme3test.terrain (9 files) 2020-04-24 11:27:27 -07:00
Stephen Gold
1491ffe775 remove an unused empty file jme3test/light/DlsfError.java 2020-04-24 11:26:47 -07:00
rvandoosselaer
4b62b70a5b Set the minimum required OpenGL profiles for the geometry and tessellation shader test cases. Resolves #1357 2020-04-22 11:15:06 -07:00
Stephen Gold
9a5b3864b2 remove an unused empty file jme3test/collision/Main.java 2020-04-22 11:14:39 -07:00
Stephen Gold
f71c312338 Fixes issue #1350 for getters (MorphTrack documentation) 2020-04-22 11:14:25 -07:00
Stephen Gold
e09adbf014 Fixes issue #1350 (MorphTrack documentation) 2020-04-22 11:14:16 -07:00
Stephen Gold
415a52df51 convert tabs to blanks in FixedScale100.frag 2020-04-22 11:14:01 -07:00
Stephen Gold
5d969f29a1 correct a typographic error in TestUseAfterFree output 2020-04-22 11:12:34 -07:00
Stephen Gold
a667f5e8cd Revert "Fixes issue #1336: AWTPanels forcing OpenGL 2.0 (Compat Profile)"
This reverts commit 84912d5803431063083be125944597966d658e8e.
2020-04-21 08:29:56 -07:00
Stephen Gold
a150deb8be improve format and rm trailing whitespace (10 files in com.jme3.opencl) 2020-04-19 10:44:15 -07:00
Stephen Gold
1fa283f06a correct the javadoc of Matrix4f.set(float[][]) -- missing "not"! 2020-04-19 10:42:53 -07:00
Stephen Gold
06a8a056c1 clarify the javadoc of Quaternion.toString() "displaced"? 2020-04-19 10:42:40 -07:00
Stephen Gold
d99c378bdc add missing javadoc tags to BufferUtils 2020-04-19 10:39:57 -07:00
Stephen Gold
33ebbef214 add some missing javadoc (2 files in com.jme3.util) 2020-04-19 10:39:53 -07:00
Stephen Gold
84912d5803 Fixes issue #1336: AWTPanels forcing OpenGL 2.0 (Compat Profile) 2020-04-19 10:39:32 -07:00
Stephen Gold
e1d5e3c64d FastMathTest: test the reversibility of coordinate transformations 2020-04-19 10:38:41 -07:00
Stephen Gold
a1fb4837f5 add missing javadoc tags to 10 files in the com.jme3.math package 2020-04-19 10:38:11 -07:00
Stephen Gold
72de37be21 resolve an unknown HTML tag in the ColorRGBA javadoc 2020-04-19 10:38:01 -07:00
Stephen Gold
4731069110 javadoc correction: Quaternion.negate() doesn't "invert" anything 2020-04-19 10:37:14 -07:00
Stephen Gold
8896cd5a68 don't refer to transforms as "matrices" in the Transform javadoc 2020-04-19 10:37:00 -07:00
Stephen Gold
ede7af0573 remove the javadoc reference to the mythical USE_FAST_TRIG setting 2020-04-19 10:36:25 -07:00
Stephen Gold
a124fcd284 remove all javadoc references to the mythical JmeException 2020-04-19 10:36:17 -07:00
Stephen Gold
e98df18a9c improve formatting and rm trailing whitespace (16 files in jme3-core) 2020-04-19 10:35:53 -07:00
Stephen Gold
ce862bc09e IndexBuffer: resolve a javadoc warning 2020-04-19 10:29:04 -07:00
Stephen Gold
3a5f9661ab jme3-terrain: handle 2 more ByteBuffer cases 2020-04-19 10:28:50 -07:00
matthias plasser
c85e2bcfd4 Fixes #1341: AudioBuffer.updateData only allows direct buffers (#1342)
* only allowing direct buffers now, see: https://hub.jmonkeyengine.org/t/solved-playing-audio-from-audiobuffer-in-audionode-causes-jre-to-die/43091/12

* style correction

Co-authored-by: Stephen Gold <sgold@sonic.net>
2020-04-19 10:28:28 -07:00
Stephen Gold
98a283beb6 remove unnecessary casts and tests for null, discovered using NetBeans (#1285) 2020-04-18 22:33:15 -07:00
rvandoosselaer
9a84e72f03 Clean up the test case and add some more context. #1340 2020-04-18 22:22:03 -07:00
rvandoosselaer
227de6f22a Add a check to see if the NB_PROBES identifier is defined. Fixes #1340 2020-04-18 22:21:47 -07:00
rvandoosselaer
ded268a660 Add a check to see if the NB_PROBES identifier is defined. Fixes #1340 2020-04-18 22:21:24 -07:00
Riccardo Balbo
6d2ea28108 Fix last query not closed in profiler 2020-04-18 22:18:51 -07:00
Ali-RS
0bdb0159be Fixed an issue with AndroidNativeImageLoader which was opening stream twice. (#1338) 2020-04-18 22:18:24 -07:00
Stephen Gold
969e2808e4 correct some typographic errors in Billboard100.frag comments 2020-04-18 22:17:47 -07:00
Stephen Gold
a96dbe8604 elimiate incidental hard tabs from jme3-examples 2020-04-18 22:17:39 -07:00
Stephen Gold
efc9c443de elimiate incidental hard tabs from jme3-core 2020-04-18 22:17:25 -07:00
Jérôme
1acd1d299a Removes tabs 2020-04-18 22:16:54 -07:00
Jérôme
0e0c75c85c Migrate TestOgreComplexAnim to new anim system
Lots of code that did nothing in old test (on feet, hand). Only eft hand anim with the bone anim in simpleUpdate works. So I rework the test to do how actionSquence work and manipulate Armature and Joint with ArmatureMask apply.
So I think there is a bug in ArmatureDebugger when apply PointSize in material. In the render view all points on armature debug have same size.
2020-04-18 22:14:24 -07:00
Jérôme
61cbaa72ee Migrate TestBlenderObjectAnim to new anim system 2020-04-18 22:13:54 -07:00
Jérôme
821a18be21 Migrate TestCutomAnim to the new Animation system 2020-04-18 22:11:35 -07:00
Jérôme
68c6f71c73 Migrate TestSpatialAnim to the new Anim class
Remove all deprecated class and migrate to the new animation system.
2020-04-18 22:11:33 -07:00
Grabli66
21cbdb5da3 Fixes error of loading assets 2020-04-18 22:11:30 -07:00
MeFisto94
7e3ae5e8ca Fixes #1319 - LWJGL2: start(true) should not freeze when context could not be initialized 2020-04-18 22:06:43 -07:00
MeFisto94
828ca9212a UBO: Re-order the caps detection for a more clean code. 2020-04-18 22:06:10 -07:00
MeFisto94
5100d0b995 UBO: GL_INVALID_ENUM on Mesa 2020-04-18 22:06:06 -07:00
MeFisto94
66f316b3aa Fixes SSBO causing GL_INVALID_ENUM in Debug Mode 2020-04-18 22:06:03 -07:00
MeFisto94
f68d88937f GLSLCompat: The Matrix3 Sub-Constructor is called mat3_sub and defers to the builtin mat3 if available. 2020-04-18 22:05:29 -07:00
MeFisto94
728a07a25f Fixing PBR on <= GLSL 130:
- GLSLCompat now implements mat3(mat4) and determinant() and inverse() for mat2 and mat3
 - PBR.glslib uses this functions again instead of one-off workarounds
2020-04-18 22:05:24 -07:00
MeFisto94
4c2c3fa375 GLDebug: Throw an IllegalArgumentException instead of an IllegalStateException 2020-04-18 22:04:49 -07:00
MeFisto94
00281b21a1 GLDebug: Throw an unchecked exception instead of returning null to enforce a crash when glGetError is not present. 2020-04-18 22:04:45 -07:00
MeFisto94
b00c245e8e GLDebug: Use a method handle instead of a string comparison to increase the performance 2020-04-18 22:04:39 -07:00
Stephen Gold
9be8f5dd3a Use a reflection-based approach to call checkError() after every call to the openGL API to reduce Code Duplication and increase Maintainability, while also fixing the regression caused by GLDebugDesktop extending from GLDebugES and thus making the Renderer think it is on mobile. 2020-04-18 22:04:13 -07:00
MeFisto94
9dfbcde88c Fixes #1304 - Don't use mat3() constructor to keep compatibility with GLSL110 2020-04-18 21:56:21 -07:00
Riccardo Balbo
391e0dc6d0 Update checkout action to v2 2020-03-30 04:27:29 -04:00
Toni Helenius
1e7e12ee69 Fix for resizing the window (issue 1191) (#1308)
* Listen for framebuffer size callbacks and set the resolution from that

* Also check the window size on the framebuffer size callback
2020-03-24 04:48:25 -04:00
Stephen Gold
f0e09b2a9e main.yml: add Gradle-wrapper validation to several jobs 2020-03-24 04:47:32 -04:00
Toni Helenius
1198908555 Lwjgl3 restart input handle (#1268)
* Reinit inputs on context restart

* Added test issue from issue #1013

* Verify that the inputs are already initialized
2020-03-24 04:44:01 -04:00
Stephen Gold
fecd018fae BufferUtils: resolve issue #1288 (rewrite isDirect()) (#1299) 2020-03-24 04:42:02 -04:00
Stephen Gold
b102eabb56 Fixes issue #1286 2020-03-24 04:37:53 -04:00
Riccardo Balbo
836455826b Fix openal-soft dead link 2020-03-24 04:36:39 -04:00
Riccardo Balbo
3c93e50d99 Update link for stb_image.h 2020-03-24 04:36:08 -04:00
Ali-RS
78779ffe0a Removed extra PostShadow Technique from PBRLighting.j3md (#1273) 2020-03-24 04:33:19 -04:00
Toni Helenius
9002d088e7 Issue 801 (#1269)
* Test case for issue #801

* Reset the context with the initial values
2020-03-24 04:33:03 -04:00
Ryan McDonough
753c3cc173 PreShadow & PostShadow Support for PBRLighting.j3md (#1265)
* Update PBRLighting.j3md

* Create PreShadowPBR.frag

* Create PostShadowPBR.frag
2020-03-24 04:31:37 -04:00
MeFisto94
55a36abe9d Fixes #1261 - Clone the Terrain Picker, so that loading a terrain from file still works (after cloning, the picker would have the wrong terrain quad instance) 2020-03-24 04:29:34 -04:00
MeFisto94
17fbedd5fe Fixes Bullet-Native Artifacts not containing natives when not building from cpp source and not using the build target. 2020-03-24 04:26:30 -04:00
Riccardo Balbo
2e30b24438 Fix #1236 non-lvalue cannot be out parameter 2020-03-24 04:21:52 -04:00
Stephen Gold
bd1b6d284c com.jme3.scene.shape.Line: protect the no-argument constructor (#1234) 2019-12-21 08:48:51 -05:00
Stephen Gold
8a04afd7a1 AnimControl: correct javadoc for the no-arg constructor (#1233) 2019-12-21 08:48:43 -05:00
Stephen Gold
f9d2e03362 Mesh: avoid NPE in getMorphTargets() when there are no targets (#1231) 2019-12-21 08:48:25 -05:00
Paul Speed
8905b3d8f8 Refactored how versions are auto-built to provide more normal versions
when building locally.
Normal auto-detected versions will be based on the base version parsed
from the most recent tag on the branch with a -SNAPSHOT appended.  If
the current commit is the tagged commit then it is used directly to
preserve backwards compatibility... but really that should be a CI
only option for most use-cases.
A new includeBranchInVersion option was added to allow the old behavior
of including the branch name in a munged version string for those
wanting to keep their experimental branch builds separate from their
normal master/version-branch builds.
2019-12-21 08:43:59 -05:00
Riccardo Balbo
a2169999e5 Remove "v" from version tag to maintain consistency with old releases 2019-12-21 05:02:37 -05:00
259 changed files with 3943 additions and 3484 deletions

View File

@ -48,6 +48,7 @@ on:
branches:
- master
- newbuild
- v3.3
- v3.3.*
- v3.2
- v3.2.*
@ -66,10 +67,11 @@ jobs:
steps:
- name: Clone the repo
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Validate the Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build
run: |
# Build
@ -93,13 +95,14 @@ jobs:
steps:
- name: Clone the repo
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Validate the Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build
run: |
gradle -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \
./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \
:jme3-android-native:assemble \
:jme3-bullet-native-android:assemble
@ -129,7 +132,7 @@ jobs:
steps:
- name: Clone the repo
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 1
@ -138,7 +141,8 @@ jobs:
with:
java-version: ${{ matrix.jdk }}
architecture: x64
- name: Validate the Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build Natives
shell: bash
env:
@ -194,7 +198,7 @@ jobs:
steps:
- name: Clone the repo
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 1
@ -233,7 +237,8 @@ jobs:
with:
name: linuxarm-natives
path: build/native
- name: Validate the Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build Engine
shell: bash
run: |
@ -402,7 +407,7 @@ jobs:
# We need to clone everything again for uploadToMaven.sh ...
- name: Clone the repo
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 1

View File

@ -158,29 +158,29 @@ task configureAndroidNDK {
gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
if(skipPrebuildLibraries!="true"&&buildNativeProjects!="true"){
if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
String rootPath = rootProject.projectDir.absolutePath
Properties nativesSnasphotProp = new Properties()
File nativesSnasphotPropF=new File("${rootPath}/natives-snapshot.properties");
File nativesSnasphotPropF = new File("${rootPath}/natives-snapshot.properties");
if(nativesSnasphotPropF.exists()){
if (nativesSnasphotPropF.exists()) {
nativesSnasphotPropF.withInputStream { nativesSnasphotProp.load(it) }
String nativesSnasphot=nativesSnasphotProp.getProperty("natives.snapshot");
String nativesUrl=PREBUILD_NATIVES_URL.replace('${natives.snapshot}',nativesSnasphot)
println "Use natives snapshot: "+nativesUrl
String nativesSnasphot = nativesSnasphotProp.getProperty("natives.snapshot");
String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnasphot)
println "Use natives snapshot: " + nativesUrl
String nativesZipFile="${rootPath}" + File.separator + "build"+ File.separator +nativesSnasphot+"-natives.zip"
String nativesPath="${rootPath}" + File.separator + "build"+ File.separator +"native"
String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnasphot + "-natives.zip"
String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
task getNativesZipFile {
outputs.file nativesZipFile
doFirst {
File target = file(nativesZipFile);
println("Download natives from "+nativesUrl+" to "+nativesZipFile);
println("Download natives from " + nativesUrl + " to " + nativesZipFile);
target.getParentFile().mkdirs();
ant.get(src: nativesUrl, dest: target);
}
@ -192,28 +192,26 @@ if(skipPrebuildLibraries!="true"&&buildNativeProjects!="true"){
dependsOn getNativesZipFile
doFirst {
for(File src : zipTree(nativesZipFile)){
String srcRel=src.getAbsolutePath().substring((int)(nativesZipFile.length()+1));
srcRel=srcRel.substring(srcRel.indexOf( File.separator)+1);
for (File src : zipTree(nativesZipFile)) {
String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1));
srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1);
File dest=new File(nativesPath+File.separator+srcRel);
File dest = new File(nativesPath + File.separator + srcRel);
boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
if (doCopy) {
println("Copy "+src+" "+dest);
println("Copy " + src + " " + dest);
dest.getParentFile().mkdirs();
Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
}
build.dependsOn extractPrebuiltNatives
assemble.dependsOn extractPrebuiltNatives
}
}
//class IncrementalReverseTask extends DefaultTask {
// @InputDirectory
// def File inputDir

View File

@ -1,5 +1,5 @@
# Version number: Major.Minor.SubMinor (e.g. 3.3.0)
jmeVersion = 3.3.0
jmeVersion = 3.3.1
# Leave empty to autogenerate
# (use -PjmeVersionName="myVersion" from commandline to specify a custom version name )
@ -8,6 +8,10 @@ jmeVersionName =
# If true, the version name will contain the commit hash
useCommitHashAsVersionName = false
# Set to true if a non-master branch name should be included in the automatically
# generated version.
includeBranchInVersion = false
# specify if JavaDoc should be built
buildJavaDoc = true

View File

@ -286,7 +286,7 @@ public class MainActivity extends AppCompatActivity implements OnItemClickListen
private boolean checkClassType(String className) {
boolean include = true;
try {
Class<?> clazz = (Class<?>) Class.forName(className);
Class<?> clazz = Class.forName(className);
if (Application.class.isAssignableFrom(clazz)) {
Log.d(TAG, "Class " + className + " is a jME Application");
} else {

View File

@ -1,5 +1,5 @@
String tremorZipFile = "TremorAndroid.zip"
String stbiUrl = 'https://raw.githubusercontent.com/nothings/stb/master/stb_image.h'
String stbiUrl = 'https://raw.githubusercontent.com/jMonkeyEngine/stb/0224a44a10564a214595797b4c88323f79a5f934/stb_image.h'
// Working directories for the ndk build.
String decodeBuildDir = "${buildDir}" + File.separator + 'decode'

View File

@ -1,11 +1,11 @@
// OpenAL Soft r1.16
String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/e5016f814a265ed592a88acea95cf912c4bfdf12.zip'
String openALSoftUrl = 'https://github.com/jMonkeyEngine/openal-soft/archive/e5016f814a265ed592a88acea95cf912c4bfdf12.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-e5016f8'
String openALSoftFolder = 'openal-soft-e5016f814a265ed592a88acea95cf912c4bfdf12'
//Working directories for the ndk build.
String openalsoftBuildDir = "${buildDir}" + File.separator + 'openalsoft'

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -684,10 +684,10 @@ public class AndroidHarnessFragment extends Fragment implements
if (viewWidth > viewHeight && viewWidth > maxResolutionDimension) {
// landscape
fixedSizeWidth = maxResolutionDimension;
fixedSizeHeight = (int)(maxResolutionDimension * ((float)viewHeight / (float)viewWidth));
fixedSizeHeight = (int)(maxResolutionDimension * (viewHeight / (float)viewWidth));
} else if (viewHeight > viewWidth && viewHeight > maxResolutionDimension) {
// portrait
fixedSizeWidth = (int)(maxResolutionDimension * ((float)viewWidth / (float)viewHeight));
fixedSizeWidth = (int)(maxResolutionDimension * (viewWidth / (float)viewHeight));
fixedSizeHeight = maxResolutionDimension;
} else if (viewWidth == viewHeight && viewWidth > maxResolutionDimension) {
fixedSizeWidth = maxResolutionDimension;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -478,7 +478,7 @@ public class MjpegFileWriter {
baos.write(fcc);
baos.write(intBytes(swapInt(cb)));
for (int i = 0; i < ind.size(); i++) {
AVIIndex in = (AVIIndex) ind.get(i);
AVIIndex in = ind.get(i);
baos.write(in.toBytes());
}

View File

@ -345,7 +345,7 @@ public class VideoRecorderAppState extends AbstractAppState {
}
public float getTimePerFrame() {
return (float) (1.0f / this.framerate);
return 1.0f / this.framerate;
}
public void update() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -561,7 +561,7 @@ public class AndroidSensorJoyInput implements SensorEventListener {
}
}
}
} else if (sensorData != null) {
} else {
if (!sensorData.haveData) {
sensorData.haveData = true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -131,8 +131,8 @@ public class AndroidTouchInput implements TouchInput {
// view width and height are 0 until the view is displayed on the screen
if (androidInput.getView().getWidth() != 0 && androidInput.getView().getHeight() != 0) {
scaleX = (float)settings.getWidth() / (float)androidInput.getView().getWidth();
scaleY = (float)settings.getHeight() / (float)androidInput.getView().getHeight();
scaleX = settings.getWidth() / (float)androidInput.getView().getWidth();
scaleY = settings.getHeight() / (float)androidInput.getView().getHeight();
}
logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}",
new Object[]{scaleX, scaleY});

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -87,7 +87,7 @@ public class TouchEventPool {
TouchEvent evt = null;
int curSize = eventPool.size();
while (curSize > 0) {
evt = (TouchEvent)eventPool.pop();
evt = eventPool.pop();
if (evt.isConsumed()) {
break;
} else {

View File

@ -52,13 +52,7 @@ import com.jme3.input.controls.SoftTextDialogInputListener;
import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.renderer.android.AndroidGL;
import com.jme3.renderer.opengl.GL;
import com.jme3.renderer.opengl.GLES_30;
import com.jme3.renderer.opengl.GLDebugES;
import com.jme3.renderer.opengl.GLExt;
import com.jme3.renderer.opengl.GLFbo;
import com.jme3.renderer.opengl.GLRenderer;
import com.jme3.renderer.opengl.GLTracer;
import com.jme3.renderer.opengl.*;
import com.jme3.system.*;
import com.jme3.util.AndroidBufferAllocator;
import com.jme3.util.BufferAllocatorFactory;
@ -208,14 +202,14 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
});
timer = new NanoTimer();
Object gl = new AndroidGL();
GL gl = new AndroidGL();
if (settings.getBoolean("GraphicsDebug")) {
gl = new GLDebugES((GL) gl, (GLExt) gl, (GLFbo) gl);
gl = (GL) GLDebug.createProxy(gl, gl, GL.class, GL2.class, GLES_30.class, GLFbo.class, GLExt.class);
}
if (settings.getBoolean("GraphicsTrace")) {
gl = GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
gl = (GL)GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
}
renderer = new GLRenderer((GL)gl, (GLExt)gl, (GLFbo)gl);
renderer = new GLRenderer(gl, (GLExt)gl, (GLFbo)gl);
renderer.initialize();
JmeSystem.setSoftTextDialogInput(this);
@ -254,7 +248,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
}
if (settings.getFrameRate() > 0) {
minFrameDuration = (long)(1000d / (double)settings.getFrameRate()); // ms
minFrameDuration = (long)(1000d / settings.getFrameRate()); // ms
logger.log(Level.FINE, "Setting min tpf: {0}ms", minFrameDuration);
} else {
minFrameDuration = 0;

View File

@ -30,7 +30,7 @@ public class AndroidNativeImageLoader implements AssetLoader {
InputStream in = null;
try {
in = info.openStream();
return load(info.openStream(), flip, tmpArray);
return load(in, flip, tmpArray);
} finally {
if (in != null){
in.close();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -252,7 +252,7 @@ public class Structure implements Cloneable {
Object fieldValue = this.getFieldValue("ID");
if (fieldValue instanceof Structure) {
Structure id = (Structure) fieldValue;
return id == null ? null : id.getFieldValue("name").toString().substring(2);// blender adds 2-charactes as a name prefix
return id.getFieldValue("name").toString().substring(2);// blender adds 2-charactes as a name prefix
}
Object name = this.getFieldValue("name", null);
return name == null ? null : name.toString().substring(2);

View File

@ -251,7 +251,7 @@ import com.jme3.util.BufferUtils;
}
}
if (vertexGroups != null && vertexGroups.size() > 0) {
if (vertexGroups.size() > 0) {
Map<Float, Integer> group = vertexGroups.get(i);
maximumWeightsPerVertex = Math.max(maximumWeightsPerVertex, group.size());
boneWeightAndIndexes.add(new TreeMap<Float, Integer>(group));

View File

@ -464,7 +464,7 @@ import com.jme3.scene.plugins.blender.textures.generating.TextureGeneratorMusgra
sum += t * amp;
}
sum *= (float) (1 << noiseDepth) / (float) ((1 << noiseDepth + 1) - 1);
sum *= (1 << noiseDepth) / (float) ((1 << noiseDepth + 1) - 1);
return sum;
}

View File

@ -409,7 +409,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P
while (it.hasNext()) {
boneName = it.next();
bone = (Bone) boneLinks.get(boneName).bone;
bone = boneLinks.get(boneName).bone;
if (!bone.hasUserControl()) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
continue;
@ -421,7 +421,7 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P
}
int depth = 0;
int maxDepth = ikChainDepth.get(bone.getName());
updateBone(boneLinks.get(bone.getName()), tpf * (float) FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
updateBone(boneLinks.get(bone.getName()), tpf * FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
Vector3f position = vars.vect1;
@ -693,10 +693,10 @@ public class KinematicRagdollControl extends AbstractPhysicsControl implements P
shape = RagdollUtils.makeShapeFromVerticeWeights(model, RagdollUtils.getBoneIndices(link.bone, skeleton, boneList), initScale, link.bone.getModelSpacePosition(), weightThreshold);
}
PhysicsRigidBody shapeNode = new PhysicsRigidBody(shape, rootMass / (float) reccount);
PhysicsRigidBody shapeNode = new PhysicsRigidBody(shape, rootMass / reccount);
shapeNode.setKinematic(mode == Mode.Kinematic);
totalMass += rootMass / (float) reccount;
totalMass += rootMass / reccount;
link.rigidBody = shapeNode;
link.initalWorldRotation = bone.getModelSpaceRotation().clone();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -229,7 +229,7 @@ public class CollisionShapeFactory {
*/
public static CollisionShape createBoxShape(Spatial spatial) {
if (spatial instanceof Geometry) {
return createSingleBoxShape((Geometry) spatial, spatial);
return createSingleBoxShape(spatial, spatial);
} else if (spatial instanceof Node) {
return createBoxCompoundShape((Node) spatial);
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -539,7 +539,7 @@ public class PhysicsSpace {
Spatial node = (Spatial) obj;
for (int i = 0; i < node.getNumControls(); i++) {
if (node.getControl(i) instanceof PhysicsControl) {
add(((PhysicsControl) node.getControl(i)));
add(node.getControl(i));
}
}
} else if (obj instanceof PhysicsCollisionObject) {
@ -581,7 +581,7 @@ public class PhysicsSpace {
Spatial node = (Spatial) obj;
for (int i = 0; i < node.getNumControls(); i++) {
if (node.getControl(i) instanceof PhysicsControl) {
remove(((PhysicsControl) node.getControl(i)));
remove(node.getControl(i));
}
}
} else if (obj instanceof PhysicsCollisionObject) {
@ -1129,7 +1129,7 @@ public class PhysicsSpace {
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end) {
List results = new LinkedList();
sweepTest(shape, start, end , results);
return (List<PhysicsSweepTestResult>) results;
return results;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -65,8 +65,10 @@ public class MorphTrack implements AnimTrack<float[]> {
/**
* Creates a morph track with the given Geometry as a target
*
* @param times a float array with the time of each frame
* @param weights the morphs for each frames
* @param times a float array with the time of each frame (alias created
* -- do not modify after passing it to this constructor)
* @param weights the morphs for each frames (alias created -- do not
* modify after passing it to this constructor)
*/
public MorphTrack(Geometry target, float[] times, float[] weights, int nbMorphTargets) {
this.target = target;
@ -77,7 +79,7 @@ public class MorphTrack implements AnimTrack<float[]> {
/**
* return the array of weights of this track
*
* @return the pre-existing array
* @return the pre-existing array -- do not modify
*/
public float[] getWeights() {
return weights;
@ -86,7 +88,7 @@ public class MorphTrack implements AnimTrack<float[]> {
/**
* returns the arrays of time for this track
*
* @return the pre-existing array
* @return the pre-existing array -- do not modify
*/
public float[] getTimes() {
return times;
@ -95,7 +97,8 @@ public class MorphTrack implements AnimTrack<float[]> {
/**
* Sets the keyframes times for this Joint track
*
* @param times the keyframes times
* @param times the keyframes times (alias created -- do not modify after
* passing it to this setter)
*/
public void setTimes(float[] times) {
if (times.length == 0) {
@ -109,9 +112,10 @@ public class MorphTrack implements AnimTrack<float[]> {
/**
* Set the weight for this morph track
*
* @param times a float array with the time of each frame
* @param weights the weights of the morphs for each frame
* @param times a float array with the time of each frame (alias created
* -- do not modify after passing it to this setter)
* @param weights the weights of the morphs for each frame (alias created
* -- do not modify after passing it to this setter)
*/
public void setKeyframes(float[] times, float[] weights) {
setTimes(times);
@ -122,7 +126,7 @@ public class MorphTrack implements AnimTrack<float[]> {
this.weights = weights;
assert times != null && times.length == weights.length;
assert times.length == weights.length;
}
}
@ -211,6 +215,7 @@ public class MorphTrack implements AnimTrack<float[]> {
@Override
public void cloneFields(Cloner cloner, Object original) {
this.target = cloner.clone(target);
// Note: interpolator, times, and weights are not cloned
}

View File

@ -17,7 +17,7 @@ public class LinearBlendSpace implements BlendSpace {
public void setBlendAction(BlendAction action) {
this.action = action;
Action[] actions = action.getActions();
step = (maxValue - minValue) / (float) (actions.length - 1);
step = (maxValue - minValue) / (actions.length - 1);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2019 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -102,7 +102,9 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
}
/**
* Serialization only. Do not use.
* Instantiate an animation control with no skeleton, suitable only for
* animations that don't contain any bone tracks. Also used for
* serialization.
*/
public AnimControl() {
}
@ -144,6 +146,7 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
/**
* Retrieve an animation from the list of animations.
*
* @param name The name of the animation to retrieve.
* @return The animation corresponding to the given name, or null, if no
* such named animation exists.
@ -155,6 +158,7 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
/**
* Adds an animation to be available for playing to this
* <code>AnimControl</code>.
*
* @param anim The animation to add.
*/
public void addAnim(Animation anim) {
@ -163,6 +167,7 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
/**
* Remove an animation so that it is no longer available for playing.
*
* @param anim The animation to remove.
*/
public void removeAnim(Animation anim) {
@ -231,6 +236,7 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
/**
* Adds a new listener to receive animation related events.
*
* @param listener The listener to add.
*/
public void addListener(AnimEventListener listener) {
@ -244,6 +250,7 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
/**
* Removes the given listener from listening to events.
*
* @param listener
* @see AnimControl#addListener(com.jme3.animation.AnimEventListener)
*/
@ -308,6 +315,7 @@ public final class AnimControl extends AbstractControl implements Cloneable, Jme
/**
* Returns the length of the given named animation.
*
* @param name The name of the animation
* @return The length of time, in seconds, of the named animation.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -287,12 +287,12 @@ public class AnimationFactory {
//frames delta
int dF = keyFrameIndex - prev;
//angle per frame for x,y ,z
float dXAngle = (x - prevRot.eulerAngles.x) / (float) dF;
float dYAngle = (y - prevRot.eulerAngles.y) / (float) dF;
float dZAngle = (z - prevRot.eulerAngles.z) / (float) dF;
float dXAngle = (x - prevRot.eulerAngles.x) / dF;
float dYAngle = (y - prevRot.eulerAngles.y) / dF;
float dZAngle = (z - prevRot.eulerAngles.z) / dF;
// the keyFrame step
int keyStep = (int) (((float) (dF)) / delta * (float) EULER_STEP);
int keyStep = (int) (dF / delta * EULER_STEP);
// the current keyFrame
int cursor = prev + keyStep;
while (cursor < keyFrameIndex) {
@ -425,7 +425,7 @@ public class AnimationFactory {
//interating over the frames
for (int j = i; j <= key; j++) {
// computing interpolation value
float val = (float) (j - i) / (float) span;
float val = (j - i) / (float) span;
//interpolationg depending on the transform type
switch (type) {
case Translation:
@ -451,7 +451,7 @@ public class AnimationFactory {
translations[j] = ((Vector3f) keyFrames[i]).clone();
break;
case Rotation:
rotations[j] = ((Quaternion) ((Rotation) keyFrames[i]).rotation).clone();
rotations[j] = ((Rotation) keyFrames[i]).rotation.clone();
break;
case Scale:
scales[j] = ((Vector3f) keyFrames[i]).clone();

View File

@ -89,7 +89,7 @@ public final class BoneTrack implements JmeCloneable, Track {
* @param scales the scale of the bone for each frame
*/
public BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) {
this.targetBoneIndex = targetBoneIndex;
this.targetBoneIndex = targetBoneIndex;
this.setKeyframes(times, translations, rotations, scales);
}

View File

@ -38,6 +38,7 @@ public class DetailedProfiler implements AppProfiler {
@Override
public void appStep(AppStep step) {
curAppPath = step.name();
if (step == AppStep.BeginFrame) {
@ -102,7 +103,10 @@ public class DetailedProfiler implements AppProfiler {
private void closeFrame() {
//close frame
if (data != null) {
if (ongoingGpuProfiling && renderer != null) {
renderer.stopProfiling();
ongoingGpuProfiling = false;
}
prevPath = null;
for (StatLine statLine : data.values()) {
@ -284,7 +288,7 @@ public class DetailedProfiler implements AppProfiler {
if (nbFramesCpu == 0) {
return 0;
}
return (double) cpuSum / (double) Math.min(nbFramesCpu, MAX_FRAMES);
return cpuSum / (double) Math.min(nbFramesCpu, MAX_FRAMES);
}
public double getAverageGpu() {
@ -292,7 +296,7 @@ public class DetailedProfiler implements AppProfiler {
return 0;
}
return (double) gpuSum / (double) Math.min(nbFramesGpu, MAX_FRAMES);
return gpuSum / (double) Math.min(nbFramesGpu, MAX_FRAMES);
}
}

View File

@ -695,7 +695,7 @@ public class LegacyApplication implements Application, SystemListener {
* Runs tasks enqueued via {@link #enqueue(Callable)}
*/
protected void runQueuedTasks() {
AppTask<?> task;
AppTask<?> task;
while( (task = taskQueue.poll()) != null ) {
if (!task.isCancelled()) {
task.invoke();

View File

@ -388,11 +388,11 @@ public class DesktopAssetManager implements AssetManager {
}
public Texture loadTexture(TextureKey key){
return (Texture) loadAsset(key);
return loadAsset(key);
}
public Material loadMaterial(String name){
return (Material) loadAsset(new MaterialKey(name));
return loadAsset(new MaterialKey(name));
}
public Texture loadTexture(String name){
@ -402,7 +402,7 @@ public class DesktopAssetManager implements AssetManager {
}
public AudioData loadAudio(AudioKey key){
return (AudioData) loadAsset(key);
return loadAsset(key);
}
public AudioData loadAudio(String name){
@ -414,7 +414,7 @@ public class DesktopAssetManager implements AssetManager {
}
public Spatial loadModel(ModelKey key){
return (Spatial) loadAsset(key);
return loadAsset(key);
}
public Spatial loadModel(String name){
@ -422,7 +422,7 @@ public class DesktopAssetManager implements AssetManager {
}
public FilterPostProcessor loadFilter(FilterKey key){
return (FilterPostProcessor) loadAsset(key);
return loadAsset(key);
}
public FilterPostProcessor loadFilter(String name){

View File

@ -31,9 +31,9 @@
*/
package com.jme3.audio;
import com.jme3.audio.AudioData.DataType;
import com.jme3.util.BufferUtils;
import com.jme3.util.NativeObject;
import java.nio.ByteBuffer;
/**
@ -85,8 +85,14 @@ public class AudioBuffer extends AudioData {
/**
* Update the data in the buffer with new data.
* @param data
* @throws IllegalArgumentException if the provided buffer is not a direct buffer
*/
public void updateData(ByteBuffer data){
if (!data.isDirect()) {
throw new IllegalArgumentException(
"Currently only direct buffers are allowed");
}
this.audioData = data;
updateNeeded = true;
}

View File

@ -161,7 +161,7 @@ public class AudioNode extends Node implements AudioSource {
@Deprecated
public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) {
this.audioKey = new AudioKey(name, stream, streamCache);
this.data = (AudioData) assetManager.loadAsset(audioKey);
this.data = assetManager.loadAsset(audioKey);
}
/**

View File

@ -821,7 +821,7 @@ public class ALAudioRenderer implements AudioRenderer, Runnable {
al.alSourcei(sourceId, EFX.AL_DIRECT_FILTER, EFX.AL_FILTER_NULL);
}
if (src.isPositional()) {
AudioSource pas = (AudioSource) src;
AudioSource pas = src;
if (pas.isReverbEnabled() && supportEfx) {
al.alSource3i(sourceId, EFX.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX.AL_FILTER_NULL);
}

View File

@ -136,8 +136,10 @@ public class BoundingBox extends BoundingVolume {
TempVars vars = TempVars.get();
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY,
Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f point;
for (int i = start; i < end; i++) {
@ -238,8 +240,12 @@ public class BoundingBox extends BoundingVolume {
float[] tmpArray = vars.skinPositions;
float minX = Float.POSITIVE_INFINITY, minY = Float.POSITIVE_INFINITY, minZ = Float.POSITIVE_INFINITY;
float maxX = Float.NEGATIVE_INFINITY, maxY = Float.NEGATIVE_INFINITY, maxZ = Float.NEGATIVE_INFINITY;
float minX = Float.POSITIVE_INFINITY,
minY = Float.POSITIVE_INFINITY,
minZ = Float.POSITIVE_INFINITY;
float maxX = Float.NEGATIVE_INFINITY,
maxY = Float.NEGATIVE_INFINITY,
maxZ = Float.NEGATIVE_INFINITY;
int iterations = (int) FastMath.ceil(points.limit() / ((float) tmpArray.length));
for (int i = iterations - 1; i >= 0; i--) {
@ -248,8 +254,8 @@ public class BoundingBox extends BoundingVolume {
for (int j = 0; j < bufLength; j += 3) {
vars.vect1.x = tmpArray[j];
vars.vect1.y = tmpArray[j+1];
vars.vect1.z = tmpArray[j+2];
vars.vect1.y = tmpArray[j + 1];
vars.vect1.z = tmpArray[j + 2];
if (vars.vect1.x < minX) {
minX = vars.vect1.x;
@ -314,7 +320,9 @@ public class BoundingBox extends BoundingVolume {
transMatrix.absoluteLocal();
Vector3f scale = trans.getScale();
vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z));
vars.vect1.set(xExtent * FastMath.abs(scale.x),
yExtent * FastMath.abs(scale.y),
zExtent * FastMath.abs(scale.z));
transMatrix.mult(vars.vect1, vars.vect2);
// Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect2.getX());
@ -335,7 +343,6 @@ public class BoundingBox extends BoundingVolume {
}
TempVars vars = TempVars.get();
float w = trans.multProj(center, box.center);
box.center.divideLocal(w);
@ -425,13 +432,12 @@ public class BoundingBox extends BoundingVolume {
// case OBB: {
// return mergeOBB((OrientedBoundingBox) volume);
// }
default:
return null;
}
}
/**
/*
* Merges this AABB with the given OBB.
*
* @param volume
@ -474,6 +480,7 @@ public class BoundingBox extends BoundingVolume {
// zExtent = max.z - center.z;
// return this;
// }
/**
* <code>mergeLocal</code> combines this bounding box locally with a second
* bounding box described by its center and extents.
@ -621,7 +628,7 @@ public class BoundingBox extends BoundingVolume {
}
}
/**
/*
* determines if this bounding box intersects with a given oriented bounding
* box.
*
@ -771,8 +778,11 @@ public class BoundingBox extends BoundingVolume {
&& clip(-direction.z, +diff.z - zExtent, t);
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
if (t[1] > t[0]) return 2;
else return 1;
if (t[1] > t[0]) {
return 2;
} else {
return 1;
}
}
return 0;
} finally {
@ -801,7 +811,7 @@ public class BoundingBox extends BoundingVolume {
}
return 0;
} else if (other instanceof Spatial) {
return ((Spatial)other).collideWith(this, results);
return other.collideWith(this, results);
} else {
throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
}
@ -855,10 +865,10 @@ public class BoundingBox extends BoundingVolume {
public float distanceToEdge(Vector3f point) {
// compute coordinates of point in box coordinate system
TempVars vars= TempVars.get();
TempVars vars = TempVars.get();
Vector3f closest = vars.vect1;
point.subtract(center,closest);
point.subtract(center, closest);
// project test point onto box
float sqrDistance = 0.0f;

View File

@ -148,24 +148,24 @@ public class BoundingSphere extends BoundingVolume {
// * <code>computeFromTris</code> creates a new Bounding Box from a given
// * set of triangles. It is used in OBBTree calculations.
// *
// * @param indices
// * @param mesh
// * @param indices
// * @param mesh
// * @param start
// * @param end
// */
// public void computeFromTris(int[] indices, Mesh mesh, int start, int end) {
// if (end - start <= 0) {
// if (end - start <= 0) {
// return;
// }
//
// Vector3f[] vertList = new Vector3f[(end - start) * 3];
// Vector3f[] vertList = new Vector3f[(end - start) * 3];
//
// int count = 0;
// for (int i = start; i < end; i++) {
// mesh.getTriangle(indices[i], verts);
// vertList[count++] = new Vector3f(verts[0]);
// vertList[count++] = new Vector3f(verts[1]);
// vertList[count++] = new Vector3f(verts[2]);
// mesh.getTriangle(indices[i], verts);
// vertList[count++] = new Vector3f(verts[0]);
// vertList[count++] = new Vector3f(verts[1]);
// vertList[count++] = new Vector3f(verts[2]);
// }
//
// averagePoints(vertList);
@ -486,7 +486,7 @@ public class BoundingSphere extends BoundingVolume {
}
// case OBB: {
// OrientedBoundingBox box = (OrientedBoundingBox) volume;
// OrientedBoundingBox box = (OrientedBoundingBox) volume;
// BoundingSphere rVal = (BoundingSphere) this.clone(null);
// return rVal.mergeOBB(box);
// }
@ -532,7 +532,7 @@ public class BoundingSphere extends BoundingVolume {
}
// case OBB: {
// return mergeOBB((OrientedBoundingBox) volume);
// return mergeOBB((OrientedBoundingBox) volume);
// }
default:
@ -1003,7 +1003,7 @@ public class BoundingSphere extends BoundingVolume {
}
return 0;
} else if (other instanceof Spatial) {
return ((Spatial)other).collideWith(this, results);
return other.collideWith(this, results);
} else {
throw new UnsupportedCollisionException();
}

View File

@ -49,7 +49,6 @@ import java.nio.FloatBuffer;
* @version $Id: BoundingVolume.java,v 1.24 2007/09/21 15:45:32 nca Exp $
*/
public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/**
* The type of bounding volume being used.
*/
@ -58,12 +57,10 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
* {@link BoundingSphere}
*/
Sphere,
/**
* {@link BoundingBox}.
*/
AABB,
/**
* Currently unsupported by jME3.
*/
@ -82,7 +79,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/**
* Grabs the checkplane we should check first.
*
*/
public int getCheckPlane() {
return checkPlane;
@ -103,7 +99,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract Type getType();
/**
*
* <code>transform</code> alters the location of the bounding volume by a
* rotation, translation and a scalar.
*
@ -116,7 +111,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
}
/**
*
* <code>transform</code> alters the location of the bounding volume by a
* rotation, translation and a scalar.
*
@ -131,7 +125,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract BoundingVolume transform(Matrix4f trans, BoundingVolume store);
/**
*
* <code>whichSide</code> returns the side on which the bounding volume
* lies on a plane. Possible values are POSITIVE_SIDE, NEGATIVE_SIDE, and
* NO_SIDE.
@ -143,7 +136,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract Plane.Side whichSide(Plane plane);
/**
*
* <code>computeFromPoints</code> generates a bounding volume that
* encompasses a collection of points.
*
@ -255,7 +247,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/
public abstract boolean intersects(Ray ray);
/**
* determines if this bounding volume and a given bounding sphere are
* intersecting.
@ -276,7 +267,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/
public abstract boolean intersectsBoundingBox(BoundingBox bb);
/**
/*
* determines if this bounding volume and a given bounding box are
* intersecting.
*
@ -284,9 +275,8 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
* the bounding box to test against.
* @return true if this volume intersects the given bounding box.
*/
// public abstract boolean intersectsOrientedBoundingBox(OrientedBoundingBox bb);
// public abstract boolean intersectsOrientedBoundingBox(OrientedBoundingBox bb);
/**
*
* determines if a given point is contained within this bounding volume.
* If the point is on the edge of the bounding volume, this method will
* return false. Use intersects(Vector3f) to check for edge intersection.
@ -299,6 +289,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/**
* Determines if a given point intersects (touches or is inside) this bounding volume.
*
* @param point the point to check
* @return true if the point lies within this bounding volume.
*/
@ -308,11 +299,11 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
@Override
public BoundingVolume clone() {
try{
try {
BoundingVolume clone = (BoundingVolume) super.clone();
clone.center = center.clone();
return clone;
}catch (CloneNotSupportedException ex){
} catch (CloneNotSupportedException ex) {
throw new AssertionError();
}
}
@ -336,4 +327,3 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
}
}
}

View File

@ -121,8 +121,8 @@ public final class Intersection {
// private boolean axisTestX01(float a, float b, float fa, float fb,
// Vector3f center, Vector3f ext,
// Vector3f v1, Vector3f v2, Vector3f v3){
// float p0 = a * v0.y - b * v0.z;
// float p2 = a * v2.y - b * v2.z;
// float p0 = a * v0.y - b * v0.z;
// float p2 = a * v2.y - b * v2.z;
// if(p0 < p2){
// min = p0;
// max = p2;
@ -130,8 +130,8 @@ public final class Intersection {
// min = p2;
// max = p0;
// }
// float rad = fa * boxhalfsize.y + fb * boxhalfsize.z;
// if(min > rad || max < -rad)
// float rad = fa * boxhalfsize.y + fb * boxhalfsize.z;
// if(min > rad || max < -rad)
// return false;
// }
public static boolean intersect(BoundingBox bbox, Vector3f v1, Vector3f v2, Vector3f v3) {

View File

@ -506,7 +506,7 @@ package com.jme3.bounding;
//// Vector3f max = _compVect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
//// Vector3f point;
//// for (int i = start; i < end; i++) {
//// mesh.getTriangle(indices[i], verts);
//// mesh.getTriangle(indices[i], verts);
//// point = verts[0];
//// if (point.x < min.x)
//// min.x = point.x;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -192,7 +192,7 @@ public class MotionPath implements Savable {
int i = 0;
for (Float len : spline.getSegmentsLength()) {
if (sum + len >= distance) {
return new Vector2f((float) i, (distance - sum) / len);
return new Vector2f(i, (distance - sum) / len);
}
sum += len;
i++;

View File

@ -93,7 +93,7 @@ public class TimeLine extends HashMap<Integer, KeyFrame> implements Savable {
}
public float getKeyFrameTime(KeyFrame keyFrame) {
return (float)keyFrame.getIndex()/(float)keyFramesPerSeconds;
return keyFrame.getIndex()/(float)keyFramesPerSeconds;
}
public Collection<KeyFrame> getAllKeyFrames() {

View File

@ -72,7 +72,7 @@ public class DefaultParticleInfluencer implements ParticleInfluencer {
* the particle to be affected
*/
protected void applyVelocityVariation(Particle particle) {
particle.velocity.set(initialVelocity);
particle.velocity.set(initialVelocity);
temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat());
temp.multLocal(2f);
temp.subtractLocal(1f, 1f, 1f);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -211,7 +211,7 @@ public class PrefilteredEnvMapFaceGenerator extends RunnableWithProgress {
nbRotations = numSamples == 1 ? 1 : 18;
}
float rad = 2f * FastMath.PI / (float) nbRotations;
float rad = 2f * FastMath.PI / nbRotations;
// offset rotation to avoid sampling pattern
float gi = (float) (FastMath.abs(N.z + N.x) * 256.0);
float offset = rad * (FastMath.cos((gi * 0.5f) % (2f * FastMath.PI)) * 0.5f + 0.5f);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -66,7 +66,7 @@ public abstract class RunnableWithProgress implements Runnable {
* @return fraction (&ge;0, &le;1)
*/
public double getProgress() {
return (double) progress / (double) end;
return progress / (double) end;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -148,7 +148,7 @@ public class CubeMapWrapper {
store = new ColorRGBA();
}
raster.setSlice(face);
return raster.getPixel((int) x, (int) y, store);
return raster.getPixel(x, y, store);
}
/**
@ -170,7 +170,7 @@ public class CubeMapWrapper {
}
mipMapRaster.setSlice(face);
mipMapRaster.setMipLevel(mipLevel);
return mipMapRaster.getPixel((int) x, (int) y, store);
return mipMapRaster.getPixel(x, y, store);
}
/**
@ -209,7 +209,7 @@ public class CubeMapWrapper {
*/
public void setPixel(int x, int y, int face, ColorRGBA color) {
raster.setSlice(face);
raster.setPixel((int) x, (int) y, color);
raster.setPixel(x, y, color);
}
/**
@ -227,7 +227,7 @@ public class CubeMapWrapper {
mipMapRaster.setSlice(face);
mipMapRaster.setMipLevel(mipLevel);
mipMapRaster.setPixel((int) x, (int) y, color);
mipMapRaster.setPixel(x, y, color);
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -194,8 +194,8 @@ public class EnvMapUtils {
/* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)]
(+ 0.5f is for texel center addressing) */
float u = (2.0f * ((float) x + 0.5f) / (float) mapSize) - 1.0f;
float v = (2.0f * ((float) y + 0.5f) / (float) mapSize) - 1.0f;
float u = (2.0f * (x + 0.5f) / mapSize) - 1.0f;
float v = (2.0f * (y + 0.5f) / mapSize) - 1.0f;
getVectorFromCubemapFaceTexCoord(x, y, mapSize, face, store, fixSeamsMethod);
@ -203,7 +203,7 @@ public class EnvMapUtils {
* U and V are the -1..1 texture coordinate on the current face.
* Get projected area for this texel */
float x0, y0, x1, y1;
float invRes = 1.0f / (float) mapSize;
float invRes = 1.0f / mapSize;
x0 = u - invRes;
y0 = v - invRes;
x1 = u + invRes;
@ -246,19 +246,19 @@ public class EnvMapUtils {
if (fixSeamsMethod == FixSeamsMethod.Stretch) {
/* Code from Nvtt : https://github.com/castano/nvidia-texture-tools/blob/master/src/nvtt/CubeSurface.cpp#L77
* transform from [0..res - 1] to [-1 .. 1], match up edges exactly. */
u = (2.0f * (float) x / ((float) mapSize - 1.0f)) - 1.0f;
v = (2.0f * (float) y / ((float) mapSize - 1.0f)) - 1.0f;
u = (2.0f * x / (mapSize - 1.0f)) - 1.0f;
v = (2.0f * y / (mapSize - 1.0f)) - 1.0f;
} else {
//Done if any other fix method or no fix method is set
/* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)]
* (+ 0.5f is for texel center addressing) */
u = (2.0f * ((float) x + 0.5f) / (float) (mapSize)) - 1.0f;
v = (2.0f * ((float) y + 0.5f) / (float) (mapSize)) - 1.0f;
u = (2.0f * (x + 0.5f) / mapSize) - 1.0f;
v = (2.0f * (y + 0.5f) / mapSize) - 1.0f;
}
if (fixSeamsMethod == FixSeamsMethod.Wrap) {
// Warp texel centers in the proximity of the edges.
float a = pow((float) mapSize, 2.0f) / pow(((float) mapSize - 1f), 3.0f);
float a = pow(mapSize, 2.0f) / pow(mapSize - 1f, 3.0f);
u = a * pow(u, 3f) + u;
v = a * pow(v, 3f) + v;
}
@ -362,14 +362,14 @@ public class EnvMapUtils {
if (fixSeamsMethod == FixSeamsMethod.Stretch) {
/* Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp
* transform from [0..res - 1] to [-1 .. 1], match up edges exactly. */
u = Math.round((u + 1.0f) * ((float) mapSize - 1.0f) * 0.5f);
v = Math.round((v + 1.0f) * ((float) mapSize - 1.0f) * 0.5f);
u = Math.round((u + 1.0f) * (mapSize - 1.0f) * 0.5f);
v = Math.round((v + 1.0f) * (mapSize - 1.0f) * 0.5f);
} else {
//Done if any other fix method or no fix method is set
/* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)]
* (+ 0.5f is for texel center addressing) */
u = Math.round((u + 1.0f) * ((float) mapSize) * 0.5f - 0.5f);
v = Math.round((v + 1.0f) * ((float) mapSize) * 0.5f - 0.5f);
u = Math.round((u + 1.0f) * mapSize * 0.5f - 0.5f);
v = Math.round((v + 1.0f) * mapSize * 0.5f - 0.5f);
}
@ -533,7 +533,7 @@ public class EnvMapUtils {
}
float phi;
long ui = i;
store.setX((float) i / (float) nbrSample);
store.setX(i / (float) nbrSample);
/* From http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
* Radical Inverse : Van der Corput */
@ -544,7 +544,7 @@ public class EnvMapUtils {
ui = ((ui & 0x00FF00FF) << 8) | ((ui & 0xFF00FF00) >>> 8);
ui = ui & 0xffffffff;
store.setY(2.3283064365386963e-10f * (float) (ui)); /* 0x100000000 */
store.setY(2.3283064365386963e-10f * ui); /* 0x100000000 */
phi = 2.0f * PI * store.y;
store.setZ(cos(phi));
@ -611,7 +611,7 @@ public class EnvMapUtils {
int size = cubeMap.getImage().getWidth();
Picture[] pics = new Picture[6];
float ratio = 128f / (float) size;
float ratio = 128f / size;
for (int i = 0; i < 6; i++) {
pics[i] = new Picture("bla");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -215,7 +215,7 @@ public class BitmapFont implements Savable {
firstCharOfLine = true;
continue;
}
BitmapCharacter c = charSet.getCharacter((int) theChar);
BitmapCharacter c = charSet.getCharacter(theChar);
if (c != null){
if (theChar == '\\' && i<text.length()-1 && text.charAt(i+1)=='#'){
if (i+5<text.length() && text.charAt(i+5)=='#'){

View File

@ -46,7 +46,7 @@ import java.util.regex.Pattern;
*/
class ColorTags {
private static final Pattern colorPattern = Pattern.compile("\\\\#([0-9a-fA-F]{8})#|\\\\#([0-9a-fA-F]{6})#|" +
"\\\\#([0-9a-fA-F]{4})#|\\\\#([0-9a-fA-F]{3})#");
"\\\\#([0-9a-fA-F]{4})#|\\\\#([0-9a-fA-F]{3})#");
private LinkedList<Range> colors = new LinkedList<Range>();
private String text;
private String original;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -178,7 +178,7 @@ public class InputManager implements RawInputListener {
if (safeMode || frameDelta == 0) {
return 1f;
} else {
return FastMath.clamp((float) timeDelta / (float) frameDelta, 0, 1);
return FastMath.clamp(timeDelta / (float) frameDelta, 0, 1);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -206,7 +206,7 @@ public class LightProbe extends Light implements Savable {
*/
@Deprecated
public BoundingVolume getBounds() {
return new BoundingSphere(((SphereProbeArea)area).getRadius(), ((SphereProbeArea)area).getCenter());
return new BoundingSphere(area.getRadius(), ((SphereProbeArea)area).getCenter());
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -104,6 +104,6 @@ public class MatParamTexture extends MatParam {
super.read(im);
InputCapsule ic = im.getCapsule(this);
texture = (Texture) value;
colorSpace = (ColorSpace) ic.readEnum("colorSpace", ColorSpace.class, null);
colorSpace = ic.readEnum("colorSpace", ColorSpace.class, null);
}
}

View File

@ -379,7 +379,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* <code>toString</code> returns the string representation of this <code>ColorRGBA</code>.
* The format of the string is:<br>
* <Class Name>: [R=RR.RRRR, G=GG.GGGG, B=BB.BBBB, A=AA.AAAA]
* Color[R.RRRR, G.GGGG, B.BBBB, A.AAAA]
* @return The string representation of this <code>ColorRGBA</code>.
*/
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,130 +36,129 @@ import java.util.List;
/**
* This class offers methods to help with curves and surfaces calculations.
*
* @author Marcin Roguski (Kealthas)
*/
public class CurveAndSurfaceMath {
private static final float KNOTS_MINIMUM_DELTA = 0.0001f;
private static final float KNOTS_MINIMUM_DELTA = 0.0001f;
/**
* A private constructor is defined to avoid instantiation of this
* class.
*/
private CurveAndSurfaceMath() {}
/**
* A private constructor is defined to avoid instantiation of this class.
*/
private CurveAndSurfaceMath() {
}
/**
* This method interpolates the data for the nurbs curve.
* @param u
* the u value
* @param nurbSpline
* the nurbs spline definition
* @param store
* the resulting point in 3D space
*/
public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) {
if (nurbSpline.getType() != SplineType.Nurb) {
throw new IllegalArgumentException("Given spline is not of a NURB type!");
}
List<Vector3f> controlPoints = nurbSpline.getControlPoints();
float[] weights = nurbSpline.getWeights();
List<Float> knots = nurbSpline.getKnots();
int controlPointAmount = controlPoints.size();
/**
* This method interpolates the data for the nurbs curve.
*
* @param u the u value
* @param nurbSpline
* the nurbs spline definition
* @param store
* the resulting point in 3D space
*/
public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) {
if (nurbSpline.getType() != SplineType.Nurb) {
throw new IllegalArgumentException("Given spline is not of a NURB type!");
}
List<Vector3f> controlPoints = nurbSpline.getControlPoints();
float[] weights = nurbSpline.getWeights();
List<Float> knots = nurbSpline.getKnots();
int controlPointAmount = controlPoints.size();
store.set(Vector3f.ZERO);
float delimeter = 0;
for (int i = 0; i < controlPointAmount; ++i) {
float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots);
store.addLocal(nurbSpline.getControlPoints().get(i)
.mult(val));
delimeter += val;
}
store.divideLocal(delimeter);
}
store.set(Vector3f.ZERO);
float delimeter = 0;
for (int i = 0; i < controlPointAmount; ++i) {
float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots);
store.addLocal(nurbSpline.getControlPoints().get(i)
.mult(val));
delimeter += val;
}
store.divideLocal(delimeter);
}
/**
* This method interpolates the data for the nurbs surface.
*
* @param u the u value
* @param v the v value
* @param controlPoints
* the nurbs' control points
* @param knots
* the nurbs' knots
* @param basisUFunctionDegree
* the degree of basis U function
* @param basisVFunctionDegree
* the degree of basis V function
* @param store
* the resulting point in 3D space
*/
public static void interpolate(float u, float v, List<List<Vector4f>> controlPoints, List<Float>[] knots,
int basisUFunctionDegree, int basisVFunctionDegree, Vector3f store) {
store.set(Vector3f.ZERO);
float delimeter = 0;
int vControlPointsAmount = controlPoints.size();
int uControlPointsAmount = controlPoints.get(0).size();
for (int i = 0; i < vControlPointsAmount; ++i) {
for (int j = 0; j < uControlPointsAmount; ++j) {
Vector4f controlPoint = controlPoints.get(i).get(j);
float val = controlPoint.w
* CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1])
* CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]);
store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val);
delimeter += val;
}
}
store.divideLocal(delimeter);
}
/**
* This method interpolates the data for the nurbs surface.
*
* @param u
* the u value
* @param v
* the v value
* @param controlPoints
* the nurbs' control points
* @param knots
* the nurbs' knots
* @param basisUFunctionDegree
* the degree of basis U function
* @param basisVFunctionDegree
* the degree of basis V function
* @param store
* the resulting point in 3D space
*/
public static void interpolate(float u, float v, List<List<Vector4f>> controlPoints, List<Float>[] knots,
int basisUFunctionDegree, int basisVFunctionDegree, Vector3f store) {
store.set(Vector3f.ZERO);
float delimeter = 0;
int vControlPointsAmount = controlPoints.size();
int uControlPointsAmount = controlPoints.get(0).size();
for (int i = 0; i < vControlPointsAmount; ++i) {
for (int j = 0; j < uControlPointsAmount; ++j) {
Vector4f controlPoint = controlPoints.get(i).get(j);
float val = controlPoint.w
* CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1])
* CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]);
store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val);
delimeter += val;
}
}
store.divideLocal(delimeter);
}
/**
* This method prepares the knots to be used. If the knots represent
* non-uniform B-splines (first and last knot values are being repeated) it
* leads to NaN results during calculations. This method adds a small number
* to each of such knots to avoid NaN's.
*
* @param knots
* the knots to be prepared to use
* @param basisFunctionDegree
* the degree of basis function
*/
// TODO: improve this; constant delta may lead to errors if the difference between tha last repeated
// point and the following one is lower than it
public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) {
float delta = KNOTS_MINIMUM_DELTA;
float prevValue = knots.get(0).floatValue();
for (int i = 1; i < knots.size(); ++i) {
float value = knots.get(i).floatValue();
if (value <= prevValue) {
value += delta;
knots.set(i, Float.valueOf(value));
delta += KNOTS_MINIMUM_DELTA;
} else {
delta = KNOTS_MINIMUM_DELTA;//reset the delta's value
}
/**
* This method prepares the knots to be used. If the knots represent non-uniform B-splines (first and last knot values are being
* repeated) it leads to NaN results during calculations. This method adds a small number to each of such knots to avoid NaN's.
* @param knots
* the knots to be prepared to use
* @param basisFunctionDegree
* the degree of basis function
*/
// TODO: improve this; constant delta may lead to errors if the difference between tha last repeated
// point and the following one is lower than it
public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) {
float delta = KNOTS_MINIMUM_DELTA;
float prevValue = knots.get(0).floatValue();
for(int i=1;i<knots.size();++i) {
float value = knots.get(i).floatValue();
if(value<=prevValue) {
value += delta;
knots.set(i, Float.valueOf(value));
delta += KNOTS_MINIMUM_DELTA;
} else {
delta = KNOTS_MINIMUM_DELTA;//reset the delta's value
}
prevValue = value;
}
}
prevValue = value;
}
}
/**
* This method computes the base function value for the NURB curve.
* @param i
* the knot index
* @param k
* the base function degree
* @param t
* the knot value
* @param knots
* the knots' values
* @return the base function value
*/
private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) {
if (k == 1) {
return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f;
} else {
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) *
CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots)
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) *
CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots);
}
}
/**
* This method computes the base function value for the NURB curve.
*
* @param i the knot index
* @param k the base function degree
* @param t the knot value
* @param knots
* the knots' values
* @return the base function value
*/
private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) {
if (k == 1) {
return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f;
} else {
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i))
* CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots)
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1))
* CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots);
}
}
}

View File

@ -56,8 +56,8 @@ public class Eigen3f implements java.io.Serializable {
calculateEigen(data);
}
public void calculateEigen(Matrix3f data) {
// prep work...
public void calculateEigen(Matrix3f data) {
// prep work...
eigenVectors[0] = new Vector3f();
eigenVectors[1] = new Vector3f();
eigenVectors[2] = new Vector3f();
@ -134,7 +134,7 @@ public class Eigen3f implements java.io.Serializable {
eigenValues[i] *= maxMagnitude;
}
}
}
}
/**
* Scale the matrix so its entries are in [-1,1]. The scaling is applied

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -41,33 +41,56 @@ import java.util.Random;
* @version $Id: FastMath.java,v 1.45 2007/08/26 08:44:20 irrisor Exp $
*/
final public class FastMath {
private FastMath() {
}
/** A "close to zero" double epsilon value for use*/
/**
* A "close to zero" double epsilon value for use
*/
public static final double DBL_EPSILON = 2.220446049250313E-16d;
/** A "close to zero" float epsilon value for use*/
/**
* A "close to zero" float epsilon value for use
*/
public static final float FLT_EPSILON = 1.1920928955078125E-7f;
/** A "close to zero" float epsilon value for use*/
/**
* A "close to zero" float epsilon value for use
*/
public static final float ZERO_TOLERANCE = 0.0001f;
public static final float ONE_THIRD = 1f / 3f;
/** The value PI as a float. (180 degrees) */
/**
* The value PI as a float. (180 degrees)
*/
public static final float PI = (float) Math.PI;
/** The value 2PI as a float. (360 degrees) */
/**
* The value 2PI as a float. (360 degrees)
*/
public static final float TWO_PI = 2.0f * PI;
/** The value PI/2 as a float. (90 degrees) */
/**
* The value PI/2 as a float. (90 degrees)
*/
public static final float HALF_PI = 0.5f * PI;
/** The value PI/4 as a float. (45 degrees) */
/**
* The value PI/4 as a float. (45 degrees)
*/
public static final float QUARTER_PI = 0.25f * PI;
/** The value 1/PI as a float. */
/**
* The value 1/PI as a float.
*/
public static final float INV_PI = 1.0f / PI;
/** The value 1/(2PI) as a float. */
/**
* The value 1/(2PI) as a float.
*/
public static final float INV_TWO_PI = 1.0f / TWO_PI;
/** A value to multiply a degree value by, to convert it to radians. */
/**
* A value to multiply a degree value by, to convert it to radians.
*/
public static final float DEG_TO_RAD = PI / 180.0f;
/** A value to multiply a radian value by, to convert it to degrees. */
/**
* A value to multiply a radian value by, to convert it to degrees.
*/
public static final float RAD_TO_DEG = 180.0f / PI;
/** A precreated random object for random numbers. */
/**
* A precreated random object for random numbers.
*/
public static final Random rand = new Random(System.currentTimeMillis());
/**
@ -146,7 +169,8 @@ final public class FastMath {
* @param store a vector3f to store the result
* @return The interpolated value between startValue and endValue.
*/
public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) {
public static Vector3f interpolateLinear(float scale, Vector3f startValue,
Vector3f endValue, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
@ -177,6 +201,7 @@ final public class FastMath {
* if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
@ -194,13 +219,15 @@ final public class FastMath {
* if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
* @param store an initialized vector to store the return value
* @return an extrapolation for the given parameters
*/
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) {
public static Vector3f extrapolateLinear(float scale, Vector3f startValue,
Vector3f endValue, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
@ -218,6 +245,7 @@ final public class FastMath {
* if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
@ -227,7 +255,8 @@ final public class FastMath {
return extrapolateLinear(scale, startValue, endValue, null);
}
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
/**
* Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
* here is the interpolation matrix
* m = [ 0.0 1.0 0.0 0.0 ]
* [-T 0.0 T 0.0 ]
@ -250,10 +279,11 @@ final public class FastMath {
c3 = 2 * T * p0 + (T - 3) * p1 + (3 - 2 * T) * p2 + -T * p3;
c4 = -T * p0 + (2 - T) * p1 + (T - 2) * p2 + T * p3;
return (float) (((c4 * u + c3) * u + c2) * u + c1);
return ((c4 * u + c3) * u + c2) * u + c1;
}
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
/**
* Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
* here is the interpolation matrix
* m = [ 0.0 1.0 0.0 0.0 ]
* [-T 0.0 T 0.0 ]
@ -270,7 +300,8 @@ final public class FastMath {
* @param store a Vector3f to store the result
* @return CatmullRom interpolation
*/
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) {
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
@ -297,7 +328,8 @@ final public class FastMath {
* @param p3 control point 3
* @return CatmullRom interpolation
*/
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) {
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
Vector3f p1, Vector3f p2, Vector3f p3) {
return interpolateCatmullRom(u, T, p0, p1, p2, p3, null);
}
@ -326,7 +358,8 @@ final public class FastMath {
+ p3 * u2 * u;
}
/**Interpolate a spline between at least 4 control points following the Bezier equation.
/**
* Interpolate a spline between at least 4 control points following the Bezier equation.
* here is the interpolation matrix
* m = [ -1.0 3.0 -3.0 1.0 ]
* [ 3.0 -6.0 3.0 0.0 ]
@ -342,7 +375,8 @@ final public class FastMath {
* @param store a Vector3f to store the result
* @return Bezier interpolation
*/
public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) {
public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1,
Vector3f p2, Vector3f p3, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
@ -352,7 +386,8 @@ final public class FastMath {
return store;
}
/**Interpolate a spline between at least 4 control points following the Bezier equation.
/**
* Interpolate a spline between at least 4 control points following the Bezier equation.
* here is the interpolation matrix
* m = [ -1.0 3.0 -3.0 1.0 ]
* [ 3.0 -6.0 3.0 0.0 ]
@ -373,6 +408,7 @@ final public class FastMath {
/**
* Compute the length of a CatmullRom spline between control points 1 and 2
*
* @param p0 control point 0
* @param p1 control point 1
* @param p2 control point 2
@ -382,7 +418,8 @@ final public class FastMath {
* @param curveTension the curve tension
* @return the length of the segment
*/
public static float getCatmullRomP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) {
public static float getCatmullRomP1toP2Length(Vector3f p0, Vector3f p1,
Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) {
float epsilon = 0.001f;
float middleValue = (startRange + endRange) * 0.5f;
@ -409,6 +446,7 @@ final public class FastMath {
/**
* Compute the length on a Bezier spline between control points 1 and 2.
*
* @param p0 control point 0
* @param p1 control point 1
* @param p2 control point 2
@ -432,6 +470,7 @@ final public class FastMath {
* Special cases:
* <ul><li>If fValue is smaller than -1, then the result is PI.
* <li>If the argument is greater than 1, then the result is 0.</ul>
*
* @param fValue The value to arc cosine.
* @return The angle, in radians.
* @see java.lang.Math#acos(double)
@ -453,6 +492,7 @@ final public class FastMath {
* Special cases:
* <ul><li>If fValue is smaller than -1, then the result is -HALF_PI.
* <li>If the argument is greater than 1, then the result is HALF_PI.</ul>
*
* @param fValue The value to arc sine.
* @return the angle in radians.
* @see java.lang.Math#asin(double)
@ -471,6 +511,7 @@ final public class FastMath {
/**
* Returns the arc tangent of an angle given in radians.<br>
*
* @param fValue The angle, in radians.
* @return fValue's atan
* @see java.lang.Math#atan(double)
@ -481,6 +522,7 @@ final public class FastMath {
/**
* A direct call to Math.atan2.
*
* @param fY
* @param fX
* @return Math.atan2(fY,fX)
@ -491,7 +533,8 @@ final public class FastMath {
}
/**
* Rounds a fValue up. A call to Math.ceil
* Rounds a fValue up. A call to Math.ceil
*
* @param fValue The value.
* @return The fValue rounded up
* @see java.lang.Math#ceil(double)
@ -502,9 +545,10 @@ final public class FastMath {
/**
* Returns cosine of an angle. Direct call to java.lang.Math
*
* @see Math#cos(double)
* @param v The angle to cosine.
* @return the cosine of the angle.
* @return the cosine of the angle.
*/
public static float cos(float v) {
return (float) Math.cos(v);
@ -512,6 +556,7 @@ final public class FastMath {
/**
* Returns the sine of an angle. Direct call to java.lang.Math
*
* @see Math#sin(double)
* @param v The angle to sine.
* @return the sine of the angle.
@ -522,6 +567,7 @@ final public class FastMath {
/**
* Returns E^fValue
*
* @param fValue Value to raise to a power.
* @return The value E^fValue
* @see java.lang.Math#exp(double)
@ -532,6 +578,7 @@ final public class FastMath {
/**
* Returns Absolute value of a float.
*
* @param fValue The value to abs.
* @return The abs of the value.
* @see java.lang.Math#abs(float)
@ -545,6 +592,7 @@ final public class FastMath {
/**
* Returns a number rounded down.
*
* @param fValue The value to round
* @return The given number rounded down
* @see java.lang.Math#floor(double)
@ -555,6 +603,7 @@ final public class FastMath {
/**
* Returns 1/sqrt(fValue)
*
* @param fValue The value to process.
* @return 1/sqrt(fValue)
* @see java.lang.Math#sqrt(double)
@ -574,6 +623,7 @@ final public class FastMath {
/**
* Returns the log base E of a value.
*
* @param fValue The value to log.
* @return The log of fValue base E
* @see java.lang.Math#log(double)
@ -585,6 +635,7 @@ final public class FastMath {
/**
* Returns the logarithm of value with given base, calculated as log(value)/log(base),
* so that pow(base, return)==value (contributed by vear)
*
* @param value The value to log.
* @param base Base of logarithm.
* @return The logarithm of value with given base
@ -594,7 +645,8 @@ final public class FastMath {
}
/**
* Returns a number raised to an exponent power. fBase^fExponent
* Returns a number raised to an exponent power. fBase^fExponent
*
* @param fBase The base value (IE 2)
* @param fExponent The exponent value (IE 3)
* @return base raised to exponent (IE 8)
@ -605,7 +657,8 @@ final public class FastMath {
}
/**
* Returns the value squared. fValue ^ 2
* Returns the value squared. fValue ^ 2
*
* @param fValue The value to square.
* @return The square of the given value.
*/
@ -615,6 +668,7 @@ final public class FastMath {
/**
* Returns the square root of a given value.
*
* @param fValue The value to sqrt.
* @return The square root of the given value.
* @see java.lang.Math#sqrt(double)
@ -624,8 +678,8 @@ final public class FastMath {
}
/**
* Returns the tangent of a value. If USE_FAST_TRIG is enabled, an approximate value
* is returned. Otherwise, a direct value is used.
* Returns the tangent of the specified angle.
*
* @param fValue The value to tangent, in radians.
* @return The tangent of fValue.
* @see java.lang.Math#tan(double)
@ -636,6 +690,7 @@ final public class FastMath {
/**
* Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise
*
* @param iValue The integer to examine.
* @return The integer's sign.
*/
@ -651,6 +706,7 @@ final public class FastMath {
/**
* Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise
*
* @param fValue The float to examine.
* @return The float's sign.
*/
@ -661,6 +717,7 @@ final public class FastMath {
/**
* Given 3 points in a 2d plane, this function computes if the points going from A-B-C
* are moving counter clock wise.
*
* @param p0 Point 0.
* @param p1 Point 1.
* @param p2 Point 2.
@ -690,6 +747,7 @@ final public class FastMath {
/**
* Test if a point is inside a triangle. 1 if the point is on the ccw side,
* -1 if the point is on the cw side, and 0 if it is on neither.
*
* @param t0 First point of the triangle.
* @param t1 Second point of the triangle.
* @param t2 Third point of the triangle.
@ -720,6 +778,7 @@ final public class FastMath {
/**
* A method that computes normal for a triangle defined by three vertices.
*
* @param v1 first vertex
* @param v2 second vertex
* @param v3 third vertex
@ -733,6 +792,24 @@ final public class FastMath {
/**
* Returns the determinant of a 4x4 matrix.
*
* @param m00 the element in row 0, column 0 of the matrix
* @param m01 the element in row 0, column 1 of the matrix
* @param m02 the element in row 0, column 2 of the matrix
* @param m03 the element in row 0, column 3 of the matrix
* @param m10 the element in row 1, column 0 of the matrix
* @param m11 the element in row 1, column 1 of the matrix
* @param m12 the element in row 1, column 2 of the matrix
* @param m13 the element in row 1, column 3 of the matrix
* @param m20 the element in row 2, column 0 of the matrix
* @param m21 the element in row 2, column 1 of the matrix
* @param m22 the element in row 2, column 2 of the matrix
* @param m23 the element in row 2, column 3 of the matrix
* @param m30 the element in row 3, column 0 of the matrix
* @param m31 the element in row 3, column 1 of the matrix
* @param m32 the element in row 3, column 2 of the matrix
* @param m33 the element in row 3, column 3 of the matrix
* @return the determinant
*/
public static float determinant(double m00, double m01, double m02,
double m03, double m10, double m11, double m12, double m13,
@ -755,7 +832,7 @@ final public class FastMath {
* Returns a random float between 0 and 1.
*
* @return A random float between <tt>0.0f</tt> (inclusive) to
* <tt>1.0f</tt> (exclusive).
* <tt>1.0f</tt> (exclusive).
*/
public static float nextRandomFloat() {
return rand.nextFloat();
@ -764,8 +841,10 @@ final public class FastMath {
/**
* Returns a random integer between min and max.
*
* @param min the desired minimum value
* @param max the desired maximum value
* @return A random int between <tt>min</tt> (inclusive) to
* <tt>max</tt> (inclusive).
* <tt>max</tt> (inclusive).
*/
public static int nextRandomInt(int min, int max) {
return (int) (nextRandomFloat() * (max - min + 1)) + min;
@ -778,6 +857,12 @@ final public class FastMath {
/**
* Converts a point from Spherical coordinates to Cartesian (using positive
* Y as up) and stores the results in the store var.
*
* @param sphereCoords the input spherical coordinates: x=distance from
* origin, y=longitude in radians, z=latitude in radians (not null,
* unaffected)
* @param store storage for the result (modified if not null)
* @return the Cartesian coordinates (either store or a new vector)
*/
public static Vector3f sphericalToCartesian(Vector3f sphereCoords,
Vector3f store) {
@ -796,6 +881,11 @@ final public class FastMath {
* Converts a point from Cartesian coordinates (using positive Y as up) to
* Spherical and stores the results in the store var. (Radius, Azimuth,
* Polar)
*
* @param cartCoords the input Cartesian coordinates (not null, unaffected)
* @param store storage for the result (modified if not null)
* @return the Cartesian coordinates: x=distance from origin, y=longitude in
* radians, z=latitude in radians (either store or a new vector)
*/
public static Vector3f cartesianToSpherical(Vector3f cartCoords,
Vector3f store) {
@ -820,6 +910,12 @@ final public class FastMath {
/**
* Converts a point from Spherical coordinates to Cartesian (using positive
* Z as up) and stores the results in the store var.
*
* @param sphereCoords the input spherical coordinates: x=distance from
* origin, y=longitude in radians, z=latitude in radians (not null,
* unaffected)
* @param store storage for the result (modified if not null)
* @return the Cartesian coordinates (either store or a new vector)
*/
public static Vector3f sphericalToCartesianZ(Vector3f sphereCoords,
Vector3f store) {
@ -838,6 +934,11 @@ final public class FastMath {
* Converts a point from Cartesian coordinates (using positive Z as up) to
* Spherical and stores the results in the store var. (Radius, Azimuth,
* Polar)
*
* @param cartCoords the input Cartesian coordinates (not null, unaffected)
* @param store storage for the result (modified if not null)
* @return the Cartesian coordinates: x=distance from origin, y=latitude in
* radians, z=longitude in radians (either store or a new vector)
*/
public static Vector3f cartesianZToSpherical(Vector3f cartCoords,
Vector3f store) {
@ -864,6 +965,10 @@ final public class FastMath {
*
* @param val -
* the angle to normalize (in radians)
* @param min
* the lower limit of the range
* @param max
* the upper limit of the range
* @return the normalized angle (also in radians)
*/
public static float normalize(float val, float min, float max) {
@ -996,6 +1101,7 @@ final public class FastMath {
/**
* Converts a range of min/max to a 0-1 range.
*
* @param value the value between min-max (inclusive).
* @param min the minimum of the range.
* @param max the maximum of the range.
@ -1004,5 +1110,4 @@ final public class FastMath {
public static float unInterpolateLinear(float value, float min, float max) {
return (value - min) / (max - min);
}
}

View File

@ -150,7 +150,7 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
origin.addLocal(compVec1);
}
origin.multLocal(1f / (float) length);
origin.multLocal(1f / length);
// compute sums of products
float sumXX = 0.0f, sumXY = 0.0f, sumXZ = 0.0f;

View File

@ -71,6 +71,11 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
/**
* <p>Creates a new LineSegment with the given origin, direction and extent.</p>
* <p>Note that the origin is not one of the ends of the LineSegment, but its center.</p>
*
* @param origin the location of the desired midpoint (alias created)
* @param direction the desired direction vector (alias created)
* @param extent the extent: 1/2 of the desired length, assuming direction
* is a unit vector
*/
public LineSegment(Vector3f origin, Vector3f direction, float extent) {
this.origin = origin;
@ -81,6 +86,9 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
/**
* <p>Creates a new LineSegment with a given origin and end. This constructor will calculate the
* center, the direction and the extent.</p>
*
* @param start location of the negative endpoint (not null, unaffected)
* @param end location of the negative endpoint (not null, unaffected)
*/
public LineSegment(Vector3f start, Vector3f end) {
this.origin = new Vector3f(0.5f * (start.x + end.x), 0.5f * (start.y + end.y), 0.5f * (start.z + end.z));
@ -604,6 +612,9 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
/**
* <p>Evaluates whether a given point is contained within the axis aligned bounding box
* that contains this LineSegment.</p><p>This function is float error aware.</p>
*
* @param point the location of the input point (not null, unaffected)
* @return true if contained in the box, otherwise false
*/
public boolean isPointInsideBounds(Vector3f point) {
return isPointInsideBounds(point, Float.MIN_VALUE);
@ -613,6 +624,10 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
* <p>Evaluates whether a given point is contained within the axis aligned bounding box
* that contains this LineSegment.</p><p>This function accepts an error parameter, which
* is added to the extent of the bounding box.</p>
*
* @param point the location of the input point (not null, unaffected)
* @param error the desired margin for error
* @return true if contained in the box, otherwise false
*/
public boolean isPointInsideBounds(Vector3f point, float error) {

View File

@ -61,7 +61,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* Constructor instantiates a new <code>Matrix3f</code> object. The
* initial values for the matrix is that of the identity matrix.
*
*/
public Matrix3f() {
loadIdentity();
@ -70,24 +69,15 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* constructs a matrix with the given values.
*
* @param m00
* 0x0 in the matrix.
* @param m01
* 0x1 in the matrix.
* @param m02
* 0x2 in the matrix.
* @param m10
* 1x0 in the matrix.
* @param m11
* 1x1 in the matrix.
* @param m12
* 1x2 in the matrix.
* @param m20
* 2x0 in the matrix.
* @param m21
* 2x1 in the matrix.
* @param m22
* 2x2 in the matrix.
* @param m00 0x0 in the matrix.
* @param m01 0x1 in the matrix.
* @param m02 0x2 in the matrix.
* @param m10 1x0 in the matrix.
* @param m11 1x1 in the matrix.
* @param m12 1x2 in the matrix.
* @param m20 2x0 in the matrix.
* @param m21 2x1 in the matrix.
* @param m22 2x2 in the matrix.
*/
public Matrix3f(float m00, float m01, float m02, float m10, float m11,
float m12, float m20, float m21, float m22) {
@ -156,15 +146,12 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
}
/**
* <code>get</code> retrieves a value from the matrix at the given
* position. If the position is invalid a <code>JmeException</code> is
* thrown.
* <code>get</code> retrieves a value from the matrix at the given position.
*
* @param i
* the row index.
* @param j
* the colum index.
* @param i the row index.
* @param j the column index.
* @return the value at (i, j).
* @throws IllegalArgumentException if either index is invalid
*/
@SuppressWarnings("fallthrough")
public float get(int i, int j) {
@ -303,6 +290,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* Normalize this matrix
*
* @return this matrix once normalized.
*/
public Matrix3f normalizeLocal() {
@ -432,6 +420,8 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* @param fb
* the buffer to fill, starting at current position. Must have
* room for 9 more floats.
* @param columnMajor
* true &rarr; column-major order, false &rarr; row-major order
* @return matrix data as a FloatBuffer. (position is advanced by 9 and any
* limit set is not changed).
*/
@ -448,7 +438,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 9);
@ -459,30 +448,29 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
public void fillFloatArray(float[] f, boolean columnMajor) {
if (columnMajor) {
f[ 0] = m00;
f[ 1] = m10;
f[ 2] = m20;
f[ 3] = m01;
f[ 4] = m11;
f[ 5] = m21;
f[ 6] = m02;
f[ 7] = m12;
f[ 8] = m22;
f[0] = m00;
f[1] = m10;
f[2] = m20;
f[3] = m01;
f[4] = m11;
f[5] = m21;
f[6] = m02;
f[7] = m12;
f[8] = m22;
} else {
f[ 0] = m00;
f[ 1] = m01;
f[ 2] = m02;
f[ 3] = m10;
f[ 4] = m11;
f[ 5] = m12;
f[ 6] = m20;
f[ 7] = m21;
f[ 8] = m22;
f[0] = m00;
f[1] = m01;
f[2] = m02;
f[3] = m10;
f[4] = m11;
f[5] = m12;
f[6] = m20;
f[7] = m21;
f[8] = m22;
}
}
/**
*
* <code>setColumn</code> sets a particular column of this matrix to that
* represented by the provided vector.
*
@ -522,7 +510,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>setRow</code> sets a particular row of this matrix to that
* represented by the provided vector.
*
@ -563,16 +550,16 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* <code>set</code> places a given value into the matrix at the given
* position. If the position is invalid a <code>JmeException</code> is
* thrown.
* position.
*
* @param i
* the row index.
* @param j
* the colum index.
* the column index.
* @param value
* the value for (i, j).
* @return this
* @throws IllegalArgumentException if either index is invalid
*/
@SuppressWarnings("fallthrough")
public Matrix3f set(int i, int j, float value) {
@ -620,14 +607,12 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>set</code> sets the values of the matrix to those supplied by the
* 3x3 two dimenion array.
*
* @param matrix
* the new values of the matrix.
* @throws JmeException
* if the array is not of size 9.
* @throws IllegalArgumentException if the matrix is not 3x3
* @return this
*/
public Matrix3f set(float[][] matrix) {
@ -652,12 +637,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* Recreate Matrix using the provided axis.
*
* @param uAxis
* Vector3f
* @param vAxis
* Vector3f
* @param wAxis
* Vector3f
* @param uAxis Vector3f
* @param vAxis Vector3f
* @param wAxis Vector3f
*/
public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) {
m00 = uAxis.x;
@ -726,7 +708,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>set</code> defines the values of the matrix based on a supplied
* <code>Quaternion</code>. It should be noted that all previous values
* will be overridden.
@ -742,7 +723,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* <code>loadIdentity</code> sets this matrix to the identity matrix.
* Where all values are zero except those along the diagonal which are one.
*
*/
public void loadIdentity() {
m01 = m02 = m10 = m12 = m20 = m21 = 0;
@ -997,6 +977,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* Inverts this matrix and stores it in the given store.
*
* @param store storage for the result (modified if not null)
* @return The store
*/
public Matrix3f invert(Matrix3f store) {
@ -1175,7 +1156,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>hashCode</code> returns the hash code value as an integer and is
* supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc.
@ -1210,7 +1190,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof Matrix3f) || o == null) {
if (!(o instanceof Matrix3f)) {
return false;
}

View File

@ -69,7 +69,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* Constructor instantiates a new <code>Matrix</code> that is set to the
* identity matrix.
*
*/
public Matrix4f() {
loadIdentity();
@ -77,6 +76,23 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* constructs a matrix with the given values.
*
* @param m00 the desired value for row 0, column 0
* @param m01 the desired value for row 0, column 1
* @param m02 the desired value for row 0, column 2
* @param m03 the desired value for row 0, column 3
* @param m10 the desired value for row 1, column 0
* @param m11 the desired value for row 1, column 1
* @param m12 the desired value for row 1, column 2
* @param m13 the desired value for row 1, column 3
* @param m20 the desired value for row 2, column 0
* @param m21 the desired value for row 2, column 1
* @param m22 the desired value for row 2, column 2
* @param m23 the desired value for row 2, column 3
* @param m30 the desired value for row 3, column 0
* @param m31 the desired value for row 3, column 1
* @param m32 the desired value for row 3, column 2
* @param m33 the desired value for row 3, column 3
*/
public Matrix4f(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
@ -105,7 +121,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* Create a new Matrix4f, given data in column-major format.
*
* @param array
* An array of 16 floats in column-major format (translation in elements 12, 13 and 14).
* An array of 16 floats in column-major format (translation in elements 12, 13 and 14).
*/
public Matrix4f(float[] array) {
set(array, false);
@ -250,14 +266,13 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>get</code> retrieves a value from the matrix at the given
* position. If the position is invalid a <code>JmeException</code> is
* thrown.
* position.
*
* @param i
* the row index.
* @param j
* the colum index.
* @param i the row index.
* @param j the column index.
* @return the value at (i, j).
* @throws IllegalArgumentException
* if either index is invalid
*/
@SuppressWarnings("fallthrough")
public float get(int i, int j) {
@ -316,8 +331,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three columns specified by the
* parameter. This column is returned as a float array of length 4.
*
* @param i
* the column to retrieve. Must be between 0 and 3.
* @param i the column to retrieve. Must be between 0 and 3.
* @return the column specified by the index.
*/
public float[] getColumn(int i) {
@ -328,8 +342,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three columns specified by the
* parameter. This column is returned as a float[4].
*
* @param i
* the column to retrieve. Must be between 0 and 3.
* @param i the column to retrieve. Must be between 0 and 3.
* @param store
* the float array to store the result in. if null, a new one
* is created.
@ -372,12 +385,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>setColumn</code> sets a particular column of this matrix to that
* represented by the provided vector.
*
* @param i
* the column to set.
* @param i the column to set.
* @param column
* the data to set.
*/
@ -420,15 +431,14 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>set</code> places a given value into the matrix at the given
* position. If the position is invalid a <code>JmeException</code> is
* thrown.
* position.
*
* @param i
* the row index.
* @param j
* the colum index.
* @param i the row index.
* @param j the column index.
* @param value
* the value for (i, j).
* @throws IllegalArgumentException
* if either index is invalid
*/
@SuppressWarnings("fallthrough")
public void set(int i, int j, float value) {
@ -505,8 +515,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param matrix
* the matrix to set the value to.
* @throws JmeException
* if the array is not of size 16.
* @throws IllegalArgumentException
* if the array isn't 4x4
*/
public void set(float[][] matrix) {
if (matrix.length != 4 || matrix[0].length != 4) {
@ -532,9 +542,25 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
m33 = matrix[3][3];
}
/**
* Sets the values of this matrix
*
* @param m00 the desired value for row 0, column 0
* @param m01 the desired value for row 0, column 1
* @param m02 the desired value for row 0, column 2
* @param m03 the desired value for row 0, column 3
* @param m10 the desired value for row 1, column 0
* @param m11 the desired value for row 1, column 1
* @param m12 the desired value for row 1, column 2
* @param m13 the desired value for row 1, column 3
* @param m20 the desired value for row 2, column 0
* @param m21 the desired value for row 2, column 1
* @param m22 the desired value for row 2, column 2
* @param m23 the desired value for row 2, column 3
* @param m30 the desired value for row 3, column 0
* @param m31 the desired value for row 3, column 1
* @param m32 the desired value for row 3, column 2
* @param m33 the desired value for row 3, column 3
*/
public void set(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
@ -564,6 +590,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param matrix
* the matrix to read the value from.
* @return this
*/
public Matrix4f set(Matrix4f matrix) {
m00 = matrix.m00;
@ -718,6 +745,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>fillFloatBuffer</code> fills a FloatBuffer object with
* the matrix data.
*
* @param fb the buffer to fill, must be correct size
* @return matrix data as a FloatBuffer.
*/
@ -753,7 +781,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 16);
@ -764,16 +791,16 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
public void fillFloatArray(float[] f, boolean columnMajor) {
if (columnMajor) {
f[ 0] = m00;
f[ 1] = m10;
f[ 2] = m20;
f[ 3] = m30;
f[ 4] = m01;
f[ 5] = m11;
f[ 6] = m21;
f[ 7] = m31;
f[ 8] = m02;
f[ 9] = m12;
f[0] = m00;
f[1] = m10;
f[2] = m20;
f[3] = m30;
f[4] = m01;
f[5] = m11;
f[6] = m21;
f[7] = m31;
f[8] = m02;
f[9] = m12;
f[10] = m22;
f[11] = m32;
f[12] = m03;
@ -781,16 +808,16 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
f[14] = m23;
f[15] = m33;
} else {
f[ 0] = m00;
f[ 1] = m01;
f[ 2] = m02;
f[ 3] = m03;
f[ 4] = m10;
f[ 5] = m11;
f[ 6] = m12;
f[ 7] = m13;
f[ 8] = m20;
f[ 9] = m21;
f[0] = m00;
f[1] = m01;
f[2] = m02;
f[3] = m03;
f[4] = m10;
f[5] = m11;
f[6] = m12;
f[7] = m13;
f[8] = m20;
f[9] = m21;
f[10] = m22;
f[11] = m23;
f[12] = m30;
@ -802,6 +829,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>readFloatBuffer</code> reads value for this matrix from a FloatBuffer.
*
* @param fb the buffer to read from, must be correct size
* @return this data as a FloatBuffer.
*/
@ -811,9 +839,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>readFloatBuffer</code> reads value for this matrix from a FloatBuffer.
*
* @param fb the buffer to read from, must be correct size
* @param columnMajor if true, this buffer should be filled with column
* major data, otherwise it will be filled row major.
* major data, otherwise it will be filled row major.
* @return this data as a FloatBuffer.
*/
public Matrix4f readFloatBuffer(FloatBuffer fb, boolean columnMajor) {
@ -859,7 +888,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>loadIdentity</code> sets this matrix to the identity matrix,
* namely all zeros with ones along the diagonal.
*
*/
public void loadIdentity() {
m01 = m02 = m03 = 0.0f;
@ -869,7 +897,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
m00 = m11 = m22 = m33 = 1.0f;
}
public void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel) {
public void fromFrustum(float near, float far, float left, float right,
float top, float bottom, boolean parallel) {
loadIdentity();
if (parallel) {
// scale
@ -1095,7 +1124,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
+ m32 * in2.m23
+ m33 * in2.m33;
store.m00 = m[0];
store.m01 = m[1];
store.m02 = m[2];
@ -1211,7 +1239,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param vec
* vec to multiply against.
*
* @return the rotated vector.
*/
public Vector4f multAcross(Vector4f vec) {
@ -1430,6 +1457,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* Inverts this matrix and stores it in the given store.
*
* @param store storage for the result (modified if not null)
* @return The store
*/
public Matrix4f invert(Matrix4f store) {
@ -1738,18 +1766,18 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
mat.m20 = m20;
mat.m21 = m21;
mat.m22 = m22;
}
}
/**
* Retrieves the scale vector from the matrix.
*
* @return the scale vector
*/
public Vector3f toScaleVector() {
Vector3f result = new Vector3f();
this.toScaleVector(result);
return result;
}
/**
* Retrieves the scale vector from the matrix.
*
* @return the scale vector
*/
public Vector3f toScaleVector() {
Vector3f result = new Vector3f();
this.toScaleVector(result);
return result;
}
/**
* Retrieves the scale vector from the matrix and stores it into a given
@ -1759,9 +1787,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* @return the store vector
*/
public Vector3f toScaleVector(Vector3f store) {
float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20);
float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21);
float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22);
float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20);
float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21);
float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22);
store.set(scaleX, scaleY, scaleZ);
return store;
}
@ -1818,7 +1846,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param translation
* the new values for the translation.
* @throws JmeException
* @throws IllegalArgumentException
* if translation is not size 3.
*/
public void setTranslation(float[] translation) {
@ -1834,12 +1862,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>setTranslation</code> will set the matrix's translation values.
*
* @param x
* value of the translation on the x axis
* @param y
* value of the translation on the y axis
* @param z
* value of the translation on the z axis
* @param x value of the translation on the x axis
* @param y value of the translation on the y axis
* @param z value of the translation on the z axis
*/
public void setTranslation(float x, float y, float z) {
m03 = x;
@ -1865,7 +1890,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param translation
* the new values for the inverse translation.
* @throws JmeException
* @throws IllegalArgumentException
* if translation is not size 3.
*/
public void setInverseTranslation(float[] translation) {
@ -1935,7 +1960,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param angles
* the Euler angles in radians.
* @throws JmeException
* @throws IllegalArgumentException
* if angles is not size 3.
*/
public void setInverseRotationRadians(float[] angles) {
@ -1972,7 +1997,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param angles
* the Euler angles in degrees.
* @throws JmeException
* @throws IllegalArgumentException
* if angles is not size 3.
*/
public void setInverseRotationDegrees(float[] angles) {
@ -1988,13 +2013,12 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>inverseTranslateVect</code> translates a given Vector3f by the
* translation part of this matrix.
*
* @param vec
* the Vector3f data to be translated.
* @throws JmeException
* @throws IllegalArgumentException
* if the size of the Vector3f is not 3.
*/
public void inverseTranslateVect(float[] vec) {
@ -2009,13 +2033,12 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>inverseTranslateVect</code> translates a given Vector3f by the
* translation part of this matrix.
*
* @param data
* the Vector3f to be translated.
* @throws JmeException
* @throws IllegalArgumentException
* if the size of the Vector3f is not 3.
*/
public void inverseTranslateVect(Vector3f data) {
@ -2025,13 +2048,12 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>inverseTranslateVect</code> translates a given Vector3f by the
* translation part of this matrix.
*
* @param data
* the Vector3f to be translated.
* @throws JmeException
* @throws IllegalArgumentException
* if the size of the Vector3f is not 3.
*/
public void translateVect(Vector3f data) {
@ -2041,7 +2063,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>inverseRotateVect</code> rotates a given Vector3f by the rotation
* part of this matrix.
*
@ -2118,7 +2139,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>hashCode</code> returns the hash code value as an integer and is
* supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc.
@ -2161,7 +2181,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof Matrix4f) || o == null) {
if (!(o instanceof Matrix4f)) {
return false;
}

View File

@ -119,9 +119,12 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
/**
* <code>setNormal</code> sets the normal of the plane.
*
* @param x the desired X component for the normal vector
* @param y the desired Y component for the normal vector
* @param z the desired Z component for the normal vector
*/
public void setNormal(float x, float y, float z) {
this.normal.set(x,y,z);
this.normal.set(x, y, z);
}
/**
@ -153,20 +156,21 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
return constant;
}
public Vector3f getClosestPoint(Vector3f point, Vector3f store){
public Vector3f getClosestPoint(Vector3f point, Vector3f store) {
// float t = constant - normal.dot(point);
// return store.set(normal).multLocal(t).addLocal(point);
float t = (constant - normal.dot(point)) / normal.dot(normal);
return store.set(normal).multLocal(t).addLocal(point);
}
public Vector3f getClosestPoint(Vector3f point){
public Vector3f getClosestPoint(Vector3f point) {
return getClosestPoint(point, new Vector3f());
}
public Vector3f reflect(Vector3f point, Vector3f store){
if (store == null)
public Vector3f reflect(Vector3f point, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
float d = pseudoDistance(point);
store.set(normal).negateLocal().multLocal(d * 2f);
@ -208,19 +212,19 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
}
}
public boolean isOnPlane(Vector3f point){
public boolean isOnPlane(Vector3f point) {
float dist = pseudoDistance(point);
if (dist < FastMath.FLT_EPSILON && dist > -FastMath.FLT_EPSILON)
if (dist < FastMath.FLT_EPSILON && dist > -FastMath.FLT_EPSILON) {
return true;
else
} else {
return false;
}
}
/**
* Initialize this plane using the three points of the given triangle.
*
* @param t
* the triangle
* @param t the triangle
*/
public void setPlanePoints(AbstractTriangle t) {
setPlanePoints(t.get1(), t.get2(), t.get3());
@ -232,7 +236,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
* @param origin
* @param normal
*/
public void setOriginNormal(Vector3f origin, Vector3f normal){
public void setOriginNormal(Vector3f origin, Vector3f normal) {
this.normal.set(normal);
this.constant = normal.x * origin.x + normal.y * origin.y + normal.z * origin.z;
}

View File

@ -43,8 +43,7 @@ import java.util.logging.Logger;
* rotation in four dimensions. This avoids "gimbal lock" and allows for smooth
* continuous rotation.
*
* <code>Quaternion</code> is defined by four floating point numbers: {x y z
* w}.
* <code>Quaternion</code> is defined by four floating point numbers: {x y z w}.
*
* @author Mark Powell
* @author Joshua Slack
@ -82,14 +81,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* Constructor instantiates a new <code>Quaternion</code> object from the
* given list of parameters.
*
* @param x
* the x value of the quaternion.
* @param y
* the y value of the quaternion.
* @param z
* the z value of the quaternion.
* @param w
* the w value of the quaternion.
* @param x the x value of the quaternion.
* @param y the y value of the quaternion.
* @param z the z value of the quaternion.
* @param w the w value of the quaternion.
*/
public Quaternion(float x, float y, float z, float w) {
this.x = x;
@ -115,17 +110,13 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
}
/**
* sets the data in a <code>Quaternion</code> object from the given list
* of parameters.
* sets the data in a <code>Quaternion</code> object from the given list of
* parameters.
*
* @param x
* the x value of the quaternion.
* @param y
* the y value of the quaternion.
* @param z
* the z value of the quaternion.
* @param w
* the w value of the quaternion.
* @param x the x value of the quaternion.
* @param y the y value of the quaternion.
* @param z the z value of the quaternion.
* @param w the w value of the quaternion.
* @return this
*/
public Quaternion set(float x, float y, float z, float w) {
@ -141,8 +132,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* passed <code>Quaternion</code> object. The values are copied producing
* a new object.
*
* @param q
* The Quaternion to copy values from.
* @param q The Quaternion to copy values from.
* @return this
*/
public Quaternion set(Quaternion q) {
@ -184,8 +174,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* Constructor instantiates a new <code>Quaternion</code> object from an
* existing quaternion, creating a copy.
*
* @param q
* the quaternion to copy.
* @param q the quaternion to copy.
*/
public Quaternion(Quaternion q) {
this.x = q.x;
@ -195,7 +184,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
}
/**
* Sets this Quaternion to {0, 0, 0, 1}. Same as calling set(0,0,0,1).
* Sets this Quaternion to {0, 0, 0, 1}. Same as calling set(0,0,0,1).
*/
public void loadIdentity() {
x = y = z = 0;
@ -219,6 +208,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
*
* @param angles
* the Euler angles of rotation (in radians).
* @return this
*/
public Quaternion fromAngles(float[] angles) {
if (angles.length != 3) {
@ -231,8 +221,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/**
* <code>fromAngles</code> builds a Quaternion from the Euler rotation
* angles (x,y,z) aka (pitch, yaw, roll)). Note that we are applying in order: (y, z, x) aka (yaw, roll, pitch) but
* we've ordered them in x, y, and z for convenience.
* angles (x,y,z) aka (pitch, yaw, roll)).
* Note that we are applying in order: (y, z, x) aka (yaw, roll, pitch)
* but we've ordered them in x, y, and z for convenience.
*
* @see <a href="http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm">http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm</a>
*
* @param xAngle
@ -244,6 +236,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* @param zAngle
* the Euler roll of rotation (in radians). (aka Bank, often
* rot around z)
* @return this
*/
public Quaternion fromAngles(float xAngle, float yAngle, float zAngle) {
float angle;
@ -315,12 +308,12 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
}
/**
*
* <code>fromRotationMatrix</code> generates a quaternion from a supplied
* matrix. This matrix is assumed to be a rotational matrix.
*
* @param matrix
* the matrix that defines the rotation.
* @return this
*/
public Quaternion fromRotationMatrix(Matrix3f matrix) {
return fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, matrix.m10,
@ -642,6 +635,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* the angle to rotate (in radians).
* @param axis
* the axis of rotation (already normalized).
* @return this
*/
public Quaternion fromAngleNormalAxis(float angle, Vector3f axis) {
if (axis.x == 0 && axis.y == 0 && axis.z == 0) {
@ -700,6 +694,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* the second quaternion.
* @param t
* the amount to interpolate between the two quaternions.
* @return this
*/
public Quaternion slerp(Quaternion q1, Quaternion q2, float t) {
// Create a local quaternion to store the interpolated quaternion
@ -805,6 +800,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/**
* Sets the values of this quaternion to the nlerp from itself to q2 by blend.
*
* @param q2
* @param blend
*/
@ -829,8 +825,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>add</code> adds the values of this quaternion to those of the
* parameter quaternion. The result is returned as a new quaternion.
*
* @param q
* the quaternion to add to this.
* @param q the quaternion to add to this.
* @return the new quaternion.
*/
public Quaternion add(Quaternion q) {
@ -841,8 +836,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>add</code> adds the values of this quaternion to those of the
* parameter quaternion. The result is stored in this Quaternion.
*
* @param q
* the quaternion to add to this.
* @param q the quaternion to add to this.
* @return This Quaternion after addition.
*/
public Quaternion addLocal(Quaternion q) {
@ -858,8 +852,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* from those of this quaternion. The result is returned as a new
* quaternion.
*
* @param q
* the quaternion to subtract from this.
* @param q the quaternion to subtract from this.
* @return the new quaternion.
*/
public Quaternion subtract(Quaternion q) {
@ -870,8 +863,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>subtract</code> subtracts the values of the parameter quaternion
* from those of this quaternion. The result is stored in this Quaternion.
*
* @param q
* the quaternion to subtract from this.
* @param q the quaternion to subtract from this.
* @return This Quaternion after subtraction.
*/
public Quaternion subtractLocal(Quaternion q) {
@ -903,8 +895,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* It IS safe for q and res to be the same object.
* It IS NOT safe for this and res to be the same object.
*
* @param q
* the quaternion to multiply this quaternion by.
* @param q the quaternion to multiply this quaternion by.
* @param res
* the quaternion to store the result in.
* @return the new quaternion.
@ -950,6 +941,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* @param axis
* the array containing the three vectors representing the
* coordinate system.
* @return this
*/
public Quaternion fromAxes(Vector3f[] axis) {
if (axis.length != 3) {
@ -970,6 +962,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* @param xAxis vector representing the x-axis of the coordinate system.
* @param yAxis vector representing the y-axis of the coordinate system.
* @param zAxis vector representing the z-axis of the coordinate system.
* @return this
*/
public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis) {
return fromRotationMatrix(xAxis.x, yAxis.x, zAxis.x, xAxis.y, yAxis.y,
@ -982,8 +975,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* corresponds to an axis of the coordinate system defined by the quaternion
* rotation.
*
* @param axis
* the array of vectors to be filled.
* @param axis the array of vectors to be filled.
*/
public void toAxes(Vector3f axis[]) {
Matrix3f tempMat = toRotationMatrix();
@ -996,8 +988,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>mult</code> multiplies this quaternion by a parameter vector. The
* result is returned as a new vector.
*
* @param v
* the vector to multiply this quaternion by.
* @param v the vector to multiply this quaternion by.
* @return the new vector.
*/
public Vector3f mult(Vector3f v) {
@ -1008,8 +999,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>mult</code> multiplies this quaternion by a parameter vector. The
* result is stored in the supplied vector
*
* @param v
* the vector to multiply this quaternion by.
* @param v the vector to multiply this quaternion by.
* @return v
*/
public Vector3f multLocal(Vector3f v) {
@ -1031,8 +1021,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* stored in this Quaternion, which is also returned for chaining. Similar
* to this *= q.
*
* @param q
* The Quaternion to multiply this one by.
* @param q The Quaternion to multiply this one by.
* @return This Quaternion, after multiplication.
*/
public Quaternion multLocal(Quaternion q) {
@ -1051,14 +1040,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* stored in this Quaternion, which is also returned for chaining. Similar
* to this *= q.
*
* @param qx -
* quat x value
* @param qy -
* quat y value
* @param qz -
* quat z value
* @param qw -
* quat w value
* @param qx quat x value
* @param qy quat y value
* @param qz quat z value
* @param qw quat w value
*
* @return This Quaternion, after multiplication.
*/
@ -1172,6 +1157,8 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/**
* <code>normalize</code> normalizes the current <code>Quaternion</code>.
* The result is stored internally.
*
* @return this
*/
public Quaternion normalizeLocal() {
float n = FastMath.invSqrt(norm());
@ -1221,8 +1208,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
}
/**
* <code>negate</code> inverts the values of the quaternion.
*
* Flip the signs of all components of this Quaternion.
*/
public void negate() {
x *= -1;
@ -1232,11 +1218,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
}
/**
* <code>toString</code> returns a string representation of this
* <code>Quaternion</code>. The format is:
*
* <code>toString</code> creates the string representation of this
* <code>Quaternion</code>. The values of the quaternion are displaced (x,
* y, z, w), in the following manner: <br>
* (x, y, z, w)
* (X.XXXX, Y.YYYY, Z.ZZZZ, W.WWWW)
*
* @return the string representation of this object.
* @see java.lang.Object#toString()
@ -1283,6 +1268,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/**
* Returns true if this quaternion is similar to the specified quaternion
* within some value of epsilon.
*
* @param other the Quaternion to compare with (not null, unaffected)
* @param epsilon the error tolerance for each component
* @return true if all 4 components are within tolerance, otherwise false
*/
public boolean isSimilar(Quaternion other, float epsilon) {
if (other == null) {
@ -1304,7 +1293,6 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
}
/**
*
* <code>hashCode</code> returns the hash code value as an integer and is
* supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc.
@ -1370,6 +1358,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* @param up
* a vector indicating the local up direction.
* (typically {0, 1, 0} in jME.)
* @return this
*/
public Quaternion lookAt(Vector3f direction, Vector3f up) {
TempVars vars = TempVars.get();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -51,9 +51,9 @@ public class Spline implements Savable {
}
private List<Vector3f> controlPoints = new ArrayList<Vector3f>();
private List<Float> knots; //knots of NURBS spline
private float[] weights; //weights of NURBS spline
private int basisFunctionDegree; //degree of NURBS spline basis function (computed automatically)
private List<Float> knots; //knots of NURBS spline
private float[] weights; //weights of NURBS spline
private int basisFunctionDegree; //degree of NURBS spline basis function (computed automatically)
private boolean cycle;
private List<Float> segmentsLength;
private float totalLength;
@ -66,6 +66,7 @@ public class Spline implements Savable {
/**
* Create a spline
*
* @param splineType the type of the spline @see {SplineType}
* @param controlPoints an array of vector to use as control points of the spline
* If the type of the curve is Bezier curve the control points should be provided
@ -80,9 +81,9 @@ public class Spline implements Savable {
* @param cycle true if the spline cycle.
*/
public Spline(SplineType splineType, Vector3f[] controlPoints, float curveTension, boolean cycle) {
if(splineType==SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
}
if (splineType == SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
}
for (int i = 0; i < controlPoints.length; i++) {
Vector3f vector3f = controlPoints[i];
this.controlPoints.add(vector3f);
@ -95,6 +96,7 @@ public class Spline implements Savable {
/**
* Create a spline
*
* @param splineType the type of the spline @see {SplineType}
* @param controlPoints a list of vector to use as control points of the spline
* If the type of the curve is Bezier curve the control points should be provided
@ -109,9 +111,9 @@ public class Spline implements Savable {
* @param cycle true if the spline cycle.
*/
public Spline(SplineType splineType, List<Vector3f> controlPoints, float curveTension, boolean cycle) {
if(splineType==SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
}
if (splineType == SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
}
type = splineType;
this.controlPoints.addAll(controlPoints);
this.curveTension = curveTension;
@ -122,26 +124,27 @@ public class Spline implements Savable {
/**
* Create a NURBS spline. A spline type is automatically set to SplineType.Nurb.
* The cycle is set to <b>false</b> by default.
*
* @param controlPoints a list of vector to use as control points of the spline
* @param nurbKnots the nurb's spline knots
* @param nurbKnots the nurb's spline knots
*/
public Spline(List<Vector4f> controlPoints, List<Float> nurbKnots) {
//input data control
for(int i=0;i<nurbKnots.size()-1;++i) {
if(nurbKnots.get(i)>nurbKnots.get(i+1)) {
throw new IllegalArgumentException("The knots values cannot decrease!");
}
}
//input data control
for (int i = 0; i < nurbKnots.size() - 1; ++i) {
if (nurbKnots.get(i) > nurbKnots.get(i + 1)) {
throw new IllegalArgumentException("The knots values cannot decrease!");
}
}
//storing the data
//storing the data
type = SplineType.Nurb;
this.weights = new float[controlPoints.size()];
this.knots = nurbKnots;
this.basisFunctionDegree = nurbKnots.size() - weights.length;
for(int i=0;i<controlPoints.size();++i) {
Vector4f controlPoint = controlPoints.get(i);
this.controlPoints.add(new Vector3f(controlPoint.x, controlPoint.y, controlPoint.z));
this.weights[i] = controlPoint.w;
for (int i = 0; i < controlPoints.size(); ++i) {
Vector4f controlPoint = controlPoints.get(i);
this.controlPoints.add(new Vector3f(controlPoint.x, controlPoint.y, controlPoint.z));
this.weights[i] = controlPoint.w;
}
CurveAndSurfaceMath.prepareNurbsKnots(knots, basisFunctionDegree);
this.computeTotalLength();
@ -175,6 +178,7 @@ public class Spline implements Savable {
/**
* Adds a controlPoint to the spline
*
* @param controlPoint a position in world space
*/
public void addControlPoint(Vector3f controlPoint) {
@ -192,6 +196,7 @@ public class Spline implements Savable {
/**
* remove the controlPoint from the spline
*
* @param controlPoint the controlPoint to remove
*/
public void removeControlPoint(Vector3f controlPoint) {
@ -201,7 +206,7 @@ public class Spline implements Savable {
}
}
public void clearControlPoints(){
public void clearControlPoints() {
controlPoints.clear();
totalLength = 0;
}
@ -225,10 +230,10 @@ public class Spline implements Savable {
totalLength += l;
}
}
} else if(type == SplineType.Bezier) {
this.computeBezierLength();
} else if(type == SplineType.Nurb) {
this.computeNurbLength();
} else if (type == SplineType.Bezier) {
this.computeBezierLength();
} else if (type == SplineType.Nurb) {
this.computeNurbLength();
} else {
this.initCatmullRomWayPoints(controlPoints);
this.computeCatmulLength();
@ -254,11 +259,11 @@ public class Spline implements Savable {
* This method calculates the Bezier curve length.
*/
private void computeBezierLength() {
float l = 0;
float l = 0;
if (controlPoints.size() > 1) {
for (int i = 0; i < controlPoints.size() - 1; i+=3) {
for (int i = 0; i < controlPoints.size() - 1; i += 3) {
l = FastMath.getBezierP1toP2Length(controlPoints.get(i),
controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3));
controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3));
segmentsLength.add(l);
totalLength += l;
}
@ -269,14 +274,17 @@ public class Spline implements Savable {
* This method calculates the NURB curve length.
*/
private void computeNurbLength() {
//TODO: implement
//TODO: implement
}
/**
* Interpolate a position on the spline
* @param value a value from 0 to 1 that represent the position between the current control point and the next one
*
* @param value a value from 0 to 1 that represent the position between the
* current control point and the next one
* @param currentControlPoint the current control point
* @param store a vector to store the result (use null to create a new one that will be returned by the method)
* @param store a vector to store the result (use null to create a new one
* that will be returned by the method)
* @return the position
*/
public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) {
@ -291,11 +299,11 @@ public class Spline implements Savable {
FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store);
break;
case Bezier:
FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store);
break;
FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store);
break;
case Nurb:
CurveAndSurfaceMath.interpolateNurbs(value, this, store);
break;
CurveAndSurfaceMath.interpolateNurbs(value, this, store);
break;
default:
break;
}
@ -304,6 +312,8 @@ public class Spline implements Savable {
/**
* returns the curve tension
*
* @return the value of the tension parameter
*/
public float getCurveTension() {
return curveTension;
@ -316,13 +326,13 @@ public class Spline implements Savable {
*/
public void setCurveTension(float curveTension) {
this.curveTension = curveTension;
if(type==SplineType.CatmullRom && !getControlPoints().isEmpty()) {
this.computeTotalLength();
if (type == SplineType.CatmullRom && !getControlPoints().isEmpty()) {
this.computeTotalLength();
}
}
/**
* returns true if the spline cycle
* @return true if the spline cycles
*/
public boolean isCycle() {
return cycle;
@ -330,27 +340,28 @@ public class Spline implements Savable {
/**
* set to true to make the spline cycle
*
* @param cycle
*/
public void setCycle(boolean cycle) {
if(type!=SplineType.Nurb) {
if (controlPoints.size() >= 2) {
if (this.cycle && !cycle) {
controlPoints.remove(controlPoints.size() - 1);
}
if (!this.cycle && cycle) {
controlPoints.add(controlPoints.get(0));
}
this.cycle = cycle;
this.computeTotalLength();
} else {
this.cycle = cycle;
}
}
if (type != SplineType.Nurb) {
if (controlPoints.size() >= 2) {
if (this.cycle && !cycle) {
controlPoints.remove(controlPoints.size() - 1);
}
if (!this.cycle && cycle) {
controlPoints.add(controlPoints.get(0));
}
this.cycle = cycle;
this.computeTotalLength();
} else {
this.cycle = cycle;
}
}
}
/**
* return the total length of the spline
* @return the total length of the spline
*/
public float getTotalLength() {
return totalLength;
@ -358,6 +369,8 @@ public class Spline implements Savable {
/**
* return the type of the spline
*
* @return the enum value
*/
public SplineType getType() {
return type;
@ -365,6 +378,7 @@ public class Spline implements Savable {
/**
* Sets the type of the spline
*
* @param type
*/
public void setType(SplineType type) {
@ -374,6 +388,8 @@ public class Spline implements Savable {
/**
* returns this spline control points
*
* @return the pre-existing list
*/
public List<Vector3f> getControlPoints() {
return controlPoints;
@ -381,54 +397,62 @@ public class Spline implements Savable {
/**
* returns a list of float representing the segments length
*
* @return the pre-existing list
*/
public List<Float> getSegmentsLength() {
return segmentsLength;
}
//////////// NURBS getters /////////////////////
/**
* This method returns the minimum nurb curve knot value. Check the nurb type before calling this method. It the curve is not of a Nurb
* type - NPE will be thrown.
* @return the minimum nurb curve knot value
*/
/**
* This method returns the minimum nurb curve knot value. Check the nurb
* type before calling this method. It the curve is not of a Nurb type - NPE
* will be thrown.
*
* @return the minimum nurb curve knot value
*/
public float getMinNurbKnot() {
return knots.get(basisFunctionDegree - 1);
return knots.get(basisFunctionDegree - 1);
}
/**
* This method returns the maximum nurb curve knot value. Check the nurb type before calling this method. It the curve is not of a Nurb
* type - NPE will be thrown.
* @return the maximum nurb curve knot value
*/
* This method returns the maximum nurb curve knot value. Check the nurb
* type before calling this method. It the curve is not of a Nurb type - NPE
* will be thrown.
*
* @return the maximum nurb curve knot value
*/
public float getMaxNurbKnot() {
return knots.get(weights.length);
return knots.get(weights.length);
}
/**
* This method returns NURBS' spline knots.
*
* @return NURBS' spline knots
*/
public List<Float> getKnots() {
return knots;
}
return knots;
}
/**
* This method returns NURBS' spline weights.
*
* @return NURBS' spline weights
*/
public float[] getWeights() {
return weights;
}
return weights;
}
/**
* This method returns NURBS' spline basis function degree.
*
* @return NURBS' spline basis function degree
*/
public int getBasisFunctionDegree() {
return basisFunctionDegree;
}
return basisFunctionDegree;
}
@Override
public void write(JmeExporter ex) throws IOException {
@ -449,7 +473,7 @@ public class Spline implements Savable {
oc.writeSavableArrayList((ArrayList) CRcontrolPoints, "CRControlPoints", null);
oc.write(curveTension, "curveTension", 0.5f);
oc.write(cycle, "cycle", false);
oc.writeSavableArrayList((ArrayList<Float>)knots, "knots", null);
oc.writeSavableArrayList((ArrayList<Float>) knots, "knots", null);
oc.write(weights, "weights", null);
oc.write(basisFunctionDegree, "basisFunctionDegree", 0);
}
@ -458,7 +482,8 @@ public class Spline implements Savable {
public void read(JmeImporter im) throws IOException {
InputCapsule in = im.getCapsule(this);
controlPoints = (ArrayList<Vector3f>) in.readSavableArrayList("controlPoints", new ArrayList<Vector3f>()); /* Empty List as default, prevents null pointers */
controlPoints = in.readSavableArrayList("controlPoints", new ArrayList<>());
/* Empty List as default, prevents null pointers */
float list[] = in.readFloatArray("segmentsLength", null);
if (list != null) {
segmentsLength = new ArrayList<Float>();
@ -468,7 +493,7 @@ public class Spline implements Savable {
}
type = in.readEnum("pathSplineType", SplineType.class, SplineType.CatmullRom);
totalLength = in.readFloat("totalLength", 0);
CRcontrolPoints = (ArrayList<Vector3f>) in.readSavableArrayList("CRControlPoints", null);
CRcontrolPoints = in.readSavableArrayList("CRControlPoints", null);
curveTension = in.readFloat("curveTension", 0.5f);
cycle = in.readBoolean("cycle", false);
knots = in.readSavableArrayList("knots", null);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -53,31 +53,32 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
private Vector3f translation = new Vector3f();
private Vector3f scale = new Vector3f(1, 1, 1);
public Transform(Vector3f translation, Quaternion rot){
public Transform(Vector3f translation, Quaternion rot) {
this.translation.set(translation);
this.rot.set(rot);
}
public Transform(Vector3f translation, Quaternion rot, Vector3f scale){
public Transform(Vector3f translation, Quaternion rot, Vector3f scale) {
this(translation, rot);
this.scale.set(scale);
}
public Transform(Vector3f translation){
public Transform(Vector3f translation) {
this(translation, Quaternion.IDENTITY);
}
public Transform(Quaternion rot){
public Transform(Quaternion rot) {
this(Vector3f.ZERO, rot);
}
public Transform(){
public Transform() {
this(Vector3f.ZERO, Quaternion.IDENTITY);
}
/**
* Sets this rotation to the given Quaternion value.
* @param rot The new rotation for this matrix.
*
* @param rot The new rotation for this Transform.
* @return this
*/
public Transform setRotation(Quaternion rot) {
@ -87,7 +88,8 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Sets this translation to the given value.
* @param trans The new translation for this matrix.
*
* @param trans The new translation for this Transform.
* @return this
*/
public Transform setTranslation(Vector3f trans) {
@ -96,7 +98,8 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
}
/**
* Return the translation vector in this matrix.
* Return the translation vector in this Transform.
*
* @return translation vector.
*/
public Vector3f getTranslation() {
@ -105,7 +108,8 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Sets this scale to the given value.
* @param scale The new scale for this matrix.
*
* @param scale The new scale for this Transform.
* @return this
*/
public Transform setScale(Vector3f scale) {
@ -115,7 +119,8 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Sets this scale to the given value.
* @param scale The new scale for this matrix.
*
* @param scale The new scale for this Transform.
* @return this
*/
public Transform setScale(float scale) {
@ -124,7 +129,8 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
}
/**
* Return the scale vector in this matrix.
* Return the scale vector in this Transform.
*
* @return scale vector.
*/
public Vector3f getScale() {
@ -132,31 +138,40 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
}
/**
* Stores this translation value into the given vector3f. If trans is null, a new vector3f is created to
* hold the value. The value, once stored, is returned.
* @param trans The store location for this matrix's translation.
* @return The value of this matrix's translation.
* Stores this translation value into the given vector3f. If trans is null,
* a new vector3f is created to hold the value. The value, once stored, is
* returned.
*
* @param trans The store location for this transform's translation.
* @return The value of this transform's translation.
*/
public Vector3f getTranslation(Vector3f trans) {
if (trans==null) trans=new Vector3f();
if (trans == null) {
trans = new Vector3f();
}
trans.set(this.translation);
return trans;
}
/**
* Stores this rotation value into the given Quaternion. If quat is null, a new Quaternion is created to
* hold the value. The value, once stored, is returned.
* @param quat The store location for this matrix's rotation.
* @return The value of this matrix's rotation.
* Stores this rotation value into the given Quaternion. If quat is null, a
* new Quaternion is created to hold the value. The value, once stored, is
* returned.
*
* @param quat The store location for this transform's rotation.
* @return The value of this transform's rotation.
*/
public Quaternion getRotation(Quaternion quat) {
if (quat==null) quat=new Quaternion();
if (quat == null) {
quat = new Quaternion();
}
quat.set(rot);
return quat;
}
/**
* Return the rotation quaternion in this matrix.
* Return the rotation quaternion in this Transform.
*
* @return rotation quaternion.
*/
public Quaternion getRotation() {
@ -164,34 +179,43 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
}
/**
* Stores this scale value into the given vector3f. If scale is null, a new vector3f is created to
* hold the value. The value, once stored, is returned.
* @param scale The store location for this matrix's scale.
* @return The value of this matrix's scale.
* Stores this scale value into the given vector3f. If scale is null, a new
* vector3f is created to hold the value. The value, once stored, is
* returned.
*
* @param scale The store location for this transform's scale.
* @return The value of this transform's scale.
*/
public Vector3f getScale(Vector3f scale) {
if (scale==null) scale=new Vector3f();
if (scale == null) {
scale = new Vector3f();
}
scale.set(this.scale);
return scale;
}
/**
* Sets this transform to the interpolation between the first transform and the second by delta amount.
* Sets this transform to the interpolation between the first transform and
* the second by delta amount.
*
* @param t1 The beginning transform.
* @param t2 The ending transform.
* @param delta An amount between 0 and 1 representing how far to interpolate from t1 to t2.
* @param delta An amount between 0 and 1 representing how far to
* interpolate from t1 to t2.
*/
public void interpolateTransforms(Transform t1, Transform t2, float delta) {
t1.rot.nlerp(t2.rot, delta);
this.rot.set(t1.rot);
this.translation.interpolateLocal(t1.translation,t2.translation,delta);
this.scale.interpolateLocal(t1.scale,t2.scale,delta);
this.translation.interpolateLocal(t1.translation, t2.translation, delta);
this.scale.interpolateLocal(t1.scale, t2.scale, delta);
}
/**
* Changes the values of this matrix according to its parent. Very similar to the concept of Node/Spatial transforms.
* @param parent The parent matrix.
* @return This matrix, after combining.
* Changes the values of this Transform according to its parent. Very similar
* to the concept of Node/Spatial transforms.
*
* @param parent The parent Transform.
* @return This Transform, after combining.
*/
public Transform combineWithParent(Transform parent) {
//applying parent scale to local scale
@ -202,56 +226,58 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
translation.multLocal(parent.scale);
//applying parent rotation to local translation, then applying parent translation to local translation.
//Note that parent.rot.multLocal(translation) doesn't modify "parent.rot" but "translation"
parent
.rot
.multLocal(translation)
.addLocal(parent.translation);
parent.rot
.multLocal(translation)
.addLocal(parent.translation);
return this;
}
/**
* Sets this matrix's translation to the given x,y,z values.
* @param x This matrix's new x translation.
* @param y This matrix's new y translation.
* @param z This matrix's new z translation.
* Sets this transform's translation to the given x,y,z values.
*
* @param x This transform's new x translation.
* @param y This transform's new y translation.
* @param z This transform's new z translation.
* @return this
*/
public Transform setTranslation(float x,float y, float z) {
translation.set(x,y,z);
public Transform setTranslation(float x, float y, float z) {
translation.set(x, y, z);
return this;
}
/**
* Sets this matrix's scale to the given x,y,z values.
* @param x This matrix's new x scale.
* @param y This matrix's new y scale.
* @param z This matrix's new z scale.
* Sets this transform's scale to the given x,y,z values.
*
* @param x This transform's new x scale.
* @param y This transform's new y scale.
* @param z This transform's new z scale.
* @return this
*/
public Transform setScale(float x, float y, float z) {
scale.set(x,y,z);
scale.set(x, y, z);
return this;
}
public Vector3f transformVector(final Vector3f in, Vector3f store){
if (store == null)
public Vector3f transformVector(final Vector3f in, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
// multiply with scale first, then rotate, finally translate (cf.
// Eberly)
return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
}
public Vector3f transformInverseVector(final Vector3f in, Vector3f store){
if (store == null)
public Vector3f transformInverseVector(final Vector3f in, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
// The author of this code should look above and take the inverse of that
// But for some reason, they didn't ..
// in.subtract(translation, store).divideLocal(scale);
// rot.inverse().mult(store, store);
in.subtract(translation, store);
rot.inverse().mult(store, store);
store.divideLocal(scale);
@ -331,15 +357,17 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
}
@Override
public String toString(){
return getClass().getSimpleName() + "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
+ "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n"
+ "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]";
public String toString() {
return getClass().getSimpleName()
+ "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
+ "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n"
+ "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]";
}
/**
* Sets this matrix to be equal to the given matrix.
* @param matrixQuat The matrix to be equal to.
* Sets this Transform to be equal to the given Transform.
*
* @param matrixQuat The Transform to be equal to.
* @return this
*/
public Transform set(Transform matrixQuat) {
@ -361,9 +389,9 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
rot.set((Quaternion)capsule.readSavable("rot", Quaternion.IDENTITY));
translation.set((Vector3f)capsule.readSavable("translation", Vector3f.ZERO));
scale.set((Vector3f)capsule.readSavable("scale", Vector3f.UNIT_XYZ));
rot.set((Quaternion) capsule.readSavable("rot", Quaternion.IDENTITY));
translation.set((Vector3f) capsule.readSavable("translation", Vector3f.ZERO));
scale.set((Vector3f) capsule.readSavable("scale", Vector3f.UNIT_XYZ));
}
@Override

View File

@ -235,6 +235,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* @param changeAmnt
* An amount between 0.0 - 1.0 representing a percentage change
* from this towards finalVec
* @return this
*/
public Vector2f interpolateLocal(Vector2f finalVec, float changeAmnt) {
this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x;
@ -253,6 +254,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* @param changeAmnt
* An amount between 0.0 - 1.0 representing a percentage change
* from beginVec towards finalVec
* @return this
*/
public Vector2f interpolateLocal(Vector2f beginVec, Vector2f finalVec,
float changeAmnt) {
@ -622,6 +624,8 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>zero</code> resets this vector's data to zero internally.
*
* @return this
*/
public Vector2f zero() {
x = y = 0;
@ -696,6 +700,10 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Returns true if this vector is similar to the specified vector within
* some value of epsilon.
*
* @param other the vector to compare with (not null, unaffected)
* @param epsilon the desired error tolerance for each component
* @return true if both components are within tolerance, otherwise false
*/
public boolean isSimilar(Vector2f other, float epsilon) {
if (other == null) {

View File

@ -29,7 +29,6 @@
* 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.math;
import com.jme3.export.*;
@ -52,7 +51,6 @@ import java.util.logging.Logger;
public final class Vector3f implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private static final Logger logger = Logger.getLogger(Vector3f.class.getName());
public final static Vector3f ZERO = new Vector3f(0, 0, 0);
@ -69,18 +67,14 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
/**
/**
* the x value of the vector.
*/
public float x;
/**
* the y value of the vector.
*/
public float y;
/**
* the z value of the vector.
*/
@ -156,7 +150,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>add</code> adds a provided vector to this vector creating a
* resultant vector which is returned. If the provided vector is null, null
* is returned.
@ -174,7 +167,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>add</code> adds the values of a provided vector storing the
* values in the supplied vector.
*
@ -212,7 +204,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>add</code> adds the provided values to this vector, creating a
* new vector that is then returned.
*
@ -249,7 +240,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>scaleAdd</code> multiplies this vector by a scalar then adds the
* given Vector3f.
*
@ -257,6 +247,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* the value to multiply this vector by.
* @param add
* the value to add
* @return this
*/
public Vector3f scaleAdd(float scalar, Vector3f add) {
x = x * scalar + add.x;
@ -266,7 +257,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>scaleAdd</code> multiplies the given vector by a scalar then adds
* the given vector.
*
@ -276,6 +266,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* the value to multiply the scalar by
* @param add
* the value to add
* @return this
*/
public Vector3f scaleAdd(float scalar, Vector3f mult, Vector3f add) {
this.x = mult.x * scalar + add.x;
@ -285,7 +276,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>dot</code> calculates the dot product of this vector with a
* provided vector. If the provided vector is null, 0 is returned.
*
@ -323,7 +313,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* the vector to store the cross product result.
* @return result, after receiving the cross product vector.
*/
public Vector3f cross(Vector3f v,Vector3f result) {
public Vector3f cross(Vector3f v, Vector3f result) {
return cross(v.x, v.y, v.z, result);
}
@ -342,7 +332,9 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return result, after receiving the cross product vector.
*/
public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) {
if (result == null) result = new Vector3f();
if (result == null) {
result = new Vector3f();
}
float resX = ((y * otherZ) - (z * otherY));
float resY = ((z * otherX) - (x * otherZ));
float resZ = ((x * otherY) - (y * otherX));
@ -375,8 +367,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return this.
*/
public Vector3f crossLocal(float otherX, float otherY, float otherZ) {
float tempx = ( y * otherZ ) - ( z * otherY );
float tempy = ( z * otherX ) - ( x * otherZ );
float tempx = (y * otherZ) - (z * otherY);
float tempy = (z * otherX) - (x * otherZ);
z = (x * otherY) - (y * otherX);
x = tempx;
y = tempy;
@ -389,10 +381,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @param other The vector to project this vector onto
* @return A new vector with the projection result
*/
public Vector3f project(Vector3f other){
public Vector3f project(Vector3f other) {
float n = this.dot(other); // A . B
float d = other.lengthSquared(); // |B|^2
return new Vector3f(other).multLocal(n/d);
return new Vector3f(other).multLocal(n / d);
}
/**
@ -402,10 +394,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @param other The vector to project this vector onto
* @return This Vector3f, set to the projection result
*/
public Vector3f projectLocal(Vector3f other){
public Vector3f projectLocal(Vector3f other) {
float n = this.dot(other); // A . B
float d = other.lengthSquared(); // |B|^2
return set(other).multLocal(n/d);
return set(other).multLocal(n / d);
}
/**
@ -415,7 +407,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return true if this vector is a unit vector (length() ~= 1),
* or false otherwise.
*/
public boolean isUnitVector(){
public boolean isUnitVector() {
float len = length();
return 0.99f < len && len < 1.01f;
}
@ -465,7 +457,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is returned.
*
@ -478,7 +469,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is supplied as the second parameter and returned.
*
@ -581,11 +571,12 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
logger.warning("Provided vector is null, null returned.");
return null;
}
if (store == null) store = new Vector3f();
if (store == null) {
store = new Vector3f();
}
return store.set(x * vec.x, y * vec.y, z * vec.z);
}
/**
* <code>divide</code> divides the values of this vector by a scalar and
* returns the result. The values of this vector remain untouched.
@ -595,7 +586,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return the result <code>Vector</code>.
*/
public Vector3f divide(float scalar) {
scalar = 1f/scalar;
scalar = 1f / scalar;
return new Vector3f(x * scalar, y * scalar, z * scalar);
}
@ -609,14 +600,13 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return this
*/
public Vector3f divideLocal(float scalar) {
scalar = 1f/scalar;
scalar = 1f / scalar;
x *= scalar;
y *= scalar;
z *= scalar;
return this;
}
/**
* <code>divide</code> divides the values of this vector by a scalar and
* returns the result. The values of this vector remain untouched.
@ -646,7 +636,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>negate</code> returns the negative of this vector. All values are
* negated and set to a new vector.
*
@ -657,7 +646,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>negateLocal</code> negates the internal values of this vector.
*
* @return this.
@ -670,7 +658,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code> subtracts the values of a given vector from those
* of this vector creating a new vector object. If the provided vector is
* null, null is returned.
@ -704,7 +691,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code>
*
* @param vec
@ -714,7 +700,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return result
*/
public Vector3f subtract(Vector3f vec, Vector3f result) {
if(result == null) {
if (result == null) {
result = new Vector3f();
}
result.x = x - vec.x;
@ -724,7 +710,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code> subtracts the provided values from this vector,
* creating a new vector that is then returned.
*
@ -773,7 +758,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
//
// return divide(1);
float length = x * x + y * y + z * z;
if (length != 1f && length != 0f){
if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length);
return new Vector3f(x * length, y * length, z * length);
}
@ -791,7 +776,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
// than the old jme normalize as this method
// is commonly used.
float length = x * x + y * y + z * z;
if (length != 1f && length != 0f){
if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length);
x *= length;
y *= length;
@ -804,9 +789,11 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>maxLocal</code> computes the maximum value for each
* component in this and <code>other</code> vector. The result is stored
* in this vector.
*
* @param other
* @return this
*/
public Vector3f maxLocal(Vector3f other){
public Vector3f maxLocal(Vector3f other) {
x = other.x > x ? other.x : x;
y = other.y > y ? other.y : y;
z = other.z > z ? other.z : z;
@ -817,9 +804,11 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>minLocal</code> computes the minimum value for each
* component in this and <code>other</code> vector. The result is stored
* in this vector.
*
* @param other
* @return this
*/
public Vector3f minLocal(Vector3f other){
public Vector3f minLocal(Vector3f other) {
x = other.x < x ? other.x : x;
y = other.y < y ? other.y : y;
z = other.z < z ? other.z : z;
@ -828,6 +817,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
/**
* <code>zero</code> resets this vector's data to zero internally.
* @return this
*/
public Vector3f zero() {
x = y = z = 0;
@ -850,47 +840,58 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
/**
* Sets this vector to the interpolation by changeAmnt from this to the finalVec
* this=(1-changeAmnt)*this + changeAmnt * finalVec
*
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalVec
* @return this
*/
public Vector3f interpolateLocal(Vector3f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*this.x + changeAmnt*finalVec.x;
this.y=(1-changeAmnt)*this.y + changeAmnt*finalVec.y;
this.z=(1-changeAmnt)*this.z + changeAmnt*finalVec.z;
this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x;
this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y;
this.z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z;
return this;
}
/**
* Sets this vector to the interpolation by changeAmnt from beginVec to finalVec
* this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
*
* @param beginVec the beginning vector (changeAmnt=0)
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from beginVec towards finalVec
* @return this
*/
public Vector3f interpolateLocal(Vector3f beginVec,Vector3f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*beginVec.x + changeAmnt*finalVec.x;
this.y=(1-changeAmnt)*beginVec.y + changeAmnt*finalVec.y;
this.z=(1-changeAmnt)*beginVec.z + changeAmnt*finalVec.z;
public Vector3f interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmnt) {
this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x;
this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y;
this.z = (1 - changeAmnt) * beginVec.z + changeAmnt * finalVec.z;
return this;
}
/**
* Check a vector... if it is null or its floats are NaN or infinite,
* return false. Else return true.
*
* @param vector the vector to check
* @return true or false as stated above.
*/
public static boolean isValidVector(Vector3f vector) {
if (vector == null) return false;
if (Float.isNaN(vector.x) ||
Float.isNaN(vector.y) ||
Float.isNaN(vector.z)) return false;
if (Float.isInfinite(vector.x) ||
Float.isInfinite(vector.y) ||
Float.isInfinite(vector.z)) return false;
return true;
if (vector == null) {
return false;
}
if (Float.isNaN(vector.x)
|| Float.isNaN(vector.y)
|| Float.isNaN(vector.z)) {
return false;
}
if (Float.isInfinite(vector.x)
|| Float.isInfinite(vector.y)
|| Float.isInfinite(vector.z)) {
return false;
}
return true;
}
public static void generateOrthonormalBasis(Vector3f u, Vector3f v, Vector3f w) {
@ -959,20 +960,34 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return true if they are equal
*/
public boolean equals(Object o) {
if (!(o instanceof Vector3f)) { return false; }
if (!(o instanceof Vector3f)) {
return false;
}
if (this == o) { return true; }
if (this == o) {
return true;
}
Vector3f comp = (Vector3f) o;
if (Float.compare(x,comp.x) != 0) return false;
if (Float.compare(y,comp.y) != 0) return false;
if (Float.compare(z,comp.z) != 0) return false;
if (Float.compare(x, comp.x) != 0) {
return false;
}
if (Float.compare(y, comp.y) != 0) {
return false;
}
if (Float.compare(z, comp.z) != 0) {
return false;
}
return true;
}
/**
* Returns true if this vector is similar to the specified vector within
* some value of epsilon.
*
* @param other the vector to compare with (not null, unaffected)
* @param epsilon the desired error tolerance for each component
* @return true if all 3 components are within tolerance, otherwise false
*/
public boolean isSimilar(Vector3f other, float epsilon) {
if (other == null) {
@ -994,6 +1009,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>hashCode</code> returns a unique code for this vector object based
* on its values. If two vectors are logically equivalent, they will return
* the same hash code value.
*
* @return the hash code value of this vector.
*/
public int hashCode() {
@ -1098,5 +1114,4 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
throw new IllegalArgumentException("index must be either 0, 1 or 2");
}
}

View File

@ -232,6 +232,8 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* the y value to add.
* @param addZ
* the z value to add.
* @param addW
* the w value to add.
* @return the result vector.
*/
public Vector4f add(float addX, float addY, float addZ, float addW) {
@ -249,6 +251,8 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* value to add to y
* @param addZ
* value to add to z
* @param addW
* the w value to add.
* @return this
*/
public Vector4f addLocal(float addX, float addY, float addZ, float addW) {
@ -268,6 +272,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* the value to multiply this vector by.
* @param add
* the value to add
* @return this
*/
public Vector4f scaleAdd(float scalar, Vector4f add) {
x = x * scalar + add.x;
@ -288,6 +293,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* the value to multiply the scalar by
* @param add
* the value to add
* @return this
*/
public Vector4f scaleAdd(float scalar, Vector4f mult, Vector4f add) {
this.x = mult.x * scalar + add.x;
@ -732,6 +738,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* component in this and <code>other</code> vector. The result is stored
* in this vector.
* @param other
* @return this
*/
public Vector4f maxLocal(Vector4f other){
x = other.x > x ? other.x : x;
@ -746,6 +753,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* component in this and <code>other</code> vector. The result is stored
* in this vector.
* @param other
* @return this
*/
public Vector4f minLocal(Vector4f other){
x = other.x < x ? other.x : x;
@ -757,6 +765,8 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
/**
* <code>zero</code> resets this vector's data to zero internally.
*
* @return this, with all components set to zero
*/
public Vector4f zero() {
x = y = z = w = 0;
@ -782,6 +792,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalVec
* @return this
*/
public Vector4f interpolateLocal(Vector4f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*this.x + changeAmnt*finalVec.x;
@ -798,6 +809,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from beginVec towards finalVec
* @return this
*/
public Vector4f interpolateLocal(Vector4f beginVec,Vector4f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*beginVec.x + changeAmnt*finalVec.x;
@ -878,6 +890,10 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
/**
* Returns true if this vector is similar to the specified vector within
* some value of epsilon.
*
* @param other the vector to compare with (not null, unaffected)
* @param epsilon the desired error tolerance for each component
* @return true if all 4 components are within tolerance, otherwise false
*/
public boolean isSimilar(Vector4f other, float epsilon) {
if (other == null) {

View File

@ -45,7 +45,7 @@ public abstract class AbstractOpenCLObject implements OpenCLObject {
@Override
public AbstractOpenCLObject register() {
OpenCLObjectManager.getInstance().registerObject(this);
return this;
return this;
}
@Override
public void release() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2016 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -53,11 +53,11 @@ public abstract class Buffer extends AbstractOpenCLObject {
super(releaser);
}
@Override
public Buffer register() {
super.register();
return this;
}
@Override
public Buffer register() {
super.register();
return this;
}
/**
* @return the size of the buffer in bytes.
@ -75,6 +75,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs a blocking read of the buffer.
* The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte read.
*
* @param queue the command queue
* @param dest the target buffer
* @param size the size in bytes being read
@ -102,6 +103,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs an async/non-blocking read of the buffer.
* The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte read.
*
* @param queue the command queue
* @param dest the target buffer
* @param size the size in bytes being read
@ -130,6 +132,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs a blocking write to the buffer.
* The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte that will be written.
*
* @param queue the command queue
* @param src the source buffer, its data is written to this buffer
* @param size the size in bytes to write
@ -157,6 +160,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs an async/non-blocking write to the buffer.
* The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte that will be written.
*
* @param queue the command queue
* @param src the source buffer, its data is written to this buffer
* @param size the size in bytes to write
@ -183,6 +187,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
/**
* Performs a blocking copy operation from this buffer to the specified buffer.
*
* @param queue the command queue
* @param dest the target buffer
* @param size the size in bytes to copy
@ -209,6 +214,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
/**
* Performs an async/non-blocking copy operation from this buffer to the specified buffer.
*
* @param queue the command queue
* @param dest the target buffer
* @param size the size in bytes to copy
@ -240,6 +246,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* provides the memory.<br>
* <b>Important:</b> The mapped memory MUST be released by calling
* {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }.
*
* @param queue the command queue
* @param size the size in bytes to map
* @param offset the offset into this buffer
@ -272,6 +279,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Unmaps a previously mapped memory.
* This releases the native resources and for WRITE_ONLY or READ_WRITE access,
* the memory content is sent back to the GPU.
*
* @param queue the command queue
* @param ptr the buffer that was previously mapped
*/
@ -283,6 +291,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* provides the memory.<br>
* <b>Important:</b> The mapped memory MUST be released by calling
* {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }.
*
* @param queue the command queue
* @param size the size in bytes to map
* @param offset the offset into this buffer
@ -291,6 +300,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* and the event indicating when the buffer contents are available
*/
public abstract AsyncMapping mapAsync(CommandQueue queue, long size, long offset, MappingAccess access);
/**
* Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess) },
* sets {@code offset} to zero.
@ -300,6 +310,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
public AsyncMapping mapAsync(CommandQueue queue, long size, MappingAccess access) {
return mapAsync(queue, size, 0, access);
}
/**
* Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess) },
* sets {@code size} to {@link #getSize() }.
@ -313,6 +324,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
/**
* Enqueues a fill operation. This method can be used to initialize or clear
* a buffer with a certain value.
*
* @param queue the command queue
* @param pattern the buffer containing the filling pattern.
* The remaining bytes specify the pattern length
@ -379,6 +391,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* done, the buffer must be released by calling
* {@link #releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
* so that OpenGL can use the VertexBuffer again.
*
* @param queue the command queue
* @return the event object
*/
@ -411,6 +424,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Call this method after the buffer object was acquired by
* {@link #acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
* to hand the control back to OpenGL.
*
* @param queue the command queue
* @return the event object
*/
@ -430,9 +444,8 @@ public abstract class Buffer extends AbstractOpenCLObject {
releaseBufferForSharingAsync(queue).release();
}
@Override
public String toString() {
return "Buffer (" + getSize() + "B)";
}
@Override
public String toString() {
return "Buffer (" + getSize() + "B)";
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2016 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -40,32 +40,33 @@ package com.jme3.opencl;
* Each command queue is associtated with exactly one device: that device
* is specified on creation ({@link Context#createQueue(com.jme3.opencl.Device) })
* and all commands are sent to this device.
*
* @author shaman
*/
public abstract class CommandQueue extends AbstractOpenCLObject {
protected Device device;
protected Device device;
protected CommandQueue(ObjectReleaser releaser, Device device) {
super(releaser);
this.device = device;
this.device = device;
}
@Override
public CommandQueue register() {
super.register();
return this;
}
@Override
public CommandQueue register() {
super.register();
return this;
}
/**
* Returns the device associated with this command queue.
* It can be used to query properties of the device that is used to execute
* the commands issued to this command queue.
* @return the associated device
*/
public Device getDevice() {
return device;
}
/**
* Returns the device associated with this command queue.
* It can be used to query properties of the device that is used to execute
* the commands issued to this command queue.
*
* @return the associated device
*/
public Device getDevice() {
return device;
}
/**
* Issues all previously queued OpenCL commands in command_queue to the
@ -83,5 +84,4 @@ public abstract class CommandQueue extends AbstractOpenCLObject {
* processed and completed. Finish is also a synchronization point.
*/
public abstract void finish();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -63,6 +63,7 @@ import java.util.logging.Logger;
* <li>Created buffers and images shared with OpenGL vertex buffers, textures and renderbuffers</li>
* <li>Create program objects from source code and source files</li>
* </ul>
*
* @author shaman
*/
public abstract class Context extends AbstractOpenCLObject {
@ -72,11 +73,11 @@ public abstract class Context extends AbstractOpenCLObject {
super(releaser);
}
@Override
public Context register() {
super.register();
return this;
}
@Override
public Context register() {
super.register();
return this;
}
/**
* Returns all available devices for this context.
@ -87,6 +88,7 @@ public abstract class Context extends AbstractOpenCLObject {
* memory size and so on, are queried over the Device instances.
* <br>
* The available devices were specified by a {@link PlatformChooser}.
*
* @return a list of devices
*/
public abstract List<? extends Device> getDevices();
@ -94,29 +96,35 @@ public abstract class Context extends AbstractOpenCLObject {
/**
* Alternative version of {@link #createQueue(com.jme3.opencl.Device) },
* just uses the first device returned by {@link #getDevices() }.
*
* @return the command queue
*/
public CommandQueue createQueue() {
return createQueue(getDevices().get(0));
}
/**
* Creates a command queue sending commands to the specified device.
* The device must be an entry of {@link #getDevices() }.
*
* @param device the target device
* @return the command queue
*/
public abstract CommandQueue createQueue(Device device);
public abstract CommandQueue createQueue(Device device);
/**
* Allocates a new buffer of the specific size and access type on the device.
*
* @param size the size of the buffer in bytes
* @param access the allowed access of this buffer from kernel code
* @return the new buffer
*/
public abstract Buffer createBuffer(long size, MemoryAccess access);
/**
* Alternative version of {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) },
* creates a buffer with read and write access.
*
* @param size the size of the buffer in bytes
* @return the new buffer
*/
@ -129,14 +137,17 @@ public abstract class Context extends AbstractOpenCLObject {
* specified by a ByteBuffer can then be used directly by kernel code,
* although the access might be slower than with native buffers
* created by {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) }.
*
* @param data the host buffer to use
* @param access the allowed access of this buffer from kernel code
* @return the new buffer
*/
public abstract Buffer createBufferFromHost(ByteBuffer data, MemoryAccess access);
/**
* Alternative version of {@link #createBufferFromHost(java.nio.ByteBuffer, com.jme3.opencl.MemoryAccess) },
* creates a buffer with read and write access.
*
* @param data the host buffer to use
* @return the new buffer
*/
@ -152,13 +163,14 @@ public abstract class Context extends AbstractOpenCLObject {
* with row and slice pitches. This buffer is then used to store the image.
* If no ByteBuffer is specified, a new buffer is allocated (this is the
* normal behaviour).
*
* @param access the allowed access of this image from kernel code
* @param format the image format
* @param descr the image descriptor
* @return the new image object
*/
public abstract Image createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr);
//TODO: add simplified methods for 1D, 2D, 3D textures
//TODO: add simplified methods for 1D, 2D, 3D textures
/**
* Queries all supported image formats for a specified memory access and
@ -168,13 +180,14 @@ public abstract class Context extends AbstractOpenCLObject {
* where {@code ImageChannelType} or {@code ImageChannelOrder} are {@code null}
* (or both). This is the case when the device supports new formats that
* are not included in this wrapper yet.
*
* @param access the memory access type
* @param type the image type (1D, 2D, 3D, ...)
* @return an array of all supported image formats
*/
public abstract ImageFormat[] querySupportedFormats(MemoryAccess access, ImageType type);
//Interop
//Interop
/**
* Creates a shared buffer from a VertexBuffer.
* The returned buffer and the vertex buffer operate on the same memory,
@ -188,6 +201,7 @@ public abstract class Context extends AbstractOpenCLObject {
* by {@link Buffer#acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
* and after modifying it, released by {@link Buffer#releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) }.
* This is needed so that OpenGL and OpenCL operations do not interfere with each other.
*
* @param vb the vertex buffer to share
* @param access the memory access for the kernel
* @return the new buffer
@ -216,6 +230,7 @@ public abstract class Context extends AbstractOpenCLObject {
* @return the OpenCL image
*/
public abstract Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access);
/**
* Creates a shared image object from a jME3 texture.
* The returned image shares the same memory with the jME3 texture, changes
@ -242,9 +257,11 @@ public abstract class Context extends AbstractOpenCLObject {
public Image bindImage(Texture texture, int miplevel, MemoryAccess access) {
return bindImage(texture.getImage(), texture.getType(), miplevel, access);
}
/**
* Alternative version to {@link #bindImage(com.jme3.texture.Texture, int, com.jme3.opencl.MemoryAccess) },
* uses {@code miplevel=0}.
*
* @param texture the jME3 texture
* @param access the allowed memory access for kernels
* @return the OpenCL image
@ -252,6 +269,7 @@ public abstract class Context extends AbstractOpenCLObject {
public Image bindImage(Texture texture, MemoryAccess access) {
return bindImage(texture, 0, access);
}
/**
* Creates a shared image object from a jME3 render buffer.
* The returned image shares the same memory with the jME3 render buffer, changes
@ -279,6 +297,7 @@ public abstract class Context extends AbstractOpenCLObject {
return bindImage(buffer.getTexture(), access);
}
}
protected abstract Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access);
/**
@ -295,6 +314,7 @@ public abstract class Context extends AbstractOpenCLObject {
* and delegates the combined source code to
* {@link #createProgramFromSourceCode(java.lang.String) }.
* Important: only absolute paths are allowed.
*
* @param sourceCode the original source code
* @param assetManager the asset manager to load the files
* @return the created program object
@ -310,6 +330,7 @@ public abstract class Context extends AbstractOpenCLObject {
}
return createProgramFromSourceCode(builder.toString());
}
private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException {
String ln;
while ((ln = reader.readLine()) != null) {
@ -319,11 +340,11 @@ public abstract class Context extends AbstractOpenCLObject {
ln = ln.substring(1);
}
if (ln.endsWith("\"")) {
ln = ln.substring(0, ln.length()-1);
ln = ln.substring(0, ln.length() - 1);
}
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(ln));
if (info == null) {
throw new AssetNotFoundException("Unable to load source file \""+ln+"\"");
throw new AssetNotFoundException("Unable to load source file \"" + ln + "\"");
}
try (BufferedReader r = new BufferedReader(new InputStreamReader(info.openStream()))) {
builder.append("//-- begin import ").append(ln).append(" --\n");
@ -390,7 +411,7 @@ public abstract class Context extends AbstractOpenCLObject {
for (String res : resources) {
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res));
if (info == null) {
throw new AssetNotFoundException("Unable to load source file \""+res+"\"");
throw new AssetNotFoundException("Unable to load source file \"" + res + "\"");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(info.openStream()))) {
while (true) {
@ -401,7 +422,7 @@ public abstract class Context extends AbstractOpenCLObject {
str.append(line).append('\n');
}
} catch (IOException ex) {
LOG.log(Level.WARNING, "unable to load source file '"+res+"'", ex);
LOG.log(Level.WARNING, "unable to load source file '" + res + "'", ex);
}
}
return createProgramFromSourceCodeWithDependencies(str.toString(), assetManager);
@ -410,6 +431,7 @@ public abstract class Context extends AbstractOpenCLObject {
/**
* Alternative version of {@link #createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.lang.String...) }
* with an empty include string
*
* @throws AssetNotFoundException if a file could not be loaded
*/
public Program createProgramFromSourceFiles(AssetManager assetManager, String... resources) {
@ -419,6 +441,7 @@ public abstract class Context extends AbstractOpenCLObject {
/**
* Alternative version of {@link #createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.util.List) }
* with an empty include string
*
* @throws AssetNotFoundException if a file could not be loaded
*/
public Program createProgramFromSourceFiles(AssetManager assetManager, List<String> resources) {
@ -443,9 +466,8 @@ public abstract class Context extends AbstractOpenCLObject {
*/
public abstract Program createProgramFromBinary(ByteBuffer binaries, Device device);
@Override
public String toString() {
return "Context (" + getDevices() + ')';
}
@Override
public String toString() {
return "Context (" + getDevices() + ')';
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -45,79 +45,92 @@ import java.util.Collection;
* @author shaman
*/
public interface Device {
/**
* @return the platform associated with this device
*/
Platform getPlatform();
/**
* The device type
*/
public static enum DeviceType {
DEFAULT,
CPU,
GPU,
ACCELEARTOR,
ALL
}
public static enum DeviceType {
DEFAULT,
CPU,
GPU,
ACCELEARTOR,
ALL
}
/**
* @return queries the device type
*/
DeviceType getDeviceType();
DeviceType getDeviceType();
/**
* @return the vendor id
*/
int getVendorId();
int getVendorId();
/**
* checks if this device is available at all, must always be tested
*
* @return checks if this device is available at all, must always be tested
*/
boolean isAvailable();
boolean isAvailable();
/**
* @return if this device has a compiler for kernel code
*/
boolean hasCompiler();
boolean hasCompiler();
/**
* @return supports double precision floats (64 bit)
*/
boolean hasDouble();
boolean hasDouble();
/**
* @return supports half precision floats (16 bit)
*/
boolean hasHalfFloat();
boolean hasHalfFloat();
/**
* @return supports error correction for every access to global or constant memory
*/
boolean hasErrorCorrectingMemory();
boolean hasErrorCorrectingMemory();
/**
* @return supports unified virtual memory (OpenCL 2.0)
*/
boolean hasUnifiedMemory();
boolean hasUnifiedMemory();
/**
* @return supports images
*/
boolean hasImageSupport();
boolean hasImageSupport();
/**
* @return supports writes to 3d images (this is an extension)
*/
boolean hasWritableImage3D();
/**
* @return supports sharing with OpenGL
*/
boolean hasOpenGLInterop();
/**
* Explictly tests for the availability of the specified extension
*
* @param extension the name of the extension
* @return {@code true} iff this extension is supported
*/
boolean hasExtension(String extension);
boolean hasExtension(String extension);
/**
* Lists all available extensions
*
* @return all available extensions
*/
Collection<? extends String> getExtensions();
Collection<? extends String> getExtensions();
/**
* Returns the number of parallel compute units on
@ -128,82 +141,100 @@ public interface Device {
* @see #getMaximumWorkItemDimensions()
* @see #getMaximumWorkItemSizes()
*/
int getComputeUnits();
int getComputeUnits();
/**
* @return maximum clock frequency of the device in MHz
*/
int getClockFrequency();
int getClockFrequency();
/**
* Returns the default compute device address space
* size specified as an unsigned integer value
* in bits. Currently supported values are 32
* or 64 bits.
*
* @return the size of an address
*/
int getAddressBits();
int getAddressBits();
/**
* @return {@code true} if this device is little endian
*/
boolean isLittleEndian();
boolean isLittleEndian();
/**
* The maximum dimension that specify the local and global work item ids.
* You can always assume to be this at least 3.
* Therefore, the ids are always three integers x,y,z.
*
* @return the maximum dimension of work item ids
*/
long getMaximumWorkItemDimensions();
long getMaximumWorkItemDimensions();
/**
* Maximum number of work-items that can be specified in each dimension of the
* work-group to {@link Kernel#Run2(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...)}.
* The array has a length of at least 3.
*
* @return the maximum size of the work group in each dimension
*/
long[] getMaximumWorkItemSizes();
long[] getMaximumWorkItemSizes();
/**
* Maximum number of work-items in a
* work-group executing a kernel on a single
* compute unit, using the data parallel
* execution model.
*
* @return maximum number of work-items in a work-group
*/
long getMaxiumWorkItemsPerGroup();
long getMaxiumWorkItemsPerGroup();
/**
* @return the maximum number of samples that can be used in a kernel
*/
int getMaximumSamplers();
int getMaximumSamplers();
/**
* @return the maximum number of images that can be used for reading in a kernel
*/
int getMaximumReadImages();
int getMaximumReadImages();
/**
* @return the maximum number of images that can be used for writing in a kernel
*/
int getMaximumWriteImages();
int getMaximumWriteImages();
/**
* Queries the maximal size of a 2D image
*
* @return an array of length 2 with the maximal size of a 2D image
*/
long[] getMaximumImage2DSize();
long[] getMaximumImage2DSize();
/**
* Queries the maximal size of a 3D image
*
* @return an array of length 3 with the maximal size of a 3D image
*/
long[] getMaximumImage3DSize();
long[] getMaximumImage3DSize();
/**
* @return the maximal size of a memory object (buffer and image) in bytes
*/
long getMaximumAllocationSize();
/**
* @return the total available global memory in bytes
*/
long getGlobalMemorySize();
/**
* @return the total available local memory in bytes
*/
long getLocalMemorySize();
/**
* Returns the maximal size of a constant buffer.
* <br>
@ -214,12 +245,13 @@ public interface Device {
* @return the maximal size of a constant buffer
*/
long getMaximumConstantBufferSize();
/**
* @return the maximal number of constant buffer arguments in a kernel call
*/
int getMaximumConstantArguments();
//TODO: cache, prefered sizes properties
//TODO: cache, prefered sizes properties
/**
* OpenCL profile string. Returns the profile name supported by the device.
* The profile name returned can be one of the following strings:<br>
@ -230,7 +262,8 @@ public interface Device {
*
* @return the profile string
*/
String getProfile();
String getProfile();
/**
* OpenCL version string. Returns the OpenCL version supported by the
* device. This version string has the following format: OpenCL space
@ -240,19 +273,23 @@ public interface Device {
*
* @return the version string
*/
String getVersion();
String getVersion();
/**
* Extracts the major version from the version string
*
* @return the major version
* @see #getVersion()
*/
int getVersionMajor();
int getVersionMajor();
/**
* Extracts the minor version from the version string
*
* @return the minor version
* @see #getVersion() }
*/
int getVersionMinor();
int getVersionMinor();
/**
* OpenCL C version string. Returns the highest OpenCL C version supported
@ -268,44 +305,53 @@ public interface Device {
*
* @return the compiler version
*/
String getCompilerVersion();
String getCompilerVersion();
/**
* Extracts the major version from the compiler version
*
* @return the major compiler version
* @see #getCompilerVersion()
*/
int getCompilerVersionMajor();
int getCompilerVersionMajor();
/**
* Extracts the minor version from the compiler version
*
* @return the minor compiler version
* @see #getCompilerVersion()
*/
int getCompilerVersionMinor();
int getCompilerVersionMinor();
/**
* @return the OpenCL software driver version string in the form
* major_number.minor_number
*/
String getDriverVersion();
String getDriverVersion();
/**
* Extracts the major version from the driver version
*
* @return the major driver version
* @see #getDriverVersion()
*/
int getDriverVersionMajor();
int getDriverVersionMajor();
/**
* Extracts the minor version from the driver version
*
* @return the minor driver version
* @see #getDriverVersion()
*/
int getDriverVersionMinor();
int getDriverVersionMinor();
/**
* @return the device name
*/
String getName();
String getName();
/**
* @return the vendor
*/
String getVendor();
String getVendor();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2016 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@ package com.jme3.opencl;
* Events are returned from kernel launches and all asynchronous operations.
* They allow to test if the action has completed and to block until the operation
* is done.
*
* @author shaman
*/
public abstract class Event extends AbstractOpenCLObject {
@ -44,22 +45,23 @@ public abstract class Event extends AbstractOpenCLObject {
super(releaser);
}
@Override
public Event register() {
super.register();
return this;
}
@Override
public Event register() {
super.register();
return this;
}
/**
* Waits until the action has finished (blocking).
* This automatically releases the event.
*/
public abstract void waitForFinished();
public abstract void waitForFinished();
/**
* Tests if the action is completed.
* If the action is completed, the event is released.
*
* @return {@code true} if the action is completed
*/
public abstract boolean isCompleted();
public abstract boolean isCompleted();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -75,7 +75,6 @@ import java.util.Objects;
* @author shaman
*/
public abstract class Image extends AbstractOpenCLObject {
/**
* {@code ImageChannelType} describes the size of the channel data type.
*/
@ -99,7 +98,7 @@ public abstract class Image extends AbstractOpenCLObject {
/**
* {@code ImageChannelOrder} specifies the number of channels and the channel layout i.e. the
memory layout in which channels are stored in the image.
* memory layout in which channels are stored in the image.
*/
public static enum ImageChannelOrder {
R, Rx, A,
@ -157,7 +156,6 @@ memory layout in which channels are stored in the image.
}
return true;
}
}
/**
@ -193,13 +191,14 @@ memory layout in which channels are stored in the image.
/*
public int numMipLevels; //They must always be set to zero
public int numSamples;
*/
*/
public ImageDescriptor() {
}
/**
* Used to specify an image with the provided ByteBuffer as soruce
*
* @param type the image type
* @param width the width
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*}
@ -219,9 +218,11 @@ memory layout in which channels are stored in the image.
this.slicePitch = slicePitch;
this.hostPtr = hostPtr;
}
/**
* Specifies an image without a host buffer, a new chunk of memory
* will be allocated.
*
* @param type the image type
* @param width the width
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*}
@ -243,53 +244,60 @@ memory layout in which channels are stored in the image.
public String toString() {
return "ImageDescriptor{" + "type=" + type + ", width=" + width + ", height=" + height + ", depth=" + depth + ", arraySize=" + arraySize + ", rowPitch=" + rowPitch + ", slicePitch=" + slicePitch + '}';
}
}
protected Image(ObjectReleaser releaser) {
super(releaser);
}
@Override
public Image register() {
super.register();
return this;
}
@Override
public Image register() {
super.register();
return this;
}
/**
* @return the width of the image
*/
public abstract long getWidth();
/**
* @return the height of the image
*/
public abstract long getHeight();
/**
* @return the depth of the image
*/
public abstract long getDepth();
/**
* @return the row pitch when the image was created from a host buffer
*/
public abstract long getRowPitch();
/**
* @return the slice pitch when the image was created from a host buffer
*/
public abstract long getSlicePitch();
/**
* @return the number of elements in the image array
* @see ImageType#IMAGE_1D_ARRAY
* @see ImageType#IMAGE_2D_ARRAY
*/
public abstract long getArraySize();
/**
* @return the image format
*/
public abstract ImageFormat getImageFormat();
/**
* @return the image type
*/
public abstract ImageType getImageType();
/**
* @return the number of bytes per pixel
*/
@ -297,6 +305,7 @@ memory layout in which channels are stored in the image.
/**
* Performs a blocking read of the image into the specified byte buffer.
*
* @param queue the command queue
* @param dest the target byte buffer
* @param origin the image origin location, see class description for the format
@ -307,8 +316,10 @@ memory layout in which channels are stored in the image.
* If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height}
*/
public abstract void readImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch);
/**
* Performs an async/non-blocking read of the image into the specified byte buffer.
*
* @param queue the command queue
* @param dest the target byte buffer
* @param origin the image origin location, see class description for the format
@ -323,6 +334,7 @@ memory layout in which channels are stored in the image.
/**
* Performs a blocking write from the specified byte buffer into the image.
*
* @param queue the command queue
* @param src the source buffer
* @param origin the image origin location, see class description for the format
@ -333,8 +345,10 @@ memory layout in which channels are stored in the image.
* If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height}
*/
public abstract void writeImage(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch);
/**
* Performs an async/non-blocking write from the specified byte buffer into the image.
*
* @param queue the command queue
* @param src the source buffer
* @param origin the image origin location, see class description for the format
@ -350,6 +364,7 @@ memory layout in which channels are stored in the image.
/**
* Performs a blocking copy operation from one image to another.
* <b>Important:</b> Both images must have the same format!
*
* @param queue the command queue
* @param dest the target image
* @param srcOrigin the source image origin, see class description for the format
@ -357,9 +372,11 @@ memory layout in which channels are stored in the image.
* @param region the copied region, see class description for the format
*/
public abstract void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region);
/**
* Performs an async/non-blocking copy operation from one image to another.
* <b>Important:</b> Both images must have the same format!
*
* @param queue the command queue
* @param dest the target image
* @param srcOrigin the source image origin, see class description for the format
@ -374,6 +391,7 @@ memory layout in which channels are stored in the image.
* The returned structure contains the mapped byte buffer and row and slice pitch.
* The event object is set to {@code null}, it is needed for the asnyc
* version {@link #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }.
*
* @param queue the command queue
* @param origin the image origin, see class description for the format
* @param region the mapped region, see class description for the format
@ -382,6 +400,7 @@ memory layout in which channels are stored in the image.
* @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping)
*/
public abstract ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
/**
* Non-blocking version of {@link #map(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }.
* The returned structure contains the mapped byte buffer and row and slice pitch.
@ -394,8 +413,10 @@ memory layout in which channels are stored in the image.
* @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping)
*/
public abstract ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
/**
* Unmaps the mapped memory
*
* @param queue the command queue
* @param mapping the mapped memory
*/
@ -421,6 +442,7 @@ memory layout in which channels are stored in the image.
public final long slicePitch;
/**
* The event object used to detect when the memory is available.
*
* @see #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess)
*/
public final Event event;
@ -431,19 +453,20 @@ memory layout in which channels are stored in the image.
this.slicePitch = slicePitch;
this.event = event;
}
public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch) {
this.buffer = buffer;
this.rowPitch = rowPitch;
this.slicePitch = slicePitch;
this.event = null;
}
}
/**
* Fills the image with the specified color.
* Does <b>only</b> work if the image channel is {@link ImageChannelType#FLOAT}
* or {@link ImageChannelType#HALF_FLOAT}.
*
* @param queue the command queue
* @param origin the image origin, see class description for the format
* @param region the size of the region, see class description for the format
@ -455,6 +478,7 @@ memory layout in which channels are stored in the image.
* Fills the image with the specified color given as four integer variables.
* Does <b>not</b> work if the image channel is {@link ImageChannelType#FLOAT}
* or {@link ImageChannelType#HALF_FLOAT}.
*
* @param queue the command queue
* @param origin the image origin, see class description for the format
* @param region the size of the region, see class description for the format
@ -467,6 +491,7 @@ memory layout in which channels are stored in the image.
* Copies this image into the specified buffer, no format conversion is done.
* This is the dual function to
* {@link Buffer#copyToImageAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image, long, long[], long[]) }.
*
* @param queue the command queue
* @param dest the target buffer
* @param srcOrigin the image origin, see class description for the format
@ -485,6 +510,7 @@ memory layout in which channels are stored in the image.
* done, the image must be released by calling
* {@link #releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) }
* so that OpenGL can use the image/texture/renderbuffer again.
*
* @param queue the command queue
* @return the event object
*/
@ -518,6 +544,7 @@ memory layout in which channels are stored in the image.
* Call this method after the image object was acquired by
* {@link #acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) }
* to hand the control back to OpenGL.
*
* @param queue the command queue
* @return the event object
*/
@ -530,6 +557,7 @@ memory layout in which channels are stored in the image.
* to hand the control back to OpenGL.
* The generated event object is directly released, resulting in
* performance improvements.
*
* @param queue the command queue
*/
public void releaseImageForSharingNoEvent(CommandQueue queue) {
@ -537,25 +565,24 @@ memory layout in which channels are stored in the image.
releaseImageForSharingAsync(queue).release();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append("Image (");
ImageType t = getImageType();
str.append(t);
str.append(", w=").append(getWidth());
if (t == ImageType.IMAGE_2D || t == ImageType.IMAGE_3D) {
str.append(", h=").append(getHeight());
}
if (t == ImageType.IMAGE_3D) {
str.append(", d=").append(getDepth());
}
if (t == ImageType.IMAGE_1D_ARRAY || t == ImageType.IMAGE_2D_ARRAY) {
str.append(", arrays=").append(getArraySize());
}
str.append(", ").append(getImageFormat());
str.append(')');
return str.toString();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append("Image (");
ImageType t = getImageType();
str.append(t);
str.append(", w=").append(getWidth());
if (t == ImageType.IMAGE_2D || t == ImageType.IMAGE_3D) {
str.append(", h=").append(getHeight());
}
if (t == ImageType.IMAGE_3D) {
str.append(", d=").append(getDepth());
}
if (t == ImageType.IMAGE_1D_ARRAY || t == ImageType.IMAGE_2D_ARRAY) {
str.append(", arrays=").append(getArraySize());
}
str.append(", ").append(getImageFormat());
str.append(')');
return str.toString();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -97,11 +97,11 @@ public abstract class Kernel extends AbstractOpenCLObject {
this.workGroupSize = new WorkSize(0);
}
@Override
public Kernel register() {
super.register();
return this;
}
@Override
public Kernel register() {
super.register();
return this;
}
/**
* @return the name of the kernel as defined in the program source code
@ -122,6 +122,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the global work size.
*
* @param ws the work size to set
*/
public void setGlobalWorkSize(WorkSize ws) {
@ -130,6 +131,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the global work size to a 1D grid
*
* @param size the size in 1D
*/
public void setGlobalWorkSize(int size) {
@ -138,6 +140,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the global work size to be a 2D grid
*
* @param width the width
* @param height the height
*/
@ -147,6 +150,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the global work size to be a 3D grid
*
* @param width the width
* @param height the height
* @param depth the depth
@ -164,6 +168,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the work group size
*
* @param ws the work group size to set
*/
public void setWorkGroupSize(WorkSize ws) {
@ -172,6 +177,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the work group size to be a 1D grid
*
* @param size the size to set
*/
public void setWorkGroupSize(int size) {
@ -180,6 +186,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the work group size to be a 2D grid
*
* @param width the width
* @param height the height
*/
@ -189,6 +196,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the work group size to be a 3D grid
*
* @param width the width
* @param height the height
* @param depth the depth
@ -211,6 +219,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Returns the maximal work group size when this kernel is executed on
* the specified device
*
* @param device the device
* @return the maximal work group size
*/
@ -249,8 +258,8 @@ public abstract class Kernel extends AbstractOpenCLObject {
try {
Matrix4f m = vars.tempMat4;
m.zero();
for (int i=0; i<3; ++i) {
for (int j=0; j<3; ++j) {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
m.set(i, j, mat.get(i, j));
}
}
@ -266,6 +275,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* argument. The size in bytes must match exactly the argument size
* as defined in the kernel code.
* Use this method to send custom structures to the kernel
*
* @param index the index of the argument
* @param buffer the raw buffer
* @param size the size in bytes
@ -279,6 +289,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* long, float, double, Vector2f, Vector4f, Quaternion, Matrix3f, Matrix4f}.
* <br>
* Note: Matrix3f and Matrix4f will be mapped to a {@code float16} (row major).
*
* @param index the index of the argument, from 0 to {@link #getArgCount()}-1
* @param arg the argument
* @throws IllegalArgumentException if the argument type is not one of the listed ones
@ -331,6 +342,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* If the returned event object is not needed and would otherwise be
* released immediately, {@link #RunNoEvent(com.jme3.opencl.CommandQueue) }
* might bring a better performance.
*
* @param queue the command queue
* @return an event object indicating when the kernel is finished
* @see #setGlobalWorkSize(com.jme3.opencl.Kernel.WorkSize)
@ -345,6 +357,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* The generated event is directly released. Therefore, the performance
* is better, but there is no way to detect when the kernel execution
* has finished. For this purpose, use {@link #Run(com.jme3.opencl.CommandQueue) }.
*
* @param queue the command queue
* @see #setGlobalWorkSize(com.jme3.opencl.Kernel.WorkSize)
* @see #setWorkGroupSize(com.jme3.opencl.Kernel.WorkSize)
@ -361,6 +374,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* size is automatically determined by the driver.
* Each object in the argument array is sent to the kernel by
* {@link #setArg(int, java.lang.Object) }.
*
* @param queue the command queue
* @param globalWorkSize the global work size
* @param args the kernel arguments
@ -384,6 +398,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* is better, but there is no way to detect when the kernel execution
* has finished. For this purpose, use
* {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
*
* @param queue the command queue
* @param globalWorkSize the global work size
* @param args the kernel arguments
@ -398,6 +413,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Sets the work sizes and arguments in one call and launches the kernel.
*
* @param queue the command queue
* @param globalWorkSize the global work size
* @param workGroupSize the work group size
@ -418,6 +434,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* is better, but there is no way to detect when the kernel execution
* has finished. For this purpose, use
* {@link #Run2(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
*
* @param queue the command queue
* @param globalWorkSize the global work size
* @param workGroupSize the work group size
@ -431,22 +448,22 @@ public abstract class Kernel extends AbstractOpenCLObject {
RunNoEvent(queue);
}
@Override
public String toString() {
return "Kernel (" + getName() + ")";
}
@Override
public String toString() {
return "Kernel (" + getName() + ")";
}
/**
* A placeholder for kernel arguments representing local kernel memory.
* This defines the size of available shared memory of a {@code __shared} kernel
* A placeholder for kernel arguments representing local kernel memory. This
* defines the size of available shared memory of a {@code __shared} kernel
* argument
*/
public static final class LocalMem {
private int size;
/**
* Creates a new LocalMem instance
*
* @param size the size of the available shared memory in bytes
*/
public LocalMem(int size) {
@ -480,10 +497,10 @@ public abstract class Kernel extends AbstractOpenCLObject {
return true;
}
@Override
public String toString() {
return "LocalMem (" + size + "B)";
}
@Override
public String toString() {
return "LocalMem (" + size + "B)";
}
}
@ -498,11 +515,11 @@ public abstract class Kernel extends AbstractOpenCLObject {
* (e.g. by {@link #setWorkGroupSizeToNull()} or {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
*/
public static final class LocalMemPerElement {
private int size;
/**
* Creates a new LocalMemPerElement instance
*
* @param size the number of bytes available for each thread within
* a work group
*/
@ -537,15 +554,16 @@ public abstract class Kernel extends AbstractOpenCLObject {
return true;
}
@Override
public String toString() {
return "LocalMemPerElement (" + size + "B)";
}
@Override
public String toString() {
return "LocalMemPerElement (" + size + "B)";
}
}
/**
* The work size (global and local) for executing a kernel
*
* @author shaman
*/
public static final class WorkSize {
@ -555,6 +573,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Creates a new work size object
*
* @param dimension the dimension (1,2,3)
* @param sizes the sizes in each dimension, the length must match the specified dimension
*/
@ -572,6 +591,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Creates a 1D work size of the specified extend
*
* @param size the size
*/
public WorkSize(long size) {
@ -580,6 +600,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Creates a 2D work size of the specified extend
*
* @param width the width
* @param height the height
*/
@ -589,6 +610,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/**
* Creates a 3D work size of the specified extend.
*
* @param width the width
* @param height the height
* @param depth the depth
@ -647,20 +669,18 @@ public abstract class Kernel extends AbstractOpenCLObject {
return true;
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append("WorkSize[");
for (int i=0; i<dimension; ++i) {
if (i>0) {
str.append(", ");
}
str.append(sizes[i]);
}
str.append(']');
return str.toString();
}
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append("WorkSize[");
for (int i = 0; i < dimension; ++i) {
if (i > 0) {
str.append(", ");
}
str.append(sizes[i]);
}
str.append(']');
return str.toString();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,23 +36,23 @@ package com.jme3.opencl;
* when the compilation failed.
* The error log returned by {@link #getLog() } contains detailed information
* where the error occurred.
*
* @author shaman
*/
public class KernelCompilationException extends OpenCLException {
private final String log;
private final String log;
public KernelCompilationException(String msg, int errorCode, String log) {
super(msg, errorCode);
this.log = log;
}
public KernelCompilationException(String msg, int errorCode, String log) {
super(msg, errorCode);
this.log = log;
}
/**
* The output of the compiler
*
* @return the output text
*/
public String getLog() {
return log;
}
public String getLog() {
return log;
}
}

View File

@ -41,18 +41,18 @@ public enum MappingAccess {
/**
* Only read access is allowed to the mapped memory.
*/
MAP_READ_ONLY,
MAP_READ_ONLY,
/**
* Only write access is allowed to the mapped memory.
*/
MAP_WRITE_ONLY,
MAP_WRITE_ONLY,
/**
* Both read and write access is allowed.
*/
MAP_READ_WRITE,
MAP_READ_WRITE,
/**
* The old memory content is completely discarded and the buffer is filled
* completely with new data. This might be faster than {@link #MAP_WRITE_ONLY}
*/
MAP_WRITE_INVALIDATE
MAP_WRITE_INVALIDATE
}

View File

@ -40,13 +40,13 @@ public enum MemoryAccess {
/**
* A kernel can both read and write the buffer.
*/
READ_WRITE,
READ_WRITE,
/**
* A kernel can only write this buffer.
*/
WRITE_ONLY,
WRITE_ONLY,
/**
* A kernel can only read this buffer
*/
READ_ONLY
READ_ONLY
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2016 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,43 +36,42 @@ package com.jme3.opencl;
* The error code and its name is reported in the message string as well as the OpenCL call that
* causes this exception. Please refer to the official OpenCL specification
* to see what might cause this exception.
*
* @author shaman
*/
public class OpenCLException extends RuntimeException {
private static final long serialVersionUID = 8471229972153694848L;
private final int errorCode;
private final int errorCode;
/**
* Creates a new instance of <code>OpenCLExceptionn</code> without detail
* message.
*/
public OpenCLException() {
errorCode = 0;
}
/**
* Creates a new instance of <code>OpenCLExceptionn</code> without detail
* message.
*/
public OpenCLException() {
errorCode = 0;
}
/**
* Constructs an instance of <code>OpenCLExceptionn</code> with the
* specified detail message.
*
* @param msg the detail message.
*/
public OpenCLException(String msg) {
super(msg);
errorCode = 0;
}
/**
* Constructs an instance of <code>OpenCLExceptionn</code> with the
* specified detail message.
*
* @param msg the detail message.
*/
public OpenCLException(String msg) {
super(msg);
errorCode = 0;
}
public OpenCLException(String msg, int errorCode) {
super(msg);
this.errorCode = errorCode;
}
public OpenCLException(String msg, int errorCode) {
super(msg);
this.errorCode = errorCode;
}
/**
* @return the error code
*/
public int getErrorCode() {
return errorCode;
}
public int getErrorCode() {
return errorCode;
}
}

View File

@ -61,7 +61,7 @@ public interface OpenCLObject {
ObjectReleaser getReleaser();
/**
* Releases this native object.
*
*
* Should delegate to {@code getReleaser().release()}.
*/
void release();
@ -71,10 +71,10 @@ public interface OpenCLObject {
* {@link OpenCLObjectManager}, you have to release it manually
* by calling {@link #release() }.
* Without registering or releasing, a memory leak might occur.
* <br>
* Returns {@code this} to allow calls like
* {@code Buffer buffer = clContext.createBuffer(1024).register();}.
* @return {@code this}
* <br>
* Returns {@code this} to allow calls like
* {@code Buffer buffer = clContext.createBuffer(1024).register();}.
* @return {@code this}
*/
OpenCLObject register();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -50,11 +50,11 @@ public abstract class Program extends AbstractOpenCLObject {
super(releaser);
}
@Override
public Program register() {
super.register();
return this;
}
@Override
public Program register() {
super.register();
return this;
}
/**
* Builds this program with the specified argument string on the specified
@ -70,40 +70,44 @@ public abstract class Program extends AbstractOpenCLObject {
* @throws KernelCompilationException if the compilation fails
* @see #build()
*/
public abstract void build(String args, Device... devices) throws KernelCompilationException;
public abstract void build(String args, Device... devices) throws KernelCompilationException;
/**
* Builds this program without additional arguments
*
* @throws KernelCompilationException if the compilation fails
*/
public void build() throws KernelCompilationException {
public void build() throws KernelCompilationException {
build("", (Device[]) null);
}
/**
* Creates the kernel with the specified name.
*
* @param name the name of the kernel as defined in the source code
* @return the kernel object
* @throws OpenCLException if the kernel was not found or some other
* error occurred
* @throws OpenCLException if the kernel was not found or some other error
* occurred
*/
public abstract Kernel createKernel(String name);
public abstract Kernel createKernel(String name);
/**
* Creates all available kernels in this program.
* The names of the kernels can then by queried by {@link Kernel#getName() }.
*
* @return an array of all kernels
*/
public abstract Kernel[] createAllKernels();
public abstract Kernel[] createAllKernels();
/**
* Queries a compiled binary representation of this program for a particular
* device. This binary can then be used e.g. in the next application launch
* to create the program from the binaries and not from the sources.
* This saves time.
*
* @param device the device from which the binaries are taken
* @return the binaries
* @see Context#createProgramFromBinary(java.nio.ByteBuffer, com.jme3.opencl.Device)
*/
public abstract ByteBuffer getBinary(Device device);
}

View File

@ -287,14 +287,14 @@ public class Camera implements Savable, Cloneable {
}
}
/**
* This method copies the settings of the given camera.
*
* @param cam
* the camera we copy the settings from
*/
/**
* This method copies the settings of the given camera.
*
* @param cam
* the camera we copy the settings from
*/
public void copyFrom(Camera cam) {
location.set(cam.location);
location.set(cam.location);
rotation.set(cam.rotation);
frustumNear = cam.frustumNear;

View File

@ -32,7 +32,6 @@
package com.jme3.renderer;
import com.jme3.material.RenderState;
import com.jme3.material.RenderState.BlendFunc;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
@ -49,96 +48,96 @@ public class RenderContext {
/**
* @see RenderState#setFaceCullMode(com.jme3.material.RenderState.FaceCullMode)
*/
public RenderState.FaceCullMode cullMode = RenderState.FaceCullMode.Off;
public RenderState.FaceCullMode cullMode;
/**
* @see RenderState#setDepthTest(boolean)
*/
public boolean depthTestEnabled = false;
public boolean depthTestEnabled;
/**
* @see RenderState#setDepthWrite(boolean)
*/
public boolean depthWriteEnabled = true;
public boolean depthWriteEnabled;
/**
* @see RenderState#setColorWrite(boolean)
*/
public boolean colorWriteEnabled = true;
public boolean colorWriteEnabled;
/**
* @see Renderer#setClipRect(int, int, int, int)
*/
public boolean clipRectEnabled = false;
public boolean clipRectEnabled;
/**
* @see RenderState#setPolyOffset(float, float)
*/
public boolean polyOffsetEnabled = false;
public boolean polyOffsetEnabled;
/**
* @see RenderState#setPolyOffset(float, float)
*/
public float polyOffsetFactor = 0;
public float polyOffsetFactor;
/**
* @see RenderState#setPolyOffset(float, float)
*/
public float polyOffsetUnits = 0;
public float polyOffsetUnits;
/**
* @see Mesh#setPointSize(float)
*/
public float pointSize = 1;
public float pointSize;
/**
* @see RenderState#setLineWidth(float)
*/
public float lineWidth = 1;
public float lineWidth;
/**
* @see RenderState#setBlendMode(com.jme3.material.RenderState.BlendMode)
*/
public RenderState.BlendMode blendMode = RenderState.BlendMode.Off;
public RenderState.BlendMode blendMode;
/**
* @see RenderState#setBlendEquation(com.jme3.material.RenderState.BlendEquation)
*/
public RenderState.BlendEquation blendEquation = RenderState.BlendEquation.Add;
public RenderState.BlendEquation blendEquation;
/**
* @see RenderState#setBlendEquationAlpha(com.jme3.material.RenderState.BlendEquationAlpha)
*/
public RenderState.BlendEquationAlpha blendEquationAlpha = RenderState.BlendEquationAlpha.InheritColor;
public RenderState.BlendEquationAlpha blendEquationAlpha;
/**
* @see RenderState#setCustomBlendFactors(com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc,
* com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc)
*/
public RenderState.BlendFunc sfactorRGB = RenderState.BlendFunc.One;
public RenderState.BlendFunc sfactorRGB;
/**
* @see RenderState#setCustomBlendFactors(com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc,
* com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc)
*/
public RenderState.BlendFunc dfactorRGB = RenderState.BlendFunc.One;
public RenderState.BlendFunc dfactorRGB;
/**
* @see RenderState#setCustomBlendFactors(com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc,
* com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc)
*/
public RenderState.BlendFunc sfactorAlpha = RenderState.BlendFunc.One;
public RenderState.BlendFunc sfactorAlpha;
/**
* @see RenderState#setCustomBlendFactors(com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc,
* com.jme3.material.RenderState.BlendFunc, com.jme3.material.RenderState.BlendFunc)
*/
public RenderState.BlendFunc dfactorAlpha = RenderState.BlendFunc.One;
public RenderState.BlendFunc dfactorAlpha;
/**
* @see RenderState#setWireframe(boolean)
*/
public boolean wireframe = false;
public boolean wireframe;
/**
* @see Renderer#setShader(com.jme3.shader.Shader)
@ -153,7 +152,7 @@ public class RenderContext {
/**
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
*/
public int boundFBO = 0;
public int boundFBO;
/**
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
@ -165,7 +164,7 @@ public class RenderContext {
*
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
*/
public int boundRB = 0;
public int boundRB;
/**
* Currently bound draw buffer
@ -178,7 +177,7 @@ public class RenderContext {
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
* @see FrameBuffer#setTargetIndex(int)
*/
public int boundDrawBuf = -1;
public int boundDrawBuf;
/**
* Currently bound read buffer
@ -187,7 +186,7 @@ public class RenderContext {
* @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer)
* @see FrameBuffer#setTargetIndex(int)
*/
public int boundReadBuf = -1;
public int boundReadBuf;
/**
* Currently bound element array vertex buffer.
@ -213,89 +212,93 @@ public class RenderContext {
*/
public int boundPixelPackPBO;
public int numTexturesSet = 0;
public int numTexturesSet;
/**
* Current bound texture IDs for each texture unit.
*
* @see Renderer#setTexture(int, com.jme3.texture.Texture)
*/
public Image[] boundTextures = new Image[16];
public final Image[] boundTextures = new Image[16];
/**
* IDList for texture units
*
* @see Renderer#setTexture(int, com.jme3.texture.Texture)
*/
public IDList textureIndexList = new IDList();
public final IDList textureIndexList = new IDList();
/**
* Currently bound texture unit
*
* @see Renderer#setTexture(int, com.jme3.texture.Texture)
*/
public int boundTextureUnit = 0;
public int boundTextureUnit;
/**
* Stencil Buffer state
*/
public boolean stencilTest = false;
public RenderState.StencilOperation frontStencilStencilFailOperation = RenderState.StencilOperation.Keep;
public RenderState.StencilOperation frontStencilDepthFailOperation = RenderState.StencilOperation.Keep;
public RenderState.StencilOperation frontStencilDepthPassOperation = RenderState.StencilOperation.Keep;
public RenderState.StencilOperation backStencilStencilFailOperation = RenderState.StencilOperation.Keep;
public RenderState.StencilOperation backStencilDepthFailOperation = RenderState.StencilOperation.Keep;
public RenderState.StencilOperation backStencilDepthPassOperation = RenderState.StencilOperation.Keep;
public RenderState.TestFunction frontStencilFunction = RenderState.TestFunction.Always;
public RenderState.TestFunction backStencilFunction = RenderState.TestFunction.Always;
public boolean stencilTest;
public RenderState.StencilOperation frontStencilStencilFailOperation;
public RenderState.StencilOperation frontStencilDepthFailOperation;
public RenderState.StencilOperation frontStencilDepthPassOperation;
public RenderState.StencilOperation backStencilStencilFailOperation;
public RenderState.StencilOperation backStencilDepthFailOperation;
public RenderState.StencilOperation backStencilDepthPassOperation;
public RenderState.TestFunction frontStencilFunction;
public RenderState.TestFunction backStencilFunction;
/**
* Vertex attribs currently bound and enabled. If a slot is null, then
* it is disabled.
*/
public VertexBuffer[] boundAttribs = new VertexBuffer[16];
public final VertexBuffer[] boundAttribs = new VertexBuffer[16];
/**
* IDList for vertex attributes
*/
public IDList attribIndexList = new IDList();
public final IDList attribIndexList = new IDList();
/**
* depth test function
*/
public RenderState.TestFunction depthFunc = RenderState.TestFunction.Less;
public RenderState.TestFunction depthFunc;
/**
* alpha test function
*/
public RenderState.TestFunction alphaFunc = RenderState.TestFunction.Greater;
public RenderState.TestFunction alphaFunc;
public int initialDrawBuf;
public int initialReadBuf;
public ColorRGBA clearColor = new ColorRGBA(0,0,0,0);
public ColorRGBA clearColor = new ColorRGBA(0, 0, 0, 0);
/**
* Reset the RenderContext to default GL state
*/
public void reset(){
public RenderContext() {
init();
}
private void init() {
cullMode = RenderState.FaceCullMode.Off;
depthTestEnabled = false;
depthWriteEnabled = false;
colorWriteEnabled = false;
depthWriteEnabled = true;
colorWriteEnabled = true;
clipRectEnabled = false;
polyOffsetEnabled = false;
polyOffsetFactor = 0;
polyOffsetUnits = 0;
pointSize = 1;
lineWidth = 1;
blendMode = RenderState.BlendMode.Off;
blendEquation = RenderState.BlendEquation.Add;
blendEquationAlpha = RenderState.BlendEquationAlpha.InheritColor;
sfactorRGB = BlendFunc.One;
dfactorRGB = BlendFunc.One;
sfactorAlpha = BlendFunc.One;
dfactorAlpha = BlendFunc.One;
sfactorRGB = RenderState.BlendFunc.One;
dfactorRGB = RenderState.BlendFunc.One;
sfactorAlpha = RenderState.BlendFunc.One;
dfactorAlpha = RenderState.BlendFunc.One;
wireframe = false;
boundShaderProgram = 0;
boundShader = null;
boundFBO = 0;
@ -308,17 +311,9 @@ public class RenderContext {
boundArrayVBO = 0;
boundPixelPackPBO = 0;
numTexturesSet = 0;
for (int i = 0; i < boundTextures.length; i++)
boundTextures[i] = null;
textureIndexList.reset();
boundTextureUnit = 0;
for (int i = 0; i < boundAttribs.length; i++)
boundAttribs[i] = null;
attribIndexList.reset();
stencilTest = false;
frontStencilStencilFailOperation = RenderState.StencilOperation.Keep;
frontStencilDepthFailOperation = RenderState.StencilOperation.Keep;
frontStencilDepthPassOperation = RenderState.StencilOperation.Keep;
@ -328,8 +323,29 @@ public class RenderContext {
frontStencilFunction = RenderState.TestFunction.Always;
backStencilFunction = RenderState.TestFunction.Always;
depthFunc = RenderState.TestFunction.LessOrEqual;
depthFunc = RenderState.TestFunction.Less;
alphaFunc = RenderState.TestFunction.Greater;
clearColor.set(0,0,0,0);
cullMode = RenderState.FaceCullMode.Off;
clearColor.set(0, 0, 0, 0);
}
/**
* Reset the RenderContext to default GL state
*/
public void reset(){
init();
for (int i = 0; i < boundTextures.length; i++) {
boundTextures[i] = null;
}
textureIndexList.reset();
for (int i = 0; i < boundAttribs.length; i++) {
boundAttribs[i] = null;
}
attribIndexList.reset();
}
}

View File

@ -1,10 +1,65 @@
/*
* 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.renderer.opengl;
import com.jme3.renderer.RendererException;
public abstract class GLDebug {
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* This class uses Reflection to intercept method calls to the Proxy Object ({@link #createProxy(GL, Object, Class[])}
* and extends them with the Error Checking in {@link #checkError()}.<br/>
* This means we don't have to generate a class with overrides for every possible method just to add a
* {@link #checkError()} call.<br/>
* Note that we should not call {@link #checkError()} for {@link GL#glGetError()}, it doesn't make sense.<br />
* Note that this class is general purpose and as such every class instance (every object) can be guarded as long as
* the passed gl instance is valid.<br/>
*
* @author MeFisto94
*/
public class GLDebug implements InvocationHandler {
protected Object obj;
protected GL gl;
protected Method methodGlGetError;
private GLDebug(GL gl, Object obj) throws NoSuchMethodException {
this.gl = gl;
this.obj = obj;
methodGlGetError = GL.class.getMethod("glGetError");
/* The NoSuchMethodException shouldn't be thrown, but since we're in a constructor and cannot fail safe
* otherwise, we throw it. */
}
protected String decodeError(int err) {
String errMsg;
@ -46,4 +101,38 @@ public abstract class GLDebug {
throw new RendererException("An OpenGL error occurred - " + decodeError(err));
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = method.invoke(obj, args);
if (method.equals(methodGlGetError)) {
return result;
}
checkError();
return result;
}
/**
* Creates a debug-proxied object, which will call {@link GL#glGetError()} after every method invocation and throw
* a {@link com.jme3.renderer.RendererException} if there was a GL Error.
*
* @param gl The GL Context, required to call {@link GL#glGetError()}
* @param obj The object which methods will be proxied
* @param implementedInterfaces The interfaces/class this object implements
* @return The Proxy object (or null if an error occured)
*/
public static Object createProxy(GL gl, Object obj, Class<?>... implementedInterfaces) {
try {
return Proxy.newProxyInstance(
GLDebug.class.getClassLoader(),
implementedInterfaces,
new GLDebug(gl, obj)
);
} catch (NoSuchMethodException nsme) {
throw new IllegalArgumentException ("Could not initialize the proxy because the glGetError method wasn't " +
"found!", nsme);
}
}
}

View File

@ -1,134 +0,0 @@
package com.jme3.renderer.opengl;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
public class GLDebugDesktop extends GLDebugES implements GL2, GL3, GL4 {
private final GL2 gl2;
private final GL3 gl3;
private final GL4 gl4;
public GLDebugDesktop(GL gl, GLExt glext, GLFbo glfbo) {
super(gl, glext, glfbo);
this.gl2 = gl instanceof GL2 ? (GL2) gl : null;
this.gl3 = gl instanceof GL3 ? (GL3) gl : null;
this.gl4 = gl instanceof GL4 ? (GL4) gl : null;
}
public void glAlphaFunc(int func, float ref) {
gl2.glAlphaFunc(func, ref);
checkError();
}
public void glPointSize(float size) {
gl2.glPointSize(size);
checkError();
}
public void glPolygonMode(int face, int mode) {
gl2.glPolygonMode(face, mode);
checkError();
}
public void glDrawBuffer(int mode) {
gl2.glDrawBuffer(mode);
checkError();
}
public void glReadBuffer(int mode) {
gl2.glReadBuffer(mode);
checkError();
}
public void glCompressedTexImage3D(int target, int level, int internalformat, int width, int height, int depth, int border, ByteBuffer data) {
gl2.glCompressedTexImage3D(target, level, internalformat, width, height, depth, border, data);
checkError();
}
public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, int format, ByteBuffer data) {
gl2.glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, data);
checkError();
}
public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border, int format, int type, ByteBuffer data) {
gl2.glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data);
checkError();
}
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) {
gl2.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
checkError();
}
public void glBindFragDataLocation(int param1, int param2, String param3) {
gl3.glBindFragDataLocation(param1, param2, param3);
checkError();
}
public void glBindVertexArray(int param1) {
gl3.glBindVertexArray(param1);
checkError();
}
public void glGenVertexArrays(IntBuffer param1) {
gl3.glGenVertexArrays(param1);
checkError();
}
@Override
public String glGetString(int param1, int param2) {
String result = gl3.glGetString(param1, param2);
checkError();
return result;
}
@Override
public int glGetUniformBlockIndex(final int program, final String uniformBlockName) {
final int result = gl3.glGetUniformBlockIndex(program, uniformBlockName);
checkError();
return result;
}
@Override
public void glBindBufferBase(final int target, final int index, final int buffer) {
gl3.glBindBufferBase(target, index, buffer);
checkError();
}
@Override
public void glDeleteVertexArrays(IntBuffer arrays) {
gl3.glDeleteVertexArrays(arrays);
checkError();
}
@Override
public void glPatchParameter(int count) {
gl4.glPatchParameter(count);
checkError();
}
@Override
public int glGetProgramResourceIndex(int program, int programInterface, String name) {
final int result = gl4.glGetProgramResourceIndex(program, programInterface, name);
checkError();
return result;
}
@Override
public void glShaderStorageBlockBinding(int program, int storageBlockIndex, int storageBlockBinding) {
gl4.glShaderStorageBlockBinding(program, storageBlockIndex, storageBlockBinding);
checkError();
}
public void glBlendEquationSeparate(int colorMode, int alphaMode) {
gl.glBlendEquationSeparate(colorMode, alphaMode);
checkError();
}
@Override
public void glUniformBlockBinding(final int program, final int uniformBlockIndex, final int uniformBlockBinding) {
gl3.glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
checkError();
}
}

View File

@ -1,662 +0,0 @@
package com.jme3.renderer.opengl;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
public class GLDebugES extends GLDebug implements GL, GL2, GLES_30, GLFbo, GLExt {
private final GLFbo glfbo;
private final GLExt glext;
public GLDebugES(GL gl, GLExt glext, GLFbo glfbo) {
this.gl = gl;
this.glext = glext;
this.glfbo = glfbo;
}
public void resetStats() {
gl.resetStats();
}
public void glActiveTexture(int texture) {
gl.glActiveTexture(texture);
checkError();
}
public void glAttachShader(int program, int shader) {
gl.glAttachShader(program, shader);
checkError();
}
@Override
public void glBeginQuery(int target, int query) {
gl.glBeginQuery(target, query);
checkError();
}
public void glBindBuffer(int target, int buffer) {
gl.glBindBuffer(target, buffer);
checkError();
}
public void glBindTexture(int target, int texture) {
gl.glBindTexture(target, texture);
checkError();
}
public void glBlendFunc(int sfactor, int dfactor) {
gl.glBlendFunc(sfactor, dfactor);
checkError();
}
public void glBlendFuncSeparate(int sfactorRGB, int dfactorRGB, int sfactorAlpha, int dFactorAlpha)
{
gl.glBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dFactorAlpha);
checkError();
}
public void glBufferData(int target, FloatBuffer data, int usage) {
gl.glBufferData(target, data, usage);
checkError();
}
public void glBufferData(int target, ShortBuffer data, int usage) {
gl.glBufferData(target, data, usage);
checkError();
}
public void glBufferData(int target, ByteBuffer data, int usage) {
gl.glBufferData(target, data, usage);
checkError();
}
public void glBufferSubData(int target, long offset, FloatBuffer data) {
gl.glBufferSubData(target, offset, data);
checkError();
}
public void glBufferSubData(int target, long offset, ShortBuffer data) {
gl.glBufferSubData(target, offset, data);
checkError();
}
public void glBufferSubData(int target, long offset, ByteBuffer data) {
gl.glBufferSubData(target, offset, data);
checkError();
}
public void glClear(int mask) {
gl.glClear(mask);
checkError();
}
public void glClearColor(float red, float green, float blue, float alpha) {
gl.glClearColor(red, green, blue, alpha);
checkError();
}
public void glColorMask(boolean red, boolean green, boolean blue, boolean alpha) {
gl.glColorMask(red, green, blue, alpha);
checkError();
}
public void glCompileShader(int shader) {
gl.glCompileShader(shader);
checkError();
}
public void glCompressedTexImage2D(int target, int level, int internalformat, int width, int height, int border, ByteBuffer data) {
gl.glCompressedTexImage2D(target, level, internalformat, width, height, border, data);
checkError();
}
public void glCompressedTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, ByteBuffer data) {
gl.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, data);
checkError();
}
public int glCreateProgram() {
int program = gl.glCreateProgram();
checkError();
return program;
}
public int glCreateShader(int shaderType) {
int shader = gl.glCreateShader(shaderType);
checkError();
return shader;
}
public void glCullFace(int mode) {
gl.glCullFace(mode);
checkError();
}
public void glDeleteBuffers(IntBuffer buffers) {
gl.glDeleteBuffers(buffers);
checkError();
}
public void glDeleteProgram(int program) {
gl.glDeleteProgram(program);
checkError();
}
public void glDeleteShader(int shader) {
gl.glDeleteShader(shader);
checkError();
}
public void glDeleteTextures(IntBuffer textures) {
gl.glDeleteTextures(textures);
checkError();
}
public void glDepthFunc(int func) {
gl.glDepthFunc(func);
checkError();
}
public void glDepthMask(boolean flag) {
gl.glDepthMask(flag);
checkError();
}
public void glDepthRange(double nearVal, double farVal) {
gl.glDepthRange(nearVal, farVal);
checkError();
}
public void glDetachShader(int program, int shader) {
gl.glDetachShader(program, shader);
checkError();
}
public void glDisable(int cap) {
gl.glDisable(cap);
checkError();
}
public void glDisableVertexAttribArray(int index) {
gl.glDisableVertexAttribArray(index);
checkError();
}
public void glDrawArrays(int mode, int first, int count) {
gl.glDrawArrays(mode, first, count);
checkError();
}
public void glDrawRangeElements(int mode, int start, int end, int count, int type, long indices) {
gl.glDrawRangeElements(mode, start, end, count, type, indices);
checkError();
}
public void glEnable(int cap) {
gl.glEnable(cap);
checkError();
}
public void glEnableVertexAttribArray(int index) {
gl.glEnableVertexAttribArray(index);
checkError();
}
@Override
public void glEndQuery(int target) {
checkError();
}
public void glGenBuffers(IntBuffer buffers) {
gl.glGenBuffers(buffers);
checkError();
}
public void glGenTextures(IntBuffer textures) {
gl.glGenTextures(textures);
checkError();
}
@Override
public void glGenQueries(int num, IntBuffer ids) {
glGenQueries(num, ids);
checkError();
}
public int glGetAttribLocation(int program, String name) {
int location = gl.glGetAttribLocation(program, name);
checkError();
return location;
}
public void glGetBoolean(int pname, ByteBuffer params) {
gl.glGetBoolean(pname, params);
checkError();
}
public int glGetError() {
// No need to check for error here? Haha
return gl.glGetError();
}
public void glGetInteger(int pname, IntBuffer params) {
gl.glGetInteger(pname, params);
checkError();
}
public void glGetProgram(int program, int pname, IntBuffer params) {
gl.glGetProgram(program, pname, params);
checkError();
}
public String glGetProgramInfoLog(int program, int maxSize) {
String infoLog = gl.glGetProgramInfoLog(program, maxSize);
checkError();
return infoLog;
}
@Override
public long glGetQueryObjectui64(int query, int pname) {
long res = gl.glGetQueryObjectui64(query, pname);
checkError();
return res;
}
@Override
public int glGetQueryObjectiv(int query, int pname) {
int res = gl.glGetQueryObjectiv(query, pname);
checkError();
return res;
}
public void glGetShader(int shader, int pname, IntBuffer params) {
gl.glGetShader(shader, pname, params);
checkError();
}
public String glGetShaderInfoLog(int shader, int maxSize) {
String infoLog = gl.glGetShaderInfoLog(shader, maxSize);
checkError();
return infoLog;
}
public String glGetString(int name) {
String string = gl.glGetString(name);
checkError();
return string;
}
public int glGetUniformLocation(int program, String name) {
int location = gl.glGetUniformLocation(program, name);
checkError();
return location;
}
public boolean glIsEnabled(int cap) {
boolean enabled = gl.glIsEnabled(cap);
checkError();
return enabled;
}
public void glLineWidth(float width) {
gl.glLineWidth(width);
checkError();
}
public void glLinkProgram(int program) {
gl.glLinkProgram(program);
checkError();
}
public void glPixelStorei(int pname, int param) {
gl.glPixelStorei(pname, param);
checkError();
}
public void glPolygonOffset(float factor, float units) {
gl.glPolygonOffset(factor, units);
checkError();
}
public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer data) {
gl.glReadPixels(x, y, width, height, format, type, data);
checkError();
}
public void glReadPixels(int x, int y, int width, int height, int format, int type, long offset) {
gl.glReadPixels(x, y, width, height, format, type, offset);
checkError();
}
public void glScissor(int x, int y, int width, int height) {
gl.glScissor(x, y, width, height);
checkError();
}
public void glShaderSource(int shader, String[] string, IntBuffer length) {
gl.glShaderSource(shader, string, length);
checkError();
}
public void glStencilFuncSeparate(int face, int func, int ref, int mask) {
gl.glStencilFuncSeparate(face, func, ref, mask);
checkError();
}
public void glStencilOpSeparate(int face, int sfail, int dpfail, int dppass) {
gl.glStencilOpSeparate(face, sfail, dpfail, dppass);
checkError();
}
public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data) {
gl.glTexImage2D(target, level, internalFormat, width, height, border, format, type, data);
checkError();
}
public void glTexParameterf(int target, int pname, float param) {
gl.glTexParameterf(target, pname, param);
checkError();
}
public void glTexParameteri(int target, int pname, int param) {
gl.glTexParameteri(target, pname, param);
checkError();
}
public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, ByteBuffer data) {
gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
checkError();
}
public void glUniform1(int location, FloatBuffer value) {
gl.glUniform1(location, value);
checkError();
}
public void glUniform1(int location, IntBuffer value) {
gl.glUniform1(location, value);
checkError();
}
public void glUniform1f(int location, float v0) {
gl.glUniform1f(location, v0);
checkError();
}
public void glUniform1i(int location, int v0) {
gl.glUniform1i(location, v0);
checkError();
}
public void glUniform2(int location, IntBuffer value) {
gl.glUniform2(location, value);
checkError();
}
public void glUniform2(int location, FloatBuffer value) {
gl.glUniform2(location, value);
checkError();
}
public void glUniform2f(int location, float v0, float v1) {
gl.glUniform2f(location, v0, v1);
checkError();
}
public void glUniform3(int location, IntBuffer value) {
gl.glUniform3(location, value);
checkError();
}
public void glUniform3(int location, FloatBuffer value) {
gl.glUniform3(location, value);
checkError();
}
public void glUniform3f(int location, float v0, float v1, float v2) {
gl.glUniform3f(location, v0, v1, v2);
checkError();
}
public void glUniform4(int location, FloatBuffer value) {
gl.glUniform4(location, value);
checkError();
}
public void glUniform4(int location, IntBuffer value) {
gl.glUniform4(location, value);
checkError();
}
public void glUniform4f(int location, float v0, float v1, float v2, float v3) {
gl.glUniform4f(location, v0, v1, v2, v3);
checkError();
}
public void glUniformMatrix3(int location, boolean transpose, FloatBuffer value) {
gl.glUniformMatrix3(location, transpose, value);
checkError();
}
public void glUniformMatrix4(int location, boolean transpose, FloatBuffer value) {
gl.glUniformMatrix4(location, transpose, value);
checkError();
}
public void glUseProgram(int program) {
gl.glUseProgram(program);
checkError();
}
public void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, long pointer) {
gl.glVertexAttribPointer(index, size, type, normalized, stride, pointer);
checkError();
}
public void glViewport(int x, int y, int width, int height) {
gl.glViewport(x, y, width, height);
checkError();
}
public void glBindFramebufferEXT(int param1, int param2) {
glfbo.glBindFramebufferEXT(param1, param2);
checkError();
}
public void glBindRenderbufferEXT(int param1, int param2) {
glfbo.glBindRenderbufferEXT(param1, param2);
checkError();
}
public int glCheckFramebufferStatusEXT(int param1) {
int result = glfbo.glCheckFramebufferStatusEXT(param1);
checkError();
return result;
}
public void glDeleteFramebuffersEXT(IntBuffer param1) {
glfbo.glDeleteFramebuffersEXT(param1);
checkError();
}
public void glDeleteRenderbuffersEXT(IntBuffer param1) {
glfbo.glDeleteRenderbuffersEXT(param1);
checkError();
}
public void glFramebufferRenderbufferEXT(int param1, int param2, int param3, int param4) {
glfbo.glFramebufferRenderbufferEXT(param1, param2, param3, param4);
checkError();
}
public void glFramebufferTexture2DEXT(int param1, int param2, int param3, int param4, int param5) {
glfbo.glFramebufferTexture2DEXT(param1, param2, param3, param4, param5);
checkError();
}
public void glGenFramebuffersEXT(IntBuffer param1) {
glfbo.glGenFramebuffersEXT(param1);
checkError();
}
public void glGenRenderbuffersEXT(IntBuffer param1) {
glfbo.glGenRenderbuffersEXT(param1);
checkError();
}
public void glGenerateMipmapEXT(int param1) {
glfbo.glGenerateMipmapEXT(param1);
checkError();
}
public void glRenderbufferStorageEXT(int param1, int param2, int param3, int param4) {
glfbo.glRenderbufferStorageEXT(param1, param2, param3, param4);
checkError();
}
public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
glfbo.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
checkError();
}
@Override
public void glBufferData(int target, long data_size, int usage) {
gl.glBufferData(target, data_size, usage);
checkError();
}
@Override
public void glGetBufferSubData(int target, long offset, ByteBuffer data) {
gl.glGetBufferSubData(target, offset, data);
checkError();
}
public void glBufferData(int target, IntBuffer data, int usage) {
glext.glBufferData(target, data, usage);
checkError();
}
public void glBufferSubData(int target, long offset, IntBuffer data) {
glext.glBufferSubData(target, offset, data);
checkError();
}
public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount) {
glext.glDrawArraysInstancedARB(mode, first, count, primcount);
checkError();
}
public void glDrawBuffers(IntBuffer bufs) {
glext.glDrawBuffers(bufs);
checkError();
}
public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount) {
glext.glDrawElementsInstancedARB(mode, indices_count, type, indices_buffer_offset, primcount);
checkError();
}
public void glGetMultisample(int pname, int index, FloatBuffer val) {
glext.glGetMultisample(pname, index, val);
checkError();
}
public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height) {
glfbo.glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
checkError();
}
public void glTexImage2DMultisample(int target, int samples, int internalformat, int width, int height, boolean fixedsamplelocations) {
glext.glTexImage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
checkError();
}
public void glVertexAttribDivisorARB(int index, int divisor) {
glext.glVertexAttribDivisorARB(index, divisor);
checkError();
}
@Override
public int glClientWaitSync(Object sync, int flags, long timeout) {
int result = glext.glClientWaitSync(sync, flags, timeout);
checkError();
return result;
}
@Override
public void glDeleteSync(Object sync) {
glext.glDeleteSync(sync);
checkError();
}
@Override
public Object glFenceSync(int condition, int flags) {
Object sync = glext.glFenceSync(condition, flags);
checkError();
return sync;
}
@Override
public void glBlendEquationSeparate(int colorMode, int alphaMode) {
gl.glBlendEquationSeparate(colorMode, alphaMode);
checkError();
}
@Override
public void glFramebufferTextureLayerEXT(int param1, int param2, int param3, int param4, int param5) {
glfbo.glFramebufferTextureLayerEXT(param1, param2, param3, param4, param5);
checkError();
}
public void glAlphaFunc(int func, float ref) {
((GL2)gl).glAlphaFunc(func, ref);
checkError();
}
public void glPointSize(float size) {
((GL2)gl).glPointSize(size);
checkError();
}
public void glPolygonMode(int face, int mode) {
((GL2)gl).glPolygonMode(face, mode);
checkError();
}
public void glDrawBuffer(int mode) {
((GL2)gl).glDrawBuffer(mode);
checkError();
}
public void glReadBuffer(int mode) {
((GL2)gl).glReadBuffer(mode);
checkError();
}
public void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth,
int border, ByteBuffer data) {
((GL2)gl).glCompressedTexImage3D(target, level, internalFormat, width, height, depth, border, data);
checkError();
}
public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width,
int height, int depth, int format, ByteBuffer data) {
((GL2)gl).glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, data);
checkError();
}
public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border,
int format, int type, ByteBuffer data) {
((GL2)gl).glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data);
checkError();
}
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) {
((GL2)gl).glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
checkError();
}
}

View File

@ -502,26 +502,6 @@ public final class GLRenderer implements Renderer {
}
}
if (hasExtension("GL_ARB_shader_storage_buffer_object")) {
caps.add(Caps.ShaderStorageBufferObject);
limits.put(Limits.ShaderStorageBufferObjectMaxBlockSize, getInteger(GL4.GL_MAX_SHADER_STORAGE_BLOCK_SIZE));
limits.put(Limits.ShaderStorageBufferObjectMaxComputeBlocks, getInteger(GL4.GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxGeometryBlocks, getInteger(GL4.GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxFragmentBlocks, getInteger(GL4.GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxVertexBlocks, getInteger(GL4.GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxTessControlBlocks, getInteger(GL4.GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxTessEvaluationBlocks, getInteger(GL4.GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxCombineBlocks, getInteger(GL4.GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS));
}
if (hasExtension("GL_ARB_uniform_buffer_object")) {
caps.add(Caps.UniformBufferObject);
limits.put(Limits.UniformBufferObjectMaxBlockSize, getInteger(GL3.GL_MAX_UNIFORM_BLOCK_SIZE));
limits.put(Limits.UniformBufferObjectMaxGeometryBlocks, getInteger(GL3.GL_MAX_GEOMETRY_UNIFORM_BLOCKS));
limits.put(Limits.UniformBufferObjectMaxFragmentBlocks, getInteger(GL3.GL_MAX_FRAGMENT_UNIFORM_BLOCKS));
limits.put(Limits.UniformBufferObjectMaxVertexBlocks, getInteger(GL3.GL_MAX_VERTEX_UNIFORM_BLOCKS));
}
if (hasExtension("GL_OES_geometry_shader") || hasExtension("GL_EXT_geometry_shader")) {
caps.add(Caps.GeometryShader);
}
@ -530,6 +510,35 @@ public final class GLRenderer implements Renderer {
caps.add(Caps.TesselationShader);
}
if (hasExtension("GL_ARB_shader_storage_buffer_object")) {
caps.add(Caps.ShaderStorageBufferObject);
limits.put(Limits.ShaderStorageBufferObjectMaxBlockSize, getInteger(GL4.GL_MAX_SHADER_STORAGE_BLOCK_SIZE));
// Commented out until we support ComputeShaders and the ComputeShader Cap
// limits.put(Limits.ShaderStorageBufferObjectMaxComputeBlocks, getInteger(GL4.GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS));
if (caps.contains(Caps.GeometryShader)) {
limits.put(Limits.ShaderStorageBufferObjectMaxGeometryBlocks, getInteger(GL4.GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS));
}
limits.put(Limits.ShaderStorageBufferObjectMaxFragmentBlocks, getInteger(GL4.GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxVertexBlocks, getInteger(GL4.GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS));
if (caps.contains(Caps.TesselationShader)) {
limits.put(Limits.ShaderStorageBufferObjectMaxTessControlBlocks, getInteger(GL4.GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS));
limits.put(Limits.ShaderStorageBufferObjectMaxTessEvaluationBlocks, getInteger(GL4.GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS));
}
limits.put(Limits.ShaderStorageBufferObjectMaxCombineBlocks, getInteger(GL4.GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS));
}
if (hasExtension("GL_ARB_uniform_buffer_object")) {
caps.add(Caps.UniformBufferObject);
limits.put(Limits.UniformBufferObjectMaxBlockSize, getInteger(GL3.GL_MAX_UNIFORM_BLOCK_SIZE));
if (caps.contains(Caps.GeometryShader)) {
limits.put(Limits.UniformBufferObjectMaxGeometryBlocks, getInteger(GL3.GL_MAX_GEOMETRY_UNIFORM_BLOCKS));
}
limits.put(Limits.UniformBufferObjectMaxFragmentBlocks, getInteger(GL3.GL_MAX_FRAGMENT_UNIFORM_BLOCKS));
limits.put(Limits.UniformBufferObjectMaxVertexBlocks, getInteger(GL3.GL_MAX_VERTEX_UNIFORM_BLOCKS));
}
if(caps.contains(Caps.OpenGL20)){
caps.add(Caps.UnpackRowLength);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2014 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -71,7 +71,7 @@ public final class GLTracer implements InvocationHandler {
private static void noEnumArgs(String method, int... argSlots) {
IntMap<Void> argSlotsMap = new IntMap<Void>();
for (int argSlot : argSlots) {
argSlotsMap.put(argSlot, (Void) null);
argSlotsMap.put(argSlot, null);
}
nonEnumArgMap.put(method, argSlotsMap);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -167,7 +167,7 @@ public class AssetLinkNode extends Node {
final InputCapsule capsule = e.getCapsule(this);
final AssetManager assetManager = e.getAssetManager();
assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>());
assetLoaderKeys = capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<>());
for (final Iterator<ModelKey> iterator = assetLoaderKeys.iterator(); iterator.hasNext(); ) {

View File

@ -1527,7 +1527,11 @@ public class Mesh implements Savable, Cloneable, JmeCloneable {
}
public MorphTarget[] getMorphTargets() {
return morphTargets.getArray();
if (morphTargets == null) {
return new MorphTarget[0];
} else {
return morphTargets.getArray();
}
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2017 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -109,7 +109,7 @@ public class WireSphere extends Mesh {
/*
* Update vertex positions for the great circle in the X-Y plane.
*/
float rate = FastMath.TWO_PI / (float) samples;
float rate = FastMath.TWO_PI / samples;
float angle = 0;
for (int i = 0; i < samples; i++) {
float x = radius * FastMath.cos(angle);
@ -130,7 +130,7 @@ public class WireSphere extends Mesh {
/*
* Update vertex positions for 'zSamples' parallel circles.
*/
float zRate = (radius * 2) / (float) (zSamples);
float zRate = (radius * 2) / zSamples;
float zHeight = -radius + (zRate / 2f);
float rb = 1f / zSamples;
float b = rb / 2f;

View File

@ -1,7 +1,7 @@
package com.jme3.scene.debug.custom;
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -134,12 +134,12 @@ public class ArmatureDebugger extends Node {
Material matWires = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWires.setBoolean("VertexColor", true);
matWires.getAdditionalRenderState().setLineWidth(3);
matWires.getAdditionalRenderState().setLineWidth(1f);
wires.setMaterial(matWires);
Material matOutline = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matOutline.setBoolean("VertexColor", true);
matOutline.getAdditionalRenderState().setLineWidth(5);
matOutline.getAdditionalRenderState().setLineWidth(1f);
outlines.setMaterial(matOutline);
Material matOutline2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");

View File

@ -161,7 +161,7 @@ public abstract class IndexBuffer {
* mesh.setBuffer(Type.Index, 3,
* indexBuffer.getFormat(), indexBuffer);
* </pre>
* @return
* @return an enum value
*/
public abstract Format getFormat();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -59,7 +59,7 @@ public class VirtualIndexBuffer extends IndexBuffer {
protected Mode meshMode;
protected int position = 0;
public VirtualIndexBuffer(int numVerts, Mode meshMode){
public VirtualIndexBuffer(int numVerts, Mode meshMode) {
this.numVerts = numVerts;
this.meshMode = meshMode;
switch (meshMode) {
@ -108,33 +108,38 @@ public class VirtualIndexBuffer extends IndexBuffer {
@Override
public int get(int i) {
if (meshMode == Mode.Triangles || meshMode == Mode.Lines || meshMode == Mode.Points){
if (meshMode == Mode.Triangles || meshMode == Mode.Lines || meshMode == Mode.Points) {
return i;
}else if (meshMode == Mode.LineStrip){
} else if (meshMode == Mode.LineStrip) {
return (i + 1) / 2;
}else if (meshMode == Mode.LineLoop){
return (i == (numVerts-1)) ? 0 : ((i + 1) / 2);
}else if (meshMode == Mode.TriangleStrip){
int triIndex = i/3;
int vertIndex = i%3;
boolean isBack = (i/3)%2==1;
if (!isBack){
} else if (meshMode == Mode.LineLoop) {
return (i == (numVerts - 1)) ? 0 : ((i + 1) / 2);
} else if (meshMode == Mode.TriangleStrip) {
int triIndex = i / 3;
int vertIndex = i % 3;
boolean isBack = (i / 3) % 2 == 1;
if (!isBack) {
return triIndex + vertIndex;
}else{
switch (vertIndex){
case 0: return triIndex + 1;
case 1: return triIndex;
case 2: return triIndex + 2;
default: throw new AssertionError();
}
} else {
switch (vertIndex) {
case 0:
return triIndex + 1;
case 1:
return triIndex;
case 2:
return triIndex + 2;
default:
throw new AssertionError();
}
}
}else if (meshMode == Mode.TriangleFan){
int vertIndex = i%3;
if (vertIndex == 0)
} else if (meshMode == Mode.TriangleFan) {
int vertIndex = i % 3;
if (vertIndex == 0) {
return 0;
else
} else {
return (i / 3) + vertIndex;
}else{
}
} else {
throw new UnsupportedOperationException();
}
}
@ -154,15 +159,15 @@ public class VirtualIndexBuffer extends IndexBuffer {
return null;
}
@Override
public IndexBuffer put (int value) {
throw new UnsupportedOperationException("Does not represent index buffer");
}
@Override
public IndexBuffer put(int value) {
throw new UnsupportedOperationException("Does not represent index buffer");
}
@Override
public Format getFormat () {
// return largest size
return Format.UnsignedInt;
}
@Override
public Format getFormat() {
// return largest size
return Format.UnsignedInt;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -198,12 +198,12 @@ public class Curve extends Mesh {
* points
*/
private void createNurbMesh(int nbSubSegments) {
if(spline.getControlPoints() != null && spline.getControlPoints().size() > 0) {
if(nbSubSegments == 0) {
nbSubSegments = spline.getControlPoints().size() + 1;
} else {
nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1;
}
if (spline.getControlPoints() != null && spline.getControlPoints().size() > 0) {
if (nbSubSegments == 0) {
nbSubSegments = spline.getControlPoints().size() + 1;
} else {
nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1;
}
float minKnot = spline.getMinNurbKnot();
float maxKnot = spline.getMaxNurbKnot();
float deltaU = (maxKnot - minKnot) / nbSubSegments;
@ -233,7 +233,7 @@ public class Curve extends Mesh {
this.setBuffer(VertexBuffer.Type.Index, 2, indices);
this.updateBound();
this.updateCounts();
}
}
}
private void createLinearMesh() {

View File

@ -55,7 +55,7 @@ public class Line extends Mesh {
/**
* No-argument constructor needed by SavableClassUtil.
*/
public Line() { // TODO protected
protected Line() {
}
public Line(Vector3f start, Vector3f end) {
@ -69,7 +69,6 @@ public class Line extends Mesh {
setBuffer(Type.Position, 3, new float[]{start.x, start.y, start.z,
end.x, end.y, end.z,});
setBuffer(Type.TexCoord, 2, new float[]{0, 0,
1, 1});

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -141,7 +141,7 @@ public class PQTorus extends Mesh {
// Move along the length of the pq torus
for (int i = 0; i < steps; i++) {
theta += thetaStep;
float circleFraction = ((float) i) / (float) steps;
float circleFraction = i / (float) steps;
// Find the point on the torus
r = (0.5f * (2.0f + FastMath.sin(q * theta)) * radius);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -199,8 +199,8 @@ public class ShaderNode implements Savable, Cloneable {
name = ic.readString("name", "");
definition = (ShaderNodeDefinition) ic.readSavable("definition", null);
condition = ic.readString("condition", null);
inputMapping = (List<VariableMapping>) ic.readSavableArrayList("inputMapping", new ArrayList<VariableMapping>());
outputMapping = (List<VariableMapping>) ic.readSavableArrayList("outputMapping", new ArrayList<VariableMapping>());
inputMapping = ic.readSavableArrayList("inputMapping", new ArrayList<>());
outputMapping = ic.readSavableArrayList("outputMapping", new ArrayList<>());
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -194,7 +194,7 @@ public class ShaderNodeDefinition implements Savable {
*/
@Override
public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = (OutputCapsule) ex.getCapsule(this);
OutputCapsule oc = ex.getCapsule(this);
oc.write(name, "name", "");
String[] str = new String[shadersLanguage.size()];
oc.write(shadersLanguage.toArray(str), "shadersLanguage", null);
@ -230,7 +230,7 @@ public class ShaderNodeDefinition implements Savable {
*/
@Override
public void read(JmeImporter im) throws IOException {
InputCapsule ic = (InputCapsule) im.getCapsule(this);
InputCapsule ic = im.getCapsule(this);
name = ic.readString("name", "");
String[] str = ic.readStringArray("shadersLanguage", null);
@ -248,8 +248,8 @@ public class ShaderNodeDefinition implements Savable {
}
type = ic.readEnum("type", Shader.ShaderType.class, null);
inputs = (List<ShaderNodeVariable>) ic.readSavableArrayList("inputs", new ArrayList<ShaderNodeVariable>());
outputs = (List<ShaderNodeVariable>) ic.readSavableArrayList("outputs", new ArrayList<ShaderNodeVariable>());
inputs = ic.readSavableArrayList("inputs", new ArrayList<>());
outputs = ic.readSavableArrayList("outputs", new ArrayList<>());
}
/**

View File

@ -92,7 +92,7 @@ public class BasicShadowRenderer implements SceneProcessor {
//DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
dummyTex = new Texture2D(size, size, Format.RGBA8);
shadowFB.setColorTexture(dummyTex);
shadowMapSize = (float)size;
shadowMapSize = size;
preshadowMat = new Material(manager, "Common/MatDefs/Shadow/PreShadow.j3md");
postshadowMat = new Material(manager, "Common/MatDefs/Shadow/BasicPostShadow.j3md");
postshadowMat.setTexture("ShadowMap", shadowMap);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -725,7 +725,7 @@ public class ShadowUtil {
*/
public static void getLitGeometriesInViewPort(Spatial rootScene, Camera vpCamera, Camera[] cameras, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) {
if (rootScene != null && rootScene instanceof Node) {
addGeometriesInCamFrustumAndViewPortFromNode(vpCamera, cameras, (Node)rootScene, mode, outputGeometryList);
addGeometriesInCamFrustumAndViewPortFromNode(vpCamera, cameras, rootScene, mode, outputGeometryList);
}
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -404,16 +404,16 @@ public final class AppSettings extends HashMap<String, Object> {
// Try loading using new method
switch (key.charAt(0)) {
case 'I':
put(key.substring(2), prefs.getInt(key, (Integer) 0));
put(key.substring(2), prefs.getInt(key, 0));
break;
case 'F':
put(key.substring(2), prefs.getFloat(key, (Float) 0f));
put(key.substring(2), prefs.getFloat(key, 0f));
break;
case 'S':
put(key.substring(2), prefs.get(key, (String) null));
put(key.substring(2), prefs.get(key, null));
break;
case 'B':
put(key.substring(2), prefs.getBoolean(key, (Boolean) false));
put(key.substring(2), prefs.getBoolean(key, false));
break;
default:
throw new UnsupportedOperationException("Undefined setting type: " + key.charAt(0));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2019 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -171,7 +171,7 @@ public abstract class JmeSystemDelegate {
return is64 ? Platform.Windows64 : Platform.Windows32;
} else if (os.contains("linux") || os.contains("freebsd")
|| os.contains("sunos") || os.contains("unix")) {
if (arch.startsWith("arm")) {
if (arch.startsWith("arm") || arch.startsWith("aarch")) {
return is64 ? Platform.Linux_ARM64 : Platform.Linux_ARM32;
} else {
return is64 ? Platform.Linux64 : Platform.Linux32;

View File

@ -110,7 +110,7 @@ public class FrameBuffer extends NativeObject {
* @return The texture to render to for this <code>RenderBuffer</code>
* or null if content should be rendered into a buffer.
*/
public Texture getTexture(){
public Texture getTexture() {
return tex;
}
@ -124,7 +124,7 @@ public class FrameBuffer extends NativeObject {
/**
* Do not use.
*/
public void setId(int id){
public void setId(int id) {
this.id = id;
}
@ -139,25 +139,25 @@ public class FrameBuffer extends NativeObject {
return face;
}
public void resetObject(){
public void resetObject() {
id = -1;
}
public RenderBuffer createDestructableClone(){
if (tex != null){
public RenderBuffer createDestructableClone() {
if (tex != null) {
return null;
}else{
RenderBuffer destructClone = new RenderBuffer();
} else {
RenderBuffer destructClone = new RenderBuffer();
destructClone.id = id;
return destructClone;
}
}
@Override
public String toString(){
if (tex != null){
public String toString() {
if (tex != null) {
return "TextureTarget[format=" + format + "]";
}else{
} else {
return "BufferTarget[format=" + format + "]";
}
}
@ -184,17 +184,18 @@ public class FrameBuffer extends NativeObject {
*
* @throws IllegalArgumentException If width or height are not positive.
*/
public FrameBuffer(int width, int height, int samples){
public FrameBuffer(int width, int height, int samples) {
super();
if (width <= 0 || height <= 0)
throw new IllegalArgumentException("FrameBuffer must have valid size.");
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("FrameBuffer must have valid size.");
}
this.width = width;
this.height = height;
this.samples = samples == 0 ? 1 : samples;
}
protected FrameBuffer(FrameBuffer src){
protected FrameBuffer(FrameBuffer src) {
super(src.id);
/*
for (RenderBuffer renderBuf : src.colorBufs){
@ -213,15 +214,17 @@ public class FrameBuffer extends NativeObject {
* @param format The format to use for the depth buffer.
* @throws IllegalArgumentException If <code>format</code> is not a depth format.
*/
public void setDepthBuffer(Image.Format format){
if (id != -1)
public void setDepthBuffer(Image.Format format) {
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
if (!format.isDepthFormat())
if (!format.isDepthFormat()) {
throw new IllegalArgumentException("Depth buffer format must be depth.");
}
depthBuf = new RenderBuffer();
depthBuf.slot = format.isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.slot = format.isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.format = format;
}
@ -231,12 +234,14 @@ public class FrameBuffer extends NativeObject {
* @param format The format to use for the color buffer.
* @throws IllegalArgumentException If <code>format</code> is not a color format.
*/
public void setColorBuffer(Image.Format format){
if (id != -1)
public void setColorBuffer(Image.Format format) {
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
if (format.isDepthFormat())
if (format.isDepthFormat()) {
throw new IllegalArgumentException("Color buffer format must be color/luminance.");
}
RenderBuffer colorBuf = new RenderBuffer();
colorBuf.slot = 0;
@ -246,23 +251,27 @@ public class FrameBuffer extends NativeObject {
colorBufs.add(colorBuf);
}
private void checkSetTexture(Texture tex, boolean depth){
private void checkSetTexture(Texture tex, boolean depth) {
Image img = tex.getImage();
if (img == null)
if (img == null) {
throw new IllegalArgumentException("Texture not initialized with RTT.");
}
if (depth && !img.getFormat().isDepthFormat())
if (depth && !img.getFormat().isDepthFormat()) {
throw new IllegalArgumentException("Texture image format must be depth.");
else if (!depth && img.getFormat().isDepthFormat())
} else if (!depth && img.getFormat().isDepthFormat()) {
throw new IllegalArgumentException("Texture image format must be color/luminance.");
}
// check that resolution matches texture resolution
if (width != img.getWidth() || height != img.getHeight())
throw new IllegalArgumentException("Texture image resolution " +
"must match FB resolution");
if (width != img.getWidth() || height != img.getHeight()) {
throw new IllegalArgumentException("Texture image resolution "
+ "must match FB resolution");
}
if (samples != tex.getImage().getMultiSamples())
if (samples != tex.getImage().getMultiSamples()) {
throw new IllegalStateException("Texture samples must match framebuffer samples");
}
}
/**
@ -273,16 +282,19 @@ public class FrameBuffer extends NativeObject {
*
* @param enabled True to enable MRT (multiple rendering targets).
*/
public void setMultiTarget(boolean enabled){
if (enabled) colorBufIndex = -1;
else colorBufIndex = 0;
public void setMultiTarget(boolean enabled) {
if (enabled) {
colorBufIndex = -1;
} else {
colorBufIndex = 0;
}
}
/**
* @return True if MRT (multiple rendering targets) is enabled.
* @see FrameBuffer#setMultiTarget(boolean)
*/
public boolean isMultiTarget(){
public boolean isMultiTarget() {
return colorBufIndex == -1;
}
@ -296,12 +308,14 @@ public class FrameBuffer extends NativeObject {
* @throws IllegalArgumentException If index is negative or doesn't map
* to any attachment on this framebuffer.
*/
public void setTargetIndex(int index){
if (index < 0 || index >= 16)
public void setTargetIndex(int index) {
if (index < 0 || index >= 16) {
throw new IllegalArgumentException("Target index must be between 0 and 16");
}
if (colorBufs.size() < index)
if (colorBufs.size() < index) {
throw new IllegalArgumentException("The target at " + index + " is not set!");
}
colorBufIndex = index;
setUpdateNeeded();
@ -312,7 +326,7 @@ public class FrameBuffer extends NativeObject {
*
* @see FrameBuffer#setTargetIndex(int)
*/
public int getTargetIndex(){
public int getTargetIndex() {
return colorBufIndex;
}
@ -324,7 +338,7 @@ public class FrameBuffer extends NativeObject {
*
* @param tex The color texture to set.
*/
public void setColorTexture(Texture2D tex){
public void setColorTexture(Texture2D tex) {
clearColorTargets();
addColorTexture(tex);
}
@ -337,7 +351,7 @@ public class FrameBuffer extends NativeObject {
*
* @param tex The color texture array to set.
*/
public void setColorTexture(TextureArray tex, int layer){
public void setColorTexture(TextureArray tex, int layer) {
clearColorTargets();
addColorTexture(tex, layer);
}
@ -359,11 +373,11 @@ public class FrameBuffer extends NativeObject {
/**
* Clears all color targets that were set or added previously.
*/
public void clearColorTargets(){
public void clearColorTargets() {
colorBufs.clear();
}
/**
/**
* Add a color buffer without a texture bound to it.
* If MRT is enabled, then each subsequently added texture or buffer can be
* rendered to through a shader that writes to the array <code>gl_FragData</code>.
@ -371,14 +385,16 @@ public class FrameBuffer extends NativeObject {
* is rendered to by the shader.
*
* @param format the format of the color buffer
* @see #addColorTexture(com.jme3.texture.Texture2D)
* @see #addColorTexture(com.jme3.texture.Texture2D)
*/
public void addColorBuffer(Image.Format format){
if (id != -1)
public void addColorBuffer(Image.Format format) {
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
if (format.isDepthFormat())
if (format.isDepthFormat()) {
throw new IllegalArgumentException("Color buffer format must be color/luminance.");
}
RenderBuffer colorBuf = new RenderBuffer();
colorBuf.slot = colorBufs.size();
@ -395,11 +411,12 @@ public class FrameBuffer extends NativeObject {
* is rendered to by the shader.
*
* @param tex The texture to add.
* @see #addColorBuffer(com.jme3.texture.Image.Format)
* @see #addColorBuffer(com.jme3.texture.Image.Format)
*/
public void addColorTexture(Texture2D tex) {
if (id != -1)
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage();
checkSetTexture(tex, false);
@ -422,8 +439,9 @@ public class FrameBuffer extends NativeObject {
* @param tex The texture array to add.
*/
public void addColorTexture(TextureArray tex, int layer) {
if (id != -1)
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage();
checkSetTexture(tex, false);
@ -437,7 +455,7 @@ public class FrameBuffer extends NativeObject {
colorBufs.add(colorBuf);
}
/**
/**
* Add a color texture to use for this framebuffer.
* If MRT is enabled, then each subsequently added texture can be
* rendered to through a shader that writes to the array <code>gl_FragData</code>.
@ -448,8 +466,9 @@ public class FrameBuffer extends NativeObject {
* @param face The face of the cube-map to render to.
*/
public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) {
if (id != -1)
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage();
checkSetTexture(tex, false);
@ -468,27 +487,30 @@ public class FrameBuffer extends NativeObject {
*
* @param tex The color texture to set.
*/
public void setDepthTexture(Texture2D tex){
if (id != -1)
public void setDepthTexture(Texture2D tex) {
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage();
checkSetTexture(tex, true);
depthBuf = new RenderBuffer();
depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.tex = tex;
depthBuf.format = img.getFormat();
}
public void setDepthTexture(TextureArray tex, int layer){
if (id != -1)
public void setDepthTexture(TextureArray tex, int layer) {
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage();
checkSetTexture(tex, true);
depthBuf = new RenderBuffer();
depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
depthBuf.tex = tex;
depthBuf.format = img.getFormat();
depthBuf.layer = layer;
@ -497,7 +519,7 @@ public class FrameBuffer extends NativeObject {
/**
* @return The number of color buffers attached to this texture.
*/
public int getNumColorBuffers(){
public int getNumColorBuffers() {
return colorBufs.size();
}
@ -505,21 +527,22 @@ public class FrameBuffer extends NativeObject {
* @param index
* @return The color buffer at the given index.
*/
public RenderBuffer getColorBuffer(int index){
public RenderBuffer getColorBuffer(int index) {
return colorBufs.get(index);
}
/**
* @return The color buffer with the index set by {@link #setTargetIndex(int)}, or null
* if no color buffers are attached.
* If MRT is disabled, the first color buffer is returned.
* If MRT is disabled, the first color buffer is returned.
*/
public RenderBuffer getColorBuffer() {
if (colorBufs.isEmpty())
if (colorBufs.isEmpty()) {
return null;
if (colorBufIndex<0 || colorBufIndex>=colorBufs.size()) {
return colorBufs.get(0);
}
}
if (colorBufIndex < 0 || colorBufIndex >= colorBufs.size()) {
return colorBufs.get(0);
}
return colorBufs.get(colorBufIndex);
}
@ -554,16 +577,17 @@ public class FrameBuffer extends NativeObject {
}
@Override
public String toString(){
public String toString() {
StringBuilder sb = new StringBuilder();
String mrtStr = colorBufIndex >= 0 ? "" + colorBufIndex : "mrt";
sb.append("FrameBuffer[format=").append(width).append("x").append(height)
.append("x").append(samples).append(", drawBuf=").append(mrtStr).append("]\n");
if (depthBuf != null)
.append("x").append(samples).append(", drawBuf=").append(mrtStr).append("]\n");
if (depthBuf != null) {
sb.append("Depth => ").append(depthBuf).append("\n");
for (RenderBuffer colorBuf : colorBufs){
}
for (RenderBuffer colorBuf : colorBufs) {
sb.append("Color(").append(colorBuf.slot)
.append(") => ").append(colorBuf).append("\n");
.append(") => ").append(colorBuf).append("\n");
}
return sb.toString();
}
@ -576,24 +600,26 @@ public class FrameBuffer extends NativeObject {
colorBufs.get(i).resetObject();
}
if (depthBuf != null)
if (depthBuf != null) {
depthBuf.resetObject();
}
setUpdateNeeded();
}
@Override
public void deleteObject(Object rendererObject) {
((Renderer)rendererObject).deleteFrameBuffer(this);
((Renderer) rendererObject).deleteFrameBuffer(this);
}
public NativeObject createDestructableClone(){
@Override
public NativeObject createDestructableClone() {
return new FrameBuffer(this);
}
@Override
public long getUniqueId() {
return ((long)OBJTYPE_FRAMEBUFFER << 32) | ((long)id);
return ((long) OBJTYPE_FRAMEBUFFER << 32) | ((long) id);
}
/**
@ -631,5 +657,4 @@ public class FrameBuffer extends NativeObject {
public boolean isSrgb() {
return srgb;
}
}

Some files were not shown because too many files have changed in this diff Show More