Ignore:
Timestamp:
Aug 23, 2017, 10:56:48 AM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
9b1c16f
Parents:
fb91143
Message:

First badly working version of THREE.js height rendering

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webclient/js/GnuBoat.js

    rfb91143 r17bc29b  
    192192                }
    193193        });
     194       
     195        $("#3dchart").empty();
     196        var width = $("#3dchart").width();
     197        var height = $("#3dchart").height();
     198
     199        var fieldOfView = 75;
     200       
     201        GnuBoat.private.renderScene = new THREE.Scene();
     202//      var aspect = width/height;
     203//      var distance = 1000;
     204//      GnuBoat.private.renderCamera = new THREE.OrthographicCamera(-distance * aspect, distance * aspect, distance, -distance, 0.1, 1000000);
     205//      GnuBoat.private.renderCamera.up = new THREE.Vector3(0, 0, 1);
     206//      GnuBoat.private.renderCamera.position.set(-1, -1, distance);
     207//      GnuBoat.private.renderCamera.lookAt(GnuBoat.private.renderScene.position);
     208       
     209        GnuBoat.private.renderCamera = new THREE.PerspectiveCamera(75, width/height, 0.1, 1000000);
     210        GnuBoat.private.renderCamera.up = new THREE.Vector3(0, 0, 1);
     211        GnuBoat.private.renderCamera.position.set(-0.01, -0.01, 15000);
     212        GnuBoat.private.renderCamera.lookAt(GnuBoat.private.renderScene.position);
     213       
     214        GnuBoat.private.renderRenderer = new THREE.WebGLRenderer();
     215        GnuBoat.private.renderRenderer.setSize(width, height);
     216        GnuBoat.private.renderRenderer.setClearColor(0xEEEEEE);
     217        document.getElementById("3dchart").appendChild(GnuBoat.private.renderRenderer.domElement);
     218
     219        GnuBoat.private.animate();
    194220}
    195221
    … …  
    233259        mapControl: null,
    234260        mapsMetadata: null,
     261        mapBounds: null,
    235262        dataMappings: {
    236263                speedthroughwater: {display: true, map: true, mapActive: false, titleLong: "Speed Through Water", titleShort: "STW", unit: "kts"},
    … …  
    242269        serverBaseUrl: null,
    243270        timerDisplay: null,
     271        renderScene: null,
     272        renderCamera: null,
     273        renderRenderer: null,
     274        renderGeometry: null,
     275        renderMaterial: null,
     276        renderCube: null,
     277        renderMapBounds: null,
     278        renderGrid: null,
    244279       
    245280        openLink: function(target)
    … …  
    293328                                var minimas = [];
    294329                                var points = [];
     330                                var densityPoints = [];
    295331                               
    296332                                var keysMap = [];
    … …  
    320356                                                        minimas[key] = track[time][key];
    321357                                                points[key].push(new L.latLng(track[time]["latitude"], track[time]["longitude"], track[time][key]));
     358                                                densityPoints.push({latitude: track[time]["latitude"], longitude: track[time]["longitude"], depth: track[time]["waterdepth"]});
    322359                                        }
    323360                                }
    … …  
    341378                                        }
    342379                                }
     380                                GnuBoat.private.drawDensityEstimation(densityPoints, maximas["waterdepth"]);
    343381                        }
    344382                }
    … …  
    371409                var mapZoomStart = (mapZoomMax - mapZoomMin)/2 + mapZoomMin;
    372410               
    373                 var mapBounds = new L.LatLngBounds(
     411                GnuBoat.private.mapBounds = new L.LatLngBounds(
    374412                                new L.LatLng(latitudeBottom, longitudeLeft),
    375413                                new L.LatLng(latitudeTop, longitudeRight));
    … …  
    389427                GnuBoat.private.mapLayerCurrent = L.tileLayer(mapMetadata["tiles"][0], {
    390428                        minZoom: mapZoomMin, maxZoom: mapZoomMax,
    391                         bounds: mapBounds,
     429                        bounds: GnuBoat.private.mapBounds,
    392430                        attribution: mapMetadata["name"],
    393431                        opacity: 0.85
    394432                        }).addTo(GnuBoat.private.map);
    395                 if(GnuBoat.private.mapControl)
     433                if(GnuBoat.private.mapControl != null)
    396434                        GnuBoat.private.mapControl.addBaseLayer(GnuBoat.private.mapLayerCurrent, "Map");
    397435                else{
    398436                        GnuBoat.private.mapControl = L.control.layers({"Map": GnuBoat.private.mapLayerCurrent}, GnuBoat.private.mapOverlaysToList(), {hideSingleBase: true, sortLayers: true, }).addTo(GnuBoat.private.map);
    399437                }
     438               
     439                // configure render scene for new map
     440                GnuBoat.private.renderSetupMap();
    400441        },
    401442       
    … …  
    423464                return overlays;
    424465        },
     466       
     467        renderSetupMap: function()
     468        {
     469                if(GnuBoat.private.mapBounds == null)
     470                        return;
     471
     472                // add map bounds
     473                if(GnuBoat.private.renderMapBounds != null)
     474                        GnuBoat.private.renderScene.remove(GnuBoat.private.renderMapBounds);
     475                var m1 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getWest());
     476                var m2 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getEast());
     477                var m3 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getNorth(), GnuBoat.private.mapBounds.getEast());
     478                var m4 = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getNorth(), GnuBoat.private.mapBounds.getWest());
     479                var geometryMapBounds = new THREE.Geometry();
     480                var materialMapBounds = new THREE.LineBasicMaterial({color: 0x000000, linewidth: 1});
     481                // z is greator 0, to draw the map boundings over the grid
     482                var vertex = new THREE.Vector3(0, 0, 2);
     483                geometryMapBounds.vertices.push(vertex);
     484                vertex = new THREE.Vector3(m2.x - m1.x, m2.y - m1.y, 2);
     485                geometryMapBounds.vertices.push(vertex);
     486                vertex = new THREE.Vector3(m3.x - m1.x, m3.y - m1.y, 2);
     487                geometryMapBounds.vertices.push(vertex);
     488                vertex = new THREE.Vector3(m4.x - m1.x, m4.y - m1.y, 2);
     489                geometryMapBounds.vertices.push(vertex);
     490                GnuBoat.private.renderMapBounds = new THREE.LineLoop(geometryMapBounds, materialMapBounds);
     491                GnuBoat.private.renderScene.add(GnuBoat.private.renderMapBounds);
     492               
     493//              var geometry = new THREE.Geometry();
     494//              geometry.vertices.push(new THREE.Vector3(0, 0, 4));
     495//              geometry.vertices.push(new THREE.Vector3(1000, 0, 4));
     496//              var line = new THREE.Line(geometry, new THREE.LineBasicMaterial({color: 0xFF0000}));
     497//              GnuBoat.private.renderScene.add(line);
     498//             
     499//              geometry = new THREE.Geometry();
     500//              geometry.vertices.push(new THREE.Vector3(0, 0, 4));
     501//              geometry.vertices.push(new THREE.Vector3(0, 1000, 4));
     502//              line = new THREE.Line(geometry, new THREE.LineBasicMaterial({color: 0x0000FF}));
     503//              GnuBoat.private.renderScene.add(line);
     504//             
     505//              geometry = new THREE.Geometry();
     506//              geometry.vertices.push(new THREE.Vector3(0, 0, 4));
     507//              geometry.vertices.push(new THREE.Vector3(0, 0, 1000));
     508//              line = new THREE.Line(geometry, new THREE.LineBasicMaterial({color: 0x00FF00}));
     509//              GnuBoat.private.renderScene.add(line);
     510
     511                // add 500m grid
     512                if(GnuBoat.private.renderGrid != null)
     513                        GnuBoat.private.renderScene.remove(GnuBoat.private.renderGrid);
     514                geometryMapBounds.computeBoundingBox();
     515                var maxLength = Math.max(geometryMapBounds.boundingBox.getSize().x, geometryMapBounds.boundingBox.getSize().y);
     516                GnuBoat.private.renderGrid = new THREE.GridHelper(maxLength, Math.round(maxLength / 500.0), 0xDDDDDD, 0xDDDDDD);
     517                GnuBoat.private.renderGrid.geometry.rotateX( Math.PI / 2 );
     518                GnuBoat.private.renderGrid.translateX(maxLength / 2.0);
     519                GnuBoat.private.renderGrid.translateY(maxLength / 2.0);
     520                GnuBoat.private.renderScene.add(GnuBoat.private.renderGrid);
     521               
     522                var distance = 0.3 * maxLength;
     523                var fieldOfView = 2 * Math.atan(maxLength / (2.0 * distance) ) * 180.0 / Math.PI;
     524                GnuBoat.private.renderCamera.position.set(0.1 * maxLength, 0.2 * maxLength, 0.3 * maxLength);
     525                GnuBoat.private.renderCamera.fov = fieldOfView;
     526                GnuBoat.private.renderCamera.updateProjectionMatrix();
     527        },
     528       
     529        drawDensityEstimation: function(densityPoints, maxima)
     530        {
     531                var material = new THREE.PointsMaterial({color: 0x00CCCC, size: 1});
     532                var geometry = new THREE.Geometry();
     533                var mercatorSouthWest = {x: 0, y: 0};
     534                if(GnuBoat.private.mapBounds != null){
     535                        mercatorSouthWest = GnuBoat.private.mercator(GnuBoat.private.mapBounds.getSouth(), GnuBoat.private.mapBounds.getWest());
     536                }
     537               
     538                for(var i = 0; i < densityPoints.length; i++){
     539                        var mercator = GnuBoat.private.mercator(densityPoints[i].latitude, densityPoints[i].longitude);
     540                        var vertex = new THREE.Vector3(mercator.x - mercatorSouthWest.x, mercator.y - mercatorSouthWest.y, (densityPoints[i].depth * -1) + maxima);
     541                        geometry.vertices.push(vertex);
     542                }
     543                // point cloud
     544                if(GnuBoat.private.renderCloud != null)
     545                        GnuBoat.private.renderScene.remove(GnuBoat.private.renderCloud);
     546                GnuBoat.private.renderCloud = new THREE.Points(geometry, material);
     547                GnuBoat.private.renderScene.add(GnuBoat.private.renderCloud);
     548        },
     549       
     550        animate: function()
     551        {
     552                requestAnimationFrame(GnuBoat.private.animate);
     553
     554//              if(GnuBoat.private.mapBounds != null){
     555//                      GnuBoat.private.camera.position.set(GnuBoat.private.mapBounds.getCenter().lng, GnuBoat.private.mapBounds.getSouth(), 0);
     556//                      GnuBoat.private.camera.up = new THREE.Vector3(0, 0, 1);
     557//                      GnuBoat.private.camera.lookAt(new THREE.Vector3(GnuBoat.private.mapBounds.getCenter().lng, GnuBoat.private.mapBounds.getCenter().lat, 0));
     558//                      GnuBoat.private.camera.zoom = 1;
     559//              }
     560               
     561//              var width = $("#3dchart").width();
     562//              var height = $("#3dchart").height();
     563//              GnuBoat.private.renderer.setSize(width, height);
     564                GnuBoat.private.renderRenderer.render(GnuBoat.private.renderScene, GnuBoat.private.renderCamera);
     565        },
     566       
     567        mercator: function(latitude, longitude)
     568        {
     569                var result = {};
     570               
     571                var earthRadius = 6378137.0;
     572               
     573                result["x"] = longitude / 180.0 * Math.PI * earthRadius;
     574                result["y"] = Math.log(Math.tan(latitude / 180.0 * Math.PI / 2.0 + Math.PI / 4.0)) * earthRadius;
     575
     576                return result;
     577        },
    425578};
Note: See TracChangeset for help on using the changeset viewer.