computeScreenSliceBuffer(scene) {
        let xCamera = scene.camera.x;
        let yCamera = scene.camera.y;
        let fDirection = scene.camera.direction;
        const SCREEN = this._options.screen;
        const METRICS = this._options.metrics;
        let xScreenSize = SCREEN.width;
        let fViewAngle = scene.camera.fov;
        let nSpacing = METRICS.spacing;
        let fAngleLeft = fDirection - fViewAngle;       // angle value at the leftmost screen column
        let fAngleRight = fDirection + fViewAngle;      // angle value at the rightmost screen column
        let wx1 = Math.cos(fAngleLeft);             // w1 = (wx1, wy1) is a normalized position around visor for the leftmost point
        let wy1 = Math.sin(fAngleLeft);
        let wx2 = Math.cos(fAngleRight);            // w2 = (wx2, wy2) is a normalized position around visor for the rightmost point
        let wy2 = Math.sin(fAngleRight);
        let dx = (wx2 - wx1) / xScreenSize;               // dx, dy help to determine all points between w1 and w2
        let dy = (wy2 - wy1) / xScreenSize;
        let fBx = wx1;                              // starting point for the raycasting process
        let fBy = wy1;                              // (fBx, fBy) is meant to be modified by (dx, dy)
        let xCam8 = xCamera / nSpacing | 0;         // cell where the visor is.
        let yCam8 = yCamera / nSpacing | 0;
        let i;
        let zbuffer = [];
        let scanCells = new MarkerRegistry();     // registry of cells traversed by rays
        scanCells.mark(xCam8, yCam8);
        this._scanCells = scanCells;
        // background
        let bg = this._background;
        if (bg) {
            this._bgCameraOffset = 2 * fDirection * bg.width / Math.PI; // 2 * (Math.PI + fDirection) * bg.width / Math.PI;
        }

		// VR
        let xl = scene.xFrom;
        let xr = scene.xTo;

        for (i = 0; i < xScreenSize; ++i) {
            const bMiddle = i === (xScreenSize >> 1);
            if (i >= xl && i <= xr) { // checks limits
                scene.resume.b = false;
                if (bMiddle) {
                    const mr = new MarkerRegistry();
                    this.castRay(scene, xCamera, yCamera, fBx, fBy, i, mr, zbuffer);
                    this._scanFrontCells = mr;
                    scanCells.merge(mr);
                    this._scanAimedCell = {
                        xCell: scene.xCell,
                        yCell: scene.yCell,
                        x: scene.xint,
                        y: scene.yint,
                        side: scene.cellSide
                    };
                } else {
                    this.castRay(scene, xCamera, yCamera, fBx, fBy, i, scanCells, zbuffer);
                }
            }
            fBx += dx;
            fBy += dy;
        }

        zbuffer = Renderer._optimizeBuffer(zbuffer);
        scene.zbuffer = zbuffer;
        this.renderSprites(scene);
        // Le tri permet d'afficher les textures semi transparente après celles qui sont derrières
        zbuffer.sort(zBufferCompare);
        if (this._storey) {
            this._storey.computeScreenSliceBuffer(scene.storeyScene);
        }
	}
/**
	 * this is phase 1 of rendering.
	 * Builds an array of screen slices
     */
