Auf Thema antworten

Ich benötige in einem Spiel, das ich entwickle, für die Rotation von Polygonen zur Kollisionsabfrage recht viel eine Rotationsmethode.


[code=Java]    /**

     * Rotiert den Punkt r um angle Grad um den Punkt. r nimmt den neuen Wert an

     * @param r Pnkt der Gedregt wird

     * @param u Punkt um den Gedreht wird

     * @param angle Gradwert der Drehung

     */

    public static void rotatePoint(Point2D r, Point2D u, float angle) {

        double tmpx;

        double tmpy;

        double tmp = Math.toRadians(angle);

        double cosAng = Math.cos(tmp);

        double sinAng = Math.sin(tmp);

       

        //Ursprung auf u schieben

        tmp = tmpx = r.getX() - u.getX();

        tmpy = r.getY() - u.getY();

        //Um Ursprung drehen

        tmpx = tmpx*cosAng-tmpy*sinAng;  //http://de.wikipedia.org/wiki/Drehmatrix

        tmpy = tmpy*cosAng+tmp*sinAng;

        //Ursprung zurückschieben

        tmpx += u.getX();

        tmpy += u.getY();

       

        r.setLocation(tmpx, tmpy);

    }[/code]


Gibt es da offensichtlichkeiten durch die ich das ganze beschleunigen kann ??

Es läuft zwar auch so, aber nunja... es interessiert mich, ob das noch besser geht^^


Oder gibt es zur Rotation von Polygonen eventuell noch Tricks ? Ich mach das derzeit einfach Punkt für Punkt.



Oben