-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleMesh.java
More file actions
111 lines (87 loc) · 4.59 KB
/
SampleMesh.java
File metadata and controls
111 lines (87 loc) · 4.59 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
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
class SampleMesh {
public ArrayList<Triangle> triangles;
public Color color;
public SampleMesh(Point center, Color c, int dimension) {
color = c;
triangles = new ArrayList<>();
Point[][] points = new Point[dimension][dimension];
int[] elevation = new int[dimension * dimension];
for (int i = 0; i < dimension * dimension; i++) {
elevation[i] = center.GetY() + (int) (Math.random() * 10);
}
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < dimension; j++) {
points[i][j] = new Point(((i - 50) * 10) + center.GetExX(), elevation[i * j],
(((50 - j) * 10) + center.GetExZ()));
}
}
java.util.Random rand = new java.util.Random(0);
float r;
float g;
float b;
float colorScaleFactor = 0.7f;
int redLowerBound = Math.max((int)(color.getRed() * (1.0 - colorScaleFactor)), 1);
int redUpperBound = Math.min((int)(Math.max(color.getRed() * (1.0 + colorScaleFactor), 2)), 256);
int greenLowerBound = Math.max((int)(color.getGreen() * (1.0 - colorScaleFactor)), 1);
int greenUpperBound = Math.min((int)(Math.max(color.getGreen() * (1.0 + colorScaleFactor), 2)), 256);
int blueLowerBound = Math.max((int)(color.getBlue() * (1.0 - colorScaleFactor)), 1);
int blueUpperBound = Math.min((int)(Math.max(color.getBlue() * (1.0 + colorScaleFactor), 2)), 256);
for (int j = 0; j < dimension - 1; j++) {
for (int i = 0; i < dimension - 1; i++) {
r = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(redUpperBound - redLowerBound) + redLowerBound) / 255.0f);
g = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(greenUpperBound - greenLowerBound) + greenLowerBound) / 255.0f);
b = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(blueUpperBound - blueLowerBound) + blueLowerBound) / 255.0f);
triangles.add(new Triangle(points[i][j], points[i + 1][j + 1], points[i][j + 1], new Color(r, g, b)));
r = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(redUpperBound - redLowerBound) + redLowerBound) / 255.0f);
g = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(greenUpperBound - greenLowerBound) + greenLowerBound) / 255.0f);
b = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(blueUpperBound - blueLowerBound) + blueLowerBound) / 255.0f);
triangles.add(new Triangle(points[i][j], points[i + 1][j + 1], points[i][j + 1], new Color(r, g, b)));
r = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(redUpperBound - redLowerBound) + redLowerBound) / 255.0f);
g = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(greenUpperBound - greenLowerBound) + greenLowerBound) / 255.0f);
b = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(blueUpperBound - blueLowerBound) + blueLowerBound) / 255.0f);
triangles.add(new Triangle(points[i][j], points[i + 1][j], points[i + 1][j + 1], new Color(r, g, b)));
r = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(redUpperBound - redLowerBound) + redLowerBound) / 255.0f);
g = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(greenUpperBound - greenLowerBound) + greenLowerBound) / 255.0f);
b = ((color == Color.black) ? rand.nextFloat() : (rand.nextInt(blueUpperBound - blueLowerBound) + blueLowerBound) / 255.0f);
triangles.add(new Triangle(points[i][j], points[i + 1][j], points[i + 1][j + 1], new Color(r, g, b)));
}
}
}
public void RotateCounterClockwiseAboutYAxis(Point p, float degrees) {
for (Triangle t : triangles)
t.RotateCounterClockwiseAboutYAxis(p, degrees);
}
public void RotateClockwiseAboutYAxis(Point p, float degrees) {
for (Triangle t : triangles)
t.RotateClockwiseAboutYAxis(p, degrees);
}
public void RotateCounterClockwiseAboutXAxis(Point p, float degrees) {
for (Triangle t : triangles)
t.RotateCounterClockwiseAboutXAxis(p, degrees);
}
public void RotateClockwiseAboutXAxis(Point p, float degrees) {
for (Triangle t : triangles)
t.RotateClockwiseAboutXAxis(p, degrees);
}
public void RotateCounterClockwiseAboutZAxis(Point p, float degrees) {
for (Triangle t : triangles)
t.RotateCounterClockwiseAboutZAxis(p, degrees);
}
public void RotateClockwiseAboutZAxis(Point p, float degrees) {
for (Triangle t : triangles)
t.RotateClockwiseAboutZAxis(p, degrees);
}
public void Draw_Mesh(BufferedImage buf) {
for (int i = 0; i < triangles.size(); i++) {
triangles.get(i).Draw_Mesh(buf);
}
}
public void Render(BufferedImage buf) {
for (int i = 0; i < triangles.size(); i++) {
triangles.get(i).Render(buf);
}
}
}