Skip to content

Commit 07525b2

Browse files
committed
Finish loading sheeps, and add animation to the sheeps
1 parent de77653 commit 07525b2

File tree

6 files changed

+80
-76
lines changed

6 files changed

+80
-76
lines changed

‎project7/LICENSE‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎project7/README.md‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎project7/brokeback.js‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
11
// Brokeback mountain scene description file
22

3-
var my_trunk = new Trunk("Trunk1",[-2,0,2], 0.5, [68/255, 36/255, 29/255],
4-
1, 32, 1.5)
5-
// var my_tent = new Tent("Tent", [0,0,0], 1, [68/255, 36/255, 29/255], 3, 2)
6-
grobjects.push(my_trunk)
7-
// grobjects.push(my_tent)
3+
var my_trunk1 = new Trunk(name = "Trunk1",
4+
position = [-2.1,0,2.1],
5+
size = 1,
6+
color = [68/255, 36/255, 29/255],
7+
radius = 0.5,
8+
numCirlce = 32,
9+
height = 0.75)
810

11+
var my_trunk2 = new Trunk(name = "Trunk2",
12+
position = [-2.1,0,1.3],
13+
size = 1,
14+
color = [68/255, 36/255, 29/255],
15+
radius = 0.8,
16+
numCirlce = 32,
17+
height = 1.3)
18+
grobjects.push(my_trunk1)
19+
grobjects.push(my_trunk2)
20+
21+
var my_tent = new Tent(name = "Tent",
22+
position = [0,0,0],
23+
size = 1,
24+
color = [203/255, 181/255, 182/255],
25+
width = 3,
26+
height = 2)
27+
grobjects.push(my_tent)
28+
29+
30+
// Adding sheeps
31+
var sheep1 = new Sheep(name = "Sheep1",
32+
position = [3,0,-3],
33+
size = 1,
34+
color = [218/255, 211/255, 192/255])
35+
36+
var sheep2 = new Sheep(name = "Sheep2",
37+
position = [4,0,-2.5],
38+
size = 1,
39+
color = [218/255, 211/255, 192/255])
40+
41+
var sheep3 = new Sheep(name = "Sheep3",
42+
position = [3.5,0,-4],
43+
size = 1,
44+
color = [218/255, 211/255, 192/255])
45+
46+
grobjects.push(sheep1)
47+
grobjects.push(sheep2)
48+
grobjects.push(sheep3)

‎project7/index.html‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616

1717
<script src="ExampleObjects/ground.js"></script>
1818

19-
<!-- This is where we load the objects for the world -->
20-
<!-- <script src="ExampleObjects/simplest.js"></script> -->
21-
<!-- <script src="ExampleObjects/texturedplane.js"></script> -->
22-
<!-- <script src="ExampleObjects/cube.js"></script> -->
19+
<!-- Load models created by me -->
2320
<script src="my_objects/trunk.js"></script>
2421
<script src="my_objects/tent.js"></script>
2522

23+
<!-- Load obj models -->
24+
<script src="loaded_objects/sheepData.js"></script>
25+
<script src="loaded_objects/sheep.js"></script>
26+
2627
<!-- Scene description files -->
2728
<script src="brokeback.js"></script>
2829