this is phase 1 of rendering.
Builds an array of screen slices
this is phase 1 of rendering . Builds an array of screen slices
computeScreenSliceBuffer(scene) {
        let xCamera = scene.camera.x;
        let yCamera = scene.camera.y;
        let fDirection = scene.camera.direction;
        const SCREEN = this._options.screen;
        const METRICS = this._options.metrics;
        let xScreenSize = SCREEN.width;
        let fViewAngle = scene.camera.fov;
        let nSpacing = METRICS.spacing;
        let fAngleLeft = fDirection - fViewAngle;       
        let fAngleRight = fDirection + fViewAngle;      
        let wx1 = Math.cos(fAngleLeft);             
        let wy1 = Math.sin(fAngleLeft);
        let wx2 = Math.cos(fAngleRight);            
        let wy2 = Math.sin(fAngleRight);
        let dx = (wx2 - wx1) / xScreenSize;               
        let dy = (wy2 - wy1) / xScreenSize;
        let fBx = wx1;                              
        let fBy = wy1;                              
        let xCam8 = xCamera / nSpacing | 0;         
        let yCam8 = yCamera / nSpacing | 0;
        let i;
        let zbuffer = [];
        let scanCells = new MarkerRegistry();     
        scanCells.mark(xCam8, yCam8);
        this._scanCells = scanCells;
        let bg = this._background;
        if (bg) {
            this._bgCameraOffset = 2 * fDirection * bg.width / Math.PI; 
        }
        let xl = scene.xFrom;
        let xr = scene.xTo;
        for (i = 0; i < xScreenSize; ++i) {
            const bMiddle = i === (xScreenSize >> 1);
            if (i >= xl && i <= xr) { 
                scene.resume.b = false;
                if (bMiddle) {
                    const mr = new MarkerRegistry();
                    this.castRay(scene, xCamera, yCamera, fBx, fBy, i, mr, zbuffer);
                    this._scanFrontCells = mr;
                    scanCells.merge(mr);
                    this._scanAimedCell = {
                        xCell: scene.xCell,
                        yCell: scene.yCell,
                        x: scene.xint,
                        y: scene.yint,
                        side: scene.cellSide
                    };
                } else {
                    this.castRay(scene, xCamera, yCamera, fBx, fBy, i, scanCells, zbuffer);
                }
            }
            fBx += dx;
            fBy += dy;
        }
        zbuffer = Renderer._optimizeBuffer(zbuffer);
        scene.zbuffer = zbuffer;
        this.renderSprites(scene);
        zbuffer.sort(zBufferCompare);
        if (this._storey) {
            this._storey.computeScreenSliceBuffer(scene.storeyScene);
        }
	}
computeScreenSliceBuffer ( scene ) { let xCamera = scene . camera . x ; let yCamera = scene . camera . y ; let fDirection = scene . camera . direction ; const SCREEN = this . _options . screen ; const METRICS = this . _options . metrics ; let xScreenSize = SCREEN . width ; let fViewAngle = scene . camera . fov ; let nSpacing = METRICS . spacing ; let fAngleLeft = fDirection - fViewAngle ; let fAngleRight = fDirection + fViewAngle ; let wx1 = Math . cos ( fAngleLeft ) ; let wy1 = Math . sin ( fAngleLeft ) ; let wx2 = Math . cos ( fAngleRight ) ; let wy2 = Math . sin ( fAngleRight ) ; let dx = ( wx2 - wx1 ) / xScreenSize ; let dy = ( wy2 - wy1 ) / xScreenSize ; let fBx = wx1 ; let fBy = wy1 ; let xCam8 = xCamera / nSpacing | 0 ; let yCam8 = yCamera / nSpacing | 0 ; let i ; let zbuffer = [ ] ; let scanCells = new MarkerRegistry ( ) ; scanCells . mark ( xCam8 , yCam8 ) ; this . _scanCells = scanCells ; let bg = this . _background ; if ( bg ) { this . _bgCameraOffset = 2 * fDirection * bg . width / Math . PI ; } let xl = scene . xFrom ; let xr = scene . xTo ; for ( i = 0 ; i < xScreenSize ; ++ i ) { const bMiddle = i === ( xScreenSize >> 1 ) ; if ( i >= xl && i <= xr ) { scene . resume . b = false ; if ( bMiddle ) { const mr = new MarkerRegistry ( ) ; this . castRay ( scene , xCamera , yCamera , fBx , fBy , i , mr , zbuffer ) ; this . _scanFrontCells = mr ; scanCells . merge ( mr ) ; this . _scanAimedCell = { xCell : scene . xCell , yCell : scene . yCell , x : scene . xint , y : scene . yint , side : scene . cellSide } ; } else { this . castRay ( scene , xCamera , yCamera , fBx , fBy , i , scanCells , zbuffer ) ; } } fBx += dx ; fBy += dy ; } zbuffer = Renderer . _optimizeBuffer ( zbuffer ) ; scene . zbuffer = zbuffer ; this . renderSprites ( scene ) ; zbuffer . sort ( zBufferCompare ) ; if ( this . _storey ) { this . _storey . computeScreenSliceBuffer ( scene . storeyScene ) ; } }
this is phase 1 of rendering.
this is phase 1 of rendering .
// angle value at the leftmost screen column // angle value at the rightmost screen column // w1 = (wx1, wy1) is a normalized position around visor for the leftmost point // w2 = (wx2, wy2) is a normalized position around visor for the rightmost point // dx, dy help to determine all points between w1 and w2 // starting point for the raycasting process // (fBx, fBy) is meant to be modified by (dx, dy) // cell where the visor is. // registry of cells traversed by rays // background // 2 * (Math.PI + fDirection) * bg.width / Math.PI; // VR // checks limits // Le tri permet d'afficher les textures semi transparente après celles qui sont derrières