Example #1
0
        public double ComputeApparentThickness(DoubleVector3 p, double thickness)
        {
            var ss1 = Project(p);
            var ss2 = Project(p + position.To(p).Cross(position.To(lookat)).ToUnit() * thickness);

            return((ss1 - ss2).Norm2D());
            //         var cameraSpace = Vector4.Transform(ToNumerics4(p), worldToCamera);
            //         return thickness * (1000f + cameraSpace.Z) / 1000f;
        }
        private DoubleVector3 PushToLand(DoubleVector3 pWorld, double computedRadius)
        {
            var paddedHoleDilationRadius = computedRadius + InternalTerrainCompilationConstants.AdditionalHoleDilationRadius + InternalTerrainCompilationConstants.TriangleEdgeBufferRadius;
            var terrainOverlayNetwork    = terrainService.CompileSnapshot().OverlayNetworkManager.CompileTerrainOverlayNetwork(paddedHoleDilationRadius);
//         Console.WriteLine("PHDR: " + paddedHoleDilationRadius);
            var bestWorldDistance = double.PositiveInfinity;
            var bestWorld         = DoubleVector3.Zero;

            foreach (var terrainOverlayNode in terrainOverlayNetwork.TerrainNodes)
            {
                var pLocal = (DoubleVector2)terrainOverlayNode.SectorNodeDescription.WorldToLocal(pWorld);
                terrainOverlayNode.LocalGeometryView.FindNearestLandPointAndIsInHole(pLocal, out var pNearestLocal);

                // clamp pNearestLocal to be within bounds, not

                var pNearestWorld = terrainOverlayNode.SectorNodeDescription.LocalToWorld(pNearestLocal);
                var worldDistance = pWorld.To(pNearestWorld).Norm2D();
                if (worldDistance < bestWorldDistance)
                {
                    bestWorldDistance = worldDistance;
                    bestWorld         = pNearestWorld;
                }
            }
            return(bestWorld);

            throw new NotImplementedException();
            //         DoubleVector3 nearestLandPoint;
            //         if (!terrainService.BuildSnapshot().FindNearestLandPointAndIsInHole(paddedHoleDilationRadius, vect, out nearestLandPoint)) {
            //            throw new InvalidOperationException("In new hole but not terrain snapshot hole.");
            //         }
            //         return nearestLandPoint;
        }
Example #3
0
        public PerspectiveProjector(DoubleVector3 position, DoubleVector3 lookat, DoubleVector3 up, double width, double height)
        {
            this.position      = position;
            this.lookat        = lookat;
            this.up            = up;
            this.width         = width;
            this.height        = height;
            this.worldToCamera =
                Matrix4x4.CreateTranslation(ToNumerics3(-1.0 * position)) *
                Matrix4x4.CreateLookAt(ToNumerics3(DoubleVector3.Zero), ToNumerics3(position.To(lookat)), ToNumerics3(up)) *
                Matrix4x4.CreateScale(-1, 1, 1);
            this.cameraToView = Matrix4x4.CreatePerspectiveFieldOfView((float)Math.PI * 2 / 4, (float)(width / height), 1f, 10000f);
//          this.cameraToView = Matrix4x4.CreatePerspectiveOffCenter(0, (float)width, (float)height, 0, 1.0f, 1000.0f);
            transform = cameraToView * worldToCamera;
        }