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

Lennart Buit & Nick Schot - Proposed changes to JMonkeyEngine… #17

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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.jme3.math.Spline.SplineType;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.math.interpolations.impl.LinearVectorInterpolation;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.mesh.IndexBuffer;
import com.jme3.scene.plugins.blender.BlenderContext;
Expand Down Expand Up @@ -849,7 +850,10 @@ public Vector3f getValueAlongCurve(float alongRatio) {
float edgeLength = vertices[i].distance(vertices[i - 1]);
if (length + edgeLength > probeLength) {
float ratioAlongEdge = (probeLength - length) / edgeLength;
return FastMath.interpolateLinear(ratioAlongEdge, vertices[i - 1], vertices[i]);

Vector3f res = new Vector3f();
new LinearVectorInterpolation<Vector3f>(vertices[i - 1], vertices[i]).interpolate(ratioAlongEdge, res);
return res;
} else if (length + edgeLength == probeLength) {
return vertices[i];
}
Expand Down
16 changes: 13 additions & 3 deletions jme3-core/src/main/java/com/jme3/animation/AnimationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.jme3.math.Quaternion;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.math.interpolations.impl.LinearQuaternionInterpolation;
import com.jme3.math.interpolations.impl.LinearVectorInterpolation;

/**
* A convenience class to easily setup a spatial keyframed animation
Expand Down Expand Up @@ -429,14 +431,22 @@ private void interpolate(Object[] keyFrames, Type type) {
//interpolationg depending on the transform type
switch (type) {
case Translation:
translations[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]);
// TODO: not very flexible, one should consider allowing to set Interpolations
Vector3f res = new Vector3f();
new LinearVectorInterpolation((Vector3f) keyFrames[i], (Vector3f) keyFrames[key]).interpolate(val, res);
translations[j] = res;
break;
case Rotation:
// TODO: not very flexible, one should consider allowing to set Interpolations
Quaternion rot = new Quaternion();
rotations[j] = rot.slerp(((Rotation) keyFrames[i]).rotation, ((Rotation) keyFrames[key]).rotation, val);
new LinearQuaternionInterpolation(((Rotation) keyFrames[i]).rotation, ((Rotation) keyFrames[key]).rotation).interpolate(val, rot);
rotations[j] = rot;
break;
case Scale:
scales[j] = FastMath.interpolateLinear(val, (Vector3f) keyFrames[i], (Vector3f) keyFrames[key]);
// TODO: not very flexible, one should consider allowing to set Interpolations
Vector3f scale = new Vector3f();
new LinearVectorInterpolation((Vector3f) keyFrames[i], (Vector3f) keyFrames[key]).interpolate(val, scale);
scales[j] = scale;
break;
}
}
Expand Down
75 changes: 71 additions & 4 deletions jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import com.jme3.math.FastMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector3f;
import com.jme3.math.interpolations.api.Interpolation;
import com.jme3.math.interpolations.impl.LinearFloatInterpolation;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
Expand Down Expand Up @@ -101,8 +103,21 @@ public class ParticleEmitter extends Geometry {

private ColorRGBA startColor = new ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f);
private ColorRGBA endColor = new ColorRGBA(0.1f, 0.1f, 0.1f, 0.0f);

/**
* Please use an instance of {@link com.jme3.math.interpolations.api.Interpolation}
*/
@Deprecated
private float startSize = 0.2f;

/**
* Please use an instance of {@link com.jme3.math.interpolations.api.Interpolation}
*/
@Deprecated
private float endSize = 2f;

private Interpolation<Float> sizeInterpolation;

private boolean worldSpace = true;
//variable that helps with computations
private transient Vector3f temp = new Vector3f();
Expand Down Expand Up @@ -196,6 +211,8 @@ public ParticleEmitter clone(boolean cloneMaterial) {

public ParticleEmitter(String name, Type type, int numParticles) {
super(name);

this.updateSizeInterpolationForStartAndEnd();
setBatchHint(BatchHint.Never);
// ignore world transform, unless user sets inLocalSpace
this.setIgnoreTransform(true);
Expand Down Expand Up @@ -237,6 +254,7 @@ public ParticleEmitter(String name, Type type, int numParticles) {
*/
public ParticleEmitter() {
super();
this.updateSizeInterpolationForStartAndEnd();
setBatchHint(BatchHint.Never);
}

Expand Down Expand Up @@ -551,8 +569,12 @@ public void setEndColor(ColorRGBA endColor) {
*
* @return the end size of the particles spawned.
*
* @see ParticleEmitter#setEndSize(float)
* @see ParticleEmitter#setEndSize(float)
*
* @Deprecated Please use {ParticleEmitter#getInterpolation} to properly get the interpolation of this particle-
* systems particle size.
*/
@Deprecated
public float getEndSize() {
return endSize;
}
Expand All @@ -566,9 +588,15 @@ public float getEndSize() {
* to its end of life.
*
* @param endSize the end size of the particles spawned.
*
* @Deprecated Please use {ParticleEmitter#setInterpolation} to properly set the interpolation of this particle-
* systems particle size.
*/
@Deprecated
public void setEndSize(float endSize) {
this.endSize = endSize;

this.updateSizeInterpolationForStartAndEnd();
}

/**
Expand Down Expand Up @@ -753,8 +781,12 @@ public void setStartColor(ColorRGBA startColor) {
*
* @return the start color of the particles spawned.
*
* @see ParticleEmitter#setStartSize(float)
* @see ParticleEmitter#setStartSize(float)
*
* @Deprecated Please use {ParticleEmitter#getInterpolation} to properly get the interpolation of this particle-
* systems particle size.
*/
@Deprecated
public float getStartSize() {
return startSize;
}
Expand All @@ -767,9 +799,15 @@ public float getStartSize() {
* to its end of life.
*
* @param startSize the start size of the particles spawned.
*
* @Deprecated Please use {ParticleEmitter#setInterpolation} to properly set the interpolation of this particle-
* systems particle size.
*/
@Deprecated
public void setStartSize(float startSize) {
this.startSize = startSize;

this.updateSizeInterpolationForStartAndEnd();
}

/**
Expand Down Expand Up @@ -954,7 +992,7 @@ private void swap(int idx1, int idx2) {
particles[idx2] = p1;
}

private void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){
/* Test */ public void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){
// applying gravity
p.velocity.x -= gravity.x * tpf;
p.velocity.y -= gravity.y * tpf;
Expand All @@ -965,7 +1003,7 @@ private void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max){
// affecting color, size and angle
float b = (p.startlife - p.life) / p.startlife;
p.color.interpolateLocal(startColor, endColor, b);
p.size = FastMath.interpolateLinear(b, startSize, endSize);
p.size = this.getSizeInterpolation().interpolate(b);
p.angle += p.rotateSpeed * tpf;

// Computing bounding volume
Expand Down Expand Up @@ -1069,6 +1107,35 @@ public boolean isEnabled() {
return enabled;
}


/**
* Gives the {@link Interpolation} that is used to increase the size of this particle
* @param interpolation The new interpolation used for the particles of this system
*/
public void setSizeInterpolation(Interpolation<Float> interpolation) {
this.sizeInterpolation = interpolation;
}

/*
* Gets the {@link Interpolation} that is used to increase the size of this particle
*
* @return The used Interpolator
*/
public Interpolation<Float> getSizeInterpolation() {
return this.sizeInterpolation;
}

/*
* Used to compute a sizeInterpolation when the old {@link setStartSize} and {@link setEndSize} methods are used.
*
* @deprecated Should be removed together with {@link setStartSize} and family
*/
@Deprecated
private void updateSizeInterpolationForStartAndEnd() {
this.sizeInterpolation = new LinearFloatInterpolation(this.startSize, this.endSize);
}


/**
* Callback from Control.update(), do not use.
* @param tpf
Expand Down
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/font/BitmapText.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void render(RenderManager rm, ColorRGBA color) {
mat.setTexture("ColorMap", page.getTexture());
//ColorRGBA original = getColor(mat, "Color");
//mat.setColor("Color", color);
mat.render(page, rm);
page.render(rm);

//if( original == null ) {
// mat.clearParam("Color");
Expand Down
13 changes: 7 additions & 6 deletions jme3-core/src/main/java/com/jme3/input/ChaseCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.jme3.input.controls.*;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.math.interpolations.api.Interpolation;
import com.jme3.math.interpolations.impl.LinearFloatInterpolation;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
Expand Down Expand Up @@ -99,7 +101,6 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
protected Vector3f temp = new Vector3f(0, 0, 0);
protected boolean invertYaxis = false;
protected boolean invertXaxis = false;

/**
* @deprecated use {@link CameraInput#CHASECAM_DOWN}
*/
Expand Down Expand Up @@ -436,7 +437,7 @@ protected void updateCamera(float tpf) {
//computing lerp factor
trailingLerpFactor = Math.min(trailingLerpFactor + tpf * tpf * trailingSensitivity, 1);
//computing rotation by linear interpolation
rotation = FastMath.interpolateLinear(trailingLerpFactor, rotation, targetRotation);
rotation = new LinearFloatInterpolation(rotation, targetRotation).interpolate(trailingLerpFactor);

//if the rotation is near the target rotation we're good, that's over
if (targetRotation + 0.01f >= rotation && targetRotation - 0.01f <= rotation) {
Expand All @@ -449,7 +450,7 @@ protected void updateCamera(float tpf) {
if (chasing) {
distance = temp.set(targetLocation).subtractLocal(cam.getLocation()).length();
distanceLerpFactor = Math.min(distanceLerpFactor + (tpf * tpf * chasingSensitivity * 0.05f), 1);
distance = FastMath.interpolateLinear(distanceLerpFactor, distance, targetDistance);
distance = new LinearFloatInterpolation(distance, targetDistance).interpolate(distanceLerpFactor);
if (targetDistance + 0.01f >= distance && targetDistance - 0.01f <= distance) {
distanceLerpFactor = 0;
chasing = false;
Expand All @@ -459,7 +460,7 @@ protected void updateCamera(float tpf) {
//linear interpolation of the distance while zooming
if (zooming) {
distanceLerpFactor = Math.min(distanceLerpFactor + (tpf * tpf * zoomSensitivity), 1);
distance = FastMath.interpolateLinear(distanceLerpFactor, distance, targetDistance);
distance = new LinearFloatInterpolation(distance, targetDistance).interpolate(distanceLerpFactor);
if (targetDistance + 0.1f >= distance && targetDistance - 0.1f <= distance) {
zooming = false;
distanceLerpFactor = 0;
Expand All @@ -469,7 +470,7 @@ protected void updateCamera(float tpf) {
//linear interpolation of the rotation while rotating horizontally
if (rotating) {
rotationLerpFactor = Math.min(rotationLerpFactor + tpf * tpf * rotationSensitivity, 1);
rotation = FastMath.interpolateLinear(rotationLerpFactor, rotation, targetRotation);
rotation = new LinearFloatInterpolation(rotation, targetRotation).interpolate(rotationLerpFactor);
if (targetRotation + 0.01f >= rotation && targetRotation - 0.01f <= rotation) {
rotating = false;
rotationLerpFactor = 0;
Expand All @@ -479,7 +480,7 @@ protected void updateCamera(float tpf) {
//linear interpolation of the rotation while rotating vertically
if (vRotating) {
vRotationLerpFactor = Math.min(vRotationLerpFactor + tpf * tpf * rotationSensitivity, 1);
vRotation = FastMath.interpolateLinear(vRotationLerpFactor, vRotation, targetVRotation);
vRotation = new LinearFloatInterpolation(vRotation, targetVRotation).interpolate(vRotationLerpFactor);
if (targetVRotation + 0.01f >= vRotation && targetVRotation - 0.01f <= vRotation) {
vRotating = false;
vRotationLerpFactor = 0;
Expand Down
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/material/MatParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void setValue(Object value) {
this.value = value;
}

void apply(Renderer r, Technique technique) {
/* TODO */ public void apply(Renderer r, Technique technique) {
technique.updateUniformParam(getPrefixedName(), getVarType(), getValue());
}

Expand Down
Loading