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

Commit e90b8ce

Browse files
committed
implemented robot
next step: animation
1 parent 49b8ed1 commit e90b8ce

8 files changed

Lines changed: 257 additions & 109 deletions

File tree

Serie 5/Computergrafik-Basecode-master/jrtr/src/main/java/jrtr/GraphLightNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
public class GraphLightNode extends GraphLeaf {
88

9-
Light light;
9+
private Light light;
1010

11-
public GraphLightNode(GraphNode parent, Light light) {
11+
public GraphLightNode(Light light) {
1212
this.light = light;
1313
}
1414

Serie 5/Computergrafik-Basecode-master/jrtr/src/main/java/jrtr/GraphSceneManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public GraphSceneManager() {
1818
Matrix4f identity = new Matrix4f();
1919
identity.setIdentity();
2020

21-
root = new GraphTransformGroup(null,identity);
21+
root = new GraphTransformGroup(identity);
2222

2323
}
2424

Serie 5/Computergrafik-Basecode-master/jrtr/src/main/java/jrtr/GraphShapeNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
public class GraphShapeNode extends GraphLeaf {
88

9-
Shape shape;
9+
private Shape shape;
1010

11-
public GraphShapeNode(GraphNode parent, Shape shape){
11+
public GraphShapeNode(Shape shape){
12+
1213
this.shape = shape;
1314
}
1415

Serie 5/Computergrafik-Basecode-master/jrtr/src/main/java/jrtr/GraphTransformGroup.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,39 @@
66

77
public class GraphTransformGroup extends GraphGroup {
88

9-
Matrix4f transformation;
10-
LinkedList<GraphTransformGroup> groups;
11-
LinkedList<GraphShapeNode> shapeNodes;
12-
LinkedList<GraphLightNode> lightNodes;
13-
14-
public GraphTransformGroup(GraphNode parent, Matrix4f transformation) {
15-
this.transformation = transformation;
9+
private Matrix4f transformation;
10+
private LinkedList<GraphTransformGroup> groups;
11+
private LinkedList<GraphShapeNode> shapeNodes;
12+
private LinkedList<GraphLightNode> lightNodes;
1613

14+
public GraphTransformGroup() {
15+
Matrix4f identity = new Matrix4f();
16+
identity.setIdentity();
17+
18+
this.transformation = identity;
19+
1720
groups = new LinkedList<GraphTransformGroup>();
1821
shapeNodes = new LinkedList<GraphShapeNode>();
1922
lightNodes = new LinkedList<GraphLightNode>();
2023
}
21-
22-
public GraphTransformGroup(GraphNode parent, GraphTransformGroup transformGroup, LinkedList<GraphTransformGroup> groups,
24+
25+
public GraphTransformGroup(Matrix4f transformation) {
26+
this();
27+
28+
this.transformation = transformation;
29+
}
30+
31+
public GraphTransformGroup(GraphTransformGroup transformGroup){
32+
this.transformation = transformGroup.getTransformation();
33+
this.groups = transformGroup.groups;
34+
this.shapeNodes = transformGroup.shapeNodes;
35+
this.lightNodes = transformGroup.lightNodes;
36+
}
37+
38+
public GraphTransformGroup(Matrix4f transformation, LinkedList<GraphTransformGroup> groups,
2339
LinkedList<GraphShapeNode> shapeNodes, LinkedList<GraphLightNode> lightNodes) {
2440

41+
this.transformation = transformation;
2542
this.groups = groups;
2643
this.shapeNodes = shapeNodes;
2744
this.lightNodes = lightNodes;
@@ -42,11 +59,11 @@ public void getShapeItems(LinkedList<RenderItem> items, Matrix4f transformation)
4259
}
4360

4461
public void add(Light light) {
45-
lightNodes.add(new GraphLightNode(this, light));
62+
lightNodes.add(new GraphLightNode(light));
4663
}
4764

4865
public void add(Shape shape) {
49-
shapeNodes.add(new GraphShapeNode(this, shape));
66+
shapeNodes.add(new GraphShapeNode(shape));
5067
}
5168

5269
public void add(GraphTransformGroup group) {
@@ -57,4 +74,8 @@ public void add(GraphTransformGroup group) {
5774
public Matrix4f getTransformation() {
5875
return transformation;
5976
}
77+
78+
public void setTransformation(Matrix4f transformation) {
79+
this.transformation = transformation;
80+
}
6081
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package simple;
2+
3+
import jrtr.RenderContext;
4+
import jrtr.Shape;
5+
import jrtr.VertexData;
6+
7+
public class Cube {
8+
9+
private static RenderContext renderContext;
10+
private Shape shape;
11+
private float scale;
12+
13+
public Cube(RenderContext renderContext){
14+
Cube.renderContext = renderContext;
15+
scale = 1;
16+
17+
shape = initCube();
18+
}
19+
20+
public Shape getShape(){
21+
shape.getTransformation().setScale(scale);
22+
return shape;
23+
}
24+
25+
public void setScale(float scale){
26+
this.scale = scale;
27+
}
28+
29+
private Shape initCube() {
30+
// Make a simple geometric object: a cube
31+
32+
// The vertex positions of the cube
33+
float v[] = {-1,-1,1, 1,-1,1, 1,1,1, -1,1,1, // front face
34+
-1,-1,-1, -1,-1,1, -1,1,1, -1,1,-1, // left face
35+
1,-1,-1,-1,-1,-1, -1,1,-1, 1,1,-1, // back face
36+
1,-1,1, 1,-1,-1, 1,1,-1, 1,1,1, // right face
37+
1,1,1, 1,1,-1, -1,1,-1, -1,1,1, // top face
38+
-1,-1,1, -1,-1,-1, 1,-1,-1, 1,-1,1}; // bottom face
39+
40+
// The vertex normals
41+
float n[] = {0,0,1, 0,0,1, 0,0,1, 0,0,1, // front face
42+
-1,0,0, -1,0,0, -1,0,0, -1,0,0, // left face
43+
0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, // back face
44+
1,0,0, 1,0,0, 1,0,0, 1,0,0, // right face
45+
0,1,0, 0,1,0, 0,1,0, 0,1,0, // top face
46+
0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0}; // bottom face
47+
48+
// The vertex colors
49+
float c[] = {1,0,0, 1,0,0, 1,0,0, 1,0,0,
50+
0,1,0, 0,1,0, 0,1,0, 0,1,0,
51+
1,0,0, 1,0,0, 1,0,0, 1,0,0,
52+
0,1,0, 0,1,0, 0,1,0, 0,1,0,
53+
0,0,1, 0,0,1, 0,0,1, 0,0,1,
54+
0,0,1, 0,0,1, 0,0,1, 0,0,1};
55+
56+
// Texture coordinates
57+
float uv[] = {0,0, 1,0, 1,1, 0,1,
58+
0,0, 1,0, 1,1, 0,1,
59+
0,0, 1,0, 1,1, 0,1,
60+
0,0, 1,0, 1,1, 0,1,
61+
0,0, 1,0, 1,1, 0,1,
62+
0,0, 1,0, 1,1, 0,1};
63+
64+
// Construct a data structure that stores the vertices, their
65+
// attributes, and the triangle mesh connectivity
66+
VertexData vertexData = renderContext.makeVertexData(24);
67+
vertexData.addElement(c, VertexData.Semantic.COLOR, 3);
68+
vertexData.addElement(v, VertexData.Semantic.POSITION, 3);
69+
vertexData.addElement(n, VertexData.Semantic.NORMAL, 3);
70+
vertexData.addElement(uv, VertexData.Semantic.TEXCOORD, 2);
71+
72+
// The triangles (three vertex indices for each triangle)
73+
int indices[] = {0,2,3, 0,1,2, // front face
74+
4,6,7, 4,5,6, // left face
75+
8,10,11, 8,9,10, // back face
76+
12,14,15, 12,13,14, // right face
77+
16,18,19, 16,17,18, // top face
78+
20,22,23, 20,21,22}; // bottom face
79+
80+
vertexData.addIndices(indices);
81+
82+
// Make a scene manager and add the object
83+
return new Shape(vertexData);
84+
}
85+
}
86+

Serie 5/Computergrafik-Basecode-master/simple/src/main/java/simple/Cylinder.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44

55
public class Cylinder {
66

7-
static RenderContext renderContext;
8-
Shape shape;
7+
private static RenderContext renderContext;
8+
private Shape shape;
99

1010

11-
public Cylinder(RenderContext renderContext, int resolution){
11+
public Cylinder(RenderContext renderContext, int resolution, float radius, float height){
1212
Cylinder.renderContext = renderContext;
1313

14-
shape = initCylinder(resolution);
14+
shape = initCylinder(resolution, radius, height);
1515
}
1616

1717
public Shape getShape(){
1818
return shape;
1919
}
2020

21-
private static Shape initCylinder(int resolution) {
21+
private static Shape initCylinder(int resolution, float radius, float height) {
2222
int res = resolution;
23-
int Radius = 1;
24-
int Height = 2;
2523

2624
float[] positions;
2725
float[] colors;
@@ -33,26 +31,26 @@ private static Shape initCylinder(int resolution) {
3331

3432
for (int i = 0; i < 3 * res; i += 3) {
3533
// Upper Circle
36-
positions[i] = (float) (Math.cos(i / 3 * 2 * Math.PI / res) * Radius); // x
37-
positions[i + 1] = Height / 2; // y
38-
positions[i + 2] = (float) (Math.sin(i / 3 * 2 * Math.PI / res) * Radius); // z
34+
positions[i] = (float) (Math.cos(i / 3 * 2 * Math.PI / res) * radius); // x
35+
positions[i + 1] = height / 2; // y
36+
positions[i + 2] = (float) (Math.sin(i / 3 * 2 * Math.PI / res) * radius); // z
3937
}
4038

4139
for (int i = 0; i < 3 * res; i += 3) {
4240
// Lower Circle
43-
positions[i + (3 * res)] = (float) Math.cos(i / 3 * 2 * Math.PI / res) * Radius;
44-
positions[i + 1 + (3 * res)] = -Height / 2;
45-
positions[i + 2 + (3 * res)] = (float) Math.sin(i / 3 * 2 * Math.PI / res) * Radius;
41+
positions[i + (3 * res)] = (float) Math.cos(i / 3 * 2 * Math.PI / res) * radius;
42+
positions[i + 1 + (3 * res)] = -height / 2;
43+
positions[i + 2 + (3 * res)] = (float) Math.sin(i / 3 * 2 * Math.PI / res) * radius;
4644
}
4745

4846
// Upper Center
4947
positions[6 * res] = 0;
50-
positions[6 * res + 1] = Height / 2;
48+
positions[6 * res + 1] = height / 2;
5149
positions[6 * res + 2] = 0;
5250

5351
// Lower Center
5452
positions[6 * res + 3] = 0;
55-
positions[6 * res + 4] = -Height / 2;
53+
positions[6 * res + 4] = -height / 2;
5654
positions[6 * res + 5] = 0;
5755

5856
// Colors

0 commit comments

Comments
 (0)