Fixed the rotation pivot and added scalability

This commit is contained in:
Ziver Koc 2007-03-18 17:38:58 +00:00
parent f25b07910e
commit 01af69cbc8
5 changed files with 33 additions and 21 deletions

View file

@ -1,4 +1,4 @@
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
2007-03-18 18:37:49:515 # Loading sound: data/sounds/test.wav
2007-03-18 18:37:49:531 # Sound sources: quantity=0
2007-03-18 18:37:49:531 # Stoping sound: source=0
2007-03-18 18:37:49:531 # Playing sound: source=0 buffer=264767544

View file

@ -130,9 +130,11 @@ public class LWJGLGameWindow {
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glPushMatrix();
//let subsystem paint
GameStateManager.getInstance().render();
render();
GL11.glPopMatrix();
//update window contents
Display.update();

View file

@ -36,7 +36,7 @@ public abstract class Entity {
this.name = name;
location = new Vector2f();
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
*/
public Vector2f getSize() {
public Vector2f getScale() {
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
*/
public void setSize(Vector2f s) {
public void setScale(Vector2f s) {
size = s;
}
@ -110,15 +110,19 @@ public abstract class Entity {
}
/**
* Sets the location of the entity in opengl plus
* the parameter values before rendering.
* Sets the location of the entity in opengl
*
* @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);
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);
}
/**

View file

@ -93,11 +93,14 @@ public class Sprite extends Entity {
//Reset The Current Modelview Matrix
GL11.glLoadIdentity();
//set rotation of the sprite
// And the rotation
setRotationGL();
//Set the location
setTranslationGL();
//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);
// bind to the appropriate texture for this sprite
texture.bindGL();

View file

@ -15,10 +15,13 @@ public class InGameState extends GameState{
public InGameState(String name){
super(name);
rootNode = new Node("InGameNode");
sprite1 = new Sprite("tank","data/units/tank.png");
sprite1.setScale(new Vector2f(0.5f,0.5f));
rootNode.add(sprite1);
sound1 = new Sound("sound","data/sounds/test.wav");
sound1.play();
sound1.loop();
rootNode.add(sound1);
}
@ -29,7 +32,7 @@ public class InGameState extends GameState{
@Override
public void update() {
sprite1.getLocation().add(0.1f);
sprite1.getLocation().add(0.5f);
sprite1.getRotation().add(0, 0, 0.5f);
sound1.getLocation().add(new Vector2f(1,0));
rootNode.update();