summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Point3Temp.java
blob: 361b57831f5fea5166f5dc083a77246b1920e63b (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package NET.worlds.scape;

public class Point3Temp {
   public float x;
   public float y;
   public float z;
   private static Recycler recycler = new Recycler();

   static {
      nativeInit();
   }

   public static native void nativeInit();

   public static Point3Temp make(float x, float y, float z) {
      Point3Temp p = (Point3Temp)recycler.alloc();
      if (p == null) {
         recycler.recycle(new Point3Temp(0));
         p = (Point3Temp)recycler.alloc();
      }

      p.x = x;
      p.y = y;
      p.z = z;
      return p;
   }

   public static Point3Temp make() {
      return make(0.0F, 0.0F, 0.0F);
   }

   public static Point3Temp make(Point3Temp p) {
      return make(p.x, p.y, p.z);
   }

   protected Point3Temp(int dummy) {
   }

   public Point3Temp copy(Point3Temp b) {
      this.set(b.x, b.y, b.z);
      return this;
   }

   public void set(float _x, float _y, float _z) {
      this.x = _x;
      this.y = _y;
      this.z = _z;
   }

   public float length() {
      return (float)Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
   }

   public float squaredLength() {
      return this.x * this.x + this.y * this.y + this.z * this.z;
   }

   public native Point3Temp times(Transform var1);

   public native Point3Temp vectorTimes(Transform var1);

   public Point3Temp normalize() {
      float len = this.length();
      if (len > 0.0F) {
         this.dividedBy(len);
      }

      return this;
   }

   public Point3Temp negate() {
      this.x = -this.x;
      this.y = -this.y;
      this.z = -this.z;
      return this;
   }

   public Point3Temp abs() {
      this.x = Math.abs(this.x);
      this.y = Math.abs(this.y);
      this.z = Math.abs(this.z);
      return this;
   }

   public static Point3Temp getDirVector(float amount, float angle) {
      angle = (float)(angle * (Math.PI / 180.0));
      return make(-amount * (float)Math.sin(angle), amount * (float)Math.cos(angle), 0.0F);
   }

   public Point3Temp plus(Point3Temp p) {
      this.x = this.x + p.x;
      this.y = this.y + p.y;
      this.z = this.z + p.z;
      return this;
   }

   public Point3Temp cross(Point3Temp p) {
      float xNew = this.y * p.z - this.z * p.y;
      float yNew = this.z * p.x - this.x * p.z;
      this.z = this.x * p.y - this.y * p.x;
      this.x = xNew;
      this.y = yNew;
      return this;
   }

   public Point3Temp plus(float v) {
      this.x += v;
      this.y += v;
      this.z += v;
      return this;
   }

   public Point3Temp minus(float v) {
      return this.plus(-v);
   }

   public Point3Temp minus(Point3Temp p) {
      this.x = this.x - p.x;
      this.y = this.y - p.y;
      this.z = this.z - p.z;
      return this;
   }

   public Point3Temp times(float v) {
      this.x *= v;
      this.y *= v;
      this.z *= v;
      return this;
   }

   public Point3Temp times(Point3Temp p) {
      this.x = this.x * p.x;
      this.y = this.y * p.y;
      this.z = this.z * p.z;
      return this;
   }

   public Point3Temp dividedBy(float v) {
      this.x /= v;
      this.y /= v;
      this.z /= v;
      return this;
   }

   public Point3Temp dividedBy(Point3Temp p) {
      this.x = this.x / p.x;
      this.y = this.y / p.y;
      this.z = this.z / p.z;
      return this;
   }

   public float dot(Point3Temp p) {
      return p.x * this.x + p.y * this.y + p.z * this.z;
   }

   public float det(Point3Temp a, Point3Temp b) {
      return this.x * a.y * b.z + a.x * b.y * this.z + b.x * this.y * a.z - this.z * a.y * b.x - a.z * b.y * this.x - b.z * this.y * a.x;
   }

   public boolean sameValue(Point3Temp p) {
      return p == null ? false : this.x == p.x && this.y == p.y && this.z == p.z;
   }

   @Override
   public String toString() {
      return this.x + "," + this.y + "," + this.z;
   }
}