01 /*
02 *
03 * Created: Jun 7 2006
04 *
05 * Copyright (C) 1999-2000 Fabien Sanglard
06 *
07 * This program is free software; you can redistribute it and/or
08 * modify it under the terms of the GNU General Public License
09 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 package rtype.entity;
23
24 import org.lwjgl.util.vector.Vector2f;
25
26 public class GLUTILS
27 {
28
29 public static Vector2f makeNormalForPoints(Vector2f p1, Vector2f p2)
30 {
31 float diffY = p2.y - p1.y;
32 float diffX = p2.x - p1.x;
33
34 return new Vector2f(-diffY/diffX,1);
35 }
36
37 public static void rotateAroundZ(Vector2f vector, float angleRadian)
38 {
39
40 double cosAngle = Math.cos(angleRadian);
41 double sinAngle = Math.sin(angleRadian);
42 float savecValue =vector.x;
43 vector.x = (float) (vector.x * cosAngle - vector.y * sinAngle);
44 vector.y = (float) (savecValue * sinAngle + vector.y * cosAngle) ;
45
46 }
47
48 public static float degresToRadians(float degres)
49 {
50 return (float)(degres * 2 * Math.PI / 360);
51 }
52
53 public static float radiansToDegres(float radians)
54 {
55 return (float)( 360 * radians / (2 * Math.PI));
56 }
57 }
|