I would like to rotate the coordinate system of an Arduino Joystick controller I purchased. The plane covers an area of 1024x1024 units and I would like redefine dynamically the orientation of the device.
This is what I've done so far:
void loop() {
int x = analogRead(X_pin);
int y = analogRead(Y_pin);
int center = 512;
float *transformed;
transformed = rotate(
float(x), float(y),
float(center), float(center)
PI/2.0
);
int tx = int(*transformed);
int ty = int(*(transformed+1));
Serial.print(tx);
Serial.print(",");
Serial.print(ty);
}
float *rotate(float x, float y, float cx, float cy, float angle) {
float out[] = {
cx + (x - cx) * cos(angle) - (y - cy) * sin(angle),
cy + (x - cx) * sin(angle) + (y - cy) * cos(angle)
};
return out;
}
Unfortunately all I'm getting is 0,0
.
Is there something wrong with the way I'm using pointers ?