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

Commit e40a5c8

Browse files
committed
Added candle light and bottle to the scene
1 parent 4f21476 commit e40a5c8

6 files changed

Lines changed: 288 additions & 172 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package simple;
2+
3+
import jrtr.*;
4+
5+
import java.util.ArrayList;
6+
7+
import javax.vecmath.Vector4f;
8+
9+
public class Scene {
10+
private ArrayList<Shape> shapes;
11+
private RenderContext renderContext;
12+
13+
public Scene(RenderContext renderContext) {
14+
this.renderContext = renderContext;
15+
16+
shapes = new ArrayList<Shape>();
17+
//shapes.add(createBottle());
18+
19+
shapes.add(createCandle());
20+
}
21+
22+
private Shape createBottle() {
23+
24+
ArrayList<Vector4f> controlPoints = new ArrayList<Vector4f>();
25+
controlPoints.add(new Vector4f(0, 0, 0, 1));
26+
controlPoints.add(new Vector4f(2, -1, 0, 1));
27+
controlPoints.add(new Vector4f(3, 0, 0, 1));
28+
controlPoints.add(new Vector4f(2, 2, 0, 1));
29+
30+
controlPoints.add(new Vector4f(2, 2, 0, 1));
31+
controlPoints.add(new Vector4f(1.5f, 3, 0, 1));
32+
controlPoints.add(new Vector4f(2, 5, 0, 1));
33+
controlPoints.add(new Vector4f(2, 6, 0, 1));
34+
35+
controlPoints.add(new Vector4f(2, 6, 0, 1));
36+
controlPoints.add(new Vector4f(2, 7, 0, 1));
37+
controlPoints.add(new Vector4f(0.75f, 9, 0, 1));
38+
controlPoints.add(new Vector4f(0.75f, 13, 0, 1));
39+
40+
BezierRotation bottleRotation = new BezierRotation(100, controlPoints, 100, renderContext);
41+
42+
Shape shape = bottleRotation.getShape();
43+
44+
shape.setMaterial(makeMaterial("greenGlass"));
45+
46+
return shape;
47+
}
48+
49+
private Shape createCandle() {
50+
ArrayList<Vector4f> controlPoints = new ArrayList<Vector4f>();
51+
controlPoints.add(new Vector4f(0, 0, 0, 1));
52+
controlPoints.add(new Vector4f(2, -2, 0, 1));
53+
controlPoints.add(new Vector4f(4, 0, 0, 1));
54+
controlPoints.add(new Vector4f(2, 4, 0, 1));
55+
56+
BezierRotation bottleRotation = new BezierRotation(100, controlPoints, 100, renderContext);
57+
58+
Shape shape = bottleRotation.getShape();
59+
60+
shape.setMaterial(makeMaterial("AppleTexture"));
61+
62+
return shape;
63+
}
64+
65+
public ArrayList<Shape> getShapes() {
66+
return shapes;
67+
}
68+
69+
private Material makeMaterial(String textureName) {
70+
71+
Shader diffuseShader = renderContext.makeShader();
72+
try {
73+
diffuseShader.load("../jrtr/shaders/diffuse.vert", "../jrtr/shaders/diffuse.frag");
74+
} catch (Exception e) {
75+
System.out.print("Problem with shader:\n");
76+
System.out.print(e.getMessage());
77+
}
78+
79+
Material material = new Material();
80+
material.shader = diffuseShader;
81+
material.texture = renderContext.makeTexture();
82+
try {
83+
material.texture.load("../textures/" + textureName + ".jpg");
84+
} catch (Exception e) {
85+
System.out.print("Could not load texture.\n");
86+
System.out.print(e.getMessage());
87+
}
88+
89+
return material;
90+
}
91+
}

0 commit comments

Comments
 (0)