Skip to content
This repository
Browse code

custom plane

  • Loading branch information...
commit b98cc0aa3c6f3c6d6ffe1d9ec3d6b1a8e566eded 1 parent 6a68adc
authored February 03, 2011
8  c3dl-dev/tests/shapes/shapes.html
@@ -15,8 +15,8 @@
15 15
     <table>
16 16
         <tr>
17 17
           <td>
18  
-            <div>Box</div>
19  
-            <canvas id="box" style="border: 2px solid blue" width="300" height="300"></canvas> <br /> 
  18
+            <div>Cube</div>
  19
+            <canvas id="cube" style="border: 2px solid blue" width="300" height="300"></canvas> <br /> 
20 20
           </td>
21 21
           <td>
22 22
             <div>Plane</div>
@@ -40,6 +40,10 @@
40 40
             <div>Custom Shape with Texture</div>
41 41
             <canvas id="customWTexture" style="border: 2px solid blue" width="300" height="300"></canvas> <br />
42 42
           </td>
  43
+          <td>
  44
+            <div>Custom Plane</div>
  45
+            <canvas id="customPlane" style="border: 2px solid blue" width="300" height="300"></canvas> <br />
  46
+          </td>
43 47
         </tr>
44 48
       </table>
45 49
   </body>
104  c3dl-dev/tests/shapes/shapes.js
... ...
@@ -1,11 +1,12 @@
1  
-c3dl.addMainCallBack(boxMain, "box");
  1
+c3dl.addMainCallBack(cubeMain, "cube");
2 2
 c3dl.addMainCallBack(planeMain, "plane");
3 3
 c3dl.addMainCallBack(sphereMain, "sphere");
4 4
 c3dl.addMainCallBack(sphere2Main, "sphereDetail");
5 5
 c3dl.addMainCallBack(customMain, "custom");
6 6
 c3dl.addMainCallBack(custom2Main, "customWTexture");
  7
+c3dl.addMainCallBack(customPlaneMain, "customPlane");
7 8
 c3dl.addModel("sphere.dae");
