HPetersItemRotateUtils.cpp
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// HPetersItemRotateUtils.cpp
// HalloweenSpaceInvaders-mobile
//
// Created by Katarzyna Kalinowska-Górska on 13/09/2019.
//
#include <stdio.h>
#include <math.h> /* atan2 */
#include "HPetersItemRotateUtils.h"
#ifndef M_PI
#define M_PI 3.14159
#endif // ! M_PI
/**
Gives the change of positions and the new rotation
of object in next iteration.
Saves result in pre-allocated array output.
dx, dy - change of coordinates in x and y
teta - new angle of rotated object
Assuming the beginning of coordinates system is
in the middle of the circle. Thus, it is important
to give valid (x0,y0). But (dx,dy) is not affected.
The start of the rotation should be at (x=0,y=-r).
*/
void RotateUtils::nextPosition(float* output, float r,float x0,float y0,float dphi){
float phi0 = atan2(y0,x0);
float phi1 = phi0 + dphi;
float teta = phi1 + M_PI/2;
float x1 = r * cos(phi1);
float y1 = r * sin(phi1);
float dx = x1 - x0;
float dy = y1 - y0;
output[0] = dx;
output[1] = dy;
output[2] = teta;
}