99
1010public 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