Added fade effect

This commit is contained in:
Ziver Koc 2007-04-08 15:57:10 +00:00
parent 793b3a99da
commit e3b9e3165a
16 changed files with 345 additions and 3 deletions

BIN
jinput-dx8.dll Normal file

Binary file not shown.

BIN
jinput-raw.dll Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
2007-04-08 17:55:07:843 # Loading texture: data/units/tank.png

Binary file not shown.

BIN
raw/media/font/org_font.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View file

@ -112,4 +112,9 @@ public class BitmapText extends Entity{
// TODO Auto-generated method stub
return null;
}
@Override
public Texture getTexture() {
return texture;
}
}

View file

@ -0,0 +1,99 @@
package ei.engine.effects;
import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;
import ei.engine.scene.Entity;
import ei.engine.texture.Texture;
/**
* Fades out/in Things
* @author Ziver
*
*/
public class Fade extends Entity{
// The entity to fade
private Entity entity;
//Temp variables
private float life;
private boolean fadeOut;
private float fade;
public Fade(String name) {
super(name);
life = 1.0f;
fadeOut = true;
fade = 0.01f;
}
/**
* Draws out the fade and the entity
*/
public void render(){
// store the current model matrix
GL11.glPushMatrix();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
entity.getTexture().getColor().setA(life);
entity.render();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// restore the model view matrix to prevent contamination
GL11.glPopMatrix();
}
/**
* Updates the fade and the entity
*/
public void update(){
if(fadeOut){
if(life > 0)life -= fade;
else life = 0;
}
else{
if(life < 1)life += fade;
else life = 1;
}
entity.update();
System.out.println(life);
}
public void setEntity(Entity e){
entity = e;
}
/**
* Set the time of the fade
*
* @param f The time of the fade
*/
public void setFade(float f){
fade = f;
}
/**
* Set if the object should fade out or in
*
* @param b True for fade out false for fade in
*/
public void fadeOut(boolean b){
fadeOut = b;
if(fadeOut)life = 1.0f;
else life = 0.0f;
}
/**
* Get the bounds of the entity
*/
public Rectangle getBound() {
return entity.getBound();
}
@Override
public Texture getTexture() {
return entity.getTexture();
}
}

View file

