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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue