diff --git a/log.txt b/log.txt index f9d51af..3369f7b 100644 --- a/log.txt +++ b/log.txt @@ -1 +1,4 @@ -Loading: data/sounds/test.wav +2007-03-17 17:23:35:625 # Loading sound: data/sounds/test.wav +2007-03-17 17:23:35:656 # Sound sources: quantity=0 +2007-03-17 17:23:35:656 # Stoping sound: source=0 +2007-03-17 17:23:35:656 # Playing sound: source=0 buffer=264767544 diff --git a/src/ei/engine/LWJGLGameWindow.java b/src/ei/engine/LWJGLGameWindow.java index 1df931f..400d5d3 100644 --- a/src/ei/engine/LWJGLGameWindow.java +++ b/src/ei/engine/LWJGLGameWindow.java @@ -65,8 +65,12 @@ public class LWJGLGameWindow { GL11.glEnable(GL11.GL_TEXTURE_2D); // disable the OpenGL depth test since we're rendering 2D graphics - GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glMatrixMode(GL11.GL_PROJECTION); + //Enable Smooth Shading + //GL11.glShadeModel(GL11.GL_SMOOTH); + //Really Nice Perspective Calculations + //GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glLoadIdentity(); GL11.glOrtho(0, width, height, 0, -1, 1); diff --git a/src/ei/engine/math/Vector2f.java b/src/ei/engine/math/Vector2f.java index 0a8ea32..93bda1a 100644 --- a/src/ei/engine/math/Vector2f.java +++ b/src/ei/engine/math/Vector2f.java @@ -1,9 +1,28 @@ package ei.engine.math; +/** + * This class holds 2 float values + * + * @author Ziver + */ + public class Vector2f { private float x; private float y; + /** + * Creates a vector whit the value zero + */ + public Vector2f(){ + this(0,0); + } + + /** + * Creates a Vector by the given values + * + * @param x The x value + * @param y The y value + */ public Vector2f(float x, float y){ this.x = x; this.y = y; @@ -28,7 +47,7 @@ public class Vector2f { } /** - * Add to the vectro + * Add to the vector * @param i The amount to add */ public void add(float i){ @@ -37,7 +56,7 @@ public class Vector2f { } /** - * Add to the vectro + * Add to the vector * @param i The amount to add */ public void add(Vector2f i){ diff --git a/src/ei/engine/math/Vector2i.java b/src/ei/engine/math/Vector2i.java index 27ec1f5..104bc3c 100644 --- a/src/ei/engine/math/Vector2i.java +++ b/src/ei/engine/math/Vector2i.java @@ -1,9 +1,28 @@ package ei.engine.math; +/** + * This class holds 2 integer values + * + * @author Ziver + */ + public class Vector2i { private int x; private int y; + /** + * Creates a vector whit the value zero + */ + public Vector2i(){ + this(0,0); + } + + /** + * Creates a Vector by the given values + * + * @param x The x value + * @param y The y value + */ public Vector2i(int x, int y){ this.x = x; this.y = y; @@ -28,7 +47,7 @@ public class Vector2i { } /** - * Add to the vectro + * Add to the vector * @param i The amount to add */ public void add(int i){ diff --git a/src/ei/engine/math/Vector3f.java b/src/ei/engine/math/Vector3f.java new file mode 100644 index 0000000..32078b9 --- /dev/null +++ b/src/ei/engine/math/Vector3f.java @@ -0,0 +1,96 @@ +package ei.engine.math; + +/** + * This class holds 3 float values + * + * @author Ziver + */ + +public class Vector3f { + private float x; + private float y; + private float z; + + /** + * Creates a vector whit the value zero + */ + public Vector3f(){ + this(0,0,0); + } + + /** + * Creates a Vector by the given values + * + * @param x The x value + * @param y The y value + * @param z The z value + */ + public Vector3f(float x, float y, float z){ + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Get the X value + * + * @return the x value in the vector + */ + public float getX(){ + return x; + } + + /** + * Get the Y value + * + * @return the y value in the vector + */ + public float getY(){ + return y; + } + + /** + * Get the Z value + * + * @return the z value in the vector + */ + public float getZ(){ + return z; + } + + /** + * Add to the vector + * @param i The amount to add + */ + public void add(float i){ + x += i; + y += i; + z += i; + } + + /** + * Add to the vector + * @param i The amount to add + */ + public void add(Vector3f i){ + x += i.getX(); + y += i.getY(); + z += i.getZ(); + } + + /** + * Add to the vector + * @param x The value to add to the x value + * @param y The value to add to the y value + * @param z The value to add to the z value + */ + public void add(float x, float y, float z){ + this.x += x; + this.y += y; + this.z += z; + } + + public String toString(){ + return "Vector2f["+x+","+y+"]"; + } +} diff --git a/src/ei/engine/scene/Entity.java b/src/ei/engine/scene/Entity.java index 40a59a0..6167aa7 100644 --- a/src/ei/engine/scene/Entity.java +++ b/src/ei/engine/scene/Entity.java @@ -3,7 +3,10 @@ */ package ei.engine.scene; +import org.lwjgl.opengl.GL11; + import ei.engine.math.Vector2f; +import ei.engine.math.Vector3f; /** * This class is the root class of all the objects that @@ -19,7 +22,7 @@ public abstract class Entity { private Vector2f location; /** The rotation of this entity in pixels*/ - private Vector2f rotation; + private Vector3f rotation; /** The size of this entity in pixels*/ private Vector2f size; @@ -31,7 +34,9 @@ public abstract class Entity { */ public Entity(String name){ this.name = name; - location = new Vector2f(0,0); + location = new Vector2f(); + rotation = new Vector3f(); + size = new Vector2f(); } /** @@ -64,7 +69,7 @@ public abstract class Entity { * * @return The Location of the entity */ - public Vector2f getRotation() { + public Vector3f getRotation() { return rotation; } @@ -73,7 +78,7 @@ public abstract class Entity { * * @param r The rotation of the entity */ - public void setRotation(Vector2f r) { + public void setRotation(Vector3f r) { rotation = r; } @@ -94,6 +99,38 @@ public abstract class Entity { public void setSize(Vector2f s) { size = s; } + + /** + * Sets the location of the entity in opengl + * before rendering. + */ + protected void setTranslationGL(){ + // translate to the right location and prepare to draw + GL11.glTranslatef(location.getX(), location.getY(), 0); + } + + /** + * Sets the location of the entity in opengl plus + * the parameter values before rendering. + * + * @param x The value to add x + * @param y The value to add y + */ + protected void setTranslationGL(float x, float y){ + // translate to the right location and prepare to draw + GL11.glTranslatef(location.getX()+x, location.getY()+y, 0); + } + + /** + * Sets the rotation of the entity in opengl + * before rendering. + */ + protected void setRotationGL(){ + // rotating the entity + GL11.glRotatef(rotation.getX(), 1.0f, 0.0f, 0.0f); // Rotate On The X Axis + GL11.glRotatef(rotation.getY(), 0.0f, 1.0f, 0.0f); // Rotate On The Y Axis + GL11.glRotatef(rotation.getZ(), 0.0f, 0.0f, 1.0f); // Rotate On The Z Axis + } /** * the render method should be implemented for every entity diff --git a/src/ei/engine/scene/Sprite.java b/src/ei/engine/scene/Sprite.java index e11af8c..51bcee0 100644 --- a/src/ei/engine/scene/Sprite.java +++ b/src/ei/engine/scene/Sprite.java @@ -83,35 +83,47 @@ public class Sprite extends Entity { } return texture.getImageHeight(); } - + /** * Draw the sprite */ public void render() { // store the current model matrix GL11.glPushMatrix(); - + //Reset The Current Modelview Matrix + GL11.glLoadIdentity(); + + //set rotation of the sprite + // And the rotation + setRotationGL(); + //Set the location + setTranslationGL(); + // bind to the appropriate texture for this sprite - texture.bind(); - - // translate to the right location and prepare to draw - GL11.glTranslatef((int)getLocation().getX(), (int)getLocation().getY(), 0); + texture.bindGL(); GL11.glColor3f(1,1,1); // draw a quad textured to match the sprite GL11.glBegin(GL11.GL_QUADS); { + //Vertex at the upper left GL11.glTexCoord2f(0, 0); GL11.glVertex2f(0, 0); + //Vertex at the down left GL11.glTexCoord2f(0, texture.getHeight()); GL11.glVertex2f(0, texture.getImageHeight()); + //Vertex at the upper right GL11.glTexCoord2f(texture.getWidth(), texture.getHeight()); GL11.glVertex2f(texture.getImageWidth(),texture.getImageHeight()); + //Vertex at the down right GL11.glTexCoord2f(texture.getWidth(), 0); GL11.glVertex2f(texture.getImageWidth(),0); } GL11.glEnd(); - + + + //Reset The Current Modelview Matrix + GL11.glLoadIdentity(); // restore the model view matrix to prevent contamination GL11.glPopMatrix(); } diff --git a/src/ei/engine/texture/Texture.java b/src/ei/engine/texture/Texture.java index 8325278..f364ca7 100644 --- a/src/ei/engine/texture/Texture.java +++ b/src/ei/engine/texture/Texture.java @@ -49,7 +49,7 @@ public class Texture { * * @param gl The GL context to bind to */ - public void bind() { + public void bindGL() { GL11.glBindTexture(target, textureID); } diff --git a/src/ei/game/gamestate/InGameState.java b/src/ei/game/gamestate/InGameState.java index 6a34fbc..4e84513 100644 --- a/src/ei/game/gamestate/InGameState.java +++ b/src/ei/game/gamestate/InGameState.java @@ -30,6 +30,7 @@ public class InGameState extends GameState{ @Override public void update() { sprite1.getLocation().add(0.1f); + sprite1.getRotation().add(0, 0, 0.5f); sound1.getLocation().add(new Vector2f(1,0)); rootNode.update(); }