This repository was archived by the owner on Sep 17, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathTransform.java
More file actions
153 lines (127 loc) · 3.16 KB
/
Copy pathTransform.java
File metadata and controls
153 lines (127 loc) · 3.16 KB
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
package Gprocessing.physics;
import org.joml.Vector2f;
/**
* Represents the position in X and Y coordinates, and the scale (width and height) of a gameObject
*/
public class Transform {
public Vector2f position;
public Vector2f scale;
/**
* Used in constructors to initialize the object.
* @param position
* @param scale
*/
private void init (Vector2f position, Vector2f scale) {
this.position = position;
this.scale = scale;
}
/**
* Creates a new empty transform.
*/
public Transform () {
init(new Vector2f(), new Vector2f());
}
/**
* If only the position is passed, the scale is not, scale is created as an empty Vector2f.
* @param position X and Y coordinates as a Vector2f
*/
public Transform (Vector2f position) {
init(position, new Vector2f());
}
/**
* @param position X and Y coordinates as a Vector2f
* @param scale scale (width and height) of the object as a Vector2f
*/
public Transform (Vector2f position, Vector2f scale) {
init(position, scale);
}
/**
* @param x X coordinate of the object
* @param y Y coordinate of the object
* @param w width of the object
* @param h height of the object
*/
public Transform (float x, float y, float w, float h) {
init(new Vector2f(x, y), new Vector2f(w, h));
}
/**
* @return Returns a new transform which is identical to this object, can be used to copy into a new Transform object.
*/
public Transform copy () {
return new Transform(new Vector2f(this.position), new Vector2f(this.scale));
}
/**
* Takes a reference to an external transform, and copies this Transform to it.
* @param to The Transform to be changed.
*/
public void copy (Transform to) {
to.position.set(this.position);
to.scale.set(this.scale);
}
/**
* Checks to see if to Transforms are equal.
* @param o Transform to be checked for equality against this instance of Transform.
* @return Returns true if instances are the same, otherwise returns false.
*/
@Override
public boolean equals (Object o) {
if (o == null) {
return false;
} if (!(o instanceof Transform)) {
return false;
}
Transform t = (Transform)o;
return t.position.equals(this.position) && t.scale.equals(this.scale);
}
/*
* I don't think that these need any explanation...
*/
public float getX () {
return this.position.x;
}
public void setX (float x) {
this.position.x = x;
}
public void addX (float x) {
this.position.x += x;
}
public float getY () {
return this.position.y;
}
public void setY (float y) {
this.position.y = y;
}
public void addY (float y) {
this.position.y += y;
}
public float getWidth () {
return this.scale.x;
}
public void setWidth (float w) {
this.scale.x = w;
}
public void addWidth (float w) {
this.scale.x += w;
}
public float getHeight () {
return this.scale.y;
}
public void setHeight (float h) {
this.scale.y = h;
}
public void addHeight (float h) {
this.scale.y += h;
}
public Vector2f getPosition() {
return position;
}
public void setPosition(Vector2f position) {
this.position = position;
}
public Vector2f getScale() {
return scale;
}
public void setScale(Vector2f scale) {
this.scale = scale;
}
}