As I said before, I understood your question.
I suggest you run this:
Quote:float Xposition, Yposition;
float rotation = 0;
float scaleFactor = 1;
float[] offsets = {
100, 100, 300, 100 };
boolean[] keys = new boolean[5];
void setup(){
size(400,200);
noStroke();
}
void draw(){
simulate();
render();
}
void simulate(){
if(keys[0]){
Yposition--;
}
if(keys[1]){
Yposition++;
}
if(keys[2]){
Xposition--;
}
if(keys[3]){
Xposition++;
}
if( keys[4] ){
rotation+=0.01;
}
}
void render(){
background(0);
// YOUR WAY in RED
fill(255,0,0);
pushMatrix();
translate(offsets[0],offsets[1]);
rotate(rotation);
scale(scaleFactor);
rect(Xposition-10,Yposition-10,20,20);
stroke(255,0,0);
line(Xposition,Yposition,Xposition,Yposition-20);
line(Xposition,Yposition-20,Xposition-5,Yposition-15);
line(Xposition,Yposition-20,Xposition+5,Yposition-15);
noStroke();
popMatrix();
// MY WAY in GREEN
fill(0,255,0);
pushMatrix();
translate(offsets[2],offsets[3]);
scale(scaleFactor);
translate(Xposition,Yposition);
rotate(rotation);
rect(-10,-10,20,20);
stroke(0,255,0);
line(0,0,0,-20);
line(0,-20,-5,-15);
line(0,-20,5,-15);
noStroke();
popMatrix();
}
void keyPressed(){
if(key==CODED){
if(keyCode==UP){
keys[0] = true;
}
if(keyCode==DOWN){
keys[1] = true;
}
if(keyCode==LEFT){
keys[2] = true;
}
if(keyCode==RIGHT){
keys[3] = true;
}
}
else {
if(key==' '){
keys[4] = true;
}
}
}
void keyReleased(){
if(key==CODED){
if(keyCode==UP){
keys[0] = false;
}
if(keyCode==DOWN){
keys[1] = false;
}
if(keyCode==LEFT){
keys[2] = false;
}
if(keyCode==RIGHT){
keys[3] = false;
}
}
else {
if(key==' '){
keys[4] = false;
}
if( key=='z'){
scaleFactor-=.1;
}
if( key=='x'){
scaleFactor+=.1;
}
}
}
Arrow keys move the objects about. Notice that they move about the same. Z and X scale the objects. Notice that they scale the same. The space bar rotates the objects. Notice that, after being rotated, they move VERY differently. This difference is due ONLY BECAUSE OF THE WAY THEY ARE BEING DRAWN - that is, they both use the same variables to determine their location/orientation, but they are using those variables in different ways. You should look at the render() function to see how those ways differ.
The short answer: Translate to your image's location with a translate() call BEFORE you rotate()!