Rotating too fast on android
in
Android Processing
•
1 year ago
Hello, I'm using processing to create an android game but I have a problem. When I try to rotate a rectangle to the mouse it rotates way too fast. I tryd this code out in gamemaker and it worked perfectly. It rotates way too fast in the .exe too.
Here is my code:
- // Build a container to hold the current rotation of the box
float boxRotation = 0; - void setup() {
// Set the size of the screen (this is not really necessary
// in Android mode, but we'll do it anyway)
size(480,800);
// Turn on smoothing to make everything pretty.
smooth();
// Set the fill and stroke color for the box and circle
fill(255);
stroke(255);
// Tell the rectangles to draw from the center point (the default is the TL corner)
rectMode(CENTER);
} - void draw() {
background(mouseY * (255.0/800), 100, 0);
boxRotation = direction_to_point(width/2,height/2,mouseX,mouseY); - // Draw the ball-and-stick
line(width/2, height/2, mouseX, mouseY);
ellipse(mouseX, mouseY, 40, 40); - // Draw the box
pushMatrix();
translate(width/2, height/2);
rotate(boxRotation);
rect(0,0, 150, 150);
popMatrix();
} - public float direction_to_point(float tempx1, float tempy1, float tempx2, float tempy2)
{
float xd = tempx2 - tempx1;
float yd = tempy2 - tempy1;
return 360-90*( 1 - signum(xd) - 2/PI*atan( yd / xd ) ); - //this is the problem^^
}
int signum(float f) {
if (f > 0)
return 1;
if (f < 0)
return -1;
return 0;}
Thanks in advance.
1