diff --git a/.gitignore b/.gitignore
index 8baaf9fc42..3977d32c4a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -147,3 +147,5 @@
/sdk/nbi/stub/ext/components/products/jdk/dist/
/sdk/jme3-dark-laf/nbproject/private/
jme3-lwjgl3/build/
+
+target/*
diff --git a/jme3-core/build.gradle b/jme3-core/build.gradle
index 8d55c3e76b..067b9d759e 100644
--- a/jme3-core/build.gradle
+++ b/jme3-core/build.gradle
@@ -6,8 +6,6 @@ sourceSets {
main {
java {
srcDir 'src/main/java'
- srcDir 'src/plugins/java'
- srcDir 'src/tools/java'
}
}
test {
@@ -20,16 +18,16 @@ sourceSets {
task updateVersionPropertiesFile << {
def verfile = file('src/main/resources/com/jme3/system/version.properties')
verfile.text = "# THIS IS AN AUTO-GENERATED FILE..\n" +
- "# DO NOT MODIFY!\n" +
+ "# DO NOT MODIFY!\n" +
"build.date=${jmeBuildDate}\n" +
"git.revision=${jmeRevision}\n" +
- "git.branch=${jmeBranchName}\n" +
- "git.hash=${jmeGitHash}\n" +
- "git.hash.short=${jmeShortGitHash}\n" +
- "git.tag=${jmeGitTag}\n" +
+ "git.branch=${jmeBranchName}\n" +
+ "git.hash=${jmeGitHash}\n" +
+ "git.hash.short=${jmeShortGitHash}\n" +
+ "git.tag=${jmeGitTag}\n" +
"name.full=jMonkeyEngine ${jmeFullVersion}\n" +
"version.full=${jmeFullVersion}\n" +
- "version.number=${jmeVersion}\n" +
+ "version.number=${jmeVersion}\n" +
"version.tag=${jmeVersionTag}"
}
diff --git a/jme3-core/build.sbt b/jme3-core/build.sbt
new file mode 100644
index 0000000000..f6a6db244c
--- /dev/null
+++ b/jme3-core/build.sbt
@@ -0,0 +1,15 @@
+// Project details
+name := "jme3-core"
+version := "3.1"
+
+// Use Java 7
+javacOptions ++= Seq("-source", "1.7", "-target", "1.7", "-g:lines")
+
+// Disable Scala compilation
+crossPaths := false
+autoScalaLibrary := false
+
+libraryDependencies += "junit" % "junit" % "4.12" % "test"
+libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
+libraryDependencies += "org.mockito" % "mockito-core" % "2.0.28-beta" % "test"
+libraryDependencies += "org.easytesting" % "fest-assert-core" % "2.0M10" % "test"
diff --git a/jme3-core/src/main/java/com/jme3/app/Application.java b/jme3-core/src/main/java/com/jme3/app/Application.java
index 9688a5d1ed..8c70b22aa6 100644
--- a/jme3-core/src/main/java/com/jme3/app/Application.java
+++ b/jme3-core/src/main/java/com/jme3/app/Application.java
@@ -279,7 +279,7 @@ private void initAudio(){
private void initCamera(){
cam = new Camera(settings.getWidth(), settings.getHeight());
- cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
+ cam.frustum.setPerspective(45f, (float)cam.getWidth() / cam.getHeight(), 1f, 1000f);
cam.setLocation(new Vector3f(0f, 0f, 10f));
cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
diff --git a/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java b/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java
index f386af5dbf..8e02983c88 100644
--- a/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java
+++ b/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java
@@ -224,10 +224,10 @@ public void postFrame(FrameBuffer out) {
capture = false;
Camera curCamera = rm.getCurrentCamera();
- int viewX = (int) (curCamera.getViewPortLeft() * curCamera.getWidth());
- int viewY = (int) (curCamera.getViewPortBottom() * curCamera.getHeight());
- int viewWidth = (int) ((curCamera.getViewPortRight() - curCamera.getViewPortLeft()) * curCamera.getWidth());
- int viewHeight = (int) ((curCamera.getViewPortTop() - curCamera.getViewPortBottom()) * curCamera.getHeight());
+ int viewX = (int) (curCamera.viewPort.getLeft() * curCamera.getWidth());
+ int viewY = (int) (curCamera.viewPort.getBottom() * curCamera.getHeight());
+ int viewWidth = (int) ((curCamera.viewPort.getRight() - curCamera.viewPort.getLeft()) * curCamera.getWidth());
+ int viewHeight = (int) ((curCamera.viewPort.getTop() - curCamera.viewPort.getBottom()) * curCamera.getHeight());
renderer.setViewPort(0, 0, width, height);
renderer.readFrameBuffer(out, outBuf);
diff --git a/jme3-core/src/plugins/java/com/jme3/asset/plugins/ClasspathLocator.java b/jme3-core/src/main/java/com/jme3/asset/plugins/ClasspathLocator.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/asset/plugins/ClasspathLocator.java
rename to jme3-core/src/main/java/com/jme3/asset/plugins/ClasspathLocator.java
diff --git a/jme3-core/src/plugins/java/com/jme3/asset/plugins/FileLocator.java b/jme3-core/src/main/java/com/jme3/asset/plugins/FileLocator.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/asset/plugins/FileLocator.java
rename to jme3-core/src/main/java/com/jme3/asset/plugins/FileLocator.java
diff --git a/jme3-core/src/plugins/java/com/jme3/asset/plugins/HttpZipLocator.java b/jme3-core/src/main/java/com/jme3/asset/plugins/HttpZipLocator.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/asset/plugins/HttpZipLocator.java
rename to jme3-core/src/main/java/com/jme3/asset/plugins/HttpZipLocator.java
diff --git a/jme3-core/src/plugins/java/com/jme3/asset/plugins/UrlAssetInfo.java b/jme3-core/src/main/java/com/jme3/asset/plugins/UrlAssetInfo.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/asset/plugins/UrlAssetInfo.java
rename to jme3-core/src/main/java/com/jme3/asset/plugins/UrlAssetInfo.java
diff --git a/jme3-core/src/plugins/java/com/jme3/asset/plugins/UrlLocator.java b/jme3-core/src/main/java/com/jme3/asset/plugins/UrlLocator.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/asset/plugins/UrlLocator.java
rename to jme3-core/src/main/java/com/jme3/asset/plugins/UrlLocator.java
diff --git a/jme3-core/src/plugins/java/com/jme3/asset/plugins/ZipLocator.java b/jme3-core/src/main/java/com/jme3/asset/plugins/ZipLocator.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/asset/plugins/ZipLocator.java
rename to jme3-core/src/main/java/com/jme3/asset/plugins/ZipLocator.java
diff --git a/jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java b/jme3-core/src/main/java/com/jme3/audio/plugins/WAVLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java
rename to jme3-core/src/main/java/com/jme3/audio/plugins/WAVLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/cursors/plugins/JmeCursor.java b/jme3-core/src/main/java/com/jme3/cursors/plugins/JmeCursor.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/cursors/plugins/JmeCursor.java
rename to jme3-core/src/main/java/com/jme3/cursors/plugins/JmeCursor.java
diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java
index ca3467781a..8d7d7e0abb 100644
--- a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java
+++ b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java
@@ -32,7 +32,6 @@
package com.jme3.effect;
import com.jme3.bounding.BoundingBox;
-import com.jme3.effect.ParticleMesh.Type;
import com.jme3.effect.influencers.DefaultParticleInfluencer;
import com.jme3.effect.influencers.ParticleInfluencer;
import com.jme3.effect.shapes.EmitterPointShape;
@@ -80,7 +79,6 @@ public class ParticleEmitter extends Geometry {
private EmitterShape shape = DEFAULT_SHAPE;
private ParticleMesh particleMesh;
private ParticleInfluencer particleInfluencer = DEFAULT_INFLUENCER;
- private ParticleMesh.Type meshType;
private Particle[] particles;
private int firstUnUsed;
private int lastUsed;
@@ -176,25 +174,16 @@ public ParticleEmitter clone(boolean cloneMaterial) {
clone.controls.add(clone.control);
// Reinitialize particle mesh
- switch (meshType) {
- case Point:
- clone.particleMesh = new ParticlePointMesh();
- clone.setMesh(clone.particleMesh);
- break;
- case Triangle:
- clone.particleMesh = new ParticleTriMesh();
- clone.setMesh(clone.particleMesh);
- break;
- default:
- throw new IllegalStateException("Unrecognized particle type: " + meshType);
- }
+ clone.particleMesh = particleMesh.clone();
+ clone.setMesh(clone.particleMesh);
+
clone.particleMesh.initParticleData(clone, clone.particles.length);
clone.particleMesh.setImagesXY(clone.imagesX, clone.imagesY);
return clone;
}
- public ParticleEmitter(String name, Type type, int numParticles) {
+ public ParticleEmitter(String name, ParticleMesh particleMesh, int numParticles) {
super(name);
setBatchHint(BatchHint.Never);
// ignore world transform, unless user sets inLocalSpace
@@ -206,8 +195,6 @@ public ParticleEmitter(String name, Type type, int numParticles) {
// particles are usually transparent
this.setQueueBucket(Bucket.Transparent);
- meshType = type;
-
// Must create clone of shape/influencer so that a reference to a static is
// not maintained
shape = shape.deepClone();
@@ -216,18 +203,9 @@ public ParticleEmitter(String name, Type type, int numParticles) {
control = new ParticleEmitterControl(this);
controls.add(control);
- switch (meshType) {
- case Point:
- particleMesh = new ParticlePointMesh();
- this.setMesh(particleMesh);
- break;
- case Triangle:
- particleMesh = new ParticleTriMesh();
- this.setMesh(particleMesh);
- break;
- default:
- throw new IllegalStateException("Unrecognized particle type: " + meshType);
- }
+ this.particleMesh = particleMesh;
+ this.setMesh(particleMesh);
+
this.setNumParticles(numParticles);
// particleMesh.initParticleData(this, particles.length);
}
@@ -278,32 +256,21 @@ public ParticleInfluencer getParticleInfluencer() {
*
*
* @return the mesh type used by the particle emitter.
- *
- * @see #setMeshType(com.jme3.effect.ParticleMesh.Type)
- * @see ParticleEmitter#ParticleEmitter(java.lang.String, com.jme3.effect.ParticleMesh.Type, int)
+ *
+ * @see ParticleEmitter#ParticleEmitter(java.lang.String, com.jme3.effect.ParticleMesh, int)
*/
- public ParticleMesh.Type getMeshType() {
- return meshType;
+ public ParticleMesh getMeshType() {
+ return particleMesh;
}
/**
* Sets the type of mesh used by the particle emitter.
* @param meshType The mesh type to use
*/
- public void setMeshType(ParticleMesh.Type meshType) {
- this.meshType = meshType;
- switch (meshType) {
- case Point:
- particleMesh = new ParticlePointMesh();
- this.setMesh(particleMesh);
- break;
- case Triangle:
- particleMesh = new ParticleTriMesh();
- this.setMesh(particleMesh);
- break;
- default:
- throw new IllegalStateException("Unrecognized particle type: " + meshType);
- }
+ public void setMeshType(ParticleMesh particleMesh) {
+ this.particleMesh = particleMesh;
+ this.setMesh(particleMesh);
+
this.setNumParticles(particles.length);
}
@@ -1088,7 +1055,7 @@ public void updateFromControl(float tpf) {
private void renderFromControl(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
- if (meshType == ParticleMesh.Type.Point) {
+ if (particleMesh.isPoint()) {
float C = cam.getProjectionMatrix().m00;
C *= cam.getWidth() * 0.5f;
@@ -1119,7 +1086,7 @@ public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(shape, "shape", DEFAULT_SHAPE);
- oc.write(meshType, "meshType", ParticleMesh.Type.Triangle);
+ ParticleMesh.writeParticleMesh(oc, particleMesh);
oc.write(enabled, "enabled", true);
oc.write(particles.length, "numParticles", 0);
oc.write(particlesPerSec, "particlesPerSec", 0);
@@ -1154,7 +1121,6 @@ public void read(JmeImporter im) throws IOException {
shape = shape.deepClone();
}
- meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle);
int numParticles = ic.readInt("numParticles", 0);
@@ -1178,18 +1144,9 @@ public void read(JmeImporter im) throws IOException {
randomAngle = ic.readBoolean("randomAngle", false);
rotateSpeed = ic.readFloat("rotateSpeed", 0);
- switch (meshType) {
- case Point:
- particleMesh = new ParticlePointMesh();
- this.setMesh(particleMesh);
- break;
- case Triangle:
- particleMesh = new ParticleTriMesh();
- this.setMesh(particleMesh);
- break;
- default:
- throw new IllegalStateException("Unrecognized particle type: " + meshType);
- }
+ particleMesh = ParticleMesh.readParticleMesh(ic);
+ this.setMesh(particleMesh);
+
this.setNumParticles(numParticles);
// particleMesh.initParticleData(this, particles.length);
// particleMesh.setImagesXY(imagesX, imagesY);
diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java b/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java
index ed1b80d2a1..43841cf2ac 100644
--- a/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java
+++ b/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java
@@ -31,11 +31,16 @@
*/
package com.jme3.effect;
+import com.jme3.export.InputCapsule;
+import com.jme3.export.JmeExporter;
+import com.jme3.export.OutputCapsule;
import com.jme3.material.RenderState;
import com.jme3.math.Matrix3f;
import com.jme3.renderer.Camera;
import com.jme3.scene.Mesh;
+import java.io.IOException;
+
/**
* The ParticleMesh is the underlying visual implementation of a
* {@link ParticleEmitter particle emitter}.
@@ -54,14 +59,37 @@ public enum Type {
* to render particles the usual way.
*/
Point,
-
+
/**
- * The particle mesh is composed of triangles. Each particle is
+ * The particle mesh is composed of triangles. Each particle is
* two triangles making a single quad.
*/
Triangle;
}
+ public Type type;
+
+ public abstract ParticleMesh clone();
+
+ public static void writeParticleMesh(OutputCapsule oc, ParticleMesh particleMesh) throws IOException {
+ oc.write(particleMesh.type, "meshType", ParticleMesh.Type.Triangle);
+ }
+
+ public static ParticleMesh readParticleMesh(InputCapsule ic) throws IOException {
+ Type meshType = ic.readEnum("meshType", Type.class, Type.Triangle);
+ switch (meshType) {
+ case Point:
+ return new ParticlePointMesh();
+ case Triangle:
+ return new ParticleTriMesh();
+ default:
+ throw new IllegalStateException("Unrecognized particle type: " + meshType);
+ }
+ }
+
+ public abstract boolean isPoint();
+ public abstract boolean isTriangle();
+
/**
* Initialize mesh data.
*
diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java b/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java
index 3f56e483b4..50244c1540 100644
--- a/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java
+++ b/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java
@@ -47,6 +47,13 @@ public class ParticlePointMesh extends ParticleMesh {
private int imagesX = 1;
private int imagesY = 1;
+ public ParticlePointMesh clone() {
+ return new ParticlePointMesh();
+ }
+
+ public boolean isPoint() { return true; }
+ public boolean isTriangle() { return false; }
+
@Override
public void setImagesXY(int imagesX, int imagesY) {
this.imagesX = imagesX;
diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java b/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java
index 8002197b04..f1daca4d80 100644
--- a/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java
+++ b/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java
@@ -53,6 +53,13 @@ public class ParticleTriMesh extends ParticleMesh {
private ParticleEmitter emitter;
// private Particle[] particlesCopy;
+ public ParticleTriMesh clone() {
+ return new ParticleTriMesh();
+ }
+
+ public boolean isPoint() { return false; }
+ public boolean isTriangle() { return true; }
+
@Override
public void initParticleData(ParticleEmitter emitter, int numParticles) {
setMode(Mode.Triangles);
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryClassField.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryClassField.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryClassField.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryClassField.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryClassObject.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryClassObject.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryClassObject.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryClassObject.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryExporter.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryExporter.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryExporter.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryExporter.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryIdContentPair.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryIdContentPair.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryIdContentPair.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryIdContentPair.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryImporter.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryImporter.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryImporter.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryInputCapsule.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryInputCapsule.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryInputCapsule.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryInputCapsule.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryOutputCapsule.java b/jme3-core/src/main/java/com/jme3/export/binary/BinaryOutputCapsule.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/BinaryOutputCapsule.java
rename to jme3-core/src/main/java/com/jme3/export/binary/BinaryOutputCapsule.java
diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/ByteUtils.java b/jme3-core/src/main/java/com/jme3/export/binary/ByteUtils.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/export/binary/ByteUtils.java
rename to jme3-core/src/main/java/com/jme3/export/binary/ByteUtils.java
diff --git a/jme3-core/src/plugins/java/com/jme3/font/plugins/BitmapFontLoader.java b/jme3-core/src/main/java/com/jme3/font/plugins/BitmapFontLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/font/plugins/BitmapFontLoader.java
rename to jme3-core/src/main/java/com/jme3/font/plugins/BitmapFontLoader.java
diff --git a/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java b/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
index dd9f00dc11..9d260bad40 100644
--- a/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
+++ b/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
@@ -331,11 +331,11 @@ protected void rotateCamera(float value, Vector3f axis){
protected void zoomCamera(float value){
// derive fovY value
- float h = cam.getFrustumTop();
- float w = cam.getFrustumRight();
+ float h = cam.frustum.getTop();
+ float w = cam.frustum.getRight();
float aspect = w / h;
- float near = cam.getFrustumNear();
+ float near = cam.frustum.getNear();
float fovY = FastMath.atan(h / near)
/ (FastMath.DEG_TO_RAD * .5f);
@@ -348,10 +348,10 @@ protected void zoomCamera(float value){
h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near;
w = h * aspect;
- cam.setFrustumTop(h);
- cam.setFrustumBottom(-h);
- cam.setFrustumLeft(-w);
- cam.setFrustumRight(w);
+ cam.frustum.setTop(h);
+ cam.frustum.setBottom(-h);
+ cam.frustum.setLeft(-w);
+ cam.frustum.setRight(w);
}
protected void riseCamera(float value){
diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/ConditionParser.java b/jme3-core/src/main/java/com/jme3/material/plugins/ConditionParser.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/material/plugins/ConditionParser.java
rename to jme3-core/src/main/java/com/jme3/material/plugins/ConditionParser.java
diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java b/jme3-core/src/main/java/com/jme3/material/plugins/J3MLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
rename to jme3-core/src/main/java/com/jme3/material/plugins/J3MLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/MatParseException.java b/jme3-core/src/main/java/com/jme3/material/plugins/MatParseException.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/material/plugins/MatParseException.java
rename to jme3-core/src/main/java/com/jme3/material/plugins/MatParseException.java
diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeDefinitionLoader.java b/jme3-core/src/main/java/com/jme3/material/plugins/ShaderNodeDefinitionLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeDefinitionLoader.java
rename to jme3-core/src/main/java/com/jme3/material/plugins/ShaderNodeDefinitionLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java b/jme3-core/src/main/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java
rename to jme3-core/src/main/java/com/jme3/material/plugins/ShaderNodeLoaderDelegate.java
diff --git a/jme3-core/src/main/java/com/jme3/math/Equality.java b/jme3-core/src/main/java/com/jme3/math/Equality.java
new file mode 100644
index 0000000000..d68f42678d
--- /dev/null
+++ b/jme3-core/src/main/java/com/jme3/math/Equality.java
@@ -0,0 +1,9 @@
+package com.jme3.math;
+
+public class Equality {
+
+ public static boolean equals(float x, float y, float delta) {
+ return Math.abs(x-y) < delta;
+ }
+
+}
diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix3f.java b/jme3-core/src/main/java/com/jme3/math/Matrix3f.java
index ca9e7287b8..178a59feef 100644
--- a/jme3-core/src/main/java/com/jme3/math/Matrix3f.java
+++ b/jme3-core/src/main/java/com/jme3/math/Matrix3f.java
@@ -1219,37 +1219,49 @@ public boolean equals(Object o) {
}
Matrix3f comp = (Matrix3f) o;
- if (Float.compare(m00, comp.m00) != 0) {
- return false;
- }
- if (Float.compare(m01, comp.m01) != 0) {
- return false;
- }
- if (Float.compare(m02, comp.m02) != 0) {
- return false;
- }
- if (Float.compare(m10, comp.m10) != 0) {
- return false;
- }
- if (Float.compare(m11, comp.m11) != 0) {
- return false;
- }
- if (Float.compare(m12, comp.m12) != 0) {
- return false;
- }
+ return
+ Float.compare(m00, comp.m00) == 0 &&
+ Float.compare(m01, comp.m01) == 0 &&
+ Float.compare(m02, comp.m02) == 0 &&
+ Float.compare(m10, comp.m10) == 0 &&
+ Float.compare(m11, comp.m11) == 0 &&
+ Float.compare(m12, comp.m12) == 0 &&
+ Float.compare(m20, comp.m20) == 0 &&
+ Float.compare(m21, comp.m21) == 0 &&
+ Float.compare(m22, comp.m22) == 0;
+ }
- if (Float.compare(m20, comp.m20) != 0) {
- return false;
- }
- if (Float.compare(m21, comp.m21) != 0) {
+ /**
+ * are these two matrices the same? they are is they both have mXX values with less than delta difference.
+ *
+ * @param o
+ * the object to compare for equality
+ * @param delta
+ * accepted limit for float comparison
+ * @return true if they are equal
+ */
+ public boolean equals(Object o, float delta) {
+ if (!(o instanceof Matrix3f) || o == null) {
return false;
}
- if (Float.compare(m22, comp.m22) != 0) {
- return false;
+
+ if (this == o) {
+ return true;
}
- return true;
+ Matrix3f comp = (Matrix3f) o;
+
+ return
+ Equality.equals(m00, comp.m00, delta) &&
+ Equality.equals(m01, comp.m01, delta) &&
+ Equality.equals(m02, comp.m02, delta) &&
+ Equality.equals(m10, comp.m10, delta) &&
+ Equality.equals(m11, comp.m11, delta) &&
+ Equality.equals(m12, comp.m12, delta) &&
+ Equality.equals(m20, comp.m20, delta) &&
+ Equality.equals(m21, comp.m21, delta) &&
+ Equality.equals(m22, comp.m22, delta);
}
public void write(JmeExporter e) throws IOException {
@@ -1423,6 +1435,15 @@ static boolean equalIdentity(Matrix3f mat) {
return true;
}
+ public Matrix4f toMatrix4f() {
+ return new Matrix4f(
+ m00, m01, m02, 0,
+ m10, m11, m12, 0,
+ m20, m21, m22, 0,
+ 0, 0, 0, 0
+ );
+ }
+
@Override
public Matrix3f clone() {
try {
diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix4f.java b/jme3-core/src/main/java/com/jme3/math/Matrix4f.java
index 159e399321..848ff9ef2b 100644
--- a/jme3-core/src/main/java/com/jme3/math/Matrix4f.java
+++ b/jme3-core/src/main/java/com/jme3/math/Matrix4f.java
@@ -584,6 +584,26 @@ public Matrix4f set(Matrix4f matrix) {
return this;
}
+ /**
+ * set sets the values of this matrix from another (3D) matrix, leaving the fourth dimension values
+ * untouched.
+ *
+ * @param matrix
+ * the matrix to read the value from.
+ */
+ public Matrix4f set(Matrix3f matrix) {
+ m00 = matrix.m00;
+ m01 = matrix.m01;
+ m02 = matrix.m02;
+ m10 = matrix.m10;
+ m11 = matrix.m11;
+ m12 = matrix.m12;
+ m20 = matrix.m20;
+ m21 = matrix.m21;
+ m22 = matrix.m22;
+ return this;
+ }
+
/**
* set sets the values of this matrix from an array of
* values assuming that the data is rowMajor order;
@@ -2163,59 +2183,63 @@ public boolean equals(Object o) {
}
Matrix4f comp = (Matrix4f) o;
- if (Float.compare(m00, comp.m00) != 0) {
- return false;
- }
- if (Float.compare(m01, comp.m01) != 0) {
- return false;
- }
- if (Float.compare(m02, comp.m02) != 0) {
- return false;
- }
- if (Float.compare(m03, comp.m03) != 0) {
- return false;
- }
- if (Float.compare(m10, comp.m10) != 0) {
- return false;
- }
- if (Float.compare(m11, comp.m11) != 0) {
- return false;
- }
- if (Float.compare(m12, comp.m12) != 0) {
- return false;
- }
- if (Float.compare(m13, comp.m13) != 0) {
+ return
+ Float.compare(m00, comp.m00) == 0 &&
+ Float.compare(m01, comp.m01) == 0 &&
+ Float.compare(m02, comp.m02) == 0 &&
+ Float.compare(m02, comp.m03) == 0 &&
+ Float.compare(m10, comp.m10) == 0 &&
+ Float.compare(m11, comp.m11) == 0 &&
+ Float.compare(m12, comp.m12) == 0 &&
+ Float.compare(m12, comp.m13) == 0 &&
+ Float.compare(m20, comp.m20) == 0 &&
+ Float.compare(m21, comp.m21) == 0 &&
+ Float.compare(m22, comp.m22) == 0 &&
+ Float.compare(m22, comp.m23) == 0 &&
+ Float.compare(m30, comp.m30) == 0 &&
+ Float.compare(m31, comp.m31) == 0 &&
+ Float.compare(m32, comp.m32) == 0 &&
+ Float.compare(m32, comp.m33) == 0;
+ }
+
+ /**
+ * are these two matrices the same? they are is they both have mXX values with less than delta difference.
+ *
+ * @param o
+ * the object to compare for equality
+ * @param delta
+ * accepted limit for float comparison
+ * @return true if they are equal
+ */
+ public boolean equals(Object o, float delta) {
+ if (!(o instanceof Matrix4f) || o == null) {
return false;
}
- if (Float.compare(m20, comp.m20) != 0) {
- return false;
- }
- if (Float.compare(m21, comp.m21) != 0) {
- return false;
- }
- if (Float.compare(m22, comp.m22) != 0) {
- return false;
- }
- if (Float.compare(m23, comp.m23) != 0) {
- return false;
+ if (this == o) {
+ return true;
}
- if (Float.compare(m30, comp.m30) != 0) {
- return false;
- }
- if (Float.compare(m31, comp.m31) != 0) {
- return false;
- }
- if (Float.compare(m32, comp.m32) != 0) {
- return false;
- }
- if (Float.compare(m33, comp.m33) != 0) {
- return false;
- }
+ Matrix4f comp = (Matrix4f) o;
- return true;
+ return
+ Equality.equals(m00, comp.m00, delta) &&
+ Equality.equals(m01, comp.m01, delta) &&
+ Equality.equals(m02, comp.m02, delta) &&
+ Equality.equals(m03, comp.m03, delta) &&
+ Equality.equals(m10, comp.m10, delta) &&
+ Equality.equals(m11, comp.m11, delta) &&
+ Equality.equals(m12, comp.m12, delta) &&
+ Equality.equals(m13, comp.m13, delta) &&
+ Equality.equals(m20, comp.m20, delta) &&
+ Equality.equals(m21, comp.m21, delta) &&
+ Equality.equals(m22, comp.m22, delta) &&
+ Equality.equals(m23, comp.m23, delta) &&
+ Equality.equals(m30, comp.m30, delta) &&
+ Equality.equals(m31, comp.m31, delta) &&
+ Equality.equals(m32, comp.m32, delta) &&
+ Equality.equals(m33, comp.m33, delta);
}
public void write(JmeExporter e) throws IOException {
diff --git a/jme3-core/src/main/java/com/jme3/math/Quaternion.java b/jme3-core/src/main/java/com/jme3/math/Quaternion.java
index 1ee1305d2d..cb085615fd 100644
--- a/jme3-core/src/main/java/com/jme3/math/Quaternion.java
+++ b/jme3-core/src/main/java/com/jme3/math/Quaternion.java
@@ -464,44 +464,18 @@ public Matrix3f toRotationMatrix(Matrix3f result) {
public Matrix4f toRotationMatrix(Matrix4f result) {
TempVars tempv = TempVars.get();
Vector3f originalScale = tempv.vect1;
-
+
result.toScaleVector(originalScale);
result.setScale(1, 1, 1);
- float norm = norm();
- // we explicitly test norm against one here, saving a division
- // at the cost of a test and branch. Is it worth it?
- float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0;
- // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs
- // will be used 2-4 times each.
- float xs = x * s;
- float ys = y * s;
- float zs = z * s;
- float xx = x * xs;
- float xy = x * ys;
- float xz = x * zs;
- float xw = w * xs;
- float yy = y * ys;
- float yz = y * zs;
- float yw = w * ys;
- float zz = z * zs;
- float zw = w * zs;
+ Matrix3f rotationMatrix3f = toRotationMatrix();
- // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here
- result.m00 = 1 - (yy + zz);
- result.m01 = (xy - zw);
- result.m02 = (xz + yw);
- result.m10 = (xy + zw);
- result.m11 = 1 - (xx + zz);
- result.m12 = (yz - xw);
- result.m20 = (xz - yw);
- result.m21 = (yz + xw);
- result.m22 = 1 - (xx + yy);
+ result.set(rotationMatrix3f);
result.setScale(originalScale);
-
+
tempv.release();
-
+
return result;
}
@@ -655,13 +629,16 @@ public float toAngleAxis(Vector3f axisStore) {
* the first quaternion.
* @param q2
* the second quaternion.
- * @param t
+ * @param changeAmnt
* the amount to interpolate between the two quaternions.
*/
- public Quaternion slerp(Quaternion q1, Quaternion q2, float t) {
+ public Quaternion slerp(Quaternion q1, Quaternion q2, float changeAmnt) {
// Create a local quaternion to store the interpolated quaternion
if (q1.x == q2.x && q1.y == q2.y && q1.z == q2.z && q1.w == q2.w) {
- this.set(q1);
+ if (this != q1) {
+ this.set(q1);
+ }
+
return this;
}
@@ -678,8 +655,8 @@ public Quaternion slerp(Quaternion q1, Quaternion q2, float t) {
}
// Set the first and second scale for the interpolation
- float scale0 = 1 - t;
- float scale1 = t;
+ float scale0 = 1 - changeAmnt;
+ float scale1 = changeAmnt;
// Check if the angle between the 2 quaternions was big enough to
// warrant such calculations
@@ -690,8 +667,8 @@ public Quaternion slerp(Quaternion q1, Quaternion q2, float t) {
// Calculate the scale for q1 and q2, according to the angle and
// it's sine value
- scale0 = FastMath.sin((1 - t) * theta) * invSinTheta;
- scale1 = FastMath.sin((t * theta)) * invSinTheta;
+ scale0 = FastMath.sin((1 - changeAmnt) * theta) * invSinTheta;
+ scale1 = FastMath.sin((changeAmnt * theta)) * invSinTheta;
}
// Calculate the x, y, z and w values for the quaternion by using a
@@ -721,43 +698,7 @@ public void slerp(Quaternion q2, float changeAmnt) {
return;
}
- float result = (this.x * q2.x) + (this.y * q2.y) + (this.z * q2.z)
- + (this.w * q2.w);
-
- if (result < 0.0f) {
- // Negate the second quaternion and the result of the dot product
- q2.x = -q2.x;
- q2.y = -q2.y;
- q2.z = -q2.z;
- q2.w = -q2.w;
- result = -result;
- }
-
- // Set the first and second scale for the interpolation
- float scale0 = 1 - changeAmnt;
- float scale1 = changeAmnt;
-
- // Check if the angle between the 2 quaternions was big enough to
- // warrant such calculations
- if ((1 - result) > 0.1f) {
- // Get the angle between the 2 quaternions, and then store the sin()
- // of that angle
- float theta = FastMath.acos(result);
- float invSinTheta = 1f / FastMath.sin(theta);
-
- // Calculate the scale for q1 and q2, according to the angle and
- // it's sine value
- scale0 = FastMath.sin((1 - changeAmnt) * theta) * invSinTheta;
- scale1 = FastMath.sin((changeAmnt * theta)) * invSinTheta;
- }
-
- // Calculate the x, y, z and w values for the quaternion by using a
- // special
- // form of linear interpolation for quaternions.
- this.x = (scale0 * this.x) + (scale1 * q2.x);
- this.y = (scale0 * this.y) + (scale1 * q2.y);
- this.z = (scale0 * this.z) + (scale1 * q2.z);
- this.w = (scale0 * this.w) + (scale1 * q2.w);
+ slerp(this, q2, changeAmnt);
}
/**
diff --git a/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java b/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java
index cf51ad0c9e..629e525d51 100644
--- a/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java
+++ b/jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java
@@ -148,10 +148,10 @@ public void initialize(RenderManager rm, ViewPort vp) {
Camera cam = vp.getCamera();
//save view port diensions
- left = cam.getViewPortLeft();
- right = cam.getViewPortRight();
- top = cam.getViewPortTop();
- bottom = cam.getViewPortBottom();
+ left = cam.viewPort.getLeft();
+ right = cam.viewPort.getRight();
+ top = cam.viewPort.getTop();
+ bottom = cam.viewPort.getBottom();
originalWidth = cam.getWidth();
originalHeight = cam.getHeight();
//first call to reshape
@@ -187,7 +187,7 @@ private void initFilter(Filter filter, ViewPort vp) {
private void renderProcessing(Renderer r, FrameBuffer buff, Material mat) {
if (buff == outputBuffer) {
viewPort.getCamera().resize(originalWidth, originalHeight, false);
- viewPort.getCamera().setViewPort(left, right, bottom, top);
+ viewPort.getCamera().viewPort.set(left, right, bottom, top);
// update is redundant because resize and setViewPort will both
// run the appropriate (and same) onXXXChange methods.
// Also, update() updates some things that don't need to be updated.
@@ -199,7 +199,7 @@ private void renderProcessing(Renderer r, FrameBuffer buff, Material mat) {
}
}else{
viewPort.getCamera().resize(buff.getWidth(), buff.getHeight(), false);
- viewPort.getCamera().setViewPort(0, 1, 0, 1);
+ viewPort.getCamera().viewPort.set(0, 1, 0, 1);
// update is redundant because resize and setViewPort will both
// run the appropriate (and same) onXXXChange methods.
// Also, update() updates some things that don't need to be updated.
@@ -332,7 +332,7 @@ public void preFrame(float tpf) {
//If the camera is initialized and there are no filter to render, the camera viewport is restored as it was
if (cameraInit) {
viewPort.getCamera().resize(originalWidth, originalHeight, true);
- viewPort.getCamera().setViewPort(left, right, bottom, top);
+ viewPort.getCamera().viewPort.set(left, right, bottom, top);
viewPort.setOutputFrameBuffer(outputBuffer);
cameraInit = false;
}
@@ -343,7 +343,7 @@ public void preFrame(float tpf) {
//to the viewportsize so that the backbuffer is rendered correctly
if (multiView) {
viewPort.getCamera().resize(width, height, false);
- viewPort.getCamera().setViewPort(0, 1, 0, 1);
+ viewPort.getCamera().viewPort.set(0, 1, 0, 1);
viewPort.getCamera().update();
renderManager.setCamera(viewPort.getCamera(), false);
}
@@ -398,7 +398,7 @@ public void cleanup() {
if (viewPort != null) {
//reseting the viewport camera viewport to its initial value
viewPort.getCamera().resize(originalWidth, originalHeight, true);
- viewPort.getCamera().setViewPort(left, right, bottom, top);
+ viewPort.getCamera().viewPort.set(left, right, bottom, top);
viewPort.setOutputFrameBuffer(outputBuffer);
viewPort = null;
@@ -422,13 +422,13 @@ public void cleanup() {
public void reshape(ViewPort vp, int w, int h) {
Camera cam = vp.getCamera();
//this has no effect at first init but is useful when resizing the canvas with multi views
- cam.setViewPort(left, right, bottom, top);
+ cam.viewPort.set(left, right, bottom, top);
//resizing the camera to fit the new viewport and saving original dimensions
cam.resize(w, h, false);
- left = cam.getViewPortLeft();
- right = cam.getViewPortRight();
- top = cam.getViewPortTop();
- bottom = cam.getViewPortBottom();
+ left = cam.viewPort.getLeft();
+ right = cam.viewPort.getRight();
+ top = cam.viewPort.getTop();
+ bottom = cam.viewPort.getBottom();
originalWidth = w;
originalHeight = h;
diff --git a/jme3-core/src/main/java/com/jme3/renderer/Camera.java b/jme3-core/src/main/java/com/jme3/renderer/Camera.java
index 0ce5bafd73..79213d2c06 100644
--- a/jme3-core/src/main/java/com/jme3/renderer/Camera.java
+++ b/jme3-core/src/main/java/com/jme3/renderer/Camera.java
@@ -65,61 +65,6 @@ public class Camera implements Savable, Cloneable {
private static final Logger logger = Logger.getLogger(Camera.class.getName());
- /**
- * The FrustumIntersect enum is returned as a result
- * of a culling check operation,
- * see {@link #contains(com.jme3.bounding.BoundingVolume) }
- */
- public enum FrustumIntersect {
-
- /**
- * defines a constant assigned to spatials that are completely outside
- * of this camera's view frustum.
- */
- Outside,
- /**
- * defines a constant assigned to spatials that are completely inside
- * the camera's view frustum.
- */
- Inside,
- /**
- * defines a constant assigned to spatials that are intersecting one of
- * the six planes that define the view frustum.
- */
- Intersects;
- }
- /**
- * LEFT_PLANE represents the left plane of the camera frustum.
- */
- private static final int LEFT_PLANE = 0;
- /**
- * RIGHT_PLANE represents the right plane of the camera frustum.
- */
- private static final int RIGHT_PLANE = 1;
- /**
- * BOTTOM_PLANE represents the bottom plane of the camera frustum.
- */
- private static final int BOTTOM_PLANE = 2;
- /**
- * TOP_PLANE represents the top plane of the camera frustum.
- */
- private static final int TOP_PLANE = 3;
- /**
- * FAR_PLANE represents the far plane of the camera frustum.
- */
- private static final int FAR_PLANE = 4;
- /**
- * NEAR_PLANE represents the near plane of the camera frustum.
- */
- private static final int NEAR_PLANE = 5;
- /**
- * FRUSTUM_PLANES represents the number of planes of the camera frustum.
- */
- private static final int FRUSTUM_PLANES = 6;
- /**
- * MAX_WORLD_PLANES holds the maximum planes allowed by the system.
- */
- private static final int MAX_WORLD_PLANES = 6;
/**
* Camera's location
*/
@@ -128,57 +73,18 @@ public enum FrustumIntersect {
* The orientation of the camera.
*/
protected Quaternion rotation;
- /**
- * Distance from camera to near frustum plane.
- */
- protected float frustumNear;
- /**
- * Distance from camera to far frustum plane.
- */
- protected float frustumFar;
- /**
- * Distance from camera to left frustum plane.
- */
- protected float frustumLeft;
- /**
- * Distance from camera to right frustum plane.
- */
- protected float frustumRight;
- /**
- * Distance from camera to top frustum plane.
- */
- protected float frustumTop;
- /**
- * Distance from camera to bottom frustum plane.
- */
- protected float frustumBottom;
+
+ public CameraFrustum frustum;
+
//Temporary values computed in onFrustumChange that are needed if a
//call is made to onFrameChange.
protected float[] coeffLeft;
protected float[] coeffRight;
protected float[] coeffBottom;
protected float[] coeffTop;
- //view port coordinates
- /**
- * Percent value on display where horizontal viewing starts for this camera.
- * Default is 0.
- */
- protected float viewPortLeft;
- /**
- * Percent value on display where horizontal viewing ends for this camera.
- * Default is 1.
- */
- protected float viewPortRight;
- /**
- * Percent value on display where vertical viewing ends for this camera.
- * Default is 1.
- */
- protected float viewPortTop;
- /**
- * Percent value on display where vertical viewing begins for this camera.
- * Default is 0.
- */
- protected float viewPortBottom;
+
+ public CameraViewport viewPort;
+
/**
* Array holding the planes that this camera will check for culling.
*/
@@ -208,8 +114,8 @@ public enum FrustumIntersect {
* Serialization only. Do not use.
*/
public Camera() {
- worldPlane = new Plane[MAX_WORLD_PLANES];
- for (int i = 0; i < MAX_WORLD_PLANES; i++) {
+ worldPlane = new Plane[CameraFrustum.MAX_WORLD_PLANES];
+ for (int i = 0; i < CameraFrustum.MAX_WORLD_PLANES; i++) {
worldPlane[i] = new Plane();
}
}
@@ -223,22 +129,14 @@ public Camera(int width, int height) {
location = new Vector3f();
rotation = new Quaternion();
- frustumNear = 1.0f;
- frustumFar = 2.0f;
- frustumLeft = -0.5f;
- frustumRight = 0.5f;
- frustumTop = 0.5f;
- frustumBottom = -0.5f;
+ frustum = new CameraFrustum(this, 1.0f, 2.0f, -0.5f, 0.5f, 0.5f, -0.5f);
coeffLeft = new float[2];
coeffRight = new float[2];
coeffBottom = new float[2];
coeffTop = new float[2];
- viewPortLeft = 0.0f;
- viewPortRight = 1.0f;
- viewPortTop = 1.0f;
- viewPortBottom = 0.0f;
+ viewPort = new CameraViewport(this, 0.0f, 1.0f, 1.0f, 0.0f);
this.width = width;
this.height = height;
@@ -257,7 +155,7 @@ public Camera clone() {
cam.viewportChanged = true;
cam.planeState = 0;
- cam.worldPlane = new Plane[MAX_WORLD_PLANES];
+ cam.worldPlane = new Plane[CameraFrustum.MAX_WORLD_PLANES];
for (int i = 0; i < worldPlane.length; i++) {
cam.worldPlane[i] = worldPlane[i].clone();
}
@@ -297,12 +195,7 @@ public void copyFrom(Camera cam) {
location.set(cam.location);
rotation.set(cam.rotation);
- frustumNear = cam.frustumNear;
- frustumFar = cam.frustumFar;
- frustumLeft = cam.frustumLeft;
- frustumRight = cam.frustumRight;
- frustumTop = cam.frustumTop;
- frustumBottom = cam.frustumBottom;
+ frustum.copyFrom(cam.frustum);
coeffLeft[0] = cam.coeffLeft[0];
coeffLeft[1] = cam.coeffLeft[1];
@@ -313,17 +206,14 @@ public void copyFrom(Camera cam) {
coeffTop[0] = cam.coeffTop[0];
coeffTop[1] = cam.coeffTop[1];
- viewPortLeft = cam.viewPortLeft;
- viewPortRight = cam.viewPortRight;
- viewPortTop = cam.viewPortTop;
- viewPortBottom = cam.viewPortBottom;
+ viewPort.copyFrom(cam.viewPort);
this.width = cam.width;
this.height = cam.height;
this.planeState = 0;
this.viewportChanged = true;
- for (int i = 0; i < MAX_WORLD_PLANES; ++i) {
+ for (int i = 0; i < CameraFrustum.MAX_WORLD_PLANES; ++i) {
worldPlane[i].setNormal(cam.worldPlane[i].getNormal());
worldPlane[i].setConstant(cam.worldPlane[i].getConstant());
}
@@ -456,128 +346,11 @@ public void resize(int width, int height, boolean fixAspect) {
onViewPortChange();
if (fixAspect /*&& !parallelProjection*/) {
- frustumRight = frustumTop * ((float) width / height);
- frustumLeft = -frustumRight;
- onFrustumChange();
+ frustum.setRight(frustum.getTop() * ((float) width / height));
+ frustum.setLeft(-frustum.getRight());
}
}
- /**
- * getFrustumBottom returns the value of the bottom frustum
- * plane.
- *
- * @return the value of the bottom frustum plane.
- */
- public float getFrustumBottom() {
- return frustumBottom;
- }
-
- /**
- * setFrustumBottom sets the value of the bottom frustum
- * plane.
- *
- * @param frustumBottom the value of the bottom frustum plane.
- */
- public void setFrustumBottom(float frustumBottom) {
- this.frustumBottom = frustumBottom;
- onFrustumChange();
- }
-
- /**
- * getFrustumFar gets the value of the far frustum plane.
- *
- * @return the value of the far frustum plane.
- */
- public float getFrustumFar() {
- return frustumFar;
- }
-
- /**
- * setFrustumFar sets the value of the far frustum plane.
- *
- * @param frustumFar the value of the far frustum plane.
- */
- public void setFrustumFar(float frustumFar) {
- this.frustumFar = frustumFar;
- onFrustumChange();
- }
-
- /**
- * getFrustumLeft gets the value of the left frustum plane.
- *
- * @return the value of the left frustum plane.
- */
- public float getFrustumLeft() {
- return frustumLeft;
- }
-
- /**
- * setFrustumLeft sets the value of the left frustum plane.
- *
- * @param frustumLeft the value of the left frustum plane.
- */
- public void setFrustumLeft(float frustumLeft) {
- this.frustumLeft = frustumLeft;
- onFrustumChange();
- }
-
- /**
- * getFrustumNear gets the value of the near frustum plane.
- *
- * @return the value of the near frustum plane.
- */
- public float getFrustumNear() {
- return frustumNear;
- }
-
- /**
- * setFrustumNear sets the value of the near frustum plane.
- *
- * @param frustumNear the value of the near frustum plane.
- */
- public void setFrustumNear(float frustumNear) {
- this.frustumNear = frustumNear;
- onFrustumChange();
- }
-
- /**
- * getFrustumRight gets the value of the right frustum plane.
- *
- * @return frustumRight the value of the right frustum plane.
- */
- public float getFrustumRight() {
- return frustumRight;
- }
-
- /**
- * setFrustumRight sets the value of the right frustum plane.
- *
- * @param frustumRight the value of the right frustum plane.
- */
- public void setFrustumRight(float frustumRight) {
- this.frustumRight = frustumRight;
- onFrustumChange();
- }
-
- /**
- * getFrustumTop gets the value of the top frustum plane.
- *
- * @return the value of the top frustum plane.
- */
- public float getFrustumTop() {
- return frustumTop;
- }
-
- /**
- * setFrustumTop sets the value of the top frustum plane.
- *
- * @param frustumTop the value of the top frustum plane.
- */
- public void setFrustumTop(float frustumTop) {
- this.frustumTop = frustumTop;
- onFrustumChange();
- }
-
/**
* getLocation retrieves the location vector of the camera.
*
@@ -730,62 +503,6 @@ public void normalize() {
onFrameChange();
}
- /**
- * setFrustum sets the frustum of this camera object.
- *
- * @param near the near plane.
- * @param far the far plane.
- * @param left the left plane.
- * @param right the right plane.
- * @param top the top plane.
- * @param bottom the bottom plane.
- * @see Camera#setFrustum(float, float, float, float,
- * float, float)
- */
- public void setFrustum(float near, float far, float left, float right,
- float top, float bottom) {
-
- frustumNear = near;
- frustumFar = far;
- frustumLeft = left;
- frustumRight = right;
- frustumTop = top;
- frustumBottom = bottom;
- onFrustumChange();
- }
-
- /**
- * setFrustumPerspective defines the frustum for the camera. This
- * frustum is defined by a viewing angle, aspect ratio, and near/far planes
- *
- * @param fovY Frame of view angle along the Y in degrees.
- * @param aspect Width:Height ratio
- * @param near Near view plane distance
- * @param far Far view plane distance
- */
- public void setFrustumPerspective(float fovY, float aspect, float near,
- float far) {
- if (Float.isNaN(aspect) || Float.isInfinite(aspect)) {
- // ignore.
- logger.log(Level.WARNING, "Invalid aspect given to setFrustumPerspective: {0}", aspect);
- return;
- }
-
- float h = FastMath.tan(fovY * FastMath.DEG_TO_RAD * .5f) * near;
- float w = h * aspect;
- frustumLeft = -w;
- frustumRight = w;
- frustumBottom = -h;
- frustumTop = h;
- frustumNear = near;
- frustumFar = far;
-
- // Camera is no longer parallel projection even if it was before
- parallelProjection = false;
-
- onFrustumChange();
- }
-
/**
* setFrame sets the orientation and location of the camera.
*
@@ -895,98 +612,6 @@ public void setPlaneState(int planeState) {
this.planeState = planeState;
}
- /**
- * getViewPortLeft gets the left boundary of the viewport
- *
- * @return the left boundary of the viewport
- */
- public float getViewPortLeft() {
- return viewPortLeft;
- }
-
- /**
- * setViewPortLeft sets the left boundary of the viewport
- *
- * @param left the left boundary of the viewport
- */
- public void setViewPortLeft(float left) {
- viewPortLeft = left;
- onViewPortChange();
- }
-
- /**
- * getViewPortRight gets the right boundary of the viewport
- *
- * @return the right boundary of the viewport
- */
- public float getViewPortRight() {
- return viewPortRight;
- }
-
- /**
- * setViewPortRight sets the right boundary of the viewport
- *
- * @param right the right boundary of the viewport
- */
- public void setViewPortRight(float right) {
- viewPortRight = right;
- onViewPortChange();
- }
-
- /**
- * getViewPortTop gets the top boundary of the viewport
- *
- * @return the top boundary of the viewport
- */
- public float getViewPortTop() {
- return viewPortTop;
- }
-
- /**
- * setViewPortTop sets the top boundary of the viewport
- *
- * @param top the top boundary of the viewport
- */
- public void setViewPortTop(float top) {
- viewPortTop = top;
- onViewPortChange();
- }
-
- /**
- * getViewPortBottom gets the bottom boundary of the viewport
- *
- * @return the bottom boundary of the viewport
- */
- public float getViewPortBottom() {
- return viewPortBottom;
- }
-
- /**
- * setViewPortBottom sets the bottom boundary of the viewport
- *
- * @param bottom the bottom boundary of the viewport
- */
- public void setViewPortBottom(float bottom) {
- viewPortBottom = bottom;
- onViewPortChange();
- }
-
- /**
- * setViewPort sets the boundaries of the viewport
- *
- * @param left the left boundary of the viewport (default: 0)
- * @param right the right boundary of the viewport (default: 1)
- * @param bottom the bottom boundary of the viewport (default: 0)
- * @param top the top boundary of the viewport (default: 1)
- */
- public void setViewPort(float left, float right, float bottom, float top) {
- this.viewPortLeft = left;
- this.viewPortRight = right;
- this.viewPortBottom = bottom;
- this.viewPortTop = top;
- onViewPortChange();
- }
-
/**
* Returns the pseudo distance from the given position to the near
* plane of the camera. This is used for render queue sorting.
@@ -994,62 +619,7 @@ public void setViewPort(float left, float right, float bottom, float top) {
* @return Distance from the far plane to the point.
*/
public float distanceToNearPlane(Vector3f pos) {
- return worldPlane[NEAR_PLANE].pseudoDistance(pos);
- }
-
- /**
- * contains tests a bounding volume against the planes of the
- * camera's frustum. The frustum's planes are set such that the normals all
- * face in towards the viewable scene. Therefore, if the bounding volume is
- * on the negative side of the plane is can be culled out.
- *
- * NOTE: This method is used internally for culling, for public usage,
- * the plane state of the bounding volume must be saved and restored, e.g:
- * BoundingVolume bv;
- *
- * @param bound the bound to check for culling
- * @return See enums in
- * Camera c;
- * int planeState = bv.getPlaneState();
- * bv.setPlaneState(0);
- * c.contains(bv);
- * bv.setPlaneState(plateState);
- * FrustumIntersect
- */
- public FrustumIntersect contains(BoundingVolume bound) {
- if (bound == null) {
- return FrustumIntersect.Inside;
- }
-
- int mask;
- FrustumIntersect rVal = FrustumIntersect.Inside;
-
- for (int planeCounter = FRUSTUM_PLANES; planeCounter >= 0; planeCounter--) {
- if (planeCounter == bound.getCheckPlane()) {
- continue; // we have already checked this plane at first iteration
- }
- int planeId = (planeCounter == FRUSTUM_PLANES) ? bound.getCheckPlane() : planeCounter;
-// int planeId = planeCounter;
-
- mask = 1 << (planeId);
- if ((planeState & mask) == 0) {
- Plane.Side side = bound.whichSide(worldPlane[planeId]);
-
- if (side == Plane.Side.Negative) {
- //object is outside of frustum
- bound.setCheckPlane(planeId);
- return FrustumIntersect.Outside;
- } else if (side == Plane.Side.Positive) {
- //object is visible on *this* plane, so mark this plane
- //so that we don't check it for sub nodes.
- planeState |= mask;
- } else {
- rVal = FrustumIntersect.Intersects;
- }
- }
- }
-
- return rVal;
+ return worldPlane[CameraFrustum.NEAR_PLANE].pseudoDistance(pos);
}
public Plane getWorldPlane(int planeId) {
@@ -1161,10 +731,10 @@ public void onViewPortChange() {
}
private void setGuiBounding() {
- float sx = width * viewPortLeft;
- float ex = width * viewPortRight;
- float sy = height * viewPortBottom;
- float ey = height * viewPortTop;
+ float sx = width * viewPort.getLeft();
+ float ex = width * viewPort.getRight();
+ float sy = height * viewPort.getBottom();
+ float ey = height * viewPort.getTop();
float xExtent = Math.max(0f, (ex - sx) / 2f);
float yExtent = Math.max(0f, (ey - sy) / 2f);
guiBounding.setCenter(sx + xExtent, sy + yExtent, 0);
@@ -1181,27 +751,27 @@ private void setGuiBounding() {
*/
public void onFrustumChange() {
if (!isParallelProjection()) {
- float nearSquared = frustumNear * frustumNear;
- float leftSquared = frustumLeft * frustumLeft;
- float rightSquared = frustumRight * frustumRight;
- float bottomSquared = frustumBottom * frustumBottom;
- float topSquared = frustumTop * frustumTop;
+ float nearSquared = frustum.getNear() * frustum.getNear();
+ float leftSquared = frustum.getLeft() * frustum.getLeft();
+ float rightSquared = frustum.getRight() * frustum.getRight();
+ float bottomSquared = frustum.getBottom() * frustum.getBottom();
+ float topSquared = frustum.getTop() * frustum.getTop();
float inverseLength = FastMath.invSqrt(nearSquared + leftSquared);
- coeffLeft[0] = -frustumNear * inverseLength;
- coeffLeft[1] = -frustumLeft * inverseLength;
+ coeffLeft[0] = -frustum.getNear() * inverseLength;
+ coeffLeft[1] = -frustum.getLeft() * inverseLength;
inverseLength = FastMath.invSqrt(nearSquared + rightSquared);
- coeffRight[0] = frustumNear * inverseLength;
- coeffRight[1] = frustumRight * inverseLength;
+ coeffRight[0] = frustum.getNear() * inverseLength;
+ coeffRight[1] = frustum.getRight() * inverseLength;
inverseLength = FastMath.invSqrt(nearSquared + bottomSquared);
- coeffBottom[0] = frustumNear * inverseLength;
- coeffBottom[1] = -frustumBottom * inverseLength;
+ coeffBottom[0] = frustum.getNear() * inverseLength;
+ coeffBottom[1] = -frustum.getBottom() * inverseLength;
inverseLength = FastMath.invSqrt(nearSquared + topSquared);
- coeffTop[0] = -frustumNear * inverseLength;
- coeffTop[1] = frustumTop * inverseLength;
+ coeffTop[0] = -frustum.getNear() * inverseLength;
+ coeffTop[1] = frustum.getTop() * inverseLength;
} else {
coeffLeft[0] = 1;
coeffLeft[1] = 0;
@@ -1216,7 +786,7 @@ public void onFrustumChange() {
coeffTop[1] = 0;
}
- projectionMatrix.fromFrustum(frustumNear, frustumFar, frustumLeft, frustumRight, frustumTop, frustumBottom, parallelProjection);
+ projectionMatrix.fromFrustum(frustum.getNear(), frustum.getFar(), frustum.getLeft(), frustum.getRight(), frustum.getTop(), frustum.getBottom(), parallelProjection);
// projectionMatrix.transposeLocal();
// The frame is effected by the frustum values
@@ -1237,56 +807,56 @@ public void onFrameChange() {
float dirDotLocation = direction.dot(location);
// left plane
- Vector3f leftPlaneNormal = worldPlane[LEFT_PLANE].getNormal();
+ Vector3f leftPlaneNormal = worldPlane[CameraFrustum.LEFT_PLANE].getNormal();
leftPlaneNormal.x = left.x * coeffLeft[0];
leftPlaneNormal.y = left.y * coeffLeft[0];
leftPlaneNormal.z = left.z * coeffLeft[0];
leftPlaneNormal.addLocal(direction.x * coeffLeft[1], direction.y
* coeffLeft[1], direction.z * coeffLeft[1]);
- worldPlane[LEFT_PLANE].setConstant(location.dot(leftPlaneNormal));
+ worldPlane[CameraFrustum.LEFT_PLANE].setConstant(location.dot(leftPlaneNormal));
// right plane
- Vector3f rightPlaneNormal = worldPlane[RIGHT_PLANE].getNormal();
+ Vector3f rightPlaneNormal = worldPlane[CameraFrustum.RIGHT_PLANE].getNormal();
rightPlaneNormal.x = left.x * coeffRight[0];
rightPlaneNormal.y = left.y * coeffRight[0];
rightPlaneNormal.z = left.z * coeffRight[0];
rightPlaneNormal.addLocal(direction.x * coeffRight[1], direction.y
* coeffRight[1], direction.z * coeffRight[1]);
- worldPlane[RIGHT_PLANE].setConstant(location.dot(rightPlaneNormal));
+ worldPlane[CameraFrustum.RIGHT_PLANE].setConstant(location.dot(rightPlaneNormal));
// bottom plane
- Vector3f bottomPlaneNormal = worldPlane[BOTTOM_PLANE].getNormal();
+ Vector3f bottomPlaneNormal = worldPlane[CameraFrustum.BOTTOM_PLANE].getNormal();
bottomPlaneNormal.x = up.x * coeffBottom[0];
bottomPlaneNormal.y = up.y * coeffBottom[0];
bottomPlaneNormal.z = up.z * coeffBottom[0];
bottomPlaneNormal.addLocal(direction.x * coeffBottom[1], direction.y
* coeffBottom[1], direction.z * coeffBottom[1]);
- worldPlane[BOTTOM_PLANE].setConstant(location.dot(bottomPlaneNormal));
+ worldPlane[CameraFrustum.BOTTOM_PLANE].setConstant(location.dot(bottomPlaneNormal));
// top plane
- Vector3f topPlaneNormal = worldPlane[TOP_PLANE].getNormal();
+ Vector3f topPlaneNormal = worldPlane[CameraFrustum.TOP_PLANE].getNormal();
topPlaneNormal.x = up.x * coeffTop[0];
topPlaneNormal.y = up.y * coeffTop[0];
topPlaneNormal.z = up.z * coeffTop[0];
topPlaneNormal.addLocal(direction.x * coeffTop[1], direction.y
* coeffTop[1], direction.z * coeffTop[1]);
- worldPlane[TOP_PLANE].setConstant(location.dot(topPlaneNormal));
+ worldPlane[CameraFrustum.TOP_PLANE].setConstant(location.dot(topPlaneNormal));
if (isParallelProjection()) {
- worldPlane[LEFT_PLANE].setConstant(worldPlane[LEFT_PLANE].getConstant() + frustumLeft);
- worldPlane[RIGHT_PLANE].setConstant(worldPlane[RIGHT_PLANE].getConstant() - frustumRight);
- worldPlane[TOP_PLANE].setConstant(worldPlane[TOP_PLANE].getConstant() - frustumTop);
- worldPlane[BOTTOM_PLANE].setConstant(worldPlane[BOTTOM_PLANE].getConstant() + frustumBottom);
+ worldPlane[CameraFrustum.LEFT_PLANE].setConstant(worldPlane[CameraFrustum.LEFT_PLANE].getConstant() + frustum.getLeft());
+ worldPlane[CameraFrustum.RIGHT_PLANE].setConstant(worldPlane[CameraFrustum.RIGHT_PLANE].getConstant() - frustum.getRight());
+ worldPlane[CameraFrustum.TOP_PLANE].setConstant(worldPlane[CameraFrustum.TOP_PLANE].getConstant() - frustum.getTop());
+ worldPlane[CameraFrustum.BOTTOM_PLANE].setConstant(worldPlane[CameraFrustum.BOTTOM_PLANE].getConstant() + frustum.getBottom());
}
// far plane
- worldPlane[FAR_PLANE].setNormal(left);
- worldPlane[FAR_PLANE].setNormal(-direction.x, -direction.y, -direction.z);
- worldPlane[FAR_PLANE].setConstant(-(dirDotLocation + frustumFar));
+ worldPlane[CameraFrustum.FAR_PLANE].setNormal(left);
+ worldPlane[CameraFrustum.FAR_PLANE].setNormal(-direction.x, -direction.y, -direction.z);
+ worldPlane[CameraFrustum.FAR_PLANE].setConstant(-(dirDotLocation + frustum.getFar()));
// near plane
- worldPlane[NEAR_PLANE].setNormal(direction.x, direction.y, direction.z);
- worldPlane[NEAR_PLANE].setConstant(dirDotLocation + frustumNear);
+ worldPlane[CameraFrustum.NEAR_PLANE].setNormal(direction.x, direction.y, direction.z);
+ worldPlane[CameraFrustum.NEAR_PLANE].setConstant(dirDotLocation + frustum.getNear());
viewMatrix.fromFrame(location, direction, up, left);
@@ -1323,8 +893,8 @@ public void setParallelProjection(final boolean value) {
* @return the z value in projection space.
*/
public float getViewToProjectionZ(float viewZPos) {
- float far = getFrustumFar();
- float near = getFrustumNear();
+ float far = frustum.getFar();
+ float near = frustum.getNear();
float a = far / (far - near);
float b = far * near / (near - far);
return a + b / viewZPos;
@@ -1360,8 +930,8 @@ public Vector3f getWorldCoordinates(Vector2f screenPosition,
inverseMat.invertLocal();
store.set(
- (screenPosition.x / getWidth() - viewPortLeft) / (viewPortRight - viewPortLeft) * 2 - 1,
- (screenPosition.y / getHeight() - viewPortBottom) / (viewPortTop - viewPortBottom) * 2 - 1,
+ (screenPosition.x / getWidth() - viewPort.getLeft()) / (viewPort.getRight() - viewPort.getLeft()) * 2 - 1,
+ (screenPosition.y / getHeight() - viewPort.getBottom()) / (viewPort.getTop() - viewPort.getBottom()) * 2 - 1,
projectionZPos * 2 - 1);
float w = inverseMat.multProj(store, store);
@@ -1402,8 +972,8 @@ public Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store) {
float w = viewProjectionMatrix.multProj(worldPosition, store);
store.divideLocal(w);
- store.x = ((store.x + 1f) * (viewPortRight - viewPortLeft) / 2f + viewPortLeft) * getWidth();
- store.y = ((store.y + 1f) * (viewPortTop - viewPortBottom) / 2f + viewPortBottom) * getHeight();
+ store.x = ((store.x + 1f) * (viewPort.getRight() - viewPort.getLeft()) / 2f + viewPort.getLeft()) * getWidth();
+ store.y = ((store.y + 1f) * (viewPort.getTop() - viewPort.getBottom()) / 2f + viewPort.getBottom()) * getHeight();
store.z = (store.z + 1f) / 2f;
return store;
@@ -1427,27 +997,27 @@ public int getHeight() {
public String toString() {
return "Camera[location=" + location + "\n, direction=" + getDirection() + "\n"
+ "res=" + width + "x" + height + ", parallel=" + parallelProjection + "\n"
- + "near=" + frustumNear + ", far=" + frustumFar + "]";
+ + "near=" + frustum.getNear() + ", far=" + frustum.getFar() + "]";
}
public void write(JmeExporter e) throws IOException {
OutputCapsule capsule = e.getCapsule(this);
capsule.write(location, "location", Vector3f.ZERO);
capsule.write(rotation, "rotation", Quaternion.DIRECTION_Z);
- capsule.write(frustumNear, "frustumNear", 1);
- capsule.write(frustumFar, "frustumFar", 2);
- capsule.write(frustumLeft, "frustumLeft", -0.5f);
- capsule.write(frustumRight, "frustumRight", 0.5f);
- capsule.write(frustumTop, "frustumTop", 0.5f);
- capsule.write(frustumBottom, "frustumBottom", -0.5f);
+ capsule.write(frustum.getNear(), "frustumNear", 1);
+ capsule.write(frustum.getFar(), "frustumFar", 2);
+ capsule.write(frustum.getLeft(), "frustumLeft", -0.5f);
+ capsule.write(frustum.getRight(), "frustumRight", 0.5f);
+ capsule.write(frustum.getTop(), "frustumTop", 0.5f);
+ capsule.write(frustum.getBottom(), "frustumBottom", -0.5f);
capsule.write(coeffLeft, "coeffLeft", new float[2]);
capsule.write(coeffRight, "coeffRight", new float[2]);
capsule.write(coeffBottom, "coeffBottom", new float[2]);
capsule.write(coeffTop, "coeffTop", new float[2]);
- capsule.write(viewPortLeft, "viewPortLeft", 0);
- capsule.write(viewPortRight, "viewPortRight", 1);
- capsule.write(viewPortTop, "viewPortTop", 1);
- capsule.write(viewPortBottom, "viewPortBottom", 0);
+ capsule.write(viewPort.getLeft(), "viewPortLeft", 0);
+ capsule.write(viewPort.getRight(), "viewPortRight", 1);
+ capsule.write(viewPort.getTop(), "viewPortTop", 1);
+ capsule.write(viewPort.getBottom(), "viewPortBottom", 0);
capsule.write(width, "width", 0);
capsule.write(height, "height", 0);
capsule.write(name, "name", null);
@@ -1457,20 +1027,24 @@ public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
location = (Vector3f) capsule.readSavable("location", Vector3f.ZERO.clone());
rotation = (Quaternion) capsule.readSavable("rotation", Quaternion.DIRECTION_Z.clone());
- frustumNear = capsule.readFloat("frustumNear", 1);
- frustumFar = capsule.readFloat("frustumFar", 2);
- frustumLeft = capsule.readFloat("frustumLeft", -0.5f);
- frustumRight = capsule.readFloat("frustumRight", 0.5f);
- frustumTop = capsule.readFloat("frustumTop", 0.5f);
- frustumBottom = capsule.readFloat("frustumBottom", -0.5f);
+ frustum.set(
+ capsule.readFloat("frustumNear", 1),
+ capsule.readFloat("frustumFar", 2),
+ capsule.readFloat("frustumLeft", -0.5f),
+ capsule.readFloat("frustumRight", 0.5f),
+ capsule.readFloat("frustumTop", 0.5f),
+ capsule.readFloat("frustumBottom", -0.5f)
+ );
coeffLeft = capsule.readFloatArray("coeffLeft", new float[2]);
coeffRight = capsule.readFloatArray("coeffRight", new float[2]);
coeffBottom = capsule.readFloatArray("coeffBottom", new float[2]);
coeffTop = capsule.readFloatArray("coeffTop", new float[2]);
- viewPortLeft = capsule.readFloat("viewPortLeft", 0);
- viewPortRight = capsule.readFloat("viewPortRight", 1);
- viewPortTop = capsule.readFloat("viewPortTop", 1);
- viewPortBottom = capsule.readFloat("viewPortBottom", 0);
+ viewPort.set(
+ capsule.readFloat("viewPortLeft", 0),
+ capsule.readFloat("viewPortRight", 1),
+ capsule.readFloat("viewPortTop", 1),
+ capsule.readFloat("viewPortBottom", 0)
+ );
width = capsule.readInt("width", 1);
height = capsule.readInt("height", 1);
name = capsule.readString("name", null);
diff --git a/jme3-core/src/main/java/com/jme3/renderer/CameraFrustum.java b/jme3-core/src/main/java/com/jme3/renderer/CameraFrustum.java
new file mode 100644
index 0000000000..7698cebb69
--- /dev/null
+++ b/jme3-core/src/main/java/com/jme3/renderer/CameraFrustum.java
@@ -0,0 +1,269 @@
+package com.jme3.renderer;
+
+import com.jme3.bounding.BoundingVolume;
+import com.jme3.math.FastMath;
+import com.jme3.math.Plane;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class CameraFrustum {
+
+ private static final Logger logger = Logger.getLogger(CameraFrustum.class.getName());
+
+ private Camera camera;
+
+ /**
+ * The Intersect enum is returned as a result
+ * of a culling check operation,
+ * see {@link #contains(com.jme3.bounding.BoundingVolume) }
+ */
+ public enum Intersect {
+
+ /**
+ * defines a constant assigned to spatials that are completely outside
+ * of this camera's view frustum.
+ */
+ Outside,
+ /**
+ * defines a constant assigned to spatials that are completely inside
+ * the camera's view frustum.
+ */
+ Inside,
+ /**
+ * defines a constant assigned to spatials that are intersecting one of
+ * the six planes that define the view frustum.
+ */
+ Intersects;
+ }
+ /**
+ * LEFT_PLANE represents the left plane of the camera frustum.
+ */
+ public static final int LEFT_PLANE = 0;
+ /**
+ * RIGHT_PLANE represents the right plane of the camera frustum.
+ */
+ public static final int RIGHT_PLANE = 1;
+ /**
+ * BOTTOM_PLANE represents the bottom plane of the camera frustum.
+ */
+ public static final int BOTTOM_PLANE = 2;
+ /**
+ * TOP_PLANE represents the top plane of the camera frustum.
+ */
+ public static final int TOP_PLANE = 3;
+ /**
+ * FAR_PLANE represents the far plane of the camera frustum.
+ */
+ public static final int FAR_PLANE = 4;
+ /**
+ * NEAR_PLANE represents the near plane of the camera frustum.
+ */
+ public static final int NEAR_PLANE = 5;
+ /**
+ * FRUSTUM_PLANES represents the number of planes of the camera frustum.
+ */
+ public static final int FRUSTUM_PLANES = 6;
+ /**
+ * MAX_WORLD_PLANES holds the maximum planes allowed by the system.
+ */
+ public static final int MAX_WORLD_PLANES = 6;
+
+
+ /**
+ * Distance from camera to near frustum plane.
+ */
+ private float near;
+ /**
+ * Distance from camera to far frustum plane.
+ */
+ private float far;
+ /**
+ * Distance from camera to left frustum plane.
+ */
+ private float left;
+ /**
+ * Distance from camera to right frustum plane.
+ */
+ private float right;
+ /**
+ * Distance from camera to top frustum plane.
+ */
+ private float top;
+ /**
+ * Distance from camera to bottom frustum plane.
+ */
+ private float bottom;
+
+ public CameraFrustum(Camera camera, float near, float far, float left, float right, float top, float bottom) {
+ this.camera = camera;
+ this.near = near;
+ this.far = far;
+ this.left = left;
+ this.right = right;
+ this.top = top;
+ this.bottom = bottom;
+ }
+
+ public void set(float near, float far, float left, float right, float top, float bottom) {
+ this.near = near;
+ this.far = far;
+ this.left = left;
+ this.right = right;
+ this.top = top;
+ this.bottom = bottom;
+ camera.onFrustumChange();
+ }
+
+ public float getNear() {
+ return near;
+ }
+
+ public void setNear(float near) {
+ this.near = near;
+ camera.onFrustumChange();
+ }
+
+ public float getFar() {
+ return far;
+ }
+
+ public void setFar(float far) {
+ this.far = far;
+ camera.onFrustumChange();
+ }
+
+ public float getLeft() {
+ return left;
+ }
+
+ public void setLeft(float left) {
+ this.left = left;
+ camera.onFrustumChange();
+ }
+
+ public float getRight() {
+ return right;
+ }
+
+ public void setRight(float right) {
+ this.right = right;
+ camera.onFrustumChange();
+ }
+
+ public float getTop() {
+ return top;
+ }
+
+ public void setTop(float top) {
+ this.top = top;
+ camera.onFrustumChange();
+ }
+
+ public float getBottom() {
+ return bottom;
+ }
+
+ public void setBottom(float bottom) {
+ this.bottom = bottom;
+ camera.onFrustumChange();
+ }
+
+ public void copyFrom(CameraFrustum other) {
+ this.near = other.near;
+ this.far = other.far;
+ this.left = other.left;
+ this.right = other.right;
+ this.top = other.top;
+ this.bottom = other.bottom;
+ camera.onFrustumChange();
+ }
+
+ /**
+ * contains tests a bounding volume against the planes of the
+ * camera's frustum. The frustum's planes are set such that the normals all
+ * face in towards the viewable scene. Therefore, if the bounding volume is
+ * on the negative side of the plane is can be culled out.
+ *
+ * NOTE: This method is used internally for culling, for public usage,
+ * the plane state of the bounding volume must be saved and restored, e.g:
+ * BoundingVolume bv;
+ *
+ * @param bound the bound to check for culling
+ * @return See enums in
+ * Camera c;
+ * int planeState = bv.getPlaneState();
+ * bv.setPlaneState(0);
+ * c.contains(bv);
+ * bv.setPlaneState(plateState);
+ * Intersect
+ */
+ public Intersect contains(BoundingVolume bound) {
+ if (bound == null) {
+ return Intersect.Inside;
+ }
+
+ int mask;
+ Intersect rVal = Intersect.Inside;
+
+ for (int planeCounter = FRUSTUM_PLANES; planeCounter >= 0; planeCounter--) {
+ if (planeCounter == bound.getCheckPlane()) {
+ continue; // we have already checked this plane at first iteration
+ }
+ int planeId = (planeCounter == FRUSTUM_PLANES) ? bound.getCheckPlane() : planeCounter;
+// int planeId = planeCounter;
+
+ mask = 1 << (planeId);
+ if ((camera.getPlaneState() & mask) == 0) {
+ Plane.Side side = bound.whichSide(camera.getWorldPlane(planeId));
+
+ if (side == Plane.Side.Negative) {
+ //object is outside of frustum
+ bound.setCheckPlane(planeId);
+ return Intersect.Outside;
+ } else if (side == Plane.Side.Positive) {
+ //object is visible on *this* plane, so mark this plane
+ //so that we don't check it for sub nodes.
+ camera.setPlaneState(camera.getPlaneState() | mask);
+ } else {
+ rVal = Intersect.Intersects;
+ }
+ }
+ }
+
+ return rVal;
+ }
+
+ /**
+ * setFrustumPerspective defines the frustum for the camera. This
+ * frustum is defined by a viewing angle, aspect ratio, and near/far planes
+ *
+ * @param fovY Frame of view angle along the Y in degrees.
+ * @param aspect Width:Height ratio
+ * @param near Near view plane distance
+ * @param far Far view plane distance
+ */
+ public void setPerspective(float fovY, float aspect, float near,
+ float far) {
+ if (Float.isNaN(aspect) || Float.isInfinite(aspect)) {
+ // ignore.
+ logger.log(Level.WARNING, "Invalid aspect given to setFrustumPerspective: {0}", aspect);
+ return;
+ }
+
+ float h = FastMath.tan(fovY * FastMath.DEG_TO_RAD * .5f) * near;
+ float w = h * aspect;
+ this.left = -w;
+ this.right = w;
+ this.bottom = -h;
+ this.top = h;
+ this.near = near;
+ this.far = far;
+
+ // Camera is no longer parallel projection even if it was before
+ camera.setParallelProjection(false);
+
+ camera.onFrustumChange();
+ }
+
+}
diff --git a/jme3-core/src/main/java/com/jme3/renderer/CameraViewport.java b/jme3-core/src/main/java/com/jme3/renderer/CameraViewport.java
new file mode 100644
index 0000000000..ee3147e300
--- /dev/null
+++ b/jme3-core/src/main/java/com/jme3/renderer/CameraViewport.java
@@ -0,0 +1,90 @@
+package com.jme3.renderer;
+
+public class CameraViewport {
+
+ private Camera camera;
+
+ //view port coordinates
+ /**
+ * Percent value on display where horizontal viewing starts for this camera.
+ * Default is 0.
+ */
+ private float left;
+ /**
+ * Percent value on display where horizontal viewing ends for this camera.
+ * Default is 1.
+ */
+ private float right;
+ /**
+ * Percent value on display where vertical viewing ends for this camera.
+ * Default is 1.
+ */
+ private float top;
+ /**
+ * Percent value on display where vertical viewing begins for this camera.
+ * Default is 0.
+ */
+ private float bottom;
+
+ public CameraViewport(Camera camera, float left, float right, float top, float bottom) {
+ this.camera = camera;
+ this.left = left;
+ this.right = right;
+ this.top = top;
+ this.bottom = bottom;
+ }
+
+ public void set(float left, float right, float top, float bottom) {
+ this.left = left;
+ this.right = right;
+ this.top = top;
+ this.bottom = bottom;
+ camera.onViewPortChange();
+ }
+
+ public float getLeft() {
+ return left;
+ }
+
+ public void setLeft(float left) {
+ this.left = left;
+ camera.onViewPortChange();
+ }
+
+ public float getRight() {
+ return right;
+ }
+
+ public void setRight(float right) {
+ this.right = right;
+ camera.onViewPortChange();
+ }
+
+ public float getTop() {
+ return top;
+ }
+
+ public void setTop(float top) {
+ this.top = top;
+ camera.onViewPortChange();
+ }
+
+ public float getBottom() {
+ return bottom;
+ }
+
+ public void setBottom(float bottom) {
+ this.bottom = bottom;
+ camera.onViewPortChange();
+ }
+
+ public void copyFrom(CameraViewport other) {
+ this.left = other.left;
+ this.right = other.right;
+ this.top = other.top;
+ this.bottom = other.bottom;
+ camera.onViewPortChange();
+ }
+
+
+}
diff --git a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
index 7aac5a6895..a5a2c6bc46 100644
--- a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
+++ b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
@@ -874,10 +874,10 @@ public void renderTranslucentQueue(ViewPort vp) {
private void setViewPort(Camera cam) {
// this will make sure to update viewport only if needed
if (cam != prevCam || cam.isViewportChanged()) {
- viewX = (int) (cam.getViewPortLeft() * cam.getWidth());
- viewY = (int) (cam.getViewPortBottom() * cam.getHeight());
- int viewX2 = (int) (cam.getViewPortRight() * cam.getWidth());
- int viewY2 = (int) (cam.getViewPortTop() * cam.getHeight());
+ viewX = (int) (cam.viewPort.getLeft() * cam.getWidth());
+ viewY = (int) (cam.viewPort.getBottom() * cam.getHeight());
+ int viewX2 = (int) (cam.viewPort.getRight() * cam.getWidth());
+ int viewY2 = (int) (cam.viewPort.getTop() * cam.getHeight());
viewWidth = viewX2 - viewX;
viewHeight = viewY2 - viewY;
uniformBindingManager.setViewPort(viewX, viewY, viewWidth, viewHeight);
@@ -913,7 +913,7 @@ private void setViewProjection(Camera cam, boolean ortho) {
* Set the camera to use for rendering.
*
* First, the camera's
- * {@link Camera#setViewPort(float, float, float, float) view port parameters}
+ * {@link Camera#viewPort#set(float, float, float, float) view port parameters}
* are applied. Then, the camera's {@link Camera#getViewMatrix() view} and
* {@link Camera#getProjectionMatrix() projection} matrices are set
* on the renderer. If ortho is true, then
diff --git a/jme3-core/src/main/java/com/jme3/scene/Geometry.java b/jme3-core/src/main/java/com/jme3/scene/Geometry.java
index 4c394101ab..9fd900cc7a 100644
--- a/jme3-core/src/main/java/com/jme3/scene/Geometry.java
+++ b/jme3-core/src/main/java/com/jme3/scene/Geometry.java
@@ -42,6 +42,7 @@
import com.jme3.material.Material;
import com.jme3.math.Matrix4f;
import com.jme3.renderer.Camera;
+import com.jme3.renderer.CameraFrustum;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.TempVars;
import java.io.IOException;
@@ -129,7 +130,7 @@ public Geometry(String name, Mesh mesh) {
@Override
public boolean checkCulling(Camera cam) {
if (isGrouped()) {
- setLastFrustumIntersection(Camera.FrustumIntersect.Outside);
+ setLastFrustumIntersection(CameraFrustum.Intersect.Outside);
return false;
}
return super.checkCulling(cam);
diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java
index 1fe68d7309..d8ce8ccb7c 100644
--- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java
+++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java
@@ -41,6 +41,7 @@
import com.jme3.material.Material;
import com.jme3.math.*;
import com.jme3.renderer.Camera;
+import com.jme3.renderer.CameraFrustum;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
@@ -137,7 +138,7 @@ public enum BatchHint {
*/
protected String name;
// scale values
- protected transient Camera.FrustumIntersect frustrumIntersects = Camera.FrustumIntersect.Intersects;
+ protected transient CameraFrustum.Intersect frustrumIntersects = CameraFrustum.Intersect.Intersects;
protected RenderQueue.Bucket queueBucket = RenderQueue.Bucket.Inherit;
protected ShadowMode shadowMode = RenderQueue.ShadowMode.Inherit;
public transient float queueDistance = Float.NEGATIVE_INFINITY;
@@ -357,26 +358,26 @@ public boolean checkCulling(Camera cam) {
CullHint cm = getCullHint();
assert cm != CullHint.Inherit;
if (cm == Spatial.CullHint.Always) {
- setLastFrustumIntersection(Camera.FrustumIntersect.Outside);
+ setLastFrustumIntersection(CameraFrustum.Intersect.Outside);
return false;
} else if (cm == Spatial.CullHint.Never) {
- setLastFrustumIntersection(Camera.FrustumIntersect.Intersects);
+ setLastFrustumIntersection(CameraFrustum.Intersect.Intersects);
return true;
}
// check to see if we can cull this node
frustrumIntersects = (parent != null ? parent.frustrumIntersects
- : Camera.FrustumIntersect.Intersects);
+ : CameraFrustum.Intersect.Intersects);
- if (frustrumIntersects == Camera.FrustumIntersect.Intersects) {
+ if (frustrumIntersects == CameraFrustum.Intersect.Intersects) {
if (getQueueBucket() == Bucket.Gui) {
return cam.containsGui(getWorldBound());
} else {
- frustrumIntersects = cam.contains(getWorldBound());
+ frustrumIntersects = cam.frustum.contains(getWorldBound());
}
}
- return frustrumIntersects != Camera.FrustumIntersect.Outside;
+ return frustrumIntersects != CameraFrustum.Intersect.Outside;
}
/**
@@ -1076,93 +1077,6 @@ public void removeLight(Light light) {
setLightListRefresh();
}
- /**
- * Translates the spatial by the given translation vector.
- *
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial move(float x, float y, float z) {
- this.localTransform.getTranslation().addLocal(x, y, z);
- setTransformRefresh();
-
- return this;
- }
-
- /**
- * Translates the spatial by the given translation vector.
- *
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial move(Vector3f offset) {
- this.localTransform.getTranslation().addLocal(offset);
- setTransformRefresh();
-
- return this;
- }
-
- /**
- * Scales the spatial by the given value
- *
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial scale(float s) {
- return scale(s, s, s);
- }
-
- /**
- * Scales the spatial by the given scale vector.
- *
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial scale(float x, float y, float z) {
- this.localTransform.getScale().multLocal(x, y, z);
- setTransformRefresh();
-
- return this;
- }
-
- /**
- * Rotates the spatial by the given rotation.
- *
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial rotate(Quaternion rot) {
- this.localTransform.getRotation().multLocal(rot);
- setTransformRefresh();
-
- return this;
- }
-
- /**
- * Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians),
- * (aka pitch, yaw, roll) in the local coordinate space.
- *
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial rotate(float xAngle, float yAngle, float zAngle) {
- TempVars vars = TempVars.get();
- Quaternion q = vars.quat1;
- q.fromAngles(xAngle, yAngle, zAngle);
- rotate(q);
- vars.release();
-
- return this;
- }
-
- /**
- * Centers the spatial in the origin of the world bound.
- * @return The spatial on which this method is called, e.g this.
- */
- public Spatial center() {
- Vector3f worldTrans = getWorldTranslation();
- Vector3f worldCenter = getWorldBound().getCenter();
-
- Vector3f absTrans = worldTrans.subtract(worldCenter);
- setLocalTranslation(absTrans);
-
- return this;
- }
-
/**
* @see #setCullHint(CullHint)
* @return the cull mode of this spatial, or if set to CullHint.Inherit, the
@@ -1350,7 +1264,7 @@ public void setUserData(String key, Object data) {
}
if(data == null){
- userData.remove(key);
+ userData.remove(key);
}else if (data instanceof Savable) {
userData.put(key, (Savable) data);
} else {
@@ -1558,7 +1472,7 @@ public RenderQueue.ShadowMode getLocalShadowMode() {
*
* @return The spatial's last frustum intersection result.
*/
- public Camera.FrustumIntersect getLastFrustumIntersection() {
+ public CameraFrustum.Intersect getLastFrustumIntersection() {
return frustrumIntersects;
}
@@ -1570,7 +1484,7 @@ public Camera.FrustumIntersect getLastFrustumIntersection() {
* @param intersects
* the new value
*/
- public void setLastFrustumIntersection(Camera.FrustumIntersect intersects) {
+ public void setLastFrustumIntersection(CameraFrustum.Intersect intersects) {
frustrumIntersects = intersects;
}
diff --git a/jme3-core/src/main/java/com/jme3/scene/SpatialTransformer.java b/jme3-core/src/main/java/com/jme3/scene/SpatialTransformer.java
new file mode 100644
index 0000000000..43a0b695d3
--- /dev/null
+++ b/jme3-core/src/main/java/com/jme3/scene/SpatialTransformer.java
@@ -0,0 +1,96 @@
+package com.jme3.scene;
+
+import com.jme3.math.Quaternion;
+import com.jme3.math.Vector3f;
+import com.jme3.util.TempVars;
+
+public class SpatialTransformer {
+
+ /**
+ * Translates the spatial by the given translation vector.
+ *
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial move(Spatial s, float x, float y, float z) {
+ s.localTransform.getTranslation().addLocal(x, y, z);
+ s.setTransformRefresh();
+
+ return s;
+ }
+
+ /**
+ * Translates the spatial by the given translation vector.
+ *
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial move(Spatial s, Vector3f offset) {
+ s.localTransform.getTranslation().addLocal(offset);
+ s.setTransformRefresh();
+
+ return s;
+ }
+
+ /**
+ * Scales the spatial by the given value
+ *
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial scale(Spatial s, float xyz) {
+ return scale(s, xyz, xyz, xyz);
+ }
+
+ /**
+ * Scales the spatial by the given scale vector.
+ *
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial scale(Spatial s, float x, float y, float z) {
+ s.localTransform.getScale().multLocal(x, y, z);
+ s.setTransformRefresh();
+
+ return s;
+ }
+
+ /**
+ * Rotates the spatial by the given rotation.
+ *
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial rotate(Spatial s, Quaternion rot) {
+ s.localTransform.getRotation().multLocal(rot);
+ s.setTransformRefresh();
+
+ return s;
+ }
+
+ /**
+ * Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians),
+ * (aka pitch, yaw, roll) in the local coordinate space.
+ *
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial rotate(Spatial s, float xAngle, float yAngle, float zAngle) {
+ TempVars vars = TempVars.get();
+ Quaternion q = vars.quat1;
+ q.fromAngles(xAngle, yAngle, zAngle);
+ rotate(s, q);
+ vars.release();
+
+ return s;
+ }
+
+ /**
+ * Centers the spatial in the origin of the world bound.
+ * @return The spatial on which this method is called, e.g this.
+ */
+ public Spatial center(Spatial s) {
+ Vector3f worldTrans = s.getWorldTranslation();
+ Vector3f worldCenter = s.getWorldBound().getCenter();
+
+ Vector3f absTrans = worldTrans.subtract(worldCenter);
+ s.setLocalTranslation(absTrans);
+
+ return s;
+ }
+
+}
diff --git a/jme3-core/src/main/java/com/jme3/scene/control/LodControl.java b/jme3-core/src/main/java/com/jme3/scene/control/LodControl.java
index 030ccbb3ad..e406e5446b 100644
--- a/jme3-core/src/main/java/com/jme3/scene/control/LodControl.java
+++ b/jme3-core/src/main/java/com/jme3/scene/control/LodControl.java
@@ -150,7 +150,7 @@ protected void controlRender(RenderManager rm, ViewPort vp) {
BoundingVolume bv = spatial.getWorldBound();
Camera cam = vp.getCamera();
- float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop());
+ float atanNH = FastMath.atan(cam.frustum.getNear() * cam.frustum.getTop());
float ratio = (FastMath.PI / (8f * atanNH));
float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio;
int level;
diff --git a/jme3-core/src/plugins/java/com/jme3/scene/plugins/MTLLoader.java b/jme3-core/src/main/java/com/jme3/scene/plugins/MTLLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/scene/plugins/MTLLoader.java
rename to jme3-core/src/main/java/com/jme3/scene/plugins/MTLLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/scene/plugins/OBJLoader.java b/jme3-core/src/main/java/com/jme3/scene/plugins/OBJLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/scene/plugins/OBJLoader.java
rename to jme3-core/src/main/java/com/jme3/scene/plugins/OBJLoader.java
diff --git a/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java b/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java
index af2df5a94a..f1a5bff678 100644
--- a/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java
+++ b/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java
@@ -242,8 +242,8 @@ public void setCamera(Camera cam, Matrix4f viewMatrix, Matrix4f projMatrix, Matr
cam.getUp(camUp);
cam.getDirection(camDir);
- near = cam.getFrustumNear();
- far = cam.getFrustumFar();
+ near = cam.frustum.getNear();
+ far = cam.frustum.getFar();
}
public void setViewPort(int viewX, int viewY, int viewWidth, int viewHeight) {
diff --git a/jme3-core/src/plugins/java/com/jme3/shader/plugins/GLSLLoader.java b/jme3-core/src/main/java/com/jme3/shader/plugins/GLSLLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/shader/plugins/GLSLLoader.java
rename to jme3-core/src/main/java/com/jme3/shader/plugins/GLSLLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/shader/plugins/ShaderDependencyNode.java b/jme3-core/src/main/java/com/jme3/shader/plugins/ShaderDependencyNode.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/shader/plugins/ShaderDependencyNode.java
rename to jme3-core/src/main/java/com/jme3/shader/plugins/ShaderDependencyNode.java
diff --git a/jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java
index 1410574eaa..cacaa7533e 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/BasicShadowRenderer.java
@@ -154,8 +154,8 @@ public void postQueue(RenderQueue rq) {
// update frustum points based on current camera
Camera viewCam = viewPort.getCamera();
ShadowUtil.updateFrustumPoints(viewCam,
- viewCam.getFrustumNear(),
- viewCam.getFrustumFar(),
+ viewCam.frustum.getNear(),
+ viewCam.frustum.getFar(),
1.0f,
points);
diff --git a/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java
index acf8a96775..bdc3fe9da8 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/DirectionalLightShadowRenderer.java
@@ -138,11 +138,11 @@ protected void updateShadowCams(Camera viewCam) {
float zFar = zFarOverride;
if (zFar == 0) {
- zFar = viewCam.getFrustumFar();
+ zFar = viewCam.frustum.getFar();
}
//We prevent computing the frustum points and splits with zeroed or negative near clip value
- float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
+ float frustumNear = Math.max(viewCam.frustum.getNear(), 0.001f);
ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
//shadowCam.setDirection(direction);
diff --git a/jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java
index f4a6455f11..08d3e4c348 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/PointLightShadowRenderer.java
@@ -92,7 +92,7 @@ private void init(int shadowMapSize) {
protected void initFrustumCam() {
Camera viewCam = viewPort.getCamera();
frustumCam = viewCam.clone();
- frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom());
+ frustumCam.frustum.set(viewCam.frustum.getNear(), zFarOverride, viewCam.frustum.getLeft(), viewCam.frustum.getRight(), viewCam.frustum.getTop(), viewCam.frustum.getBottom());
}
@@ -122,7 +122,7 @@ protected void updateShadowCams(Camera viewCam) {
shadowCams[5].setAxes(Vector3f.UNIT_Z.mult(-1f), Vector3f.UNIT_Y, Vector3f.UNIT_X);
for (int i = 0; i < CAM_NUMBER; i++) {
- shadowCams[i].setFrustumPerspective(90f, 1f, 0.1f, light.getRadius());
+ shadowCams[i].frustum.setPerspective(90f, 1f, 0.1f, light.getRadius());
shadowCams[i].setLocation(light.getPosition());
shadowCams[i].update();
shadowCams[i].updateViewProjection();
diff --git a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java
index e06b5c3375..241c100198 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java
@@ -395,11 +395,11 @@ public void postQueue(RenderQueue rq) {
float zFar = zFarOverride;
if (zFar == 0) {
- zFar = viewCam.getFrustumFar();
+ zFar = viewCam.frustum.getFar();
}
//We prevent computing the frustum points and splits with zeroed or negative near clip value
- float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
+ float frustumNear = Math.max(viewCam.frustum.getNear(), 0.001f);
ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
//shadowCam.setDirection(direction);
diff --git a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java
index 888dc2fa81..edce2e273a 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java
@@ -76,6 +76,6 @@ public static float computeZFar(GeometryList occ, GeometryList recv, Camera cam)
BoundingBox bbOcc = ShadowUtil.computeUnionBound(occ, mat);
BoundingBox bbRecv = ShadowUtil.computeUnionBound(recv, mat);
- return min(max(bbOcc.getZExtent() - bbOcc.getCenter().z, bbRecv.getZExtent() - bbRecv.getCenter().z), cam.getFrustumFar());
+ return min(max(bbOcc.getZExtent() - bbOcc.getCenter().z, bbRecv.getZExtent() - bbRecv.getCenter().z), cam.frustum.getFar());
}
}
diff --git a/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java b/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java
index d97a354f96..71dc928624 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java
@@ -39,6 +39,7 @@
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
+import com.jme3.renderer.CameraFrustum;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.RenderQueue;
@@ -103,11 +104,11 @@ public static void updateFrustumPoints(Camera viewCam,
Vector3f dir = viewCam.getDirection();
Vector3f up = viewCam.getUp();
- float depthHeightRatio = viewCam.getFrustumTop() / viewCam.getFrustumNear();
+ float depthHeightRatio = viewCam.frustum.getTop() / viewCam.frustum.getNear();
float near = nearOverride;
float far = farOverride;
- float ftop = viewCam.getFrustumTop();
- float fright = viewCam.getFrustumRight();
+ float ftop = viewCam.frustum.getTop();
+ float fright = viewCam.frustum.getRight();
float ratio = fright / ftop;
float near_height;
@@ -288,9 +289,9 @@ public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) {
shadowCam.setProjectionMatrix(null);
if (ortho) {
- shadowCam.setFrustum(-1, 1, -1, 1, 1, -1);
+ shadowCam.frustum.set(-1, 1, -1, 1, 1, -1);
} else {
- shadowCam.setFrustumPerspective(45, 1, 1, 150);
+ shadowCam.frustum.setPerspective(45, 1, 1, 150);
}
Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix();
@@ -465,7 +466,7 @@ public static void updateShadowCamera(ViewPort viewPort,
shadowCam.setProjectionMatrix(null);
if (ortho) {
- shadowCam.setFrustum(-1, 1, -1, 1, 1, -1);
+ shadowCam.frustum.set(-1, 1, -1, 1, 1, -1);
}
// create transform to rotate points to viewspace
@@ -608,7 +609,7 @@ public static void getGeometriesInCamFrustum(GeometryList inputGeometryList,
Geometry g = inputGeometryList.get(i);
int planeState = camera.getPlaneState();
camera.setPlaneState(0);
- if (camera.contains(g.getWorldBound()) != Camera.FrustumIntersect.Outside) {
+ if (camera.frustum.contains(g.getWorldBound()) != CameraFrustum.Intersect.Outside) {
outputGeometryList.add(g);
}
camera.setPlaneState(planeState);
@@ -667,14 +668,14 @@ static private boolean checkShadowMode(RenderQueue.ShadowMode shadowMode, Render
private static void addGeometriesInCamFrustumFromNode(Camera camera, Node scene, RenderQueue.ShadowMode mode, GeometryList outputGeometryList) {
if (scene.getCullHint() == Spatial.CullHint.Always) return;
camera.setPlaneState(0);
- if (camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside) {
+ if (camera.frustum.contains(scene.getWorldBound()) != CameraFrustum.Intersect.Outside) {
for (Spatial child: scene.getChildren()) {
if (child instanceof Node) addGeometriesInCamFrustumFromNode(camera, (Node)child, mode, outputGeometryList);
else if (child instanceof Geometry && child.getCullHint() != Spatial.CullHint.Always) {
camera.setPlaneState(0);
if (checkShadowMode(child.getShadowMode(), mode) &&
!((Geometry)child).isGrouped() &&
- camera.contains(child.getWorldBound()) != Camera.FrustumIntersect.Outside) {
+ camera.frustum.contains(child.getWorldBound()) != CameraFrustum.Intersect.Outside) {
outputGeometryList.add((Geometry)child);
}
}
@@ -703,7 +704,7 @@ public static void getGeometriesInLightRadius(GeometryList inputGeometryList,
Camera camera = cameras[j];
int planeState = camera.getPlaneState();
camera.setPlaneState(0);
- inFrustum = camera.contains(g.getWorldBound()) != Camera.FrustumIntersect.Outside;
+ inFrustum = camera.frustum.contains(g.getWorldBound()) != CameraFrustum.Intersect.Outside;
camera.setPlaneState(planeState);
}
if (inFrustum) {
@@ -743,7 +744,7 @@ private static void addGeometriesInCamFrustumAndViewPortFromNode(Camera vpCamera
Camera camera = cameras[j];
int planeState = camera.getPlaneState();
camera.setPlaneState(0);
- inFrustum = camera.contains(scene.getWorldBound()) != Camera.FrustumIntersect.Outside && scene.checkCulling(vpCamera);
+ inFrustum = camera.frustum.contains(scene.getWorldBound()) != CameraFrustum.Intersect.Outside && scene.checkCulling(vpCamera);
camera.setPlaneState(planeState);
}
if (inFrustum) {
diff --git a/jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java
index b291e722e0..2628aec7cc 100644
--- a/jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java
+++ b/jme3-core/src/main/java/com/jme3/shadow/SpotLightShadowRenderer.java
@@ -99,7 +99,7 @@ private void init(int shadowMapSize) {
protected void initFrustumCam() {
Camera viewCam = viewPort.getCamera();
frustumCam = viewCam.clone();
- frustumCam.setFrustum(viewCam.getFrustumNear(), zFarOverride, viewCam.getFrustumLeft(), viewCam.getFrustumRight(), viewCam.getFrustumTop(), viewCam.getFrustumBottom());
+ frustumCam.frustum.set(viewCam.frustum.getNear(), zFarOverride, viewCam.frustum.getLeft(), viewCam.frustum.getRight(), viewCam.frustum.getTop(), viewCam.frustum.getBottom());
}
/**
@@ -125,15 +125,15 @@ protected void updateShadowCams(Camera viewCam) {
float zFar = zFarOverride;
if (zFar == 0) {
- zFar = viewCam.getFrustumFar();
+ zFar = viewCam.frustum.getFar();
}
//We prevent computing the frustum points and splits with zeroed or negative near clip value
- float frustumNear = Math.max(viewCam.getFrustumNear(), 0.001f);
+ float frustumNear = Math.max(viewCam.frustum.getNear(), 0.001f);
ShadowUtil.updateFrustumPoints(viewCam, frustumNear, zFar, 1.0f, points);
//shadowCam.setDirection(direction);
- shadowCam.setFrustumPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange());
+ shadowCam.frustum.setPerspective(light.getSpotOuterAngle() * FastMath.RAD_TO_DEG * 2.0f, 1, 1f, light.getSpotRange());
shadowCam.getRotation().lookAt(light.getDirection(), shadowCam.getUp());
shadowCam.setLocation(light.getPosition());
diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java b/jme3-core/src/main/java/com/jme3/texture/plugins/DDSLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java
rename to jme3-core/src/main/java/com/jme3/texture/plugins/DDSLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/DXTFlipper.java b/jme3-core/src/main/java/com/jme3/texture/plugins/DXTFlipper.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/texture/plugins/DXTFlipper.java
rename to jme3-core/src/main/java/com/jme3/texture/plugins/DXTFlipper.java
diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/HDRLoader.java b/jme3-core/src/main/java/com/jme3/texture/plugins/HDRLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/texture/plugins/HDRLoader.java
rename to jme3-core/src/main/java/com/jme3/texture/plugins/HDRLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/ImageFlipper.java b/jme3-core/src/main/java/com/jme3/texture/plugins/ImageFlipper.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/texture/plugins/ImageFlipper.java
rename to jme3-core/src/main/java/com/jme3/texture/plugins/ImageFlipper.java
diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/PFMLoader.java b/jme3-core/src/main/java/com/jme3/texture/plugins/PFMLoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/texture/plugins/PFMLoader.java
rename to jme3-core/src/main/java/com/jme3/texture/plugins/PFMLoader.java
diff --git a/jme3-core/src/plugins/java/com/jme3/texture/plugins/TGALoader.java b/jme3-core/src/main/java/com/jme3/texture/plugins/TGALoader.java
similarity index 100%
rename from jme3-core/src/plugins/java/com/jme3/texture/plugins/TGALoader.java
rename to jme3-core/src/main/java/com/jme3/texture/plugins/TGALoader.java
diff --git a/jme3-core/src/tools/java/jme3tools/converters/RGB565.java b/jme3-core/src/main/java/com/jme3tools/converters/RGB565.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/converters/RGB565.java
rename to jme3-core/src/main/java/com/jme3tools/converters/RGB565.java
diff --git a/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java b/jme3-core/src/main/java/com/jme3tools/optimize/GeometryBatchFactory.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java
rename to jme3-core/src/main/java/com/jme3tools/optimize/GeometryBatchFactory.java
diff --git a/jme3-core/src/tools/java/jme3tools/optimize/LodGenerator.java b/jme3-core/src/main/java/com/jme3tools/optimize/LodGenerator.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/optimize/LodGenerator.java
rename to jme3-core/src/main/java/com/jme3tools/optimize/LodGenerator.java
diff --git a/jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java b/jme3-core/src/main/java/com/jme3tools/optimize/TextureAtlas.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/optimize/TextureAtlas.java
rename to jme3-core/src/main/java/com/jme3tools/optimize/TextureAtlas.java
diff --git a/jme3-core/src/tools/java/jme3tools/savegame/SaveGame.java b/jme3-core/src/main/java/com/jme3tools/savegame/SaveGame.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/savegame/SaveGame.java
rename to jme3-core/src/main/java/com/jme3tools/savegame/SaveGame.java
diff --git a/jme3-core/src/tools/java/jme3tools/shader/ShaderDebug.java b/jme3-core/src/main/java/com/jme3tools/shader/ShaderDebug.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/shader/ShaderDebug.java
rename to jme3-core/src/main/java/com/jme3tools/shader/ShaderDebug.java
diff --git a/jme3-core/src/tools/java/jme3tools/shadercheck/CgcValidator.java b/jme3-core/src/main/java/com/jme3tools/shadercheck/CgcValidator.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/shadercheck/CgcValidator.java
rename to jme3-core/src/main/java/com/jme3tools/shadercheck/CgcValidator.java
diff --git a/jme3-core/src/tools/java/jme3tools/shadercheck/GpuAnalyzerValidator.java b/jme3-core/src/main/java/com/jme3tools/shadercheck/GpuAnalyzerValidator.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/shadercheck/GpuAnalyzerValidator.java
rename to jme3-core/src/main/java/com/jme3tools/shadercheck/GpuAnalyzerValidator.java
diff --git a/jme3-core/src/tools/java/jme3tools/shadercheck/ShaderCheck.java b/jme3-core/src/main/java/com/jme3tools/shadercheck/ShaderCheck.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/shadercheck/ShaderCheck.java
rename to jme3-core/src/main/java/com/jme3tools/shadercheck/ShaderCheck.java
diff --git a/jme3-core/src/tools/java/jme3tools/shadercheck/Validator.java b/jme3-core/src/main/java/com/jme3tools/shadercheck/Validator.java
similarity index 100%
rename from jme3-core/src/tools/java/jme3tools/shadercheck/Validator.java
rename to jme3-core/src/main/java/com/jme3tools/shadercheck/Validator.java
diff --git a/jme3-core/src/test/java/com/jme3/SetupTest.java b/jme3-core/src/test/java/com/jme3/SetupTest.java
deleted file mode 100644
index fdf35dbf34..0000000000
--- a/jme3-core/src/test/java/com/jme3/SetupTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2009-2015 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;
-
-import org.junit.Test;
-
-/**
- *
- * @author davidB
- */
-public class SetupTest {
-
- @Test(expected=AssertionError.class)
- public void testAssertionEnabled() {
- assert false;
- }
-}
diff --git a/jme3-core/src/test/java/com/jme3/collision/CollisionUtil.java b/jme3-core/src/test/java/com/jme3/collision/CollisionUtil.java
index 43d7b20f0e..30913e25b5 100644
--- a/jme3-core/src/test/java/com/jme3/collision/CollisionUtil.java
+++ b/jme3-core/src/test/java/com/jme3/collision/CollisionUtil.java
@@ -32,6 +32,7 @@
package com.jme3.collision;
import com.jme3.bounding.BoundingVolume;
+import static org.junit.Assert.assertTrue;
/**
* Utilities for testing collision.
@@ -45,23 +46,23 @@ private static void checkCollisionBase(Collidable a, Collidable b, int expected)
if (a instanceof BoundingVolume && b instanceof BoundingVolume) {
BoundingVolume bv1 = (BoundingVolume) a;
BoundingVolume bv2 = (BoundingVolume) b;
- assert bv1.intersects(bv2) == (expected != 0);
+ assertTrue("intersection matches expectation", bv1.intersects(bv2) == (expected != 0));
}
// Test standard collideWith method
CollisionResults results = new CollisionResults();
int numCollisions = a.collideWith(b, results);
- assert results.size() == numCollisions;
- assert numCollisions == expected;
+ assertTrue("result contains all collisions", results.size() == numCollisions);
+ assertTrue("number of collisions as expected", numCollisions == expected);
// force the results to be sorted here..
results.getClosestCollision();
if (results.size() > 0) {
- assert results.getCollision(0) == results.getClosestCollision();
+ assertTrue("the first collison is the closest", results.getCollision(0) == results.getClosestCollision());
}
if (results.size() == 1) {
- assert results.getClosestCollision() == results.getFarthestCollision();
+ assertTrue("if there is a single collision, the closest matches the farthest", results.getClosestCollision() == results.getFarthestCollision());
}
}
diff --git a/jme3-core/src/test/java/com/jme3/light/LightFilterTest.java b/jme3-core/src/test/java/com/jme3/light/LightFilterTest.java
index 447682964b..e9475e1513 100644
--- a/jme3-core/src/test/java/com/jme3/light/LightFilterTest.java
+++ b/jme3-core/src/test/java/com/jme3/light/LightFilterTest.java
@@ -36,10 +36,12 @@
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
+import com.jme3.scene.SpatialTransformer;
import com.jme3.scene.shape.Box;
import com.jme3.util.TempVars;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertTrue;
/**
* Test light filtering for various light types.
@@ -52,30 +54,33 @@ public class LightFilterTest {
private Camera cam;
private Geometry geom;
private LightList list;
+ private SpatialTransformer spatialTransformer;
private void checkFilteredLights(int expected) {
geom.updateGeometricState();
filter.setCamera(cam); // setCamera resets the intersection cache
list.clear();
filter.filterLights(geom, list);
- assert list.size() == expected;
+ assertTrue("list has expected size", list.size() == expected);
}
@Before
public void setUp() {
filter = new DefaultLightFilter();
-
+
cam = new Camera(512, 512);
- cam.setFrustumPerspective(45, 1, 1, 1000);
+ cam.frustum.setPerspective(45, 1, 1, 1000);
cam.setLocation(Vector3f.ZERO);
cam.lookAtDirection(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
filter.setCamera(cam);
-
+
Box box = new Box(1, 1, 1);
geom = new Geometry("geom", box);
geom.setLocalTranslation(0, 0, 10);
geom.updateGeometricState();
list = new LightList(geom);
+
+ spatialTransformer = new SpatialTransformer();
}
@Test
@@ -118,7 +123,7 @@ public void testPointFiltering() {
checkFilteredLights(1);
// Move the geometry away
- geom.move(0, 0, FastMath.ZERO_TOLERANCE);
+ spatialTransformer.move(geom, 0, 0, FastMath.ZERO_TOLERANCE);
checkFilteredLights(0);
// Test if the algorithm converts the sphere
@@ -190,7 +195,7 @@ public void testSpotFiltering() {
// The spot is not touching the near plane of the camera yet,
// should still be culled.
sl.setSpotRange(1f - FastMath.ZERO_TOLERANCE);
- assert !sl.intersectsFrustum(cam, vars);
+ assertTrue("spotlight intersects frustum", !sl.intersectsFrustum(cam, vars));
// should be culled from the geometry's PoV
checkFilteredLights(0);
@@ -198,7 +203,7 @@ public void testSpotFiltering() {
sl.setSpotRange(1f);
// still culled from the geometry's PoV
checkFilteredLights(0);
- assert sl.intersectsFrustum(cam, vars);
+ assertTrue("spotlight intersects frustum after touching near plane", sl.intersectsFrustum(cam, vars));
} finally {
vars.release();
}
diff --git a/jme3-core/src/test/java/com/jme3/light/LightSortTest.java b/jme3-core/src/test/java/com/jme3/light/LightSortTest.java
index 593cc9d3ec..9ef57b9d5b 100644
--- a/jme3-core/src/test/java/com/jme3/light/LightSortTest.java
+++ b/jme3-core/src/test/java/com/jme3/light/LightSortTest.java
@@ -36,6 +36,7 @@
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import org.junit.Test;
+import static org.junit.Assert.assertTrue;
/**
* Test light sorting (in the scene graph) for various light types.
@@ -43,7 +44,21 @@
* @author Kirill Vainer
*/
public class LightSortTest {
-
+
+ private void checkDefaultLightListSorting(LightList list) {
+ assertTrue("first AmbientLight", list.get(0) instanceof AmbientLight); // Ambients always first
+ assertTrue("second DirectionalLight", list.get(1) instanceof DirectionalLight); // .. then directionals
+ assertTrue("third SpotLight", list.get(2) instanceof SpotLight); // Spot is 0 units away from geom
+ assertTrue("fourth PointLight", list.get(3) instanceof PointLight); // .. and point is 1 unit away.
+ }
+
+ private void checkMovedLightListSorting(LightList list) {
+ assertTrue("first AmbientLight after moving geometry", list.get(0) instanceof AmbientLight);
+ assertTrue("second DirectionalLight after moving geometry", list.get(1) instanceof DirectionalLight);
+ assertTrue("third SpotLight after moving geometry", list.get(2) instanceof PointLight);
+ assertTrue("fourth PointLight after moving geometry", list.get(3) instanceof SpotLight);
+ }
+
@Test
public void testSimpleSort() {
Geometry g = new Geometry("test", new Mesh());
@@ -55,11 +70,8 @@ public void testSimpleSort() {
list.add(new AmbientLight());
list.sort(true);
-
- assert list.get(0) instanceof AmbientLight; // Ambients always first
- assert list.get(1) instanceof DirectionalLight; // .. then directionals
- assert list.get(2) instanceof SpotLight; // Spot is 0 units away from geom
- assert list.get(3) instanceof PointLight; // .. and point is 1 unit away.
+
+ checkDefaultLightListSorting(list);
}
@Test
@@ -85,20 +97,14 @@ public void testSceneGraphSort() {
LightList list = g.getWorldLightList();
// check the sorting (when geom is at 0,0,0)
- assert list.get(0) instanceof AmbientLight;
- assert list.get(1) instanceof DirectionalLight;
- assert list.get(2) instanceof SpotLight;
- assert list.get(3) instanceof PointLight;
-
+ checkDefaultLightListSorting(list);
+
// move the geometry closer to the point light
g.setLocalTranslation(Vector3f.UNIT_X);
n.updateGeometricState();
-
- assert list.get(0) instanceof AmbientLight;
- assert list.get(1) instanceof DirectionalLight;
- assert list.get(2) instanceof PointLight;
- assert list.get(3) instanceof SpotLight;
-
+
+ checkMovedLightListSorting(list);
+
// now move the point light away from the geometry
// and the spot light closer
diff --git a/jme3-core/src/test/java/com/jme3/math/FastMathTest.java b/jme3-core/src/test/java/com/jme3/math/FastMathTest.java
index a74390d422..9b09341a97 100644
--- a/jme3-core/src/test/java/com/jme3/math/FastMathTest.java
+++ b/jme3-core/src/test/java/com/jme3/math/FastMathTest.java
@@ -32,6 +32,7 @@
package com.jme3.math;
import org.junit.Test;
+import static org.junit.Assert.assertTrue;
/**
* Verifies that algorithms in {@link FastMath} are working correctly.
@@ -47,13 +48,13 @@ private int nearestPowerOfTwoSlow(int number) {
@Test
public void testNearestPowerOfTwo() {
for (int i = -100; i < 1; i++) {
- assert FastMath.nearestPowerOfTwo(i) == 1;
+ assertTrue("is 1 for negative power", FastMath.nearestPowerOfTwo(i) == 1);
}
for (int i = 1; i < 10000; i++) {
int nextPowerOf2 = FastMath.nearestPowerOfTwo(i);
- assert i <= nextPowerOf2;
- assert FastMath.isPowerOfTwo(nextPowerOf2);
- assert nextPowerOf2 == nearestPowerOfTwoSlow(i);
+ assertTrue("is not smaller than the power", i <= nextPowerOf2);
+ assertTrue("is actually a power of two", FastMath.isPowerOfTwo(nextPowerOf2));
+ assertTrue("is correct", nextPowerOf2 == nearestPowerOfTwoSlow(i));
}
}
}
diff --git a/jme3-core/src/test/java/com/jme3/math/QuaternionTest.java b/jme3-core/src/test/java/com/jme3/math/QuaternionTest.java
new file mode 100644
index 0000000000..39d67f9887
--- /dev/null
+++ b/jme3-core/src/test/java/com/jme3/math/QuaternionTest.java
@@ -0,0 +1,119 @@
+package com.jme3.math;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class QuaternionTest {
+
+ private float delta = 0.001f; // Delta for float comparison
+
+ @Test
+ public void identity() {
+ Quaternion q = new Quaternion();
+
+ assertTrue("new quaternion equals identity", q.isIdentity());
+ assertTrue("new quaternion equals static identity", q.equals(Quaternion.IDENTITY));
+
+ q.set(1,2,3,4);
+
+ assertFalse("changed quaternion not equals identity", q.isIdentity());
+
+ q.loadIdentity();
+
+ assertTrue("loaded identity", q.isIdentity());
+ }
+
+ @Test
+ public void average() {
+ Quaternion rotateQuarterZ = new Quaternion();
+ Quaternion rotateHalfZ = new Quaternion();
+
+ float quarterRotation = (float) (2 * Math.PI / 4); // Rotation of 90 degrees in radians
+ float halfRotation = (float) (2 * Math.PI / 2); // Rotation of 180 degrees in radians
+
+ rotateQuarterZ.fromAngles(0, 0, 0);
+ rotateHalfZ.fromAngles(halfRotation, 0, 0);
+
+ Quaternion average = new Quaternion();
+
+ average.slerp(rotateHalfZ, rotateQuarterZ, 0.5f);
+
+ float[] averageAngles = average.toAngles(null);
+
+ assertEquals("angle x", averageAngles[0], -quarterRotation, delta);
+ assertEquals("angle y", averageAngles[1], 0, delta);
+ assertEquals("angle z", averageAngles[2], 0, delta);
+
+ float[] givenAngles = {
+ -quarterRotation, 0, 0
+ };
+
+ Quaternion expectationFromAngles = new Quaternion(givenAngles);
+
+ float[] expectedAngles = expectationFromAngles.toAngles(null);
+
+ assertEquals("expected angle x", averageAngles[0], expectedAngles[0], delta);
+ assertEquals("expected angle y", averageAngles[1], expectedAngles[1], delta);
+ assertEquals("expected angle z", averageAngles[2], expectedAngles[2], delta);
+ }
+
+ @Test
+ public void slerpConstructor() {
+ Quaternion rotateQuarterZ = new Quaternion();
+ Quaternion rotateHalfZ = new Quaternion();
+
+ rotateQuarterZ.fromAngles(0, 0, 0);
+ rotateHalfZ.fromAngles(1, 0, 0);
+
+ Quaternion slerped = new Quaternion();
+
+ slerped.slerp(rotateHalfZ, rotateQuarterZ, 0.5f);
+
+ Quaternion constructed = new Quaternion(rotateQuarterZ, rotateHalfZ, 0.5f);
+
+ assertTrue("slerp should have same functionality as slerp constructor", slerped.equals(constructed));
+ }
+
+ @Test
+ public void normalization() {
+ int x = 10;
+
+ Quaternion q = new Quaternion(x,x,x,x);
+
+ float norm = 4 * (x*x);
+
+ assertEquals("norm should be sum of square of elements", q.norm(), norm, delta);
+
+ q.normalizeLocal();
+
+ assertEquals("norm of normalized quaternion should be 1", q.norm(), 1, delta);
+ }
+
+ @Test
+ public void rotationMatrices() {
+ Vector3f yAxis = new Vector3f(0,1,0);
+
+ float angle = (float) (2 * Math.PI / 4); // Rotation of 90 degrees in radians
+
+ Quaternion q = new Quaternion();
+
+ q.fromAngleAxis(angle, yAxis);
+
+ Matrix3f rotationMatrix3d = new Matrix3f();
+ Matrix4f rotationMatrix4d = new Matrix4f();
+
+ q.toRotationMatrix(rotationMatrix3d);
+ q.toRotationMatrix(rotationMatrix4d);
+
+ Matrix3f expectedRotationMatrix3d = new Matrix3f();
+ Matrix4f expectedRotationMatrix4d = new Matrix4f();
+
+ expectedRotationMatrix3d.fromAngleAxis(angle, yAxis);
+ expectedRotationMatrix4d.fromAngleAxis(angle, yAxis);
+
+ assertTrue("90 degree y-axis rotation matrix 3d", rotationMatrix3d.equals(expectedRotationMatrix3d, delta));
+ }
+}
diff --git a/jme3-core/src/test/java/com/jme3/util/ListMapTest.java b/jme3-core/src/test/java/com/jme3/util/ListMapTest.java
index 5f4cf3eee7..180e701d0c 100644
--- a/jme3-core/src/test/java/com/jme3/util/ListMapTest.java
+++ b/jme3-core/src/test/java/com/jme3/util/ListMapTest.java
@@ -33,6 +33,7 @@
import java.util.Map.Entry;
import org.junit.Test;
+import static org.junit.Assert.assertTrue;
/**
* Check if the {@link ListMap} class is working correctly.
@@ -45,19 +46,20 @@ public class ListMapTest {
public void testListMap() {
ListMap