Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactorings by Jasper Denkers #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@
/sdk/nbi/stub/ext/components/products/jdk/dist/
/sdk/jme3-dark-laf/nbproject/private/
jme3-lwjgl3/build/

target/*
14 changes: 6 additions & 8 deletions jme3-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ sourceSets {
main {
java {
srcDir 'src/main/java'
srcDir 'src/plugins/java'
srcDir 'src/tools/java'
}
}
test {
Expand All @@ -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}"
}

Expand Down
15 changes: 15 additions & 0 deletions jme3-core/build.sbt
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/app/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
83 changes: 20 additions & 63 deletions jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);


Expand All @@ -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);
Expand Down
32 changes: 30 additions & 2 deletions jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>ParticleMesh</code> is the underlying visual implementation of a
* {@link ParticleEmitter particle emitter}.
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions jme3-core/src/main/java/com/jme3/input/FlyByCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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){
Expand Down
9 changes: 9 additions & 0 deletions jme3-core/src/main/java/com/jme3/math/Equality.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading