Hey,
kann mir jemand mal bei der Mathematik folgender Funktion nachhelfen?
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// Return a rotated version of this point.
// hotspot: The point around which to rotate.
// angle: The amount of degrees to rotate by, clockwise.
GL_point rotate( const GL_point &hotspot, float angle ) const
{
//Move the hotspot to 0,0
GL_point r(m_x - hotspot.m_x, m_y - hotspot.m_y);
// distance between point & hotspot
const float c = static_cast<float>(sqrt(r.m_x*r.m_x + r.m_y*r.m_y));
const float nw = static_cast<float>(atan2(r.m_y, r.m_x) + ((angle + 180) * M_PI / 180));
r.m_x = static_cast<float>((sin(1.5 * M_PI - nw) * c) /*+ 0.5*/) + hotspot.m_x;
r.m_y = -static_cast<float>((sin(nw) * c) /*+ 0.5*/) + hotspot.m_y;
return r;
}
|
r ist also der Punkt in das lokale Koordinatensystem des Hotspots transformiert, c müsste dann die Distanz zwischen Punkt und Hotspot sein, aber was in nw berechnet wird, erschließt sich mir schon nicht so ganz. Anscheinend ist das der Winkel zwischen Hotspot und Punkt + gewünschtem Rotationswinkel + 180° in Radiants. Aber wozu die 180°? Müsste ich die nicht einfach weglassen, wenn ich ne normale Rotation will oder 360° - Hotspot/Punkt-Winkel - gew. Rotationswinkel berechnen, wenn die Rotation im Uhrzeigersinn laufen soll? Entsprechend verstehe ich überhaupt nicht mehr, was im nächten Schritt dieser Sinus von 3/2 PI - nw sein soll...
Erstaunlicherweise scheint aber wirklich das Richtige herauszukommen O_o