1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package erland.game.tileadventure;
20
21 public class Vector3D implements Cloneable {
22 private float x;
23 private float y;
24 private float z;
25
26 public Vector3D() {}
27
28 public Vector3D(float x, float y, float z) {
29 setVector(x,y,z);
30 }
31
32 public Vector3D(float x, float y, float z, float length) {
33 setVector(x,y,z);
34 setLength(length);
35 }
36 public void setVector(Vector3D p) {
37 this.x = p.x;
38 this.y = p.y;
39 this.z = p.z;
40 }
41 public void setVector(float x, float y, float z) {
42 this.x = x;
43 this.y = y;
44 this.z = z;
45 }
46
47 public float getX() {
48 return x;
49 }
50
51 public float getY() {
52 return y;
53 }
54
55 public float getZ() {
56 return z;
57 }
58 public void setLength(float length) {
59 double multiplier = length/getLength();
60 this.x *= multiplier;
61 this.y *= multiplier;
62 this.z *= multiplier;
63 }
64 public float getLength() {
65 return (float) Math.sqrt(x*x+y*y+z*z);
66 }
67
68 public Object clone() {
69 try {
70 return super.clone();
71 } catch (CloneNotSupportedException e) {
72 return null;
73 }
74 }
75 }