diff options
author | Valerio Virgillito | 2012-04-04 15:58:49 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 15:58:49 -0700 |
commit | 347b4179be5581841fc94825dcb18901e625c670 (patch) | |
tree | 93556d56b049aa47c615a8b58add230cd96da166 /js/helper-classes/RDGE/src/core/script/renderUtils.js | |
parent | 9f1806a7134ec4744a8009e6a7467f5cea04cabf (diff) | |
parent | e721a7c1009f298a1bd8fea583da14535e039880 (diff) | |
download | ninja-347b4179be5581841fc94825dcb18901e625c670.tar.gz |
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/renderUtils.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/renderUtils.js | 644 |
1 files changed, 315 insertions, 329 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/renderUtils.js b/js/helper-classes/RDGE/src/core/script/renderUtils.js index baa38560..cc9b31ae 100755 --- a/js/helper-classes/RDGE/src/core/script/renderUtils.js +++ b/js/helper-classes/RDGE/src/core/script/renderUtils.js | |||
@@ -4,383 +4,369 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | renderUtils = {} | 7 | var RDGE = RDGE || {}; |
8 | RDGE.renderUtils = RDGE.renderUtils || {}; | ||
8 | 9 | ||
9 | /* | 10 | /* |
10 | * Creates an indexed box primitive | 11 | * Creates an indexed box primitive |
11 | * @return a rdge primitive | 12 | * @return a rdge primitive |
12 | */ | 13 | */ |
13 | renderUtils.createBox = function() | 14 | RDGE.renderUtils.createBox = function () { |
14 | { | 15 | var renderer = RDGE.globals.engine.getContext().renderer; |
15 | var renderer = g_Engine.getContext().renderer; | 16 | |
16 | 17 | var coords = | |
17 | var coords= | 18 | [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, // front |
18 | [ 1,1,1, -1,1,1, -1,-1,1, 1,-1,1, // front | 19 | 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, // right |
19 | 1,1,1, 1,-1,1, 1,-1,-1, 1,1,-1, // right | 20 | 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, // top |
20 | 1,1,1, 1,1,-1, -1,1,-1, -1,1,1, // top | 21 | -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, // left |
21 | -1,1,1, -1,1,-1, -1,-1,-1, -1,-1,1, // left | 22 | -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, // bottom |
22 | -1,-1,-1, 1,-1,-1, 1,-1,1, -1,-1,1, // bottom | 23 | 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1]; // back |
23 | 1,-1,-1, -1,-1,-1, -1,1,-1, 1,1,-1]; // back | 24 | |
24 | 25 | var normals = | |
25 | var normals= | 26 | [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // front |
26 | [ 0,0,1, 0,0,1, 0,0,1, 0,0,1, // front | 27 | 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // right |
27 | 1,0,0, 1,0,0, 1,0,0, 1,0,0, // right | 28 | 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top |
28 | 0,1,0, 0,1,0, 0,1,0, 0,1,0, // top | 29 | -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left |
29 | -1,0,0, -1,0,0, -1,0,0, -1,0,0, // left | 30 | 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // bottom |
30 | 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0, // bottom | 31 | 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]; // back |
31 | 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1]; // back | 32 | |
32 | 33 | var uvs = | |
33 | 34 | [1, 1, 0, 1, 0, 0, 1, 0, // front | |
34 | 35 | 0, 1, 0, 0, 1, 0, 1, 1, // right | |
35 | var uvs= | 36 | 1, 0, 1, 1, 0, 1, 0, 0, // top |
36 | [ 1,1, 0,1, 0,0, 1,0, // front | 37 | 1, 1, 0, 1, 0, 0, 1, 0, // left |
37 | 0,1, 0,0, 1,0, 1,1, // right | 38 | 0, 0, 1, 0, 1, 1, 0, 1, // bottom |
38 | 1,0, 1,1, 0,1, 0,0, // top | 39 | 0, 0, 1, 0, 1, 1, 0, 1]; // back |
39 | 1,1, 0,1, 0,0, 1,0, // left | 40 | |
40 | 0,0, 1,0, 1,1, 0,1, // bottom | 41 | var indices = |
41 | 0,0, 1,0, 1,1, 0,1]; // back | 42 | [0, 1, 2, 0, 2, 3, // front |
42 | 43 | 4, 5, 6, 4, 6, 7, // right | |
43 | var indices= | 44 | 8, 9, 10, 8, 10, 11, // top |
44 | [ 0,1,2,0,2,3, // front | 45 | 12, 13, 14, 12, 14, 15, // left |
45 | 4,5,6,4,6,7, // right | 46 | 16, 17, 18, 16, 18, 19, // bottom |
46 | 8,9,10,8,10,11, // top | 47 | 20, 21, 22, 20, 22, 23]; // back |
47 | 12,13,14,12,14,15, // left | 48 | |
48 | 16,17,18,16,18,19, // bottom | 49 | |
49 | 20,21,22,20,22,23]; // back | 50 | var prim = new RDGE.rdgePrimitiveDefinition(); |
50 | 51 | ||
51 | 52 | prim.vertexDefinition = | |
52 | var prim = new rdgePrimitiveDefinition(); | ||
53 | |||
54 | prim.vertexDefinition= | ||
55 | { | 53 | { |
56 | "vert":{'type':rdgeConstants.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 54 | "vert": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
57 | "a_pos":{'type':rdgeConstants.VS_ELEMENT_POS, 'bufferIndex':0, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 55 | "a_pos": { 'type': RDGE.rdgeConstants.VS_ELEMENT_POS, 'bufferIndex': 0, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
58 | 56 | ||
59 | "normal":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 57 | "normal": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
60 | "a_nrm":{'type':rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex':1, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 58 | "a_nrm": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT3, 'bufferIndex': 1, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
61 | 59 | ||
62 | "texcoord":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC}, | 60 | "texcoord": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC }, |
63 | "a_uv":{'type':rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex':2, 'bufferUsage': rdgeConstants.BUFFER_STATIC} | 61 | "a_uv": { 'type': RDGE.rdgeConstants.VS_ELEMENT_FLOAT2, 'bufferIndex': 2, 'bufferUsage': RDGE.rdgeConstants.BUFFER_STATIC } |
64 | }; | 62 | }; |
65 | 63 | ||
66 | prim.bufferStreams= | 64 | prim.bufferStreams = |
67 | [ | 65 | [ |
68 | coords, | 66 | coords, |
69 | normals, | 67 | normals, |
70 | uvs | 68 | uvs |
71 | ]; | 69 | ]; |
72 | 70 | ||
73 | prim.streamUsage= | 71 | prim.streamUsage = |
74 | [ | 72 | [ |
75 | rdgeConstants.BUFFER_STATIC, | 73 | RDGE.rdgeConstants.BUFFER_STATIC, |
76 | rdgeConstants.BUFFER_STATIC, | 74 | RDGE.rdgeConstants.BUFFER_STATIC, |
77 | rdgeConstants.BUFFER_STATIC | 75 | RDGE.rdgeConstants.BUFFER_STATIC |
78 | ]; | 76 | ]; |
79 | 77 | ||
80 | prim.indexUsage = rdgeConstants.BUFFER_STREAM; | 78 | prim.indexUsage = RDGE.rdgeConstants.BUFFER_STREAM; |
81 | prim.indexBuffer = indices; | 79 | prim.indexBuffer = indices; |
82 | 80 | ||
83 | prim.type = rdgeConstants.TRIANGLES; | 81 | prim.type = RDGE.rdgeConstants.TRIANGLES; |
84 | 82 | ||
85 | renderer.createPrimitive(prim); | 83 | renderer.createPrimitive(prim); |
86 | 84 | ||
87 | return prim; | 85 | return prim; |
88 | } | 86 | }; |
89 | 87 | ||
90 | // | 88 | // |
91 | // makeSphere | 89 | // makeSphere |
92 | // | 90 | // |
93 | // Create a sphere with the passed number of latitude and longitude bands and the passed radius. | 91 | // Create a sphere with the passed number of latitude and longitude bands and the passed radius. |
94 | // Sphere has vertices, normals and texCoords. Create VBOs for each as well as the index array. | 92 | // Sphere has vertices, normals and texCoords. Create VBOs for each as well as the index array. |
95 | // Return an object with the following properties: | 93 | // Return an object with the following properties: |
96 | // | 94 | // |
97 | // normalObject WebGLBuffer object for normals | 95 | // normalObject WebGLBuffer object for normals |
98 | // texCoordObject WebGLBuffer object for texCoords | 96 | // texCoordObject WebGLBuffer object for texCoords |
99 | // vertexObject WebGLBuffer object for vertices | 97 | // vertexObject WebGLBuffer object for vertices |
100 | // indexObject WebGLBuffer object for indices | 98 | // indexObject WebGLBuffer object for indices |
101 | // numIndices The number of indices in the indexObject | 99 | // numIndices The number of indices in the indexObject |
102 | // | 100 | // |
103 | function makeSphere(ctx, radius, lats, longs) | 101 | RDGE.renderUtils.makeSphere = function (ctx, radius, lats, longs) { |
104 | { | 102 | var geometryData = []; |
105 | var geometryData = [ ]; | 103 | var normalData = []; |
106 | var normalData = [ ]; | 104 | var texCoordData = []; |
107 | var texCoordData = [ ]; | 105 | var indexData = []; |
108 | var indexData = [ ]; | 106 | |
109 | 107 | for (var latNumber = 0; latNumber <= lats; ++latNumber) { | |
110 | for (var latNumber = 0; latNumber <= lats; ++latNumber) { | 108 | for (var longNumber = 0; longNumber <= longs; ++longNumber) { |
111 | for (var longNumber = 0; longNumber <= longs; ++longNumber) { | 109 | var theta = latNumber * Math.PI / lats; |
112 | var theta = latNumber * Math.PI / lats; | 110 | var phi = longNumber * 2 * Math.PI / longs; |
113 | var phi = longNumber * 2 * Math.PI / longs; | 111 | var sinTheta = Math.sin(theta); |
114 | var sinTheta = Math.sin(theta); | 112 | var sinPhi = Math.sin(phi); |
115 | var sinPhi = Math.sin(phi); | 113 | var cosTheta = Math.cos(theta); |
116 | var cosTheta = Math.cos(theta); | 114 | var cosPhi = Math.cos(phi); |
117 | var cosPhi = Math.cos(phi); | 115 | |
118 | 116 | var x = cosPhi * sinTheta; | |
119 | var x = cosPhi * sinTheta; | 117 | var y = cosTheta; |
120 | var y = cosTheta; | 118 | var z = sinPhi * sinTheta; |
121 | var z = sinPhi * sinTheta; | 119 | var u = 1 - (longNumber / longs); |
122 | var u = 1-(longNumber/longs); | 120 | var v = latNumber / lats; |
123 | var v = latNumber/lats; | 121 | |
124 | 122 | normalData.push(x); | |
125 | normalData.push(x); | 123 | normalData.push(y); |
126 | normalData.push(y); | 124 | normalData.push(z); |
127 | normalData.push(z); | 125 | texCoordData.push(u); |
128 | texCoordData.push(u); | 126 | texCoordData.push(v); |
129 | texCoordData.push(v); | 127 | geometryData. |