Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 806507d

Browse files
committed
minor update
- fixed normals - now just one curve is computed and its points and normals are rotated instead of computing several curves with rotated control points
1 parent c74eed7 commit 806507d

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

Serie 6/Computergrafik-Basecode-master/simple/src/main/java/simple/BezierCurve.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public ArrayList<Vector4f> getNormals() {
6060

6161
public class Segment {
6262
private Vector4f p0, p1, p2, p3;
63-
private ArrayList<Vector4f> points;
64-
private ArrayList<Vector4f> normals;
63+
private ArrayList<Vector4f> points, normals;
6564

6665
public Segment(Vector4f p0, Vector4f p1, Vector4f p2, Vector4f p3) {
6766
this.p0 = p0;
@@ -101,7 +100,7 @@ private void deCasteljau(float i, float nPoints) {
101100
x = linearLinterpolation(t, r0, r1);
102101

103102
normal = new Vector4f();
104-
normal.sub(r1, r0);
103+
normal.sub(r0, r1);
105104

106105
points.add(x);
107106
normals.add(new Vector4f(-normal.y, normal.x, normal.z, normal.w));

Serie 6/Computergrafik-Basecode-master/simple/src/main/java/simple/BezierRotation.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class BezierRotation {
1111

12-
private ArrayList<BezierCurve> bCurves;
12+
private BezierCurve bCurve;
1313
private float[] points;
1414
private float[] colors;
1515
private float[] normals;
@@ -30,21 +30,25 @@ public class BezierRotation {
3030
* the control points for the whole curve
3131
*/
3232
public BezierRotation(int nPoints, ArrayList<Vector4f> controlPoints, int nRotations, RenderContext renderContext) {
33-
bCurves = new ArrayList<BezierCurve>();
33+
bCurve = new BezierCurve(nPoints, controlPoints);
34+
35+
// bCurves = new ArrayList<BezierCurve>();
3436

3537
// TODO: set test variable
3638
boolean test = false;
3739

38-
for (int i = 0; i < nRotations; i++) {
39-
bCurves.add(new BezierCurve(nPoints, rotateArray(controlPoints, ((float) i) / ((float) nRotations))));
40-
}
40+
/*
41+
* for (int i = 0; i < nRotations; i++) { bCurves.add(new
42+
* BezierCurve(nPoints, rotateArray(controlPoints, ((float) i) /
43+
* ((float) nRotations)))); }
44+
*/
4145

4246
if (test) {
43-
test(bCurves.get(0), nPoints, renderContext);
47+
test(bCurve, nPoints, renderContext);
4448
}
4549

4650
if (!test) {
47-
concatinateCurves();
51+
concatinateCurves(nRotations);
4852
calculateColors(nPoints, nRotations);
4953
calculateIndices(nPoints, nRotations);
5054
createShape(nRotations * nPoints, renderContext);
@@ -92,14 +96,19 @@ public Shape getShape() {
9296
* collects all points and normals from the existing curves and stores them
9397
* in the points and normals member arrays.
9498
*/
95-
private void concatinateCurves() {
99+
private void concatinateCurves(int nRotations) {
96100
ArrayList<Vector4f> points = new ArrayList<Vector4f>();
97101
ArrayList<Vector4f> normals = new ArrayList<Vector4f>();
98102

99-
for (BezierCurve c : bCurves) {
103+
for (int i = 0; i < nRotations; i++) {
104+
points.addAll(rotateArray(bCurve.getPoints(), ((float) i) / ((float) nRotations)));
105+
normals.addAll(rotateArray(bCurve.getNormals(), ((float) i) / ((float) nRotations)));
106+
}
107+
108+
/*for (BezierCurve c : bCurves) {
100109
points.addAll(c.getPoints());
101110
normals.addAll(c.getNormals());
102-
}
111+
}*/
103112

104113
this.points = toBArray(points);
105114
this.normals = toBArray(normals);
@@ -111,7 +120,7 @@ private void concatinateCurves() {
111120
private void calculateColors(int nPoints, int nRotations) {
112121
this.colors = new float[nPoints * nRotations * 3];
113122

114-
for (int i = 0; i < colors.length; i++){
123+
for (int i = 0; i < colors.length; i++) {
115124
colors[i] = 1;
116125
}
117126
}
@@ -123,11 +132,11 @@ private void calculateIndices(int nPoints, int nRotations) {
123132
for (int j = 0; j < nRotations; j++) {
124133
for (int i = 0; i < 6 * (nPoints - 1); i += 6) {
125134

126-
indices.add((i / 6 + (j * nPoints)) );
135+
indices.add((i / 6 + (j * nPoints)));
127136
indices.add(((i / 6 + (j * nPoints)) + 1 + (nPoints)) % ((nPoints) * nRotations));
128137
indices.add(((i / 6 + (j * nPoints)) + (nPoints)) % ((nPoints) * nRotations));
129138

130-
indices.add((i / 6 + (j * nPoints)) );
139+
indices.add((i / 6 + (j * nPoints)));
131140
indices.add(((i / 6 + (j * nPoints)) + 1) % ((nPoints) * nRotations));
132141
indices.add(((i / 6 + (j * nPoints) + 1) + (nPoints)) % ((nPoints) * nRotations));
133142
}
@@ -146,11 +155,14 @@ private void createShape(int size, RenderContext renderContext) {
146155
shape = new Shape(vData);
147156
}
148157

149-
private ArrayList<Vector4f> rotateArray(ArrayList<Vector4f> controlPoints, float angle) {
158+
/**
159+
* @return a rotated array by 1/angle. the original array is not changed
160+
*/
161+
private ArrayList<Vector4f> rotateArray(ArrayList<Vector4f> vectors, float angle) {
150162

151163
ArrayList<Vector4f> results = new ArrayList<Vector4f>();
152164

153-
for (Vector4f v : controlPoints) {
165+
for (Vector4f v : vectors) {
154166
results.add(rotate(v, angle));
155167
}
156168

0 commit comments

Comments
 (0)