@ -272,6 +272,11 @@ public class Particles extends Entity{
(int)getLocation().getY(),
(int)size, (int)size);
}
@Override
public Texture getTexture() {
return texture;
}
}
class Particle { // Particles Structure

View file

@ -7,6 +7,7 @@ import ei.engine.math.Vector2f;
import ei.engine.math.Vector3f;
import ei.engine.scene.Entity;
import ei.engine.scene.Sprite;
import ei.engine.texture.Texture;
/**
* This class is a progress meter
@ -217,4 +218,9 @@ public class ProgressBar extends Entity{
return null;
}
}
@Override
public Texture getTexture() {
return bar.getTexture();
}
}

View file

@ -0,0 +1,132 @@
package ei.engine.math;
/**
* This class holds 3 float values
*
* @author Ziver
*/
public class Vector4f {
private float r;
private float g;
private float b;
private float a;
/**
* Creates a vector whit the value zero
*/
public Vector4f(){
this(0,0,0,0);
}
/**
* Creates a Vector by the given values
*
* @param r The r value
* @param g The g value
* @param b The b value
* @param a The a value
*/
public Vector4f(float r, float g, float b, float a){
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
/**
* Get the R value
*
* @return the r value in the vector
*/
public float getR(){
return r;
}
/**
* Get the G value
*
* @return the g value in the vector
*/
public float getG(){
return g;
}
/**
* Get the B value
*
* @return the b value in the vector
*/
public float getB(){
return b;
}
/**
* Get the A value
*
* @return the a value in the vector
*/
public float getA(){
return a;
}
/**
* Set the A value
*
* param the a value in the vector
*/
public void setA(float a){
this.a = a;
}
/**
* Add to the vector
*
* @param i The amount to add
*/
public void add(float i){
r += i;
g += i;
b += i;
}
/**
* Add to the vector
*
* @param i The amount to add
*/
public void add(Vector4f i){
r += i.getR();
g += i.getG();
b += i.getB();
a += i.getA();
}
/**
* Add to the vector
*
* @param r The value to add to the r value
* @param g The value to add to the g value
* @param b The value to add to the b value
* @param a The value to add to the a value
*/
public void add(float r, float g, float b, float a){
this.r += r;
this.g += g;
this.b += b;
this.a += a;
}
/**
* Returns a copy of this vector
*
* @return A copy of this vector
*/
public Vector4f getCopy(){
return new Vector4f(r,g,b,a);
}
public String toString(){
return "Vector4f["+r+","+g+","+b+","+a+"]";
}
}

View file

@ -9,6 +9,7 @@ import org.lwjgl.opengl.GL11;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector3f;
import ei.engine.texture.Texture;
/**
* This class is the root class of all the objects that
@ -157,4 +158,6 @@ public abstract class Entity {
public void update(){}
public abstract Rectangle getBound();
public abstract Texture getTexture();
}

View file

@ -2,6 +2,8 @@ package ei.engine.scene;
import java.util.ArrayList;
import org.lwjgl.opengl.GL11;
public class Node extends Sprite {
/** the sprites of this node */
protected ArrayList<Entity> entities;
@ -63,9 +65,23 @@ public class Node extends Sprite {
* Draw all the Entities in the node
*/
public void render() {
// store the current model matrix
GL11.glPushMatrix();
//Sets the location
super.setTranslationGL();
//the rotation
//super.setRotationGL(texture.getImageWidth()/2,texture.getImageHeight()/2);
//Sets the scale of the sprite
super.setScaleGL();
for(int i=0; i<entities.size() ;i++){
entities.get(i).getTexture().setColor(getTexture().getColor());
entities.get(i).render();
}
// restore the model view matrix to prevent contamination
GL11.glPopMatrix();
}
/**

View file

@ -27,7 +27,7 @@ public class Sprite extends Entity {
*/
public Sprite(String name) {
super(name);
texture = null;
texture = new Texture();
}
/**
@ -101,7 +101,7 @@ public class Sprite extends Entity {
// bind to the appropriate texture for this sprite
texture.bindGL();
// draw a quad textured to match the sprite
GL11.glBegin(GL11.GL_QUADS);
{

View file

@ -4,6 +4,7 @@ import java.awt.Rectangle;
import ei.engine.math.Vector3f;
import ei.engine.scene.Entity;
import ei.engine.texture.Texture;
/**
* A sound that can be played through OpenAL
@ -103,4 +104,9 @@ public class Sound extends Entity{
10, 10);
}
@Override
public Texture getTexture() {
return null;
}
}

View file

@ -0,0 +1,44 @@
package ei.engine.test;
import ei.engine.LWJGLGameWindow;
import ei.engine.effects.Fade;
import ei.engine.math.Vector3f;
import ei.engine.scene.Node;
import ei.engine.scene.Sprite;
public class FadeTest extends LWJGLGameWindow{
private Fade fade;
public static void main(String[] args){
new FadeTest();
}
public FadeTest() {
super("FadeTest");
}
public void init(){
fade = new Fade("InGameNode");
Node rootNode = new Node("InGameNode");
Sprite sprite1 = new Sprite("tank","data/units/tank.png");
//sprite1.setScale(new Vector2f(0.5f,0.5f));
sprite1.setLocation(new Vector3f(200,200,0.2f));
rootNode.add(sprite1);
fade.setEntity(rootNode);
fade.fadeOut(true);
}
@Override
public void render() {
fade.render();
}
@Override
public void update() {
super.update();
fade.update();
}
}

View file

@ -2,6 +2,8 @@ package ei.engine.texture;
import org.lwjgl.opengl.GL11;
import ei.engine.math.Vector4f;
/**
* A texture to be bound within JOGL. This object is responsible for
* keeping track of a given OpenGL texture and for calculating the
@ -14,6 +16,7 @@ import org.lwjgl.opengl.GL11;
*
* @author Kevin Glass
* @author Brian Matzon
* @author Ziver Koc
*/
public class Texture {
/** The GL target type */
@ -32,6 +35,8 @@ public class Texture {
private float widthRatio;
/** The ratio of the height of the image to the texture */
private float heightRatio;
/** The color and alpha of this texture */
private Vector4f color;
/**
* Create a empty texture
@ -40,6 +45,7 @@ public class Texture {
public Texture(){
this.target = -1;
this.textureID = -1;
color = new Vector4f(1,1,1,1);
}
/**
@ -51,6 +57,25 @@ public class Texture {
public Texture(int target,int textureID) {
this.target = target;
this.textureID = textureID;
color = new Vector4f(1,1,1,1);
}
/**
* Set the color of this texture
*
* @param v The color of this texture
*/
public void setColor(Vector4f v){
color = v;
}
/**
* Get the color of this texture
*
* @return The color of this texture
*/
public Vector4f getColor(){
return color;
}
/**
@ -60,7 +85,7 @@ public class Texture {
*/
public void bindGL() {
GL11.glBindTexture(target, textureID);
GL11.glColor3f(1,1,1);
GL11.glColor4f(color.getR(),color.getG(),color.getB(),color.getA());
}
/**