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

Commit 7ec533f

Browse files
committed
small patch
- fixed several segments
1 parent 806507d commit 7ec533f

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class BezierRotation {
3131
*/
3232
public BezierRotation(int nPoints, ArrayList<Vector4f> controlPoints, int nRotations, RenderContext renderContext) {
3333
bCurve = new BezierCurve(nPoints, controlPoints);
34+
int nSegments = controlPoints.size()/4 %4;
3435

3536
// bCurves = new ArrayList<BezierCurve>();
3637

@@ -50,13 +51,14 @@ public BezierRotation(int nPoints, ArrayList<Vector4f> controlPoints, int nRotat
5051
if (!test) {
5152
concatinateCurves(nRotations);
5253
calculateColors(nPoints, nRotations);
53-
calculateIndices(nPoints, nRotations);
54-
createShape(nRotations * nPoints, renderContext);
54+
calculateIndices(nPoints, nRotations, nSegments);
55+
createShape(points.length/3, renderContext);
5556
}
5657
}
5758

5859
private void test(BezierCurve bCurve, int nPoints, RenderContext renderContext) {
5960
bCurve.getPoints().add(new Vector4f(0, 1, 0, 1));
61+
bCurve.getNormals().add(new Vector4f(-1,0,0,0));
6062

6163
points = toBArray(bCurve.getPoints());
6264
colors = new float[points.length];
@@ -66,7 +68,7 @@ private void test(BezierCurve bCurve, int nPoints, RenderContext renderContext)
6668
for (int i = 0; i < colors.length; i++)
6769
colors[i] = 1;
6870

69-
VertexData vData = renderContext.makeVertexData(nPoints + 1);
71+
VertexData vData = renderContext.makeVertexData(points.length/3);
7072

7173
vData.addElement(points, VertexData.Semantic.POSITION, 3);
7274
vData.addElement(colors, VertexData.Semantic.COLOR, 3);
@@ -118,27 +120,27 @@ private void concatinateCurves(int nRotations) {
118120
* set all colors to white
119121
*/
120122
private void calculateColors(int nPoints, int nRotations) {
121-
this.colors = new float[nPoints * nRotations * 3];
123+
this.colors = new float[points.length];
122124

123125
for (int i = 0; i < colors.length; i++) {
124126
colors[i] = 1;
125127
}
126128
}
127129

128130
// TODO: not yet finished
129-
private void calculateIndices(int nPoints, int nRotations) {
131+
private void calculateIndices(int nPoints, int nRotations, int nSegments) {
130132
ArrayList<Integer> indices = new ArrayList<Integer>();
131133

132134
for (int j = 0; j < nRotations; j++) {
133-
for (int i = 0; i < 6 * (nPoints - 1); i += 6) {
135+
for (int i = 0; i < 6 * (nPoints *nSegments - 1); i += 6) {
134136

135-
indices.add((i / 6 + (j * nPoints)));
136-
indices.add(((i / 6 + (j * nPoints)) + 1 + (nPoints)) % ((nPoints) * nRotations));
137-
indices.add(((i / 6 + (j * nPoints)) + (nPoints)) % ((nPoints) * nRotations));
137+
indices.add((i / 6 + (j * nPoints * nSegments)));
138+
indices.add(((i / 6 + (j * nPoints * nSegments)) + 1 + (nPoints * nSegments)) % ((nPoints * nSegments) * nRotations));
139+
indices.add(((i / 6 + (j * nPoints * nSegments)) + (nPoints * nSegments)) % ((nPoints * nSegments) * nRotations));
138140

139-
indices.add((i / 6 + (j * nPoints)));
140-
indices.add(((i / 6 + (j * nPoints)) + 1) % ((nPoints) * nRotations));
141-
indices.add(((i / 6 + (j * nPoints) + 1) + (nPoints)) % ((nPoints) * nRotations));
141+
indices.add((i / 6 + (j * nPoints * nSegments)));
142+
indices.add(((i / 6 + (j * nPoints * nSegments)) + 1) % ((nPoints * nSegments) * nRotations));
143+
indices.add(((i / 6 + (j * nPoints * nSegments) + 1) + (nPoints * nSegments)) % ((nPoints * nSegments) * nRotations));
142144
}
143145
}
144146
this.indices = toIArray(indices);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ public void init(RenderContext r)
102102
controlPoints.add(new Vector4f(0,0,0,1));
103103
controlPoints.add(new Vector4f(1,0,0,1));
104104
controlPoints.add(new Vector4f(1,2,0,1));
105-
controlPoints.add(new Vector4f(0,2,0,1));
105+
controlPoints.add(new Vector4f(0.5f,2,0,1));
106106

107-
BezierRotation bRotation = new BezierRotation(100, controlPoints, 100, renderContext);
107+
controlPoints.add(new Vector4f(0.5f,2,0,1));
108+
controlPoints.add(new Vector4f(1,2,0,1));
109+
controlPoints.add(new Vector4f(1,4,0,1));
110+
controlPoints.add(new Vector4f(0,4,0,1));
111+
112+
BezierRotation bRotation = new BezierRotation(30, controlPoints, 30, renderContext);
108113
shape = bRotation.getShape();
109114
sceneManager.addShape(shape);
110115

0 commit comments

Comments
 (0)