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
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue