added a test for the particle engine

This commit is contained in:
Ziver Koc 2007-03-25 20:48:23 +00:00
parent e3f5017007
commit d3a6c31dd1
4 changed files with 419 additions and 18 deletions

View file

@ -7,10 +7,6 @@ package ei.engine.effects;
* Visit Our Sites At www.tiptup.com and nehe.gamedev.net
*/
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

View file

@ -30,13 +30,14 @@ import ei.engine.texture.TextureLoader;
*
*/
public class Particles extends Entity{
public int maxParticles = 1000;
public boolean regenerate = true;
public boolean enabled = true;
public boolean rainbow = true; // Rainbow Mode?
public float slowdown = 1.0f; // Slow Down Particles
public float xspeed = 00; // Base X Speed (To Allow Keyboard Direction Of Tail)
public float yspeed = 000; // Base Y Speed (To Allow Keyboard Direction Of Tail)
public float xspeed = 0.0f; // Base X Speed (To Allow Keyboard Direction Of Tail)
public float yspeed = 0.0f; // Base Y Speed (To Allow Keyboard Direction Of Tail)
public float MaxSpeedX = 500; // The Max Random Speed On X Axis
public float MaxSpeedY = 500; // The Max Random Speed On Y Axis
@ -56,7 +57,6 @@ public class Particles extends Entity{
{0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f}
};
private final int MAX_PARTICLES = 1000;
private Particle particle[];
private int col; // Current Color Selection
private int delay; // Rainbow Effect Delay
@ -74,9 +74,9 @@ public class Particles extends Entity{
*
*/
public void reset(){
particle = new Particle[MAX_PARTICLES];
particle = new Particle[maxParticles];
for(int i=0;i<MAX_PARTICLES;i++) {
for(int i=0;i<maxParticles;i++) {
particle[i] = new Particle();
particle[i].life = -1.0f;
}
@ -94,13 +94,13 @@ public class Particles extends Entity{
}
private void init() {
for (int i=0;i<MAX_PARTICLES;i++){ // Initials All The Textures
for (int i=0;i<maxParticles;i++){ // Initials All The Textures
particle[i].active = true; // Make All The Particles Active
particle[i].life = life; // Give All The Particles Full Life
particle[i].fade = ((float)(Math.random() * 100.0)) / 1000.0f + 0.003f; // Random Fade Speed
particle[i].r = colors[i * (colors.length / MAX_PARTICLES)][0]; // Select Red Rainbow Color
particle[i].g = colors[i * (colors.length / MAX_PARTICLES)][1]; // Select Red Rainbow Color
particle[i].b = colors[i * (colors.length / MAX_PARTICLES)][2]; // Select Red Rainbow Color
particle[i].r = colors[i * (colors.length / maxParticles)][0]; // Select Red Rainbow Color
particle[i].g = colors[i * (colors.length / maxParticles)][1]; // Select Red Rainbow Color
particle[i].b = colors[i * (colors.length / maxParticles)][2]; // Select Red Rainbow Color
particle[i].xi = ((float)((Math.random() * MaxSpeedX)) - (MaxSpeedX/2)) * 10.0f; // Random Speed On X Axis
particle[i].yi = ((float)((Math.random() * MaxSpeedY)) - (MaxSpeedY/2)) * 10.0f; // Random Speed On Y Axis
particle[i].zi = ((float)((Math.random() * MaxSpeedZ)) - (MaxSpeedZ/2)) * 10.0f; // Random Speed On Z Axis
@ -116,10 +116,10 @@ public class Particles extends Entity{
MaxSpeedZ = 500;
pullForceX = 0.0f;
pullForceY = -0.8f;
pullForceY = 0.0f;
pullForceZ = 0.0f;
life = 6.0f;
life = 1.0f;
size = 20.0f;
//regenerate = false;
@ -135,7 +135,7 @@ public class Particles extends Entity{
texture.bindGL();
for(int i=0;i<MAX_PARTICLES;i++) { // Loop Through All The Particles
for(int i=0;i<maxParticles;i++) { // Loop Through All The Particles
if (particle[i].active) { // If The Particle Is Active
float x = particle[i].x; // Grab Our Particle X Position
float y = particle[i].y; // Grab Our Particle Y Position
@ -179,8 +179,8 @@ public class Particles extends Entity{
particle[i].y = getLocation().getY(); // Center On Y Axis
particle[i].z = getZ(); // Center On Z Axis
particle[i].xi = ((float)((Math.random() * MaxSpeedX)) - (MaxSpeedX/2)) * 10.0f; // X Axis Speed And Direction
particle[i].yi = ((float)((Math.random() * MaxSpeedY)) - (MaxSpeedY/2)) * 10.0f; // Y Axis Speed And Direction
particle[i].xi = xspeed + ((float)((Math.random() * MaxSpeedX)) - (MaxSpeedX/2)) * 10.0f; // X Axis Speed And Direction
particle[i].yi = yspeed + ((float)((Math.random() * MaxSpeedY)) - (MaxSpeedY/2)) * 10.0f; // Y Axis Speed And Direction
particle[i].zi = ((float)((Math.random() * MaxSpeedZ)) - (MaxSpeedZ/2)) * 10.0f; // Z Axis Speed And Direction
particle[i].r = colors[col][0]; // Select Red From Color Table

View file

@ -0,0 +1,57 @@
package ei.engine.test;
import ei.engine.LWJGLGameWindow;
import ei.engine.effects.Particles;
import ei.engine.math.Vector2f;
import ei.engine.scene.Node;
public class ParticlesTest extends LWJGLGameWindow{
private ParticlesTestFrame ptf;
private Particles p;
private Node rootNode;
public static void main(String[] args){
new ParticlesTest();
}
public ParticlesTest() {
super("ParticlesTest");
}
protected void init(){
rootNode = new Node("InGameNode");
ptf = new ParticlesTestFrame();
ptf.getJFrame().setVisible(true);
p = new Particles("particle");
p.setLocation(new Vector2f(200,200));
rootNode.add(p);
}
protected void update() {
super.update();
p.life = ptf.life.getValue();
p.MaxSpeedX = ptf.maxSpeedX.getValue();
p.MaxSpeedY = ptf.maxSpeedY.getValue();
p.MaxSpeedZ = ptf.maxSpeedZ.getValue();
p.pullForceX = ptf.pullForceX.getValue();
p.pullForceY = ptf.pullForceY.getValue();
p.pullForceZ = ptf.pullForceZ.getValue();
p.rainbow = ptf.rainbow.isSelected();
p.regenerate = ptf.regenerate.isSelected();
p.size = ptf.size.getValue();
p.slowdown = ptf.slowdown.getValue();
p.xspeed = ptf.xspeed.getValue();
p.yspeed = ptf.yspeed.getValue();
rootNode.update();
}
/**
* this method shid be overriden
*/
protected void render(){
rootNode.render();
}
}

View file

@ -0,0 +1,348 @@
package ei.engine.test;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JCheckBox;
import java.awt.FlowLayout;
import javax.swing.JSlider;
import javax.swing.JLabel;
public class ParticlesTestFrame{
private static final long serialVersionUID = 1L;
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="106,71"
private JPanel jContentPane = null;
public JCheckBox regenerate = null;
public JCheckBox rainbow = null;
public JSlider slowdown = null;
public JSlider yspeed = null;
public JSlider xspeed = null;
public JSlider maxSpeedX = null;
public JSlider maxSpeedY = null;
public JSlider maxSpeedZ = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
public JSlider pullForceX = null;
public JSlider pullForceY = null;
public JSlider pullForceZ = null;
private JLabel jLabel2 = null;
public JSlider life = null;
private JLabel jLabel3 = null;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
public JSlider size = null;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
public JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setSize(new Dimension(219, 627));
jFrame.setTitle("ParticleTest");
jFrame.setContentPane(getJContentPane());
}
return jFrame;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel5 = new JLabel();
jLabel5.setText("size");
jLabel4 = new JLabel();
jLabel4.setText("Speed");
jLabel3 = new JLabel();
jLabel3.setText("Slowdown");
jLabel2 = new JLabel();
jLabel2.setText("Life");
FlowLayout flowLayout = new FlowLayout();
flowLayout.setHgap(5);
jLabel1 = new JLabel();
jLabel1.setText("pullForce");
jLabel = new JLabel();
jLabel.setText("MaxSpeed");
jContentPane = new JPanel();
jContentPane.setLayout(flowLayout);
jContentPane.add(getRegenerate(), null);
jContentPane.add(getRainbow(), null);
jContentPane.add(jLabel3, null);
jContentPane.add(getSlowdown(), null);
jContentPane.add(jLabel4, null);
jContentPane.add(getXspeed(), null);
jContentPane.add(getYspeed(), null);
jContentPane.add(jLabel, null);
jContentPane.add(getMaxSpeedX(), null);
jContentPane.add(getMaxSpeedY(), null);
jContentPane.add(getMaxSpeedZ(), null);
jContentPane.add(jLabel1, null);
jContentPane.add(getPullForceX(), null);
jContentPane.add(getPullForceY(), null);
jContentPane.add(getPullForceZ(), null);
jContentPane.add(jLabel2, null);
jContentPane.add(getLife(), null);
jContentPane.add(jLabel5, null);
jContentPane.add(getSize(), null);
}
return jContentPane;
}
/**
* This method initializes regenerate
*
* @return javax.swing.JCheckBox
*/
private JCheckBox getRegenerate() {
if (regenerate == null) {
regenerate = new JCheckBox();
regenerate.setSelected(true);
regenerate.setText("Regenerate");
regenerate.setName("");
}
return regenerate;
}
/**
* This method initializes rainbow
*
* @return javax.swing.JCheckBox
*/
private JCheckBox getRainbow() {
if (rainbow == null) {
rainbow = new JCheckBox();
rainbow.setText("Rainbow");
rainbow.setName("jCheckBox1");
rainbow.setSelected(true);
}
return rainbow;
}
/**
* This method initializes slowdown
*
* @return javax.swing.JSlider
*/
private JSlider getSlowdown() {
if (slowdown == null) {
slowdown = new JSlider();
slowdown.setMaximum(10);
slowdown.setPaintTicks(true);
slowdown.setPaintLabels(true);
slowdown.setToolTipText("Slowdown");
slowdown.setName("Slowdown");
slowdown.setSnapToTicks(true);
slowdown.setMinorTickSpacing(1);
slowdown.setMajorTickSpacing(1);
slowdown.setValue(1);
}
return slowdown;
}
/**
* This method initializes yspeed
*
* @return javax.swing.JSlider
*/
private JSlider getYspeed() {
if (yspeed == null) {
yspeed = new JSlider();
yspeed.setName("yspeed");
yspeed.setMaximum(1000);
yspeed.setPaintLabels(true);
yspeed.setPaintTicks(false);
yspeed.setValue(1);
yspeed.setSnapToTicks(false);
yspeed.setMajorTickSpacing(200);
yspeed.setToolTipText("yspeed");
}
return yspeed;
}
/**
* This method initializes xspeed
*
* @return javax.swing.JSlider
*/
private JSlider getXspeed() {
if (xspeed == null) {
xspeed = new JSlider();
xspeed.setName("xspeed");
xspeed.setMaximum(1000);
xspeed.setPaintLabels(true);
xspeed.setPaintTicks(false);
xspeed.setValue(1);
xspeed.setSnapToTicks(false);
xspeed.setMajorTickSpacing(200);
xspeed.setToolTipText("xspeed");
}
return xspeed;
}
/**
* This method initializes maxSpeedX
*
* @return javax.swing.JSlider
*/
private JSlider getMaxSpeedX() {
if (maxSpeedX == null) {
maxSpeedX = new JSlider();
maxSpeedX.setName("MaxSpeedX");
maxSpeedX.setMaximum(1000);
maxSpeedX.setPaintLabels(true);
maxSpeedX.setPaintTicks(false);
maxSpeedX.setValue(400);
maxSpeedX.setSnapToTicks(false);
maxSpeedX.setMajorTickSpacing(200);
maxSpeedX.setToolTipText("MaxSpeedX");
}
return maxSpeedX;
}
/**
* This method initializes maxSpeedY
*
* @return javax.swing.JSlider
*/
private JSlider getMaxSpeedY() {
if (maxSpeedY == null) {
maxSpeedY = new JSlider();
maxSpeedY.setName("MaxSpeedY");
maxSpeedY.setMaximum(1000);
maxSpeedY.setPaintLabels(true);
maxSpeedY.setPaintTicks(false);
maxSpeedY.setValue(400);
maxSpeedY.setSnapToTicks(false);
maxSpeedY.setMajorTickSpacing(200);
maxSpeedY.setToolTipText("MaxSpeedY");
}
return maxSpeedY;
}
/**
* This method initializes maxSpeedZ
*
* @return javax.swing.JSlider
*/
private JSlider getMaxSpeedZ() {
if (maxSpeedZ == null) {
maxSpeedZ = new JSlider();
maxSpeedZ.setName("MaxSpeedZ");
maxSpeedZ.setMaximum(1000);
maxSpeedZ.setPaintLabels(true);
maxSpeedZ.setPaintTicks(false);
maxSpeedZ.setValue(1);
maxSpeedZ.setSnapToTicks(false);
maxSpeedZ.setMajorTickSpacing(200);
maxSpeedZ.setToolTipText("MaxSpeedZ");
}
return maxSpeedZ;
}
/**
* This method initializes pullForceX
*
* @return javax.swing.JSlider
*/
private JSlider getPullForceX() {
if (pullForceX == null) {
pullForceX = new JSlider();
pullForceX.setName("pullForceX");
pullForceX.setMaximum(50);
pullForceX.setPaintLabels(true);
pullForceX.setPaintTicks(false);
pullForceX.setValue(1);
pullForceX.setSnapToTicks(true);
pullForceX.setMajorTickSpacing(5);
pullForceX.setToolTipText("pullForceX");
}
return pullForceX;
}
/**
* This method initializes pullForceY
*
* @return javax.swing.JSlider
*/
private JSlider getPullForceY() {
if (pullForceY == null) {
pullForceY = new JSlider();
pullForceY.setName("pullForceY");
pullForceY.setMaximum(50);
pullForceY.setPaintLabels(true);
pullForceY.setPaintTicks(false);
pullForceY.setValue(1);
pullForceY.setSnapToTicks(true);
pullForceY.setMajorTickSpacing(5);
pullForceY.setToolTipText("pullForceY");
}
return pullForceY;
}
/**
* This method initializes pullForceZ
*
* @return javax.swing.JSlider
*/
private JSlider getPullForceZ() {
if (pullForceZ == null) {
pullForceZ = new JSlider();
pullForceZ.setName("pullForceZ");
pullForceZ.setMaximum(50);
pullForceZ.setPaintLabels(true);
pullForceZ.setPaintTicks(false);
pullForceZ.setValue(1);
pullForceZ.setSnapToTicks(true);
pullForceZ.setMajorTickSpacing(5);
pullForceZ.setToolTipText("pullForceZ");
}
return pullForceZ;
}
/**
* This method initializes life
*
* @return javax.swing.JSlider
*/
private JSlider getLife() {
if (life == null) {
life = new JSlider();
life.setName("life");
life.setMaximum(10);
life.setPaintLabels(true);
life.setPaintTicks(false);
life.setValue(1);
life.setSnapToTicks(true);
life.setMajorTickSpacing(1);
life.setToolTipText("life");
}
return life;
}
/**
* This method initializes size
*
* @return javax.swing.JSlider
*/
private JSlider getSize() {
if (size == null) {
size = new JSlider();
size.setName("size");
size.setMaximum(50);
size.setPaintLabels(true);
size.setPaintTicks(false);
size.setValue(5);
size.setSnapToTicks(true);
size.setMajorTickSpacing(5);
size.setToolTipText("size");
}
return size;
}
}