8  
-function boxMain(canvasName){
  9
+function cubeMain(canvasName){
9 10
   scn = new c3dl.Scene();
10 11
   scn.setCanvasTag(canvasName);
11 12
   renderer = new c3dl.WebGL();
@@ -14,13 +15,13 @@ function boxMain(canvasName){
14 15
   scn.init(canvasName);
15 16
   
16 17
   if (renderer.isReady()) {
17  
-    var box = new c3dl.Box(5,5,5);
18  
-    box.setAngularVel([0.0, -0.001, 0.0]);
19  
-    box.setTexture("testing.jpg");
  18
+    var cube = new c3dl.Cube(5,5,5);
  19
+    cube.setAngularVel([0.0, -0.001, 0.0]);
  20
+    cube.setTexture("testing.jpg");
20 21
     var cam = new c3dl.FreeCamera();
21 22
     cam.setPosition([0.0, 0.0, 15.0]);
22 23
     cam.setLookAtPoint([0.0, 0.0, 0.0]);
23  
-    scn.addObjectToScene(box);
  24
+    scn.addObjectToScene(cube);
24 25
     scn.setCamera(cam);
25 26
     scn.startScene();
26 27
   }
@@ -129,4 +130,95 @@ function custom2Main(canvasName){
129 130
     scn.setCamera(cam);
130 131
     scn.startScene();
131 132
   }
  133
+}
  134
+var cam;
  135
+function customPlaneMain(canvasName){
  136
+  scn = new c3dl.Scene();
  137
+  scn.setCanvasTag(canvasName);
  138
+  renderer = new c3dl.WebGL();
  139
+  renderer.createRenderer(this);
  140
+  scn.setRenderer(renderer);
  141
+  scn.init(canvasName);
  142
+  
  143
+  if (renderer.isReady()) {
  144
+    //var vert = [-5,-5, -5,5, 0,5, 0,0, 5,0, 5,-5]; //norm up
  145
+    //var vert = [-5,-5, -5,5, 5,5, 5,-5]; //norm up
  146
+   // var vert = [5,5, -5,5, -5,-5, 5,-5]; //norm down
  147
+   
  148
+    var vert= [0,0, 5,-5, 0,-5]; //norm up
  149
+    //var vert= [0,-5, 0,0, 5,-5]; //norm up
  150
+    //var vert= [5,-5, 0,-5, 0,0]; //norm up
  151
+    //var vert= [0,0, 0,-5, 5,-5]; //norm down
  152
+    //var vert= [0,-5, 5,-5, 0,0]; //norm down
  153
+    //var vert= [5,-5, 0,0, 0,-5]; //norm down
  154
+    var customPlane = new c3dl.CustomPlane(vert);
  155
+    cam = new c3dl.FreeCamera();
  156
+    cam.setPosition([0.0, 3, 10]);
  157
+    cam.setLookAtPoint([0.0, 0.0, 0.0]);
  158
+    scn.addObjectToScene(customPlane);
  159
+    scn.setCamera(cam);
  160
+    scn.startScene();
  161
+    scn.setKeyboardCallback(onKeyUp, onKeyDown);
  162
+  }
  163
+}
  164
+
  165
+var keysDown = (
  166
+function keysDown() {
  167
+  var key_w = false,
  168
+      key_a = false,
  169
+      key_s = false,
  170
+      key_d = false;
  171
+  return {
  172
+    "KEY_W": key_w,
  173
+    "KEY_A": key_a,
  174
+    "KEY_S": key_s,
  175
+    "KEY_D": key_d,
  176
+  };
  177
+})();
  178
+  
  179
+//Keys
  180
+const KEY_D = 68;
  181
+const KEY_A = 65;
  182
+const KEY_W = 87;
  183
+const KEY_S = 83;
  184
+
  185
+function onKeyDown(event) {
  186
+  switch (event.keyCode) {
  187
+  case KEY_W:
  188
+    cam.setPosition([cam.getPosition()[0],cam.getPosition()[1]-0.5,cam.getPosition()[2]]);
  189
+       cam.setLookAtPoint([0.0, 0.0, 0.0]);
  190
+    break;
  191
+  case KEY_A:
  192
+    keysDown.KEY_A = true;
  193
+    break;
  194
+  case KEY_S:
  195
+      cam.setPosition([cam.getPosition()[0],cam.getPosition()[1]+0.5,cam.getPosition()[2]]);
  196
+       cam.setLookAtPoint([0.0, 0.0, 0.0]);
  197
+    break;
  198
+  case KEY_D:
  199
+    keysDown.KEY_D = true;
  200
+    break;
  201
+  default:
  202
+    break;
  203
+  }
  204
+}
  205
+
  206
+//When a key is released down
  207
+function onKeyUp(event) {
  208
+  switch (event.keyCode) {
  209
+  case KEY_W:
  210
+    keysDown.KEY_W = false;
  211
+    break;
  212
+  case KEY_A:
  213
+    keysDown.KEY_A = false;
  214
+    break;
  215
+  case KEY_S:
  216
+    keysDown.KEY_S = false;
  217
+    break;
  218
+  case KEY_D:
  219
+    keysDown.KEY_D = false;
  220
+    break;
  221
+  default:
  222
+    break;
  223
+  }
132 224
 }
3  c3dl/c3dapi.js
@@ -77,10 +77,11 @@ c3dl_require('actors/line.js');
77 77
 
78 78
 //shapes
79 79
 c3dl_require('shapes/shape.js');
80  
-c3dl_require('shapes/box.js');
  80
+c3dl_require('shapes/cube.js');
81 81
 c3dl_require('shapes/plane.js');
82 82
 c3dl_require('shapes/sphere.js');
83 83
 c3dl_require('shapes/custom.js');
  84
+c3dl_require('shapes/customplane.js');
84 85
 
85 86
 //frustum culling
86 87
 c3dl_require('frustum_culling/frustum.js');
1  c3dl/collada/primitiveset.js
@@ -30,6 +30,7 @@ c3dl.PrimitiveSet = function ()
30 30
   this.type = null;
31 31
   this.lineList = null;
32 32
   this.boundingVolume = null;
  33
+  this.fillType = null;
33 34
   this.buffers =
34 35
   {
35 36
   };
14  c3dl/shaders/model/standard/std_callback.js
@@ -114,11 +114,19 @@ c3dl.std_callback = function (renderingObj)
114 114
 
115 115
     // VERTICES
116 116
     renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices());
117  
-    if (currColl.sphere) {
118  
-      glCanvas3D.drawArrays(glCanvas3D.TRIANGLE_STRIP, 0, currColl.getVertices().length / 3);
  117
+    if (renderer.getFillMode() === c3dl.FILL) {
  118
+      if (currColl.fillType === "TRIANGLE_STRIP") {
  119
+        glCanvas3D.drawArrays(glCanvas3D.TRIANGLE_STRIP, 0, currColl.getVertices().length / 3);
  120
+      }
  121
+      else if (currColl.fillType === "TRIANGLE_FAN") {
  122
+        glCanvas3D.drawArrays(glCanvas3D.TRIANGLE_FAN, 0, currColl.getVertices().length / 3);
  123
+      }
  124
+      else {
  125
+        glCanvas3D.drawArrays(glCanvas3D.TRIANGLES, 0, currColl.getVertices().length / 3);
  126
+      }
119 127
     }
120 128
     else {
121  
-      glCanvas3D.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
  129
+      glCanvas3D.drawArrays(c3dl.WIRE_FRAME, 0, currColl.getVertices().length / 3);
122 130
     }
123 131
     glCanvas3D.enable(glCanvas3D.POLYGON_OFFSET_FILL);
124 132
   }
4  c3dl/shapes/box.js → c3dl/shapes/cube.js
@@ -3,7 +3,7 @@
3 3
   Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
4 4
 */
5 5
 
6  
-c3dl.Box = c3dl.inherit(c3dl.Shape, function () {
  6
+c3dl.Cube = c3dl.inherit(c3dl.Shape, function () {
7 7
   c3dl._superc(this);
8 8
   this.primitiveSets[0] = new c3dl.PrimitiveSet();
9 9
   var vertices = new C3DL_FLOAT_ARRAY([
@@ -38,7 +38,7 @@ c3dl.Box = c3dl.inherit(c3dl.Shape, function () {
38 38
   }
39 39
 });
40 40
 
41  
-c3dl.Box.prototype.init = function (length, width, height) {
  41
+c3dl.Cube.prototype.init = function (length, width, height) {
42 42
   length = parseFloat(length);
43 43
   width = parseFloat(width);
44 44
   height = parseFloat(height);
40  c3dl/shapes/customplane.js
... ...
@@ -0,0 +1,40 @@
  1
+/*
  2
+  Copyright (c) 2008 Seneca College
  3
+  Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
  4
+*/
  5
+
  6
+c3dl.CustomPlane = c3dl.inherit(c3dl.Shape, function () {
  7
+  c3dl._superc(this);
  8
+  this.primitiveSets[0] = new c3dl.PrimitiveSet();
  9
+  var vertices = new C3DL_FLOAT_ARRAY(arguments[0].length/2*3);
  10
+  var normals = new C3DL_FLOAT_ARRAY(arguments[0].length/2*3);
  11
+  var axis = [0,1,0];
  12
+  if (arguments[1]) {
  13
+    if (arguments[1] === "X") {
  14
+      axis = [1,0,0];
  15
+    }
  16
+    else if (arguments[1] === "Y") {
  17
+      axis = [0,1,0];
  18
+    }
  19
+    else if (arguments[1] === "Z") {
  20
+      axis = [0,0,1];
  21
+    }
  22
+  }
  23
+  if (arguments[2]) {
  24
+    c3dl.multiplyVector(axis, 1, axis);
  25
+  }
  26
+  for (var i = 0, j=0; i < arguments[0].length; i+=2,j+=3) {
  27
+    vertices[j] = arguments[0][i];
  28
+    vertices[j+1] = 0;
  29
+    vertices[j+2] = arguments[0][i+1];
  30
+    normals[j] = axis[0];
  31
+    normals[j+1] = axis[1];
  32
+    normals[j+2] = axis[2];
  33
+  }
  34
+  this.primitiveSets[0].init(vertices, normals);
  35
+  this.primitiveSets[0].fillType = "TRIANGLE_FAN";
  36
+  this.boundingVolume.init(vertices);
  37
+});
  38
+
  39
+
  40
+ 
2  c3dl/shapes/sphere.js
@@ -107,7 +107,7 @@ c3dl.Sphere = c3dl.inherit(c3dl.Shape, function () {
107 107
   var normals = new C3DL_FLOAT_ARRAY(sphereArray);
108 108
   texCoords = new C3DL_FLOAT_ARRAY(texCoords);
109 109
   this.primitiveSets[0].init(vertices, normals, texCoords);
110  
-  this.primitiveSets[0].sphere = true;
  110
+  this.primitiveSets[0].fillType = "TRIANGLE_STRIP";
111 111
   this.boundingVolume.init(vertices);
112 112
   this.scale([0.5,0.5,0.5]);
113 113
   this.init(arguments[0])

0 notes on commit b98cc0a

Please sign in to comment.
Something went wrong with that request. Please try again.