29-
<!-- I am adding the helicopter -->
30-
<!-- <script src="Helicopter/helicopter.js"></script> -->
31-
3230
<!-- This gets loaded LAST (actually, it probably doesn't have to) -->
3331
<script src="graphicstown.js"></script>
3432
</body>

‎project7/my_objects/tent.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ function printNormal(num, numCir, normals){
165165
// Compute the length of each pole
166166
var poleVertexes = []
167167
for(var i = 0; i < this.vertexes.length; i++){
168-
console.log(this.vertexes[i])
169168
poleVertexes[i] = [this.vertexes[i][0] + this.poleOffset,
170169
this.vertexes[i][1],
171170
this.vertexes[i][2] + this.poleOffset]
@@ -259,7 +258,6 @@ function printNormal(num, numCir, normals){
259258
})()
260259

261260
// Tent(name, position, size, color, width, height)
262-
grobjects.push(new Tent("Tent", [0,0,0], 1, [203/255, 181/255, 182/255],
263-
3, 2))
261+
264262

265263

‎project7/my_objects/trunk.js‎

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ var grobjects = grobjects || []
77
var Trunk = undefined
88
var m4 = m4 || twgl.m4
99
var v3 = v3 || twgl.v3
10-
//var SpinningCube = undefined;
11-
1210

1311
// Helper functions
1412

@@ -110,16 +108,11 @@ function printNormal(num, numCir, normals){
110108
(function() {
111109
"use strict"
112110

113-
var shaderProgram = undefined
114-
var buffers = undefined
115-
var triangles = []
116-
var vertexPosRaw = []
117-
var vertexColorsRaw = []
118-
var vertexNormalRaw = []
119-
120111
// constructor for Trunk
121112
Trunk = function Trunk(name, position, size, color, radius, numCircle,
122113
height) {
114+
this.shaderProgram = undefined
115+
this.buffer = undefined
123116
this.name = name
124117
this.position = position || [0,0,0]
125118
this.size = size || 1.0
@@ -131,33 +124,35 @@ function printNormal(num, numCir, normals){
131124

132125
// One of the object necessary function
133126
Trunk.prototype.init = function(drawingState) {
127+
var triangles = []
128+
var vertexPosRaw = []
129+
var vertexColorsRaw = []
130+
var vertexNormalRaw = []
131+
this.buffer = null
132+
134133
// Get the gl content
135134
var gl=drawingState.gl
136135

137136
// Share the shader with all trunks
138-
if (!shaderProgram) {
139-
shaderProgram = twgl.createProgramInfo(gl, ["trunk-vs", "trunk-fs"]);
137+
this.shaderProgram = twgl.createProgramInfo(gl, ["trunk-vs", "trunk-fs"]);
138+
139+
// Add triangles
140+
addCylinder(this.position, this.radius, this.numCircle,
141+
this.color, this.height, triangles)
142+
143+
// Convert triangles to webgl array info
144+
var results = triangleToVertex(triangles)
145+
vertexPosRaw.push(...results[0])
146+
vertexColorsRaw.push(...results[1])
147+
vertexNormalRaw.push(...results[2])
148+
149+
var arrays = {
150+
vpos : {numComponents:3, data: new Float32Array(vertexPosRaw)},
151+
vnormal : {numComponents:3, data: new Float32Array(vertexNormalRaw)},
152+
vcolor : {numComponents:3, data: new Float32Array(vertexColorsRaw)}
140153
}
141-
if (!buffers) {
142-
143-
// Add triangles
144-
addCylinder(this.position, this.radius, this.numCircle,
145-
this.color, this.height, triangles)
146154

147-
// Convert triangles to webgl array info
148-
var results = triangleToVertex(triangles)
149-
vertexPosRaw.push(...results[0])
150-
vertexColorsRaw.push(...results[1])
151-
vertexNormalRaw.push(...results[2])
152-
153-
var arrays = {
154-
vpos : { numComponents: 3, data: new Float32Array(vertexPosRaw)},
155-
vnormal : {numComponents:3, data: new Float32Array(vertexNormalRaw)},
156-
vcolor : {numComponents: 3, data: new Float32Array(vertexColorsRaw)}
157-
}
158-
159-
buffers = twgl.createBufferInfoFromArrays(drawingState.gl,arrays)
160-
}
155+
this.buffer = twgl.createBufferInfoFromArrays(drawingState.gl,arrays)
161156
}
162157

163158
Trunk.prototype.draw = function(drawingState) {
@@ -166,16 +161,15 @@ function printNormal(num, numCir, normals){
166161
twgl.m4.setTranslation(modelM,this.position,modelM)
167162

168163
var gl = drawingState.gl
169-
gl.useProgram(shaderProgram.program)
170-
twgl.setBuffersAndAttributes(gl,shaderProgram,buffers)
171-
twgl.setUniforms(shaderProgram,{
164+
gl.useProgram(this.shaderProgram.program)
165+
twgl.setBuffersAndAttributes(gl,this.shaderProgram, this.buffer)
166+
twgl.setUniforms(this.shaderProgram,{
172167
view:drawingState.view,
173168
proj:drawingState.proj,
174169
lightdir:drawingState.sunDirection,
175-
//lightdir: [0,1,0],
176170
cubecolor:this.color,
177171
model: modelM })
178-
twgl.drawBufferInfo(gl, gl.TRIANGLES, buffers)
172+
twgl.drawBufferInfo(gl, gl.TRIANGLES, this.buffer)
179173
}
180174
Trunk.prototype.center = function(drawingState) {
181175
return this.position

0 commit comments

Comments
 (0)