Subversion Repositories distributed

Compare Revisions

No changes between revisions

Regard whitespace Rev 25 → Rev 26

/ViaThinkSoft Distributed/src/test/fraktal3d/Room.java
File deleted
/ViaThinkSoft Distributed/src/test/fraktal3d/RoomBorderEnum.java
File deleted
/ViaThinkSoft Distributed/src/test/fraktal3d/BouncingBall.java
1,153 → 1,22
package test.fraktal3d;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.MaterialState;
import com.jme.util.Timer;
import com.jme.scene.Node;
 
public class BouncingBall extends SimpleGame {
 
// Modellvariablen
private Room room = new Room(50, 50, 50, 1);
private Vector3f mBallMove = new Vector3f();;
private Sphere ball;
 
// Kräfte
private Vector3f g_mPerSec = new Vector3f(0, -9.81f, 0);
private Vector3f bounceLoss_mPerSec = new Vector3f(0.99f, 0.9f, 0.99f);
 
// Anfangswert
private Vector3f v_mPerSec = new Vector3f(100, 0, 50);
 
@Override
protected void simpleInitGame() {
this.ball = createBall("Ball", 50, 50, 2);
 
// Scene einstellen
// Kamaraentfernung erhöhen
cam.setLocation(new Vector3f(0, 50, 150));
 
// Elemente an rootNode anhängen
rootNode.attachChild(this.room.getRoomNode());
rootNode.attachChild(this.ball);
}
new Raumplan(rootNode, 25, 0, 0, 0, LockDirectoryEnum.LOCK_NOTHING).los(rootNode, 25, 0, 0, 0, LockDirectoryEnum.LOCK_NOTHING);
 
private Sphere createBall(String str, int zSam, int radSam, float radius) {
Sphere ball = new Sphere(str, zSam, radSam, radius);
ball.setLocalTranslation(this.mBallMove);
 
MaterialState materialState = display.getRenderer()
.createMaterialState();
float opacityAmount = 0.3f;
materialState
.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
materialState
.setDiffuse(new ColorRGBA(0.1f, 0.5f, 0.8f, opacityAmount));
materialState
.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
materialState.setShininess(128.0f);
materialState
.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
 
materialState.setEmissive(new ColorRGBA(0.5f, 0.0f, 0.0f, 0.1f));
 
ball.setRenderState(materialState);
ball.updateRenderState();
 
this.mBallMove.y = room.getBorderPosition(RoomBorderEnum.UP).y
- ball.getRadius();
this.mBallMove.x = room.getBorderPosition(RoomBorderEnum.LEFT).x
+ ball.getRadius();
this.mBallMove.z = room.getBorderPosition(RoomBorderEnum.LEFT).z
+ ball.getRadius();
 
return ball;
// rootNode.attachChild(new Raumplan(new Node(), 25, 0, 0, 0, LockDirectoryEnum.LOCK_NOTHING).getRoomNode());
}
 
@Override
protected void simpleUpdate() {
// Frames werden an die Systemzeit angepasst und für das realistische
// Model variiert
float time = Timer.getTimer().getTimePerFrame() * 4;
 
calculateForces(this.mBallMove.x >= room
.getBorderPosition(RoomBorderEnum.LEFT).x
+ ball.getRadius()
&& this.mBallMove.x <= room
.getBorderPosition(RoomBorderEnum.RIGHT).x
- ball.getRadius(), this.mBallMove.y >= room
.getBorderPosition(RoomBorderEnum.DOWN).y
+ ball.getRadius()
&& this.mBallMove.y <= room
.getBorderPosition(RoomBorderEnum.UP).y
- ball.getRadius(), this.mBallMove.z >= room
.getBorderPosition(RoomBorderEnum.BACK).z
+ ball.getRadius()
&& this.mBallMove.z <= room
.getBorderPosition(RoomBorderEnum.FRONT).z
- ball.getRadius(), time);
 
this.mBallMove.addLocal(this.v_mPerSec.mult(time));
}
 
private void calculateForces(boolean xCollision, boolean yCollision,
boolean zCollision, float time) {
 
// Kollision mit den Wänden
if (!yCollision) {
this.bounceLoss_mPerSec.mult(0.9f);
 
this.v_mPerSec.x *= this.bounceLoss_mPerSec.x;
this.v_mPerSec.y *= -this.bounceLoss_mPerSec.y;
this.v_mPerSec.z *= this.bounceLoss_mPerSec.z;
 
if (this.mBallMove.y < room.getBorderPosition(RoomBorderEnum.DOWN).y
+ ball.getRadius()) {
this.mBallMove.y = room.getBorderPosition(RoomBorderEnum.DOWN).y
+ ball.getRadius();
 
} else {
this.mBallMove.y = room.getBorderPosition(RoomBorderEnum.UP).y
- ball.getRadius();
}
 
} else if (!xCollision) {
this.v_mPerSec.x *= -this.bounceLoss_mPerSec.y;
this.v_mPerSec.y *= this.bounceLoss_mPerSec.x;
this.v_mPerSec.z *= this.bounceLoss_mPerSec.z;
 
if (this.mBallMove.x < room.getBorderPosition(RoomBorderEnum.LEFT).x
+ ball.getRadius()) {
this.mBallMove.x = room.getBorderPosition(RoomBorderEnum.LEFT).x
+ ball.getRadius();
 
} else {
this.mBallMove.x = room.getBorderPosition(RoomBorderEnum.RIGHT).x
- ball.getRadius();
}
} else if (!zCollision) {
this.v_mPerSec.x *= this.bounceLoss_mPerSec.x;
this.v_mPerSec.y *= this.bounceLoss_mPerSec.z;
this.v_mPerSec.z *= -this.bounceLoss_mPerSec.y;
 
if (this.mBallMove.z < room.getBorderPosition(RoomBorderEnum.BACK).z
+ ball.getRadius()) {
this.mBallMove.z = room.getBorderPosition(RoomBorderEnum.BACK).z
+ ball.getRadius();
 
} else {
this.mBallMove.z = room.getBorderPosition(RoomBorderEnum.FRONT).z
- ball.getRadius();
}
}
 
// Kräfte setzen
this.v_mPerSec.addLocal(this.g_mPerSec.mult(time));
 
}
 
/**
* @param args
*/
/ViaThinkSoft Distributed/src/test/fraktal3d/Raumplan.java
0,0 → 1,76
package test.fraktal3d;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
 
public class Raumplan {
private Box centerbox;
private static final int Abbruch_Size = 5;
private static final float Size_Faktor = 0.5f;
private static final float Abstand_Initial = 0.5f;
private static final float Abstand_Faktor = 0.5f;
public Raumplan(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
this.centerbox = new Box("Center-Box", new Vector3f(x, y, z), new Vector3f(size, size, size));
}
public void los(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
if (size > Abbruch_Size) {
new Raumplan(getRoomNode(), size, x-Abstand_Initial, y-Abstand_Initial, z-Abstand_Initial, LockDirectoryEnum.LOCK_X_POS).los(this.getRoomNode(), size*Size_Faktor, x-Abstand_Initial, y-Abstand_Initial, z-Abstand_Initial, LockDirectoryEnum.LOCK_X_POS);
}
 
rootNode.attachChild(getRoomNode());
}
 
protected Node getRoomNode() {
Node roomNode = new Node();
float opacityAmount = 1.0f;
DisplaySystem display = DisplaySystem.getDisplaySystem();
MaterialState materialState = display.getRenderer()
.createMaterialState();
// the sphere material taht will be modified to make the sphere
// look opaque then transparent then opaque and so on
materialState = display.getRenderer().createMaterialState();
materialState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
materialState.setDiffuse(new ColorRGBA(0.1f, 0.5f, 0.8f, opacityAmount));
materialState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
materialState.setShininess(128.0f);
materialState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
materialState.setEnabled(true);
// IMPORTANT: this is used to handle the internal sphere faces when
// setting them to transparent, try commenting this line to see what
// happens
materialState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);
centerbox.setRenderState(materialState);
centerbox.updateRenderState();
roomNode.attachChild(centerbox);
// to handle transparency: a BlendState
// an other tutorial will be made to deal with the possibilities of this
// RenderState
final BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
alphaState.setBlendEnabled(true);
alphaState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
alphaState.setTestEnabled(true);
alphaState.setTestFunction(BlendState.TestFunction.GreaterThan);
alphaState.setEnabled(true);
centerbox.setRenderState(alphaState);
centerbox.updateRenderState();
return roomNode;
}
 
}
/ViaThinkSoft Distributed/src/test/fraktal3d/LockDirectoryEnum.java
0,0 → 1,10
package test.fraktal3d;
 
public enum LockDirectoryEnum {
LOCK_NOTHING,
LOCK_X_POS, LOCK_X_NEG,
LOCK_Y_POS, LOCK_Y_NEG,
LOCK_Z_POS, LOCK_Z_NEG;
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property