Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -------------------------------------------------------------------- */
- var canvas, ctx;
- var canvasWidth, halfCanvasWidth;
- var canvasHeight, halfCanvasHeight;
- var space; // 3D Engine
- var scene; // 3D Scene
- /* -------------------------------------------------------------------- */
- /**
- * Space is a simple 3D system.
- *
- * Y+ = up
- * Z+ = into screen
- * X+ = right
- */
- function Space() {
- this.m = this.createMatrixIdentity();
- this.mStack = [];
- }
- Space.prototype.createMatrixIdentity = function() {
- return [
- [1, 0, 0, 0],
- [0, 1, 0, 0],
- [0, 0, 1, 0],
- [0, 0, 0, 1]
- ];
- }
- /**
- * Multiplies two 4x4 matricies together.
- */
- Space.prototype.matrixMultiply = function(m1, m2) {
- var result = this.createMatrixIdentity();
- var width = m1[0].length;
- var height = m1.length;
- if (width != m2.length) {
- // error
- }
- for (var x = 0; x < width; x++) {
- for (var y = 0; y < height; y++) {
- var sum = 0;
- for (var z = 0; z < width; z++) {
- sum += m1[y][z] * m2[z][x];
- }
- result[y][x] = sum;
- }
- }
- return result;
- }
- /**
- * Transforms a coordinate using the current transformation
- * matrix, then flattens it using the projection matrix.
- */
- Space.prototype.flatten = function(point) {
- var p = [[point.x, point.y, point.z, 1]];
- var pm = this.matrixMultiply(p, this.m);
- point.tx = pm[0][0];
- point.ty = pm[0][1];
- point.tz = pm[0][2];
- // lazy projection
- point.fx = halfCanvasWidth + (canvasWidth * point.tx / point.tz);
- point.fy = halfCanvasHeight -(canvasWidth * point.ty / point.tz);
- }
- /**
- * Translate (move) the current transformation matrix
- */
- Space.prototype.translate = function(x, y, z) {
- var m = [
- [1, 0, 0, 0],
- [0, 1, 0, 0],
- [0, 0, 1, 0],
- [x, y, z, 1]
- ];
- this.m = this.matrixMultiply(m, this.m);
- }
- /**
- * Rotate the current transformation matrix. Rotations are
- * world-oriented, and occur in y,x,z order.
- */
- Space.prototype.rotate = function(x, y, z) {
- if (y) {
- var cosY = Math.cos(y);
- var sinY = Math.sin(y);
- var rotY = [
- [cosY, 0, sinY, 0],
- [0, 1, 0, 0],
- [-sinY, 0, cosY, 0],
- [0, 0, 0, 1]
- ];
- this.m = this.matrixMultiply(this.m, rotY);
- }
- if (x) {
- var cosX = Math.cos(x);
- var sinX = Math.sin(x);
- var rotX = [
- [1, 0, 0, 0],
- [0, cosX, -sinX, 0],
- [0, sinX, cosX,0],
- [0, 0, 0, 1]
- ];
- this.m = this.matrixMultiply(this.m, rotX);
- }
- if (z) {
- var cosZ = Math.cos(z);
- var sinZ = Math.sin(z);
- var rotZ = [
- [cosZ, -sinZ, 0, 0],
- [sinZ, cosZ, 0, 0],
- [0, 0, 1, 0],
- [0, 0, 0, 1]
- ];
- this.m = this.matrixMultiply(this.m, rotZ);
- }
- }
- /**
- * Pushes the current transformation onto the stack
- */
- Space.prototype.push = function() {
- this.mStack.push(this.m);
- this.m = [
- [this.m[0][0], this.m[0][1], this.m[0][2], this.m[0][3]],
- [this.m[1][0], this.m[1][1], this.m[1][2], this.m[1][3]],
- [this.m[2][0], this.m[2][1], this.m[2][2], this.m[2][3]],
- [this.m[3][0], this.m[3][1], this.m[3][2], this.m[3][3]]
- ];
- }
- /**
- * Pops the end off the transformation stack
- */
- Space.prototype.pop = function() {
- this.m = this.mStack.pop();
- }
- /* -------------------------------------------------------------------- */
- /**
- * A 3d coordinate
- */
- function Point(x, y, z) {
- this.x = x;
- this.y = y;
- this.z = z;
- // Relative to camera coordinates
- this.tx;
- this.ty;
- this.tz;
- // Flattened coordinates
- this.fx;
- this.fy;
- }
- /**
- * A Shape is made up of polygons
- */
- function Shape() {
- this.points = [];
- this.polygons = [];
- }
- /**
- * Draws the shape
- */
- Shape.prototype.draw = function(drawlist) {
- for (var i = 0; i< this.points.length; i++) {
- space.flatten(this.points[i]);
- }
- for (var i = 0; i< this.polygons.length; i++) {
- var poly = this.polygons[i]; // convenience
- space.flatten(poly.origin);
- // lazy backface culling
- if (poly.normal && this.backface) {
- space.flatten(poly.normal);
- var originDist = Math.pow(poly.origin.tx, 2)
- + Math.pow(poly.origin.ty, 2)
- + Math.pow(poly.origin.tz, 2);
- var normalDist = Math.pow(poly.normal.tx, 2)
- + Math.pow(poly.normal.ty, 2)
- + Math.pow(poly.normal.tz, 2);
- if(originDist > normalDist) {
- drawlist.push(poly);
- }
- } else {
- drawlist.push(poly);
- }
- }
- }
- /**
- * A polygon is a connection of points in the shape object. You
- * should probably try to make them coplanar.
- */
- function Polygon(points, normal, backface, type, color) {
- this.points = points;
- this.origin = new Point(0, 0, 0);
- for(var i = 0; i < this.points.length; i++) {
- this.origin.x += this.points[i].x;
- this.origin.y += this.points[i].y;
- this.origin.z += this.points[i].z;
- }
- this.origin.x /= this.points.length;
- this.origin.y /= this.points.length;
- this.origin.z /= this.points.length;
- if (normal) {
- this.normal = new Point(this.origin.x + normal.x,
- this.origin.y + normal.y,
- this.origin.z + normal.z);
- } else {
- this.normal = null;
- }
- this.backface = backface;
- this.type = type;
- this.color = color;
- }
- Polygon.SOLID = 0;
- Polygon.WIRE = 1;
- /**
- * Draws the polygon. Assumes that the points have already been
- * flattened.
- */
- Polygon.prototype.draw = function() {
- ctx.beginPath();
- ctx.moveTo(this.points[0].fx, this.points[0].fy);
- for(var i = 0; i < this.points.length; i++) {
- ctx.lineTo(this.points[i].fx, this.points[i].fy);
- }
- ctx.closePath();
- var color = this.color;
- /*
- // Do lighting here
- lightvector = Math.abs(this.normal.x + this.normal.y);
- if(lightvector > 1) {
- lightvector = 1;
- }
- color[0] = (color[0] * lightvector).toString();
- color[1] = (color[1] * lightvector).toString();
- color[2] = (color[2] * lightvector).toString();
- */
- if (color.length > 3) {
- var style = ["rgba(",
- color[0], ",",
- color[1], ",",
- color[2], ",",
- color[3], ")"].join("");
- } else {
- var style = ["rgb(",
- color[0], ",",
- color[1], ",",
- color[2], ")"].join("");
- }
- if (this.type == Polygon.SOLID) {
- ctx.fillStyle = style;
- ctx.fill();
- } else if (this.type == Polygon.WIRE) {
- ctx.strokeStyle = style;
- ctx.stroke();
- }
- }
- /* -------------------------------------------------------------------- */
- /**
- * Scene describes the 3D environment
- */
- function Scene() {
- this.shapes = {};
- this.camera = new Point(0, 0, 0);
- this.cameraTarget = new Point(0, 0, 0);
- this.cameraRotation = 0;
- this.drawlist = [];
- }
- /**
- * Draw the world
- */
- Scene.prototype.draw = function() {
- space.push();
- // Camera transformation
- space.translate(
- -this.camera.x,
- -this.camera.y,
- -this.camera.z
- );
- // Camera rotation
- var xdiff = this.cameraTarget.x - this.camera.x;
- var ydiff = this.cameraTarget.y - this.camera.y;
- var zdiff = this.cameraTarget.z - this.camera.z;
- var xzdist = Math.sqrt(Math.pow(xdiff, 2) + Math.pow(zdiff, 2));
- var xrot = -Math.atan2(ydiff, xzdist); // up/down rotation
- var yrot = Math.atan2(xdiff, zdiff); // left/right rotation
- space.rotate(xrot, yrot, this.cameraRotation);
- // Drawing
- this.drawlist = [];
- for(var i in this.shapes) {
- this.shapes[i].draw(this.drawlist);
- }
- // Depth sorting (warning: this is only enough to drive this demo - feel
- // free to contribute a better system).
- this.drawlist.sort(function (poly1, poly2) {
- return poly2.origin.tz - poly1.origin.tz;
- });
- for (var i = 0; i < this.drawlist.length; i++) {
- this.drawlist[i].draw();
- }
- space.pop();
- }
- /* -------------------------------------------------------------------- */
- var count = 0;
- function loop() {
- ctx.clearRect(0, 0, canvasWidth, canvasHeight);
- // scene.camera.x = 70*Math.sin(count);
- // scene.camera.y = 70;
- // scene.camera.z = 70*Math.cos(count);
- // scene.cameraRotation = count / 10;
- scene.camera.x = 0;
- scene.camera.y = 0;
- scene.camera.z = 2048;
- count += 0.01;
- scene.draw();
- }
- function load() {
- // Init drawing system
- canvas = document.getElementById("cv");
- ctx = canvas.getContext("2d");
- canvasWidth = canvas.width;
- canvasHeight = canvas.height;
- halfCanvasWidth = canvasWidth * 0.5;
- halfCanvasHeight = canvasHeight * 0.5;
- // Init 3D components
- space = new Space();
- scene = new Scene();
- /////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////// UPSTRAIRS //////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- ctx.font = "30px Calibri"; // vložení textu
- ctx.fillText("Hello World", 200, 20);
- // Create a box shape and add it to the scene
- scene.shapes['shopsUpBackground'] = new Shape();
- var psub = scene.shapes['shopsUpBackground'].points; // for convenience
- psub[0] = new Point(-1024, 56, 9); // left bottom
- psub[1] = new Point(1024, 56, 9); // right bottom
- psub[2] = new Point(1024, 526, 9); // right top
- psub[3] = new Point(-1024, 526, 9); // left top
- // Shops background
- scene.shapes['shopsUpBackground'].polygons.push(new Polygon(
- [psub[0], psub[1], psub[2], psub[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [222, 222, 222]
- ));
- //////////////////////// SHOPS //////////////////////////////////////////
- ///////////////////////////////////// SHOP 1 START //////////////////////////////////////////////
- scene.shapes['shop1'] = new Shape();
- var ps1 = scene.shapes['shop1'].points; // for convenience
- ps1[0] = new Point(1024, 66, 10); // left bottom
- ps1[1] = new Point(694, 66, 10); // right bottom
- ps1[2] = new Point(694, 466, 10); // right top
- ps1[3] = new Point(1024, 466, 10); // left top
- // Background
- scene.shapes['shop1'].polygons.push(new Polygon(
- [ps1[0], ps1[1], ps1[2], ps1[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop1Header'] = new Shape();
- var ps1h = scene.shapes['shop1Header'].points; // for convenience
- ps1h[0] = new Point(1024, 400, 11); // left bottom
- ps1h[1] = new Point(694, 400, 11); // right bottom
- ps1h[2] = new Point(694, 466, 11); // right top
- ps1h[3] = new Point(1024, 466, 11); // left top
- // Background
- scene.shapes['shop1Header'].polygons.push(new Polygon(
- [ps1h[0], ps1h[1], ps1h[2], ps1h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 1 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 2 START //////////////////////////////////////////////
- scene.shapes['shop2'] = new Shape();
- var ps2 = scene.shapes['shop2'].points; // for convenience
- ps2[0] = new Point(680, 66, 10); // left bottom
- ps2[1] = new Point(350, 66, 10); // right bottom
- ps2[2] = new Point(350, 466, 10); // right top
- ps2[3] = new Point(680, 466, 10); // left top
- // Background
- scene.shapes['shop2'].polygons.push(new Polygon(
- [ps2[0], ps2[1], ps2[2], ps2[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop2Header'] = new Shape();
- var ps2h = scene.shapes['shop2Header'].points; // for convenience
- ps2h[0] = new Point(680, 400, 11); // left bottom
- ps2h[1] = new Point(350, 400, 11); // right bottom
- ps2h[2] = new Point(350, 466, 11); // right top
- ps2h[3] = new Point(680, 466, 11); // left top
- // Background
- scene.shapes['shop2Header'].polygons.push(new Polygon(
- [ps2h[0], ps2h[1], ps2h[2], ps2h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 2 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 3 START //////////////////////////////////////////////
- scene.shapes['shop3'] = new Shape();
- var ps3 = scene.shapes['shop3'].points; // for convenience
- ps3[0] = new Point(336, 66, 10); // left bottom
- ps3[1] = new Point(6, 66, 10); // right bottom
- ps3[2] = new Point(6, 466, 10); // right top
- ps3[3] = new Point(336, 466, 10); // left top
- // Background
- scene.shapes['shop3'].polygons.push(new Polygon(
- [ps3[0], ps3[1], ps3[2], ps3[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop3Header'] = new Shape();
- var ps3h = scene.shapes['shop3Header'].points; // for convenience
- ps3h[0] = new Point(336, 400, 11); // left bottom
- ps3h[1] = new Point(6, 400, 11); // right bottom
- ps3h[2] = new Point(6, 466, 11); // right top
- ps3h[3] = new Point(336, 466, 11); // left top
- // Background
- scene.shapes['shop3Header'].polygons.push(new Polygon(
- [ps3h[0], ps3h[1], ps3h[2], ps3h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 3 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 4 START //////////////////////////////////////////////
- scene.shapes['shop4'] = new Shape();
- var ps4 = scene.shapes['shop4'].points; // for convenience
- ps4[0] = new Point(-8, 66, 10); // left bottom
- ps4[1] = new Point(-338, 66, 10); // right bottom
- ps4[2] = new Point(-338, 466, 10); // right top
- ps4[3] = new Point(-8, 466, 10); // left top
- // Background
- scene.shapes['shop4'].polygons.push(new Polygon(
- [ps4[0], ps4[1], ps4[2], ps4[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop4Header'] = new Shape();
- var ps4h = scene.shapes['shop4Header'].points; // for convenience
- ps4h[0] = new Point(-8, 400, 11); // left bottom
- ps4h[1] = new Point(-338, 400, 11); // right bottom
- ps4h[2] = new Point(-338, 466, 11); // right top
- ps4h[3] = new Point(-8, 466, 11); // left top
- // Background
- scene.shapes['shop4Header'].polygons.push(new Polygon(
- [ps4h[0], ps4h[1], ps4h[2], ps4h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 4 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 5 START //////////////////////////////////////////////
- scene.shapes['shop5'] = new Shape();
- var ps5 = scene.shapes['shop5'].points; // for convenience
- ps5[0] = new Point(-352, 66, 10); // left bottom
- ps5[1] = new Point(-682, 66, 10); // right bottom
- ps5[2] = new Point(-682, 466, 10); // right top
- ps5[3] = new Point(-352, 466, 10); // left top
- // Background
- scene.shapes['shop5'].polygons.push(new Polygon(
- [ps5[0], ps5[1], ps5[2], ps5[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop5Header'] = new Shape();
- var ps5h = scene.shapes['shop5Header'].points; // for convenience
- ps5h[0] = new Point(-352, 400, 11); // left bottom
- ps5h[1] = new Point(-682, 400, 11); // right bottom
- ps5h[2] = new Point(-682, 466, 11); // right top
- ps5h[3] = new Point(-352, 466, 11); // left top
- // Background
- scene.shapes['shop5Header'].polygons.push(new Polygon(
- [ps5h[0], ps5h[1], ps5h[2], ps5h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 5 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 6 START //////////////////////////////////////////////
- scene.shapes['shop6'] = new Shape();
- var ps6 = scene.shapes['shop6'].points; // for convenience
- ps6[0] = new Point(-696, 66, 10); // left bottom
- ps6[1] = new Point(-1024, 66, 10); // right bottom
- ps6[2] = new Point(-1024, 466, 10); // right top
- ps6[3] = new Point(-696, 466, 10); // left top
- // Background
- scene.shapes['shop6'].polygons.push(new Polygon(
- [ps6[0], ps6[1], ps6[2], ps6[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop6Header'] = new Shape();
- var ps6h = scene.shapes['shop6Header'].points; // for convenience
- ps6h[0] = new Point(-696, 400, 11); // left bottom
- ps6h[1] = new Point(-1024, 400, 11); // right bottom
- ps6h[2] = new Point(-1024, 466, 11); // right top
- ps6h[3] = new Point(-696, 466, 11); // left top
- // Background
- scene.shapes['shop6Header'].polygons.push(new Polygon(
- [ps6h[0], ps6h[1], ps6h[2], ps6h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 6 END /////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////// END UPSTAIRS ///////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////// DOWNSTAIRS //////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- // Create a box shape and add it to the scene
- // scene.shapes['shopslinedown'] = new Shape();
- // var p = scene.shapes['shopslinedown'].points; // for convenience
- //
- // p[0] = new Point(-245, -109, 10); // left bottom
- // p[1] = new Point(245, -109, 10); // right bottom
- // p[2] = new Point(245, -110, 10); // right top
- // p[3] = new Point(-245, -110, 10); // left top
- //
- //
- // // Line upstairs
- // scene.shapes['shopslinedown'].polygons.push(new Polygon(
- // [p[0], p[1], p[2], p[3] ],
- // new Point(0, 0, 1),
- // true /* double-sided */,
- // Polygon.SOLID,
- // [0, 0, 255]
- // ));
- // Create a box shape and add it to the scene
- scene.shapes['shopsDownBackground'] = new Shape();
- var psdb = scene.shapes['shopsDownBackground'].points; // for convenience
- psdb[0] = new Point(-1024, -520, 9); // left bottom
- psdb[1] = new Point(1024, -520, 9); // right bottom
- psdb[2] = new Point(1024, -50, 9); // right top
- psdb[3] = new Point(-1024, -50, 9); // left top
- // Line upstairs
- scene.shapes['shopsDownBackground'].polygons.push(new Polygon(
- [psdb[0], psdb[1], psdb[2], psdb[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [222, 222, 222]
- ));
- //////////////////////// SHOPS //////////////////////////////////////////
- ///////////////////////////////////// SHOP 7 START //////////////////////////////////////////////
- scene.shapes['shop7'] = new Shape();
- var ps7 = scene.shapes['shop7'].points; // for convenience
- ps7[0] = new Point(1024, -510, 10); // left bottom
- ps7[1] = new Point(694, -510, 10); // right bottom
- ps7[2] = new Point(694, -110, 10); // right top
- ps7[3] = new Point(1024, -110, 10); // left top
- // Background
- scene.shapes['shop7'].polygons.push(new Polygon(
- [ps7[0], ps7[1], ps7[2], ps7[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop7Header'] = new Shape();
- var ps7h = scene.shapes['shop7Header'].points; // for convenience
- ps7h[0] = new Point(1024, -176, 11); // left bottom
- ps7h[1] = new Point(694, -176, 11); // right bottom
- ps7h[2] = new Point(694, -110, 11); // right top
- ps7h[3] = new Point(1024, -110, 11); // left top
- // Background
- scene.shapes['shop7Header'].polygons.push(new Polygon(
- [ps7h[0], ps7h[1], ps7h[2], ps7h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 7 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 8 START //////////////////////////////////////////////
- scene.shapes['shop8'] = new Shape();
- var ps8 = scene.shapes['shop8'].points; // for convenience
- ps8[0] = new Point(680, -510, 10); // left bottom
- ps8[1] = new Point(350, -510, 10); // right bottom
- ps8[2] = new Point(350, -110, 10); // right top
- ps8[3] = new Point(680, -110, 10); // left top
- // Background
- scene.shapes['shop8'].polygons.push(new Polygon(
- [ps8[0], ps8[1], ps8[2], ps8[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop8Header'] = new Shape();
- var ps8h = scene.shapes['shop8Header'].points; // for convenience
- ps8h[0] = new Point(680, -176, 11); // left bottom
- ps8h[1] = new Point(350, -176, 11); // right bottom
- ps8h[2] = new Point(350, -110, 11); // right top
- ps8h[3] = new Point(680, -110, 11); // left top
- // Background
- scene.shapes['shop8Header'].polygons.push(new Polygon(
- [ps8h[0], ps8h[1], ps8h[2], ps8h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 8 END /////////////////////////////////////////////////
- ///////////////////////////////////// STAIRS /////////////////////////////////////////
- scene.shapes['stairsRailLeft'] = new Shape();
- var pstrl = scene.shapes['stairsRailLeft'].points; // for convenience
- pstrl[0] = new Point(338, -520, 11); // left bottom
- pstrl[1] = new Point(334, -520, 11); // right bottom
- pstrl[2] = new Point(334, 250, 11); // right top
- pstrl[3] = new Point(338, 250, 11); // left top
- // Strairs background
- scene.shapes['stairsRailLeft'].polygons.push(new Polygon(
- [pstrl[0], pstrl[1], pstrl[2], pstrl[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [50, 50, 50]
- ));
- scene.shapes['stairsBackground'] = new Shape();
- var pstb = scene.shapes['stairsBackground'].points; // for convenience
- pstb[0] = new Point(334, -520, 10); // left bottom
- pstb[1] = new Point(-336, -520, 10); // right bottom
- pstb[2] = new Point(-336, 56, 10); // right top
- pstb[3] = new Point(334, 56, 10); // left top
- // Strairs background
- scene.shapes['stairsBackground'].polygons.push(new Polygon(
- [pstb[0], pstb[1], pstb[2], pstb[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [240, 240, 240]
- ));
- scene.shapes['stairsRailCenter1'] = new Shape();
- var pstrc1 = scene.shapes['stairsRailCenter1'].points; // for convenience
- pstrc1[0] = new Point(1, -520, 11); // left bottom
- pstrc1[1] = new Point(0, -520, 11); // right bottom
- pstrc1[2] = new Point(0, 250, 11); // right top
- pstrc1[3] = new Point(1, 250, 11); // left top
- // Strairs background
- scene.shapes['stairsRailCenter1'].polygons.push(new Polygon(
- [pstrc1[0], pstrc1[1], pstrc1[2], pstrc1[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [50, 50, 50]
- ));
- scene.shapes['stairsRailCenter2'] = new Shape();
- var pstrc2 = scene.shapes['stairsRailCenter2'].points; // for convenience
- pstrc2[0] = new Point(-3, -520, 11); // left bottom
- pstrc2[1] = new Point(-4, -520, 11); // right bottom
- pstrc2[2] = new Point(-4, 250, 11); // right top
- pstrc2[3] = new Point(-3, 250, 11); // left top
- // Strairs background
- scene.shapes['stairsRailCenter2'].polygons.push(new Polygon(
- [pstrc2[0], pstrc2[1], pstrc2[2], pstrc2[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [50, 50, 50]
- ));
- scene.shapes['stairsRailRight'] = new Shape();
- var pstrr = scene.shapes['stairsRailRight'].points; // for convenience
- pstrr[0] = new Point(-336, -520, 11); // left bottom
- pstrr[1] = new Point(-340, -520, 11); // right bottom
- pstrr[2] = new Point(-340, 250, 11); // right top
- pstrr[3] = new Point(-336, 250, 11); // left top
- // Strairs background
- scene.shapes['stairsRailRight'].polygons.push(new Polygon(
- [pstrr[0], pstrr[1], pstrr[2], pstrr[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [50, 50, 50]
- ));
- ///////////////////////////////////// STAIRS END /////////////////////////////////////////
- ///////////////////////////////////// SHOP 9 START //////////////////////////////////////////////
- scene.shapes['shop9'] = new Shape();
- var ps9 = scene.shapes['shop9'].points; // for convenience
- ps9[0] = new Point(-352, -510, 10); // left bottom
- ps9[1] = new Point(-682, -510, 10); // right bottom
- ps9[2] = new Point(-682, -110, 10); // right top
- ps9[3] = new Point(-352, -110, 10); // left top
- // Background
- scene.shapes['shop9'].polygons.push(new Polygon(
- [ps9[0], ps9[1], ps9[2], ps9[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop9Header'] = new Shape();
- var ps9h = scene.shapes['shop9Header'].points; // for convenience
- ps9h[0] = new Point(-352, -176, 11); // left bottom
- ps9h[1] = new Point(-682, -176, 11); // right bottom
- ps9h[2] = new Point(-682, -110, 11); // right top
- ps9h[3] = new Point(-352, -110, 11); // left top
- // Background
- scene.shapes['shop9Header'].polygons.push(new Polygon(
- [ps9h[0], ps9h[1], ps9h[2], ps9h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 9 END /////////////////////////////////////////////////
- ///////////////////////////////////// SHOP 10 START //////////////////////////////////////////////
- scene.shapes['shop10'] = new Shape();
- var ps10 = scene.shapes['shop10'].points; // for convenience
- ps10[0] = new Point(-696, -510, 11); // left bottom
- ps10[1] = new Point(-1024, -510, 11); // right bottom
- ps10[2] = new Point(-1024, -110, 11); // right top
- ps10[3] = new Point(-696, -110, 11); // left top
- // Background
- scene.shapes['shop10'].polygons.push(new Polygon(
- [ps10[0], ps10[1], ps10[2], ps10[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [177, 216, 249]
- ));
- scene.shapes['shop10Header'] = new Shape();
- var ps10h = scene.shapes['shop10Header'].points; // for convenience
- ps10h[0] = new Point(-696, -176, 11); // left bottom
- ps10h[1] = new Point(-1024, -176, 11); // right bottom
- ps10h[2] = new Point(-1024, -110, 11); // right top
- ps10h[3] = new Point(-696, -110, 11); // left top
- // Background
- scene.shapes['shop10Header'].polygons.push(new Polygon(
- [ps10h[0], ps10h[1], ps10h[2], ps10h[3] ],
- new Point(0, 0, 1),
- true /* double-sided */,
- Polygon.SOLID,
- [175, 175, 175]
- ));
- ///////////////////////////////////// SHOP 10 END ////////////////////////////////////////////////
- //
- // scene.shapes['shop11'] = new Shape();
- // var ps11 = scene.shapes['shop11'].points; // for convenience
- //
- //// ps11[0] = new Point(336, -510, 10); // left bottom
- //// ps11[1] = new Point(6, -510, 10); // right bottom
- //// ps11[2] = new Point(6, -110, 10); // right top
- //// ps11[3] = new Point(336, -110, 10); // left top
- // ps11[0] = new Point(5000, 5000, 5000); // left bottom
- // ps11[1] = new Point(5000, 5000, 5000); // right bottom
- // ps11[2] = new Point(5000, 5000, 5000); // right top
- // ps11[3] = new Point(5000, 5000, 5000); // left top
- //
- // // Shops background
- // scene.shapes['shop11'].polygons.push(new Polygon(
- // [ps11[0], ps11[1], ps11[2], ps11[3] ],
- // new Point(0, 0, 1),
- // true /* double-sided */,
- // Polygon.SOLID,
- // [177, 216, 249]
- // ));
- //
- // scene.shapes['shop12'] = new Shape();
- // var ps12 = scene.shapes['shop12'].points; // for convenience
- //
- //// ps12[0] = new Point(-8, -510, 10); // left bottom
- //// ps12[1] = new Point(-338, -510, 10); // right bottom
- //// ps12[2] = new Point(-338, -110, 10); // right top
- //// ps12[3] = new Point(-8, -110, 10); // left top
- // ps12[0] = new Point(5001, 5001, 5001); // left bottom
- // ps12[1] = new Point(5001, 5001, 5001); // right bottom
- // ps12[2] = new Point(5001, 5001, 5001); // right top
- // ps12[3] = new Point(5001, 5001, 5001); // left top
- //
- // // Shops background
- // scene.shapes['shop12'].polygons.push(new Polygon(
- // [ps12[0], ps12[1], ps12[2], ps12[3] ],
- // new Point(0, 0, 1),
- // true /* double-sided */,
- // Polygon.SOLID,
- // [177, 216, 249]
- // ));
- /////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////// END DOWNSTAIRS ///////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////
- loop();
- }
- /* -------------------------------------------------------------------- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement