Advertisement
Guest User

Untitled

a guest
Dec 12th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* -------------------------------------------------------------------- */
  2.  
  3.         var canvas, ctx;
  4.         var canvasWidth, halfCanvasWidth;
  5.         var canvasHeight, halfCanvasHeight;
  6.  
  7.         var space;  // 3D Engine
  8.         var scene;  // 3D Scene
  9.  
  10.         /* -------------------------------------------------------------------- */
  11.  
  12.         /**
  13.          * Space is a simple 3D system.
  14.          *
  15.          * Y+ = up
  16.          * Z+ = into screen
  17.          * X+ = right
  18.          */
  19.         function Space() {
  20.             this.m = this.createMatrixIdentity();
  21.             this.mStack = [];
  22.         }
  23.  
  24.         Space.prototype.createMatrixIdentity = function() {
  25.             return [
  26.                 [1, 0, 0, 0],
  27.                 [0, 1, 0, 0],
  28.                 [0, 0, 1, 0],
  29.                 [0, 0, 0, 1]
  30.             ];
  31.         }
  32.  
  33.         /**
  34.          * Multiplies two 4x4 matricies together.
  35.          */
  36.         Space.prototype.matrixMultiply = function(m1, m2) {
  37.             var result = this.createMatrixIdentity();
  38.  
  39.             var width = m1[0].length;
  40.             var height = m1.length;
  41.  
  42.             if (width != m2.length) {
  43.                 // error
  44.             }
  45.  
  46.             for (var x = 0; x < width; x++) {
  47.                 for (var y = 0; y < height; y++) {
  48.                     var sum = 0;
  49.  
  50.                     for (var z = 0; z < width; z++) {
  51.                         sum += m1[y][z] * m2[z][x];
  52.                     }
  53.  
  54.                     result[y][x] = sum;
  55.                 }
  56.             }
  57.  
  58.             return result;
  59.         }
  60.  
  61.         /**
  62.          * Transforms a coordinate using the current transformation
  63.          * matrix, then flattens it using the projection matrix.
  64.          */
  65.         Space.prototype.flatten = function(point) {
  66.             var p = [[point.x, point.y, point.z, 1]];
  67.             var pm = this.matrixMultiply(p, this.m);
  68.  
  69.             point.tx = pm[0][0];
  70.             point.ty = pm[0][1];
  71.             point.tz = pm[0][2];
  72.  
  73.             // lazy projection
  74.             point.fx = halfCanvasWidth + (canvasWidth * point.tx / point.tz);
  75.             point.fy = halfCanvasHeight -(canvasWidth * point.ty / point.tz);
  76.         }
  77.  
  78.         /**
  79.          * Translate (move) the current transformation matrix
  80.          */
  81.         Space.prototype.translate = function(x, y, z) {
  82.             var m = [
  83.                 [1, 0, 0, 0],
  84.                 [0, 1, 0, 0],
  85.                 [0, 0, 1, 0],
  86.                 [x, y, z, 1]
  87.             ];
  88.  
  89.             this.m = this.matrixMultiply(m, this.m);
  90.         }
  91.  
  92.         /**
  93.          * Rotate the current transformation matrix. Rotations are
  94.          * world-oriented, and occur in y,x,z order.
  95.          */
  96.         Space.prototype.rotate = function(x, y, z) {
  97.             if (y) {
  98.                 var cosY = Math.cos(y);
  99.                 var sinY = Math.sin(y);
  100.                 var rotY = [
  101.                     [cosY, 0, sinY, 0],
  102.                     [0, 1, 0, 0],
  103.                     [-sinY, 0, cosY, 0],
  104.                     [0, 0, 0, 1]
  105.                 ];
  106.  
  107.                 this.m = this.matrixMultiply(this.m, rotY);
  108.             }
  109.  
  110.             if (x) {
  111.                 var cosX = Math.cos(x);
  112.                 var sinX = Math.sin(x);
  113.                 var rotX = [
  114.                     [1, 0, 0, 0],
  115.                     [0, cosX, -sinX, 0],
  116.                     [0, sinX, cosX,0],
  117.                     [0, 0, 0, 1]
  118.                 ];
  119.                 this.m = this.matrixMultiply(this.m, rotX);
  120.             }
  121.  
  122.             if (z) {
  123.                 var cosZ = Math.cos(z);
  124.                 var sinZ = Math.sin(z);
  125.                 var rotZ = [
  126.                     [cosZ, -sinZ, 0, 0],
  127.                     [sinZ, cosZ, 0, 0],
  128.                     [0, 0, 1, 0],
  129.                     [0, 0, 0, 1]
  130.                 ];
  131.  
  132.                 this.m = this.matrixMultiply(this.m, rotZ);
  133.             }
  134.         }
  135.  
  136.         /**
  137.          * Pushes the current transformation onto the stack
  138.          */
  139.         Space.prototype.push = function() {
  140.             this.mStack.push(this.m);
  141.             this.m = [
  142.                 [this.m[0][0], this.m[0][1], this.m[0][2], this.m[0][3]],
  143.                 [this.m[1][0], this.m[1][1], this.m[1][2], this.m[1][3]],
  144.                 [this.m[2][0], this.m[2][1], this.m[2][2], this.m[2][3]],
  145.                 [this.m[3][0], this.m[3][1], this.m[3][2], this.m[3][3]]
  146.             ];
  147.         }
  148.  
  149.         /**
  150.          * Pops the end off the transformation stack
  151.          */
  152.         Space.prototype.pop = function() {
  153.             this.m = this.mStack.pop();
  154.         }
  155.  
  156.         /* -------------------------------------------------------------------- */
  157.  
  158.         /**
  159.          * A 3d coordinate
  160.          */
  161.         function Point(x, y, z) {
  162.             this.x = x;
  163.             this.y = y;
  164.             this.z = z;
  165.  
  166.             // Relative to camera coordinates
  167.             this.tx;
  168.             this.ty;
  169.             this.tz;
  170.  
  171.             // Flattened coordinates
  172.             this.fx;
  173.             this.fy;
  174.         }
  175.  
  176.         /**
  177.          * A Shape is made up of polygons
  178.          */
  179.         function Shape() {
  180.             this.points = [];
  181.             this.polygons = [];
  182.         }
  183.  
  184.         /**
  185.          * Draws the shape
  186.          */
  187.         Shape.prototype.draw = function(drawlist) {
  188.             for (var i = 0; i< this.points.length; i++) {
  189.                 space.flatten(this.points[i]);
  190.             }
  191.  
  192.             for (var i = 0; i< this.polygons.length; i++) {
  193.                 var poly = this.polygons[i]; // convenience
  194.  
  195.                 space.flatten(poly.origin);
  196.  
  197.                 // lazy backface culling
  198.                 if (poly.normal && this.backface) {
  199.                     space.flatten(poly.normal);
  200.  
  201.                     var originDist = Math.pow(poly.origin.tx, 2)
  202.                                                  + Math.pow(poly.origin.ty, 2)
  203.                                                  + Math.pow(poly.origin.tz, 2);
  204.  
  205.                     var normalDist = Math.pow(poly.normal.tx, 2)
  206.                                                  + Math.pow(poly.normal.ty, 2)
  207.                                                  + Math.pow(poly.normal.tz, 2);
  208.  
  209.                     if(originDist > normalDist) {
  210.                         drawlist.push(poly);
  211.                     }
  212.                 } else {
  213.                     drawlist.push(poly);
  214.                 }
  215.             }
  216.         }
  217.  
  218.         /**
  219.          * A polygon is a connection of points in the shape object. You
  220.          * should probably try to make them coplanar.
  221.          */
  222.         function Polygon(points, normal, backface, type, color) {
  223.             this.points = points;
  224.  
  225.             this.origin = new Point(0, 0, 0);
  226.             for(var i = 0; i < this.points.length; i++) {
  227.                 this.origin.x += this.points[i].x;
  228.                 this.origin.y += this.points[i].y;
  229.                 this.origin.z += this.points[i].z;
  230.             }
  231.  
  232.             this.origin.x /= this.points.length;
  233.             this.origin.y /= this.points.length;
  234.             this.origin.z /= this.points.length;
  235.  
  236.             if (normal) {
  237.                 this.normal = new Point(this.origin.x + normal.x,
  238.                                                                 this.origin.y + normal.y,
  239.                                                                 this.origin.z + normal.z);
  240.             } else {
  241.                 this.normal = null;
  242.             }
  243.  
  244.             this.backface = backface;
  245.             this.type = type;
  246.             this.color = color;
  247.         }
  248.  
  249.         Polygon.SOLID = 0;
  250.         Polygon.WIRE = 1;
  251.  
  252.         /**
  253.          * Draws the polygon. Assumes that the points have already been
  254.          * flattened.
  255.          */
  256.         Polygon.prototype.draw = function() {
  257.             ctx.beginPath();
  258.             ctx.moveTo(this.points[0].fx, this.points[0].fy);
  259.  
  260.             for(var i = 0; i < this.points.length; i++) {
  261.                 ctx.lineTo(this.points[i].fx, this.points[i].fy);
  262.             }
  263.  
  264.             ctx.closePath();
  265.  
  266.             var color = this.color;
  267.  
  268.             /*
  269.             // Do lighting here
  270.             lightvector = Math.abs(this.normal.x + this.normal.y);
  271.             if(lightvector > 1) {
  272.                 lightvector = 1;
  273.             }
  274.  
  275.             color[0] = (color[0] * lightvector).toString();
  276.             color[1] = (color[1] * lightvector).toString();
  277.             color[2] = (color[2] * lightvector).toString();
  278.             */
  279.  
  280.             if (color.length > 3) {
  281.                 var style = ["rgba(",
  282.                              color[0], ",",
  283.                              color[1], ",",
  284.                              color[2], ",",
  285.                              color[3], ")"].join("");
  286.             } else {
  287.                 var style = ["rgb(",
  288.                              color[0], ",",
  289.                              color[1], ",",
  290.                              color[2], ")"].join("");
  291.             }
  292.  
  293.             if (this.type == Polygon.SOLID) {
  294.                 ctx.fillStyle = style;
  295.                 ctx.fill();
  296.             } else if (this.type == Polygon.WIRE) {
  297.                 ctx.strokeStyle = style;
  298.                 ctx.stroke();
  299.             }
  300.         }
  301.  
  302.         /* -------------------------------------------------------------------- */
  303.  
  304.         /**
  305.          * Scene describes the 3D environment
  306.          */
  307.         function Scene() {
  308.             this.shapes = {};
  309.             this.camera = new Point(0, 0, 0);
  310.             this.cameraTarget = new Point(0, 0, 0);
  311.             this.cameraRotation = 0;
  312.  
  313.             this.drawlist = [];
  314.         }
  315.  
  316.         /**
  317.          * Draw the world
  318.          */
  319.         Scene.prototype.draw = function() {
  320.             space.push();
  321.  
  322.             // Camera transformation
  323.             space.translate(
  324.                 -this.camera.x,
  325.                 -this.camera.y,
  326.                 -this.camera.z
  327.             );
  328.  
  329.             // Camera rotation
  330.             var xdiff = this.cameraTarget.x - this.camera.x;
  331.             var ydiff = this.cameraTarget.y - this.camera.y;
  332.             var zdiff = this.cameraTarget.z - this.camera.z;
  333.  
  334.             var xzdist = Math.sqrt(Math.pow(xdiff, 2) + Math.pow(zdiff, 2));
  335.  
  336.             var xrot = -Math.atan2(ydiff, xzdist); // up/down rotation
  337.             var yrot =  Math.atan2(xdiff, zdiff);  // left/right rotation
  338.  
  339.             space.rotate(xrot, yrot, this.cameraRotation);
  340.  
  341.             // Drawing
  342.             this.drawlist = [];
  343.  
  344.             for(var i in this.shapes) {
  345.                 this.shapes[i].draw(this.drawlist);
  346.             }
  347.  
  348.             // Depth sorting (warning: this is only enough to drive this demo - feel
  349.             // free to contribute a better system).
  350.             this.drawlist.sort(function (poly1, poly2) {
  351.                 return poly2.origin.tz - poly1.origin.tz;
  352.             });
  353.  
  354.             for (var i = 0; i < this.drawlist.length; i++) {
  355.                 this.drawlist[i].draw();
  356.             }
  357.  
  358.             space.pop();
  359.         }
  360.  
  361.         /* -------------------------------------------------------------------- */
  362.  
  363.         var count = 0;
  364.  
  365.         function loop() {
  366.             ctx.clearRect(0, 0, canvasWidth, canvasHeight);
  367.  
  368. //          scene.camera.x = 70*Math.sin(count);
  369. //          scene.camera.y = 70;
  370. //          scene.camera.z = 70*Math.cos(count);
  371. //          scene.cameraRotation = count / 10;
  372.                         scene.camera.x = 0;
  373.                         scene.camera.y = 0;
  374.                         scene.camera.z = 2048;
  375.  
  376.             count += 0.01;
  377.             scene.draw();
  378.         }
  379.  
  380.  
  381.  
  382.         function load() {
  383.                         // Init drawing system
  384.             canvas = document.getElementById("cv");
  385.             ctx = canvas.getContext("2d");
  386.  
  387.             canvasWidth = canvas.width;
  388.             canvasHeight = canvas.height;
  389.             halfCanvasWidth = canvasWidth * 0.5;
  390.             halfCanvasHeight = canvasHeight * 0.5;
  391.  
  392.             // Init 3D components
  393.             space = new Space();
  394.             scene = new Scene();
  395.                        
  396. /////////////////////////////////////////////////////////////////////////////////////////
  397. ///////////////////////////////// UPSTRAIRS //////////////////////////////////////////////
  398. /////////////////////////////////////////////////////////////////////////////////////////
  399.  
  400.  
  401. ctx.font = "30px Calibri"; // vložení textu
  402. ctx.fillText("Hello World", 200, 20);
  403.                        
  404.                         // Create a box shape and add it to the scene
  405.             scene.shapes['shopsUpBackground'] = new Shape();
  406.             var psub = scene.shapes['shopsUpBackground'].points; // for convenience
  407.                        
  408.             psub[0] = new Point(-1024, 56, 9);  // left  bottom
  409.             psub[1] = new Point(1024, 56, 9);   // right bottom
  410.             psub[2] = new Point(1024, 526, 9);    // right top  
  411.             psub[3] = new Point(-1024, 526, 9);   // left  top    
  412.  
  413.  
  414.             // Shops background
  415.             scene.shapes['shopsUpBackground'].polygons.push(new Polygon(
  416.                 [psub[0], psub[1], psub[2], psub[3] ],
  417.                 new Point(0, 0, 1),
  418.                 true /* double-sided */,
  419.                 Polygon.SOLID,
  420.                 [222, 222, 222]
  421.             ));
  422.                            
  423. //////////////////////// SHOPS //////////////////////////////////////////
  424.  
  425.  
  426. ///////////////////////////////////// SHOP 1 START //////////////////////////////////////////////
  427.             scene.shapes['shop1'] = new Shape();
  428.             var ps1 = scene.shapes['shop1'].points; // for convenience
  429.                        
  430.             ps1[0] = new Point(1024, 66, 10);  // left  bottom
  431.             ps1[1] = new Point(694, 66, 10);   // right bottom
  432.             ps1[2] = new Point(694, 466, 10);    // right top  
  433.             ps1[3] = new Point(1024, 466, 10);   // left  top    
  434.  
  435.  
  436.             // Background
  437.             scene.shapes['shop1'].polygons.push(new Polygon(
  438.                 [ps1[0], ps1[1], ps1[2], ps1[3] ],
  439.                 new Point(0, 0, 1),
  440.                 true /* double-sided */,
  441.                 Polygon.SOLID,
  442.                 [177, 216, 249]
  443.             ));
  444.                        
  445.                         scene.shapes['shop1Header'] = new Shape();
  446.             var ps1h = scene.shapes['shop1Header'].points; // for convenience
  447.                        
  448.             ps1h[0] = new Point(1024, 400, 11);  // left  bottom
  449.             ps1h[1] = new Point(694, 400, 11);   // right bottom
  450.             ps1h[2] = new Point(694, 466, 11);    // right top  
  451.             ps1h[3] = new Point(1024, 466, 11);   // left  top    
  452.  
  453.  
  454.             // Background
  455.             scene.shapes['shop1Header'].polygons.push(new Polygon(
  456.                 [ps1h[0], ps1h[1], ps1h[2], ps1h[3] ],
  457.                 new Point(0, 0, 1),
  458.                 true /* double-sided */,
  459.                 Polygon.SOLID,
  460.                 [175, 175, 175]
  461.             ));      
  462.  
  463.  
  464. ///////////////////////////////////// SHOP 1 END /////////////////////////////////////////////////
  465.                        
  466. ///////////////////////////////////// SHOP 2 START //////////////////////////////////////////////
  467.                        
  468.                         scene.shapes['shop2'] = new Shape();
  469.             var ps2 = scene.shapes['shop2'].points; // for convenience
  470.                        
  471.             ps2[0] = new Point(680, 66, 10);  // left  bottom
  472.             ps2[1] = new Point(350, 66, 10);   // right bottom
  473.             ps2[2] = new Point(350, 466, 10);    // right top  
  474.             ps2[3] = new Point(680, 466, 10);   // left  top    
  475.  
  476.  
  477.             // Background
  478.             scene.shapes['shop2'].polygons.push(new Polygon(
  479.                 [ps2[0], ps2[1], ps2[2], ps2[3] ],
  480.                 new Point(0, 0, 1),
  481.                 true /* double-sided */,
  482.                 Polygon.SOLID,
  483.                 [177, 216, 249]
  484.             ));
  485.                        
  486.                         scene.shapes['shop2Header'] = new Shape();
  487.             var ps2h = scene.shapes['shop2Header'].points; // for convenience
  488.                        
  489.             ps2h[0] = new Point(680, 400, 11);  // left  bottom
  490.             ps2h[1] = new Point(350, 400, 11);   // right bottom
  491.             ps2h[2] = new Point(350, 466, 11);    // right top  
  492.             ps2h[3] = new Point(680, 466, 11);   // left  top    
  493.  
  494.  
  495.             // Background
  496.             scene.shapes['shop2Header'].polygons.push(new Polygon(
  497.                 [ps2h[0], ps2h[1], ps2h[2], ps2h[3] ],
  498.                 new Point(0, 0, 1),
  499.                 true /* double-sided */,
  500.                 Polygon.SOLID,
  501.                 [175, 175, 175]
  502.             ));
  503. ///////////////////////////////////// SHOP 2 END /////////////////////////////////////////////////
  504.                        
  505. ///////////////////////////////////// SHOP 3 START //////////////////////////////////////////////
  506.                            
  507.                         scene.shapes['shop3'] = new Shape();
  508.             var ps3 = scene.shapes['shop3'].points; // for convenience
  509.                        
  510.             ps3[0] = new Point(336, 66, 10);  // left  bottom
  511.             ps3[1] = new Point(6, 66, 10);   // right bottom
  512.             ps3[2] = new Point(6, 466, 10);    // right top  
  513.             ps3[3] = new Point(336, 466, 10);   // left  top    
  514.  
  515.  
  516.             // Background
  517.             scene.shapes['shop3'].polygons.push(new Polygon(
  518.                 [ps3[0], ps3[1], ps3[2], ps3[3] ],
  519.                 new Point(0, 0, 1),
  520.                 true /* double-sided */,
  521.                 Polygon.SOLID,
  522.                 [177, 216, 249]
  523.             ));
  524.                        
  525.                         scene.shapes['shop3Header'] = new Shape();
  526.             var ps3h = scene.shapes['shop3Header'].points; // for convenience
  527.                        
  528.             ps3h[0] = new Point(336, 400, 11);  // left  bottom
  529.             ps3h[1] = new Point(6, 400, 11);   // right bottom
  530.             ps3h[2] = new Point(6, 466, 11);    // right top  
  531.             ps3h[3] = new Point(336, 466, 11);   // left  top    
  532.  
  533.  
  534.             // Background
  535.             scene.shapes['shop3Header'].polygons.push(new Polygon(
  536.                 [ps3h[0], ps3h[1], ps3h[2], ps3h[3] ],
  537.                 new Point(0, 0, 1),
  538.                 true /* double-sided */,
  539.                 Polygon.SOLID,
  540.                 [175, 175, 175]
  541.             ));
  542.   ///////////////////////////////////// SHOP 3 END /////////////////////////////////////////////////
  543.                          
  544.   ///////////////////////////////////// SHOP 4 START //////////////////////////////////////////////                      
  545.                        
  546.                         scene.shapes['shop4'] = new Shape();
  547.             var ps4 = scene.shapes['shop4'].points; // for convenience
  548.                        
  549.             ps4[0] = new Point(-8, 66, 10);  // left  bottom
  550.             ps4[1] = new Point(-338, 66, 10);   // right bottom
  551.             ps4[2] = new Point(-338, 466, 10);    // right top  
  552.             ps4[3] = new Point(-8, 466, 10);   // left  top    
  553.  
  554.  
  555.             // Background
  556.             scene.shapes['shop4'].polygons.push(new Polygon(
  557.                 [ps4[0], ps4[1], ps4[2], ps4[3] ],
  558.                 new Point(0, 0, 1),
  559.                 true /* double-sided */,
  560.                 Polygon.SOLID,
  561.                 [177, 216, 249]
  562.             ));
  563.                        
  564.                         scene.shapes['shop4Header'] = new Shape();
  565.             var ps4h = scene.shapes['shop4Header'].points; // for convenience
  566.                        
  567.             ps4h[0] = new Point(-8, 400, 11);  // left  bottom
  568.             ps4h[1] = new Point(-338, 400, 11);   // right bottom
  569.             ps4h[2] = new Point(-338, 466, 11);    // right top  
  570.             ps4h[3] = new Point(-8, 466, 11);   // left  top    
  571.  
  572.  
  573.             // Background
  574.             scene.shapes['shop4Header'].polygons.push(new Polygon(
  575.                 [ps4h[0], ps4h[1], ps4h[2], ps4h[3] ],
  576.                 new Point(0, 0, 1),
  577.                 true /* double-sided */,
  578.                 Polygon.SOLID,
  579.                 [175, 175, 175]
  580.             ));
  581.                          
  582. ///////////////////////////////////// SHOP 4 END /////////////////////////////////////////////////
  583.                          
  584. ///////////////////////////////////// SHOP 5 START //////////////////////////////////////////////        
  585.  
  586.                         scene.shapes['shop5'] = new Shape();
  587.             var ps5 = scene.shapes['shop5'].points; // for convenience
  588.                        
  589.             ps5[0] = new Point(-352, 66, 10);  // left  bottom
  590.             ps5[1] = new Point(-682, 66, 10);   // right bottom
  591.             ps5[2] = new Point(-682, 466, 10);    // right top  
  592.             ps5[3] = new Point(-352, 466, 10);   // left  top    
  593.  
  594.  
  595.             // Background
  596.             scene.shapes['shop5'].polygons.push(new Polygon(
  597.                 [ps5[0], ps5[1], ps5[2], ps5[3] ],
  598.                 new Point(0, 0, 1),
  599.                 true /* double-sided */,
  600.                 Polygon.SOLID,
  601.                 [177, 216, 249]
  602.             ));
  603.                        
  604.                         scene.shapes['shop5Header'] = new Shape();
  605.             var ps5h = scene.shapes['shop5Header'].points; // for convenience
  606.                        
  607.             ps5h[0] = new Point(-352, 400, 11);  // left  bottom
  608.             ps5h[1] = new Point(-682, 400, 11);   // right bottom
  609.             ps5h[2] = new Point(-682, 466, 11);    // right top  
  610.             ps5h[3] = new Point(-352, 466, 11);   // left  top    
  611.  
  612.  
  613.             // Background
  614.             scene.shapes['shop5Header'].polygons.push(new Polygon(
  615.                 [ps5h[0], ps5h[1], ps5h[2], ps5h[3] ],
  616.                 new Point(0, 0, 1),
  617.                 true /* double-sided */,
  618.                 Polygon.SOLID,
  619.                 [175, 175, 175]
  620.             ));
  621.                            
  622. ///////////////////////////////////// SHOP 5 END /////////////////////////////////////////////////
  623.                            
  624. ///////////////////////////////////// SHOP 6 START //////////////////////////////////////////////                            
  625.                        
  626.                         scene.shapes['shop6'] = new Shape();
  627.             var ps6 = scene.shapes['shop6'].points; // for convenience
  628.                        
  629.             ps6[0] = new Point(-696, 66, 10);  // left  bottom
  630.             ps6[1] = new Point(-1024, 66, 10);   // right bottom
  631.             ps6[2] = new Point(-1024, 466, 10);    // right top  
  632.             ps6[3] = new Point(-696, 466, 10);   // left  top    
  633.  
  634.  
  635.             // Background
  636.             scene.shapes['shop6'].polygons.push(new Polygon(
  637.                 [ps6[0], ps6[1], ps6[2], ps6[3] ],
  638.                 new Point(0, 0, 1),
  639.                 true /* double-sided */,
  640.                 Polygon.SOLID,
  641.                 [177, 216, 249]
  642.             ));    
  643.                        
  644.                         scene.shapes['shop6Header'] = new Shape();
  645.             var ps6h = scene.shapes['shop6Header'].points; // for convenience
  646.                        
  647.             ps6h[0] = new Point(-696, 400, 11);  // left  bottom
  648.             ps6h[1] = new Point(-1024, 400, 11);   // right bottom
  649.             ps6h[2] = new Point(-1024, 466, 11);    // right top  
  650.             ps6h[3] = new Point(-696, 466, 11);   // left  top    
  651.  
  652.  
  653.             // Background
  654.             scene.shapes['shop6Header'].polygons.push(new Polygon(
  655.                 [ps6h[0], ps6h[1], ps6h[2], ps6h[3] ],
  656.                 new Point(0, 0, 1),
  657.                 true /* double-sided */,
  658.                 Polygon.SOLID,
  659.                 [175, 175, 175]
  660.             ));    
  661.  
  662. ///////////////////////////////////// SHOP 6 END /////////////////////////////////////////////////
  663.                        
  664.  
  665. /////////////////////////////////////////////////////////////////////////////////////////
  666. //////////////////////////////// END UPSTAIRS ///////////////////////////////////////////
  667. /////////////////////////////////////////////////////////////////////////////////////////
  668.  
  669. /////////////////////////////////////////////////////////////////////////////////////////
  670. ///////////////////////////////// DOWNSTAIRS //////////////////////////////////////////////
  671. /////////////////////////////////////////////////////////////////////////////////////////
  672.  
  673.             // Create a box shape and add it to the scene
  674. //          scene.shapes['shopslinedown'] = new Shape();
  675. //          var p = scene.shapes['shopslinedown'].points; // for convenience
  676. //                        
  677. //          p[0] = new Point(-245, -109, 10);  // left  bottom
  678. //          p[1] = new Point(245, -109, 10);   // right bottom
  679. //          p[2] = new Point(245, -110, 10);    // right top  
  680. //          p[3] = new Point(-245, -110, 10);   // left  top    
  681. //
  682. //
  683. //          // Line upstairs
  684. //          scene.shapes['shopslinedown'].polygons.push(new Polygon(
  685. //              [p[0], p[1], p[2], p[3] ],
  686. //              new Point(0, 0, 1),
  687. //              true /* double-sided */,
  688. //              Polygon.SOLID,
  689. //              [0, 0, 255]
  690. //          ));
  691.                            
  692.                        
  693.                                     // Create a box shape and add it to the scene
  694.             scene.shapes['shopsDownBackground'] = new Shape();
  695.             var psdb = scene.shapes['shopsDownBackground'].points; // for convenience
  696.                        
  697.             psdb[0] = new Point(-1024, -520, 9);  // left  bottom
  698.             psdb[1] = new Point(1024, -520, 9);   // right bottom
  699.             psdb[2] = new Point(1024, -50, 9);    // right top  
  700.             psdb[3] = new Point(-1024, -50, 9);   // left  top    
  701.  
  702.  
  703.             // Line upstairs
  704.             scene.shapes['shopsDownBackground'].polygons.push(new Polygon(
  705.                 [psdb[0], psdb[1], psdb[2], psdb[3] ],
  706.                 new Point(0, 0, 1),
  707.                 true /* double-sided */,
  708.                 Polygon.SOLID,
  709.                 [222, 222, 222]
  710.             ));
  711.                            
  712.  
  713. //////////////////////// SHOPS //////////////////////////////////////////
  714.  
  715. ///////////////////////////////////// SHOP 7 START //////////////////////////////////////////////
  716.  
  717.             scene.shapes['shop7'] = new Shape();
  718.             var ps7 = scene.shapes['shop7'].points; // for convenience
  719.                        
  720.             ps7[0] = new Point(1024, -510, 10);  // left  bottom
  721.             ps7[1] = new Point(694, -510, 10);   // right bottom
  722.             ps7[2] = new Point(694, -110, 10);    // right top  
  723.             ps7[3] = new Point(1024, -110, 10);   // left  top    
  724.  
  725.  
  726.             // Background
  727.             scene.shapes['shop7'].polygons.push(new Polygon(
  728.                 [ps7[0], ps7[1], ps7[2], ps7[3] ],
  729.                 new Point(0, 0, 1),
  730.                 true /* double-sided */,
  731.                 Polygon.SOLID,
  732.                 [177, 216, 249]
  733.             ));
  734.                            
  735.                         scene.shapes['shop7Header'] = new Shape();
  736.             var ps7h = scene.shapes['shop7Header'].points; // for convenience
  737.                        
  738.             ps7h[0] = new Point(1024, -176, 11);  // left  bottom
  739.             ps7h[1] = new Point(694, -176, 11);   // right bottom
  740.             ps7h[2] = new Point(694, -110, 11);    // right top  
  741.             ps7h[3] = new Point(1024, -110, 11);   // left  top    
  742.  
  743.  
  744.             // Background
  745.             scene.shapes['shop7Header'].polygons.push(new Polygon(
  746.                 [ps7h[0], ps7h[1], ps7h[2], ps7h[3] ],
  747.                 new Point(0, 0, 1),
  748.                 true /* double-sided */,
  749.                 Polygon.SOLID,
  750.                 [175, 175, 175]
  751.             ));  
  752.  
  753. ///////////////////////////////////// SHOP 7 END /////////////////////////////////////////////////
  754.  
  755. ///////////////////////////////////// SHOP 8 START //////////////////////////////////////////////
  756.  
  757.  
  758.                         scene.shapes['shop8'] = new Shape();
  759.             var ps8 = scene.shapes['shop8'].points; // for convenience
  760.                        
  761.             ps8[0] = new Point(680, -510, 10);  // left  bottom
  762.             ps8[1] = new Point(350, -510, 10);   // right bottom
  763.             ps8[2] = new Point(350, -110, 10);    // right top  
  764.             ps8[3] = new Point(680, -110, 10);   // left  top    
  765.  
  766.  
  767.             // Background
  768.             scene.shapes['shop8'].polygons.push(new Polygon(
  769.                 [ps8[0], ps8[1], ps8[2], ps8[3] ],
  770.                 new Point(0, 0, 1),
  771.                 true /* double-sided */,
  772.                 Polygon.SOLID,
  773.                 [177, 216, 249]
  774.             ));
  775.                        
  776.                         scene.shapes['shop8Header'] = new Shape();
  777.             var ps8h = scene.shapes['shop8Header'].points; // for convenience
  778.                        
  779.             ps8h[0] = new Point(680, -176, 11);  // left  bottom
  780.             ps8h[1] = new Point(350, -176, 11);   // right bottom
  781.             ps8h[2] = new Point(350, -110, 11);    // right top  
  782.             ps8h[3] = new Point(680, -110, 11);   // left  top    
  783.  
  784.  
  785.             // Background
  786.             scene.shapes['shop8Header'].polygons.push(new Polygon(
  787.                 [ps8h[0], ps8h[1], ps8h[2], ps8h[3] ],
  788.                 new Point(0, 0, 1),
  789.                 true /* double-sided */,
  790.                 Polygon.SOLID,
  791.                 [175, 175, 175]
  792.             ));  
  793. ///////////////////////////////////// SHOP 8 END /////////////////////////////////////////////////
  794.  
  795. /////////////////////////////////////  STAIRS /////////////////////////////////////////                        
  796.                         scene.shapes['stairsRailLeft'] = new Shape();
  797.             var pstrl = scene.shapes['stairsRailLeft'].points; // for convenience
  798.                          
  799.                         pstrl[0] = new Point(338, -520, 11);  // left  bottom
  800.             pstrl[1] = new Point(334, -520, 11);   // right bottom
  801.             pstrl[2] = new Point(334, 250, 11);    // right top  
  802.             pstrl[3] = new Point(338, 250, 11);   // left  top
  803.  
  804.  
  805.             // Strairs background
  806.             scene.shapes['stairsRailLeft'].polygons.push(new Polygon(
  807.                 [pstrl[0], pstrl[1], pstrl[2], pstrl[3] ],
  808.                 new Point(0, 0, 1),
  809.                 true /* double-sided */,
  810.                 Polygon.SOLID,
  811.                 [50, 50, 50]
  812.             ));
  813.                            
  814.                         scene.shapes['stairsBackground'] = new Shape();
  815.             var pstb = scene.shapes['stairsBackground'].points; // for convenience
  816.                          
  817.                         pstb[0] = new Point(334, -520, 10);  // left  bottom
  818.             pstb[1] = new Point(-336, -520, 10);   // right bottom
  819.             pstb[2] = new Point(-336, 56, 10);    // right top  
  820.             pstb[3] = new Point(334, 56, 10);   // left  top
  821.                        
  822.             // Strairs background
  823.             scene.shapes['stairsBackground'].polygons.push(new Polygon(
  824.                 [pstb[0], pstb[1], pstb[2], pstb[3] ],
  825.                 new Point(0, 0, 1),
  826.                 true /* double-sided */,
  827.                 Polygon.SOLID,
  828.                 [240, 240, 240]
  829.             ));
  830.                        
  831.                         scene.shapes['stairsRailCenter1'] = new Shape();
  832.             var pstrc1 = scene.shapes['stairsRailCenter1'].points; // for convenience
  833.                          
  834.                         pstrc1[0] = new Point(1, -520, 11);  // left  bottom
  835.             pstrc1[1] = new Point(0, -520, 11);   // right bottom
  836.             pstrc1[2] = new Point(0, 250, 11);    // right top  
  837.             pstrc1[3] = new Point(1, 250, 11);   // left  top
  838.  
  839.             // Strairs background
  840.             scene.shapes['stairsRailCenter1'].polygons.push(new Polygon(
  841.                 [pstrc1[0], pstrc1[1], pstrc1[2], pstrc1[3] ],
  842.                 new Point(0, 0, 1),
  843.                 true /* double-sided */,
  844.                 Polygon.SOLID,
  845.                 [50, 50, 50]
  846.             ));  
  847.                          
  848.                         scene.shapes['stairsRailCenter2'] = new Shape();
  849.             var pstrc2 = scene.shapes['stairsRailCenter2'].points; // for convenience
  850.                          
  851.                         pstrc2[0] = new Point(-3, -520, 11);  // left  bottom
  852.             pstrc2[1] = new Point(-4, -520, 11);   // right bottom
  853.             pstrc2[2] = new Point(-4, 250, 11);    // right top  
  854.             pstrc2[3] = new Point(-3, 250, 11);   // left  top
  855.  
  856.             // Strairs background
  857.             scene.shapes['stairsRailCenter2'].polygons.push(new Polygon(
  858.                 [pstrc2[0], pstrc2[1], pstrc2[2], pstrc2[3] ],
  859.                 new Point(0, 0, 1),
  860.                 true /* double-sided */,
  861.                 Polygon.SOLID,
  862.                 [50, 50, 50]
  863.             ));  
  864.                            
  865.                         scene.shapes['stairsRailRight'] = new Shape();
  866.             var pstrr = scene.shapes['stairsRailRight'].points; // for convenience
  867.                          
  868.                         pstrr[0] = new Point(-336, -520, 11);  // left  bottom
  869.             pstrr[1] = new Point(-340, -520, 11);   // right bottom
  870.             pstrr[2] = new Point(-340, 250, 11);    // right top  
  871.             pstrr[3] = new Point(-336, 250, 11);   // left  top
  872.  
  873.             // Strairs background
  874.             scene.shapes['stairsRailRight'].polygons.push(new Polygon(
  875.                 [pstrr[0], pstrr[1], pstrr[2], pstrr[3] ],
  876.                 new Point(0, 0, 1),
  877.                 true /* double-sided */,
  878.                 Polygon.SOLID,
  879.                 [50, 50, 50]
  880.             ));        
  881.  
  882. /////////////////////////////////////  STAIRS END /////////////////////////////////////////
  883.  
  884.  
  885. ///////////////////////////////////// SHOP 9 START //////////////////////////////////////////////
  886.  
  887.                         scene.shapes['shop9'] = new Shape();
  888.             var ps9 = scene.shapes['shop9'].points; // for convenience
  889.                        
  890.             ps9[0] = new Point(-352, -510, 10);  // left  bottom
  891.             ps9[1] = new Point(-682, -510, 10);   // right bottom
  892.             ps9[2] = new Point(-682, -110, 10);    // right top  
  893.             ps9[3] = new Point(-352, -110, 10);   // left  top    
  894.  
  895.  
  896.             // Background
  897.             scene.shapes['shop9'].polygons.push(new Polygon(
  898.                 [ps9[0], ps9[1], ps9[2], ps9[3] ],
  899.                 new Point(0, 0, 1),
  900.                 true /* double-sided */,
  901.                 Polygon.SOLID,
  902.                 [177, 216, 249]
  903.             ));
  904.                          
  905.                         scene.shapes['shop9Header'] = new Shape();
  906.             var ps9h = scene.shapes['shop9Header'].points; // for convenience
  907.                        
  908.             ps9h[0] = new Point(-352, -176, 11);  // left  bottom
  909.             ps9h[1] = new Point(-682, -176, 11);   // right bottom
  910.             ps9h[2] = new Point(-682, -110, 11);    // right top  
  911.             ps9h[3] = new Point(-352, -110, 11);   // left  top    
  912.  
  913.  
  914.             // Background
  915.             scene.shapes['shop9Header'].polygons.push(new Polygon(
  916.                 [ps9h[0], ps9h[1], ps9h[2], ps9h[3] ],
  917.                 new Point(0, 0, 1),
  918.                 true /* double-sided */,
  919.                 Polygon.SOLID,
  920.                 [175, 175, 175]
  921.             ));  
  922.                            
  923. ///////////////////////////////////// SHOP 9 END /////////////////////////////////////////////////
  924.                            
  925. ///////////////////////////////////// SHOP 10 START //////////////////////////////////////////////    
  926.  
  927.                         scene.shapes['shop10'] = new Shape();
  928.             var ps10 = scene.shapes['shop10'].points; // for convenience
  929.                        
  930.             ps10[0] = new Point(-696, -510, 11);  // left  bottom
  931.             ps10[1] = new Point(-1024, -510, 11);   // right bottom
  932.             ps10[2] = new Point(-1024, -110, 11);    // right top  
  933.             ps10[3] = new Point(-696, -110, 11);   // left  top    
  934.  
  935.  
  936.             // Background
  937.             scene.shapes['shop10'].polygons.push(new Polygon(
  938.                 [ps10[0], ps10[1], ps10[2], ps10[3] ],
  939.                 new Point(0, 0, 1),
  940.                 true /* double-sided */,
  941.                 Polygon.SOLID,
  942.                 [177, 216, 249]
  943.             ));    
  944.  
  945.                         scene.shapes['shop10Header'] = new Shape();
  946.             var ps10h = scene.shapes['shop10Header'].points; // for convenience
  947.                        
  948.             ps10h[0] = new Point(-696, -176, 11);  // left  bottom
  949.             ps10h[1] = new Point(-1024, -176, 11);   // right bottom
  950.             ps10h[2] = new Point(-1024, -110, 11);    // right top  
  951.             ps10h[3] = new Point(-696, -110, 11);   // left  top    
  952.  
  953.  
  954.             // Background
  955.             scene.shapes['shop10Header'].polygons.push(new Polygon(
  956.                 [ps10h[0], ps10h[1], ps10h[2], ps10h[3] ],
  957.                 new Point(0, 0, 1),
  958.                 true /* double-sided */,
  959.                 Polygon.SOLID,
  960.                 [175, 175, 175]
  961.             ));
  962.  
  963. ///////////////////////////////////// SHOP 10 END ////////////////////////////////////////////////
  964.  
  965.  
  966. //
  967. //                        scene.shapes['shop11'] = new Shape();
  968. //          var ps11 = scene.shapes['shop11'].points; // for convenience
  969. //                        
  970. ////            ps11[0] = new Point(336, -510, 10);  // left  bottom
  971. ////            ps11[1] = new Point(6, -510, 10);   // right bottom
  972. ////            ps11[2] = new Point(6, -110, 10);    // right top  
  973. ////            ps11[3] = new Point(336, -110, 10);   // left  top    
  974. //                  ps11[0] = new Point(5000, 5000, 5000);  // left  bottom
  975. //          ps11[1] = new Point(5000, 5000, 5000);   // right bottom
  976. //          ps11[2] = new Point(5000, 5000, 5000);    // right top  
  977. //          ps11[3] = new Point(5000, 5000, 5000);   // left  top  
  978. //
  979. //          // Shops background
  980. //          scene.shapes['shop11'].polygons.push(new Polygon(
  981. //              [ps11[0], ps11[1], ps11[2], ps11[3] ],
  982. //              new Point(0, 0, 1),
  983. //              true /* double-sided */,
  984. //              Polygon.SOLID,
  985. //              [177, 216, 249]
  986. //          ));
  987. //                            
  988. //                        scene.shapes['shop12'] = new Shape();
  989. //          var ps12 = scene.shapes['shop12'].points; // for convenience
  990. //                        
  991. ////            ps12[0] = new Point(-8, -510, 10);  // left  bottom
  992. ////            ps12[1] = new Point(-338, -510, 10);   // right bottom
  993. ////            ps12[2] = new Point(-338, -110, 10);    // right top  
  994. ////            ps12[3] = new Point(-8, -110, 10);   // left  top    
  995. //                        ps12[0] = new Point(5001, 5001, 5001);  // left  bottom
  996. //          ps12[1] = new Point(5001, 5001, 5001);   // right bottom
  997. //          ps12[2] = new Point(5001, 5001, 5001);    // right top  
  998. //          ps12[3] = new Point(5001, 5001, 5001);   // left  top
  999. //
  1000. //          // Shops background
  1001. //          scene.shapes['shop12'].polygons.push(new Polygon(
  1002. //              [ps12[0], ps12[1], ps12[2], ps12[3] ],
  1003. //              new Point(0, 0, 1),
  1004. //              true /* double-sided */,
  1005. //              Polygon.SOLID,
  1006. //              [177, 216, 249]
  1007. //          ));
  1008. /////////////////////////////////////////////////////////////////////////////////////////
  1009. //////////////////////////////// END DOWNSTAIRS ///////////////////////////////////////////
  1010. /////////////////////////////////////////////////////////////////////////////////////////
  1011.  
  1012.  
  1013.  
  1014. loop();
  1015.         }
  1016.  
  1017.         /* -------------------------------------------------------------------- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement