Help please to make atan2() return the correct angle.
in
Programming Questions
•
11 months ago
So I'm struggling to find the correct transform and equation to put in atan2(). I'll try to be as concise as possible and I hope someone can help!
In a system just to shift the transform matrix smoothly to change the view.. Hopefully the variable and array names are explanatory enough.
An if it's important at all, I start drawing the screen as such:
Can someone explain what numbers need to be where? D:
In a system just to shift the transform matrix smoothly to change the view.. Hopefully the variable and array names are explanatory enough.
- void mainGameLoop() {
- drawGameArena();
- //move camera
- if (cameraFree == false) {
- pushMatrix();
- translate(cameraX, cameraY);
- cameraDir = atan2(objectY[objectSelected] - cameraY, objectX[objectSelected] - cameraX);
- popMatrix();
- cameraVel = sqrt(dist(cameraX, cameraY, objectX[objectSelected], objectY[objectSelected])) / 2;
- cameraVelX = cos(cameraDir) * cameraVel;
- cameraVelY = sin(cameraDir) * cameraVel;
- cameraX += cameraVelX;
- cameraY += cameraVelY;
- }
- }
An if it's important at all, I start drawing the screen as such:
- void drawGameArena() {
- pushMatrix();
- translate(cameraX - (width/2), cameraY - (height/2));
- <draw stuff>
- }
Can someone explain what numbers need to be where? D:
1