Fixed the rotation pivot and added scalability
This commit is contained in:
parent
f25b07910e
commit
01af69cbc8
5 changed files with 33 additions and 21 deletions
8
log.txt
8
log.txt
|
|
@ -1,4 +1,4 @@
|
||||||
2007-03-17 17:23:35:625 # Loading sound: data/sounds/test.wav
|
2007-03-18 18:37:49:515 # Loading sound: data/sounds/test.wav
|
||||||
2007-03-17 17:23:35:656 # Sound sources: quantity=0
|
2007-03-18 18:37:49:531 # Sound sources: quantity=0
|
||||||
2007-03-17 17:23:35:656 # Stoping sound: source=0
|
2007-03-18 18:37:49:531 # Stoping sound: source=0
|
||||||
2007-03-17 17:23:35:656 # Playing sound: source=0 buffer=264767544
|
2007-03-18 18:37:49:531 # Playing sound: source=0 buffer=264767544
|
||||||
|
|
|
||||||
|
|
@ -129,10 +129,12 @@ public class LWJGLGameWindow {
|
||||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||||
GL11.glLoadIdentity();
|
GL11.glLoadIdentity();
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
//let subsystem paint
|
//let subsystem paint
|
||||||
GameStateManager.getInstance().render();
|
GameStateManager.getInstance().render();
|
||||||
render();
|
render();
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
//update window contents
|
//update window contents
|
||||||
Display.update();
|
Display.update();
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ public abstract class Entity {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
location = new Vector2f();
|
location = new Vector2f();
|
||||||
rotation = new Vector3f();
|
rotation = new Vector3f();
|
||||||
size = new Vector2f();
|
size = new Vector2f(1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,20 +83,20 @@ public abstract class Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the size of the entity
|
* Get the scale of the entity
|
||||||
*
|
*
|
||||||
* @return The Location of the entity
|
* @return The Location of the entity
|
||||||
*/
|
*/
|
||||||
public Vector2f getSize() {
|
public Vector2f getScale() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the size of this entity in pixels
|
* set the scale of this entity in pixels
|
||||||
*
|
*
|
||||||
* @param s The size of the entity
|
* @param s The size of the entity
|
||||||
*/
|
*/
|
||||||
public void setSize(Vector2f s) {
|
public void setScale(Vector2f s) {
|
||||||
size = s;
|
size = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,15 +110,19 @@ public abstract class Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the location of the entity in opengl plus
|
* Sets the location of the entity in opengl
|
||||||
* the parameter values before rendering.
|
|
||||||
*
|
*
|
||||||
* @param x The value to add x
|
* @param x The value to add x
|
||||||
* @param y The value to add y
|
* @param y The value to add y
|
||||||
*/
|
*/
|
||||||
protected void setTranslationGL(float x, float y){
|
protected void setTranslationGL(float x, float y){
|
||||||
// translate to the right location and prepare to draw
|
// translate to the right location and prepare to draw
|
||||||
GL11.glTranslatef(location.getX()+x, location.getY()+y, 0);
|
GL11.glTranslatef(x,y, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setScaleGL(){
|
||||||
|
// translate to the right location and prepare to draw
|
||||||
|
GL11.glScalef(size.getX(), size.getY(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -92,13 +92,16 @@ public class Sprite extends Entity {
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
//Reset The Current Modelview Matrix
|
//Reset The Current Modelview Matrix
|
||||||
GL11.glLoadIdentity();
|
GL11.glLoadIdentity();
|
||||||
|
|
||||||
|
//Sets the scale of the sprite
|
||||||
|
super.setScaleGL();
|
||||||
|
//Sets the location
|
||||||
|
super.setTranslationGL();
|
||||||
|
//the rotation
|
||||||
|
super.setRotationGL();
|
||||||
|
//and sets back the rotation so that the rotation pivot is the center of the sprite
|
||||||
|
super.setTranslationGL(-texture.getImageWidth()/2,-texture.getImageHeight()/2);
|
||||||
|
|
||||||
//set rotation of the sprite
|
|
||||||
// And the rotation
|
|
||||||
setRotationGL();
|
|
||||||
//Set the location
|
|
||||||
setTranslationGL();
|
|
||||||
|
|
||||||
// bind to the appropriate texture for this sprite
|
// bind to the appropriate texture for this sprite
|
||||||
texture.bindGL();
|
texture.bindGL();
|
||||||
GL11.glColor3f(1,1,1);
|
GL11.glColor3f(1,1,1);
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,13 @@ public class InGameState extends GameState{
|
||||||
public InGameState(String name){
|
public InGameState(String name){
|
||||||
super(name);
|
super(name);
|
||||||
rootNode = new Node("InGameNode");
|
rootNode = new Node("InGameNode");
|
||||||
|
|
||||||
sprite1 = new Sprite("tank","data/units/tank.png");
|
sprite1 = new Sprite("tank","data/units/tank.png");
|
||||||
|
sprite1.setScale(new Vector2f(0.5f,0.5f));
|
||||||
rootNode.add(sprite1);
|
rootNode.add(sprite1);
|
||||||
|
|
||||||
sound1 = new Sound("sound","data/sounds/test.wav");
|
sound1 = new Sound("sound","data/sounds/test.wav");
|
||||||
sound1.play();
|
sound1.loop();
|
||||||
rootNode.add(sound1);
|
rootNode.add(sound1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +32,7 @@ public class InGameState extends GameState{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
sprite1.getLocation().add(0.1f);
|
sprite1.getLocation().add(0.5f);
|
||||||
sprite1.getRotation().add(0, 0, 0.5f);
|
sprite1.getRotation().add(0, 0, 0.5f);
|
||||||
sound1.getLocation().add(new Vector2f(1,0));
|
sound1.getLocation().add(new Vector2f(1,0));
|
||||||
rootNode.update();
|
rootNode.update();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue