Added rotation capability and added a new calss Vector3f that holds 3 float values for ex rotation
This commit is contained in:
parent
c0c78e74dc
commit
dd696b2760
9 changed files with 208 additions and 17 deletions
5
log.txt
5
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
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ public class LWJGLGameWindow {
|
|||
// disable the OpenGL depth test since we're rendering 2D graphics
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
96
src/ei/engine/math/Vector3f.java
Normal file
96
src/ei/engine/math/Vector3f.java
Normal file
|
|
@ -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+"]";
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +100,38 @@ public abstract class Entity {
|
|||
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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -90,28 +90,40 @@ public class Sprite extends Entity {
|
|||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue