Path: blob/main/projects/missiles/src/wall.js
1835 views
MG.tunnelWall = (function (rootNode) {1var DTHETA = 20;2var NUM_SEGMENTS = 5;34var NEAR_CLIPPING_PLANE = 25;56var GRADIENT_START = MG.LINE_OF_SIGHT;7var GRADIENT_STOP = GRADIENT_START - MG.BARRIER_SPACING;8910var mTheta = 0;1112var mSegments = [];1314return {15init: function (rootNode) {1617var gradient = document.createElementNS(NAMESPACE_SVG, 'linearGradient');18gradient.id = 'tunnel-wall-segment-fade-gradient';19gradient.setAttribute('gradientUnits', 'userSpaceOnUse');20rootNode.appendChild(gradient);2122var gradientStart = document.createElementNS(NAMESPACE_SVG, 'stop');23gradientStart.setAttribute('offset', (5*NEAR_CLIPPING_PLANE / GRADIENT_START) + '');24gradientStart.setAttribute('stop-color', '#fff');25gradient.appendChild(gradientStart);2627var gradientStop = document.createElementNS(NAMESPACE_SVG, 'stop');28gradientStop.setAttribute('offset', (5*NEAR_CLIPPING_PLANE / GRADIENT_STOP) + '');29gradientStop.setAttribute('stop-color', '#000');30gradient.appendChild(gradientStop);3132for (var i=0; i < NUM_SEGMENTS; i++) {3334mSegments[i] = document.createElementNS(NAMESPACE_SVG, 'path');35mSegments[i].setAttribute('class', 'wall-segment-dark');36mSegments[i].setAttribute('d', 'M 0,0 l 1000,50 l 0,-50 z');3738mSegments[i].setAttribute('fill', 'url(#tunnel-wall-segment-fade-gradient)');394041rootNode.appendChild(mSegments[i]) ;42}4344this.updateDOM(0,0,0);45},4647update: function (dt) {48mTheta = mTheta + dt * DTHETA;49mTheta %= 360;50},5152updateDOM: function (x, y, offset) {5354for (var i=0; i<NUM_SEGMENTS; i++) {55var segmentTheta = mTheta + 360*i/NUM_SEGMENTS;5657var x_ = -x * Math.cos(segmentTheta*Math.PI/180) + -y * Math.sin(segmentTheta*Math.PI/180);58var y_ = -x * Math.sin(segmentTheta*Math.PI/180) + y * Math.cos(segmentTheta*Math.PI/180);5960var scale_x_ = 0.1*MG.PROJECTION_PLANE_DISTANCE * (1 - x_/MG.TUNNEL_RADIUS)61/ (Math.tan(Math.PI * MG.FIELD_OF_VIEW/360.0)*NEAR_CLIPPING_PLANE);62var scale_y_ = 0.1*MG.PROJECTION_PLANE_DISTANCE63/ (Math.tan(Math.PI * MG.FIELD_OF_VIEW/360.0)*NEAR_CLIPPING_PLANE);6465var skew = 180*Math.atan(y_/MG.TUNNEL_RADIUS)/Math.PI;6667mSegments[i].setAttribute('transform', 'rotate(' + segmentTheta + ') '68+ 'scale(' + scale_x_ + ',' + scale_y_ + ') '69+ 'skewY(' + skew + ')' );70717273}74}75}76}());777879