-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
43 lines (35 loc) · 1.38 KB
/
Shape.java
File metadata and controls
43 lines (35 loc) · 1.38 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
import java.util.ArrayList;
public class Shape {
public ArrayList<Geometry> geometries;
public Vector3 position;
public Shape(ArrayList<Geometry> geometries){
this.geometries = geometries;
// get the average of the positions
Vector3 averagePosition = new Vector3(0,0,0);
for(int i = 0; i < geometries.size(); i++){
averagePosition = Vector3.addVectors(averagePosition, geometries.get(i).position);
}
averagePosition = Vector3.multiplyVector(averagePosition, 1.0 / geometries.size());
this.position = averagePosition;
for(int i = 0; i < geometries.size(); i++){
Geometry g = geometries.get(i);
for(int j = 0; j < g.vertices.size(); j++){
Vertex vertex = g.vertices.get(j);
Vector3 diff = Vector3.subtractVectors(Vector3.addVectors(vertex.position, g.position), averagePosition);
g.vertices.get(j).position = diff;
}
g.position = averagePosition;
}
}
public void moveTo(Vector3 position){
this.position = new Vector3(position);
for(int i = 0; i < geometries.size(); i++){
geometries.get(i).position = position;
}
}
public void Rotate(Vector3 angle){
for(int i = 0; i < geometries.size(); i++){
geometries.get(i).Rotate(angle);
}
}
}