Пример #1
0
        /// <summary>
        /// Recalculates the grid bounds + interval values
        /// 重复计算网格边界和间隔值
        /// </summary>
        public void ComputeGridValues(DrawArgs drawArgs)
        {
            double vr = drawArgs.WorldCamera.TrueViewRange.Radians;

            // Compensate for closer grid towards poles
            vr *= 1 + Math.Abs(Math.Sin(drawArgs.WorldCamera.Latitude.Radians));

            if (vr < 0.17)
            {
                LatitudeInterval = 1;
            }
            else if (vr < 0.6)
            {
                LatitudeInterval = 2;
            }
            else if (vr < 1.0)
            {
                LatitudeInterval = 5;
            }
            else
            {
                LatitudeInterval = 10;
            }

            LongitudeInterval = LatitudeInterval;

            if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(MathEngine.SphericalToCartesian(90, 0, radius)) ||
                drawArgs.WorldCamera.ViewFrustum.ContainsPoint(MathEngine.SphericalToCartesian(-90, 0, radius)))
            {
                // Pole visible, 10 degree longitude spacing forced
                LongitudeInterval = 10;
            }

            MinVisibleLongitude = LongitudeInterval >= 10 ? -180 : (int)drawArgs.WorldCamera.Longitude.Degrees / LongitudeInterval * LongitudeInterval - 18 * LongitudeInterval;
            MaxVisibleLongitude = LongitudeInterval >= 10 ? 180 : (int)drawArgs.WorldCamera.Longitude.Degrees / LongitudeInterval * LongitudeInterval + 18 * LongitudeInterval;
            MinVisibleLatitude  = (int)drawArgs.WorldCamera.Latitude.Degrees / LatitudeInterval * LatitudeInterval - 9 * LatitudeInterval;
            MaxVisibleLatitude  = (int)drawArgs.WorldCamera.Latitude.Degrees / LatitudeInterval * LatitudeInterval + 9 * LatitudeInterval;

            if (MaxVisibleLatitude - MinVisibleLatitude >= 180 || LongitudeInterval == 10)
            {
                MinVisibleLatitude = -90;
                MaxVisibleLatitude = 90;
            }
            LongitudePointCount = (MaxVisibleLongitude - MinVisibleLongitude) / LongitudeInterval + 1;
            LatitudePointCount  = (MaxVisibleLatitude - MinVisibleLatitude) / LatitudeInterval + 1;
            int vertexPointCount = Math.Max(LatitudePointCount, LongitudePointCount);

            if (lineVertices == null || vertexPointCount > lineVertices.Length)
            {
                lineVertices = new CustomVertex.PositionColored[Math.Max(LatitudePointCount, LongitudePointCount)];
            }

            radius = WorldRadius;
            if (drawArgs.WorldCamera.Altitude < 0.10f * WorldRadius)
            {
                useZBuffer = false;
            }
            else
            {
                useZBuffer = true;
                double bRadius = WorldRadius * 1.01f;
                double nRadius = WorldRadius + 0.015f * drawArgs.WorldCamera.Altitude;

                radius = Math.Min(nRadius, bRadius);
            }
        }
Пример #2
0
        /// <summary>
        /// Loads visible place names from one file.
        /// If cache files are appropriately named only files in view are hit
        /// </summary>
        void UpdateNames(WorldWindWFSPlacenameFile placenameFileDescriptor, ArrayList tempPlacenames, DrawArgs drawArgs)
        {
            // TODO: Replace with bounding box frustum intersection test
            double viewRange = drawArgs.WorldCamera.TrueViewRange.Degrees;
            double north     = drawArgs.WorldCamera.Latitude.Degrees + viewRange;
            double south     = drawArgs.WorldCamera.Latitude.Degrees - viewRange;
            double west      = drawArgs.WorldCamera.Longitude.Degrees - viewRange;
            double east      = drawArgs.WorldCamera.Longitude.Degrees + viewRange;

            //TODO: Implement GML parsing
            if (placenameFileDescriptor.north < south)
            {
                return;
            }
            if (placenameFileDescriptor.south > north)
            {
                return;
            }
            if (placenameFileDescriptor.east < west)
            {
                return;
            }
            if (placenameFileDescriptor.west > east)
            {
                return;
            }

            WorldWindPlacename[] tilednames = placenameFileDescriptor.PlaceNames;
            if (tilednames == null)
            {
                return;
            }

            tempPlacenames.Capacity = tempPlacenames.Count + tilednames.Length;
            WorldWindPlacename curPlace = new WorldWindPlacename();

            for (int i = 0; i < tilednames.Length; i++)
            {
                if (m_placeNames != null && curPlaceNameIndex < m_placeNames.Length)
                {
                    curPlace = m_placeNames[curPlaceNameIndex];
                }

                WorldWindPlacename pn = tilednames[i];
                float lat             = pn.Lat;
                float lon             = pn.Lon;

                // for easier hit testing

                float lonRanged = lon;
                if (lonRanged < west)
                {
                    lonRanged += 360; // add a revolution
                }
                if (lat > north || lat < south || lonRanged > east || lonRanged < west)
                {
                    continue;
                }

                float elevation = 0;
                if (m_parentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 300000)
                {
                    elevation = (float)m_parentWorld.TerrainAccessor.GetElevationAt(lat, lon);
                }
                float altitude = (float)(m_parentWorld.EquatorialRadius + World.Settings.VerticalExaggeration * m_altitude + World.Settings.VerticalExaggeration * elevation);
                pn.cartesianPoint = MathEngine.SphericalToCartesian(lat, lon, altitude);
                float distanceSq = Vector3.LengthSq(pn.cartesianPoint - drawArgs.WorldCamera.Position);
                if (distanceSq > m_maximumDistanceSq)
                {
                    continue;
                }
                if (distanceSq < m_minimumDistanceSq)
                {
                    continue;
                }

                if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(pn.cartesianPoint))
                {
                    continue;
                }

                tempPlacenames.Add(pn);
            }
        }
Пример #3
0
 public void InitMathEngine()
 {
     _mathEngine = new MathEngine(1, 2, 3);
 }
Пример #4
0
        /// <summary>
        /// Render the grid lines
        /// 渲染网格线
        /// </summary>
        public override void Render(DrawArgs drawArgs)
        {
            if (!World.Settings.showLatLonLines)
            {
                return;
            }

            ComputeGridValues(drawArgs);

            float offsetDegrees = (float)drawArgs.WorldCamera.TrueViewRange.Degrees / 6;

            drawArgs.device.RenderState.ZBufferEnable = useZBuffer;

            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
            drawArgs.device.VertexFormat    = CustomVertex.PositionColored.Format;
            drawArgs.device.Transform.World = Matrix.Translation(
                (float)-drawArgs.WorldCamera.ReferenceCenter.X,
                (float)-drawArgs.WorldCamera.ReferenceCenter.Y,
                (float)-drawArgs.WorldCamera.ReferenceCenter.Z
                );

            Vector3 referenceCenter = new Vector3(
                (float)drawArgs.WorldCamera.ReferenceCenter.X,
                (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                (float)drawArgs.WorldCamera.ReferenceCenter.Z);

            // Turn off light
            if (World.Settings.EnableSunShading)
            {
                drawArgs.device.RenderState.Lighting = false;
            }

            // Draw longitudes
            for (float longitude = MinVisibleLongitude; longitude < MaxVisibleLongitude; longitude += LongitudeInterval)
            {
                // Draw longitude lines
                int vertexIndex = 0;
                for (float latitude = MinVisibleLatitude; latitude <= MaxVisibleLatitude; latitude += LatitudeInterval)
                {
                    Vector3 pointXyz = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                    lineVertices[vertexIndex].X     = pointXyz.X;
                    lineVertices[vertexIndex].Y     = pointXyz.Y;
                    lineVertices[vertexIndex].Z     = pointXyz.Z;
                    lineVertices[vertexIndex].Color = World.Settings.latLonLinesColor;
                    vertexIndex++;
                }
                drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, LatitudePointCount - 1, lineVertices);

                // Draw longitude label
                float lat = (float)(drawArgs.WorldCamera.Latitude).Degrees;
                if (lat > 70)
                {
                    lat = 70;
                }
                Vector3 v = MathEngine.SphericalToCartesian(lat, (float)longitude, radius);
                if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(v))
                {
                    // Make sure longitude is in -180 .. 180 range
                    int longitudeRanged = (int)longitude;
                    if (longitudeRanged <= -180)
                    {
                        longitudeRanged += 360;
                    }
                    else if (longitudeRanged > 180)
                    {
                        longitudeRanged -= 360;
                    }

                    string s = Math.Abs(longitudeRanged).ToString();
                    if (longitudeRanged < 0)
                    {
                        s += "W";
                    }
                    else if (longitudeRanged > 0 && longitudeRanged < 180)
                    {
                        s += "E";
                    }

                    v = drawArgs.WorldCamera.Project(v - referenceCenter);
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle((int)v.X + 2, (int)v.Y, 10, 10);
                    drawArgs.DefaultDrawingFont.DrawText(null, s, rect.Left, rect.Top, World.Settings.latLonLinesColor);
                }
            }

            // Draw latitudes
            for (float latitude = MinVisibleLatitude; latitude <= MaxVisibleLatitude; latitude += LatitudeInterval)
            {
                // Draw latitude label
                float longitude = (float)(drawArgs.WorldCamera.Longitude).Degrees + offsetDegrees;

                Vector3 v = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(v))
                {
                    v = drawArgs.WorldCamera.Project(v - referenceCenter);
                    float latLabel = latitude;
                    if (latLabel > 90)
                    {
                        latLabel = 180 - latLabel;
                    }
                    else if (latLabel < -90)
                    {
                        latLabel = -180 - latLabel;
                    }
                    string s = ((int)Math.Abs(latLabel)).ToString();
                    if (latLabel > 0)
                    {
                        s += "N";
                    }
                    else if (latLabel < 0)
                    {
                        s += "S";
                    }
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle((int)v.X, (int)v.Y, 10, 10);
                    drawArgs.DefaultDrawingFont.DrawText(null, s, rect.Left, rect.Top, World.Settings.latLonLinesColor);
                }

                // Draw latitude line
                int vertexIndex = 0;
                for (longitude = MinVisibleLongitude; longitude <= MaxVisibleLongitude; longitude += LongitudeInterval)
                {
                    Vector3 pointXyz = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                    lineVertices[vertexIndex].X = pointXyz.X;
                    lineVertices[vertexIndex].Y = pointXyz.Y;
                    lineVertices[vertexIndex].Z = pointXyz.Z;

                    if (latitude == 0)
                    {
                        lineVertices[vertexIndex].Color = World.Settings.equatorLineColor;
                    }
                    else
                    {
                        lineVertices[vertexIndex].Color = World.Settings.latLonLinesColor;
                    }

                    vertexIndex++;
                }
                drawArgs.device.DrawUserPrimitives(PrimitiveType.LineStrip, LongitudePointCount - 1, lineVertices);
            }

            if (World.Settings.showTropicLines && IsEarth)
            {
                RenderTropicLines(drawArgs);
            }

            // Restore state
            drawArgs.device.Transform.World = drawArgs.WorldCamera.WorldMatrix;
            if (!useZBuffer)
            {
                // Reset Z buffer setting
                drawArgs.device.RenderState.ZBufferEnable = true;
            }
            if (World.Settings.EnableSunShading)
            {
                drawArgs.device.RenderState.Lighting = true;
            }
        }
Пример #5
0
        public override void Update(DrawArgs drawArgs)
        {
            try
            {
                if (!drawArgs.WorldCamera.ViewFrustum.Intersects(boundingBox))
                {
                    Dispose();
                    return;
                }

                if (!isLoaded)
                {
                    Load();
                }

                if (linePoints != null)
                {
                    if ((lastUpdatedPosition - drawArgs.WorldCamera.Position).LengthSq() < 10 * 10)                  // Update if camera moved more than 10 meters
                    {
                        if (Math.Abs(this.verticalExaggeration - World.Settings.VerticalExaggeration) < 0.01)
                        {
                            // Already loaded and up-to-date
                            return;
                        }
                    }
                }

                verticalExaggeration = World.Settings.VerticalExaggeration;

                ArrayList renderablePoints   = new ArrayList();
                Vector3   lastPointProjected = Vector3.Empty;
                Vector3   currentPointProjected;
                Vector3   currentPointXyz = Vector3.Empty;

                Vector3 rc = new Vector3(
                    (float)drawArgs.WorldCamera.ReferenceCenter.X,
                    (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                    (float)drawArgs.WorldCamera.ReferenceCenter.Z
                    );

                for (int i = 0; i < sphericalCoordinates.Length; i++)
                {
                    double altitude = 0;
                    if (_parentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 3000000)
                    {
                        altitude = _terrainAccessor.GetElevationAt(
                            sphericalCoordinates[i].X,
                            sphericalCoordinates[i].Y,
                            (100.0 / drawArgs.WorldCamera.ViewRange.Degrees));
                    }

                    currentPointXyz = MathEngine.SphericalToCartesian(
                        this.sphericalCoordinates[i].X,
                        this.sphericalCoordinates[i].Y,
                        this._parentWorld.EquatorialRadius + this.heightAboveSurface +
                        this.verticalExaggeration * altitude);

                    currentPointProjected = drawArgs.WorldCamera.Project(currentPointXyz - rc);

                    float       dx = lastPointProjected.X - currentPointProjected.X;
                    float       dy = lastPointProjected.Y - currentPointProjected.Y;
                    float       distanceSquared = dx * dx + dy * dy;
                    const float minimumPointSpacingSquaredPixels = 2 * 2;
                    if (distanceSquared > minimumPointSpacingSquaredPixels)
                    {
                        renderablePoints.Add(currentPointXyz);
                        lastPointProjected = currentPointProjected;
                    }
                }

                // Add the last point if it's not already in there
                int pointCount = renderablePoints.Count;
                if (pointCount > 0 && (Vector3)renderablePoints[pointCount - 1] != currentPointXyz)
                {
                    renderablePoints.Add(currentPointXyz);
                    pointCount++;
                }

                CustomVertex.PositionColored[] newLinePoints = new CustomVertex.PositionColored[pointCount];
                for (int i = 0; i < pointCount; i++)
                {
                    currentPointXyz    = (Vector3)renderablePoints[i];
                    newLinePoints[i].X = currentPointXyz.X;
                    newLinePoints[i].Y = currentPointXyz.Y;
                    newLinePoints[i].Z = currentPointXyz.Z;

                    newLinePoints[i].Color = this.lineColor;
                }

                this.linePoints = newLinePoints;

                lastUpdatedPosition = drawArgs.WorldCamera.Position;
                System.Threading.Thread.Sleep(1);
            }
            catch
            {
            }
        }
Пример #6
0
        private void RenderBar(DrawArgs drawArgs)
        {
            bool lighting = drawArgs.device.RenderState.Lighting;

            drawArgs.device.RenderState.Lighting = false;

            Matrix translation = Matrix.Translation(

                (float)(m_cartesianPoint.X - drawArgs.WorldCamera.ReferenceCenter.X),

                (float)(m_cartesianPoint.Y - drawArgs.WorldCamera.ReferenceCenter.Y),

                (float)(m_cartesianPoint.Z - drawArgs.WorldCamera.ReferenceCenter.Z)

                );



            if (m_extrudeVertices == null)
            {
                CreateExtrude(drawArgs.device);
            }



            if (m_useScaling)
            {
                double targetPercent = (m_targetScalar - m_scalarMinimum) / (m_scalarMaximum - m_scalarMinimum);

                if (m_currentPercent != targetPercent)
                {
                    double delta = Math.Abs(targetPercent - m_currentPercent);

                    delta *= 0.1;

                    if (m_currentPercent < targetPercent)
                    {
                        m_currentPercent += delta;
                    }

                    else
                    {
                        m_currentPercent -= delta;
                    }
                }



                if (getColor(m_currentPercent).ToArgb() != m_extrudeVertices[0].Color)
                {
                    UpdateColor(m_currentPercent);
                }

                RenderedHeight = m_currentPercent * World.Settings.VerticalExaggeration * m_height;

                drawArgs.device.Transform.World = Matrix.Scaling(m_scaleX, m_scaleY, (float)-m_currentPercent * World.Settings.VerticalExaggeration * (float)m_height);
            }

            else
            {
                if (m_color != m_extrudeVertices[0].Color)
                {
                    UpdateColor(m_color);
                }

                RenderedHeight = m_height * World.Settings.VerticalExaggeration;

                drawArgs.device.Transform.World = Matrix.Scaling(m_scaleX, m_scaleY, (float)-m_height * World.Settings.VerticalExaggeration);
            }



            drawArgs.device.Transform.World *= Matrix.RotationY((float)-MathEngine.DegreesToRadians(90));

            drawArgs.device.Transform.World *= Matrix.RotationY((float)-MathEngine.DegreesToRadians(m_latitude));

            drawArgs.device.Transform.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(m_longitude));

            drawArgs.device.Transform.World *= translation;



            drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;

            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

            drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;

            drawArgs.device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;

            drawArgs.device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;

            drawArgs.device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, m_extrudeVertices.Length, m_extrudeIndices.Length / 3, m_extrudeIndices, true, m_extrudeVertices);

            drawArgs.device.DrawIndexedUserPrimitives(PrimitiveType.LineList, 0, m_outlineVertices.Length, m_outlineIndices.Length / 2, m_outlineIndices, true, m_outlineVertices);

            drawArgs.device.RenderState.Lighting = lighting;
        }
Пример #7
0
        /// <summary>
        /// Creates a PositionColored sphere centered on zero
        /// </summary>
        /// <param name="device">The current direct3D drawing device.</param>
        /// <param name="radius">The sphere's radius</param>
        /// <param name="slices">Number of slices (Horizontal resolution).</param>
        /// <param name="stacks">Number of stacks. (Vertical resolution)</param>
        /// <returns></returns>
        /// <remarks>
        /// Number of vertices in the sphere will be (slices+1)*(stacks+1)<br/>
        /// Number of faces	:slices*stacks*2
        /// Number of Indexes	: Number of faces * 3;
        /// </remarks>
        private Mesh ColoredSphere(Device device, float radius, int slices, int stacks)
        {
            int numVertices = (slices + 1) * (stacks + 1);
            int numFaces    = slices * stacks * 2;
            int indexCount  = numFaces * 3;

            Mesh mesh = new Mesh(numFaces, numVertices, MeshFlags.Managed, CustomVertex.PositionColored.Format, device);

            // Get the original sphere's vertex buffer.
            int [] ranks = new int[1];
            ranks[0] = mesh.NumberVertices;
            System.Array arr = mesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionColored), LockFlags.None, ranks);

            // Set the vertex buffer
            int vertIndex = 0;

            for (int stack = 0; stack <= stacks; stack++)
            {
                double latitude = -90 + ((float)stack / stacks * (float)180.0);
                for (int slice = 0; slice <= slices; slice++)
                {
                    CustomVertex.PositionColored pnt = new CustomVertex.PositionColored();
                    double  longitude = 180 - ((float)slice / slices * (float)360);
                    Vector3 v         = MathEngine.SphericalToCartesian(latitude, longitude, radius);
                    pnt.X     = v.X;
                    pnt.Y     = v.Y;
                    pnt.Z     = v.Z;
                    pnt.Color = Color.Black.ToArgb();
                    //pnt.Tu = (float)slice/slices;
                    //pnt.Tv = 1.0f-(float)stack/stacks;
                    arr.SetValue(pnt, vertIndex++);
                }
            }

            mesh.VertexBuffer.Unlock();
            ranks[0] = indexCount;
            arr      = mesh.LockIndexBuffer(typeof(short), LockFlags.None, ranks);
            int   i            = 0;
            short bottomVertex = 0;
            short topVertex    = 0;

            for (short x = 0; x < stacks; x++)
            {
                bottomVertex = (short)((slices + 1) * x);
                topVertex    = (short)(bottomVertex + slices + 1);
                for (int y = 0; y < slices; y++)
                {
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    arr.SetValue(topVertex, i++);
                    arr.SetValue(bottomVertex, i++);
                    arr.SetValue((short)(bottomVertex + 1), i++);
                    arr.SetValue((short)(topVertex + 1), i++);
                    bottomVertex++;
                    topVertex++;
                }
            }
            mesh.IndexBuffer.SetData(arr, 0, LockFlags.None);
            //mesh.ComputeNormals();

            return(mesh);
        }
Пример #8
0
 public void Init()
 {
     mathEngine = new MathEngine();
 }
Пример #9
0
        /// <summary>
        /// Builds the image's mesh
        /// 构建影像的纹理
        /// </summary>
        protected virtual void CreateMesh()
        {
            int    upperBound  = meshPointCount - 1;
            float  scaleFactor = (float)1 / upperBound;
            double latrange    = Math.Abs(maxLat - minLat);
            double lonrange;

            if (minLon < maxLon)
            {
                lonrange = maxLon - minLon;
            }
            else
            {
                lonrange = 360.0f + maxLon - minLon;
            }

            int opacityColor = System.Drawing.Color.FromArgb(this.m_opacity, 0, 0, 0).ToArgb();

            vertices = new CustomVertex.PositionNormalTextured[meshPointCount * meshPointCount];
            if (UsingUDLRDrawing)
            {
                //采用四角坐标绘制
                double startlatrange = Math.Abs(UpLat - LeftLat);
                double startlonrange;
                if (UpLon > LeftLon)
                {
                    startlonrange = UpLon - LeftLon;
                }
                else
                {
                    startlonrange = 360.0f + UpLon - LeftLon;
                }

                double endlatrange = Math.Abs(RightLat - DownLat);
                double endlonrange;
                if (RightLon > DownLon)
                {
                    endlonrange = RightLon - DownLon;
                }
                else
                {
                    endlonrange = 360.0f + RightLon - DownLon;
                }

                for (int i = 0; i < meshPointCount; i++)
                {
                    double[] startloc = new double[2];
                    startloc[0] = UpLat - startlatrange * scaleFactor * i;
                    startloc[1] = UpLon - startlonrange * scaleFactor * i;

                    double[] endloc = new double[2];
                    endloc[0] = RightLat - endlatrange * scaleFactor * i;
                    endloc[1] = RightLon - endlonrange * scaleFactor * i;

                    latrange = startloc[0] - endloc[0];
                    lonrange = endloc[1] - startloc[1];
                    for (int j = 0; j < meshPointCount; j++)
                    {
                        double height = 0;

                        if (this._terrainAccessor != null)
                        {
                            height = this.verticalExaggeration * this._terrainAccessor.GetElevationAt(
                                (double)startloc[0] - scaleFactor * latrange * j,
                                (double)startloc[1] + scaleFactor * lonrange * j,
                                (double)upperBound / latrange);
                        }

                        Vector3 pos = MathEngine.SphericalToCartesian(
                            startloc[0] - scaleFactor * latrange * j,
                            startloc[1] + scaleFactor * lonrange * j,
                            layerRadius + height);

                        vertices[i * meshPointCount + j].X = pos.X;
                        vertices[i * meshPointCount + j].Y = pos.Y;
                        vertices[i * meshPointCount + j].Z = pos.Z;

                        vertices[i * meshPointCount + j].Tu = j * scaleFactor;
                        vertices[i * meshPointCount + j].Tv = i * scaleFactor;
                        //	vertices[i*meshPointCount + j].Color = opacityColor;
                    }
                }
            }
            else
            {
                //采用最大最小经纬度绘制
                for (int i = 0; i < meshPointCount; i++)
                {
                    for (int j = 0; j < meshPointCount; j++)
                    {
                        double height = 0;
                        if (this._terrainAccessor != null)
                        {
                            height = this.verticalExaggeration * this._terrainAccessor.GetElevationAt(
                                (double)maxLat - scaleFactor * latrange * i,
                                (double)minLon + scaleFactor * lonrange * j,
                                (double)upperBound / latrange);
                        }

                        Vector3 pos = MathEngine.SphericalToCartesian(
                            maxLat - scaleFactor * latrange * i,
                            minLon + scaleFactor * lonrange * j,
                            layerRadius + height);

                        vertices[i * meshPointCount + j].X = pos.X;
                        vertices[i * meshPointCount + j].Y = pos.Y;
                        vertices[i * meshPointCount + j].Z = pos.Z;

                        vertices[i * meshPointCount + j].Tu = j * scaleFactor;
                        vertices[i * meshPointCount + j].Tv = i * scaleFactor;
                        //	vertices[i*meshPointCount + j].Color = opacityColor;
                    }
                }
            }

            indices = new short[2 * upperBound * upperBound * 3];
            for (int i = 0; i < upperBound; i++)
            {
                for (int j = 0; j < upperBound; j++)
                {
                    indices[(2 * 3 * i * upperBound) + 6 * j]     = (short)(i * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 1] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 2] = (short)(i * meshPointCount + j + 1);

                    indices[(2 * 3 * i * upperBound) + 6 * j + 3] = (short)(i * meshPointCount + j + 1);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 4] = (short)((i + 1) * meshPointCount + j);
                    indices[(2 * 3 * i * upperBound) + 6 * j + 5] = (short)((i + 1) * meshPointCount + j + 1);
                }
            }

            calculate_normals(ref vertices, indices);
        }
Пример #10
0
        // Read star catalog and build vertex list
        private void LoadStars()
        {
            string DecSep = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            sphereRadius = drawArgs.WorldCamera.WorldRadius * 20;
            refWidth     = drawArgs.device.Viewport.Width;
            StarCount    = 0;
            FlareCount   = 0;
            int    idxRAhms = 2;                        // Catalog field indices
            int    idxDEdms = 3;
            int    idxVmag  = 4;
            int    idxBV    = 5;
            string line;
            int    isData = 0;

            // Count stars and flares
            TextReader tr = File.OpenText(Path.Combine(pluginPath, catalogFileName));

            while ((line = tr.ReadLine()) != null)
            {
                if (line.Length < 3)
                {
                    continue;
                }
                if (line.Substring(0, 1) == "#")
                {
                    continue;
                }
                if (isData == 0 && line.IndexOf("RA") != -1)                // Field names here
                {
                    // Find out fields indices
                    string[] fieldData = line.Split(';');
                    for (int i = 0; i < fieldData.Length; i++)
                    {
                        if (fieldData[i] == "RAhms")
                        {
                            idxRAhms = i;
                        }
                        if (fieldData[i] == "DEdms")
                        {
                            idxDEdms = i;
                        }
                        if (fieldData[i] == "Vmag")
                        {
                            idxVmag = i;
                        }
                        if (fieldData[i] == "B-V")
                        {
                            idxBV = i;
                        }
                    }
                }
                if (isData == 1)                // Star data here
                {
                    StarCount++;                // just counting now...
                    // Data in ';' separated values
                    string[] starData = line.Split(';');
                    string   Vmag     = starData[idxVmag];                      // Aparent magnitude	" 4.78"
                    // check magnitude -1.5 - 10 for flares
                    double VM = Convert.ToDouble(Vmag.Replace(".", DecSep));
                    if (VM < FlareMag)
                    {
                        FlareCount++;
                    }
                }
                if (line.Substring(0, 3) == "---")
                {
                    isData = 1;
                }
            }
            tr.Close();

            // Create vertex buffer for stars
            int idx = 0;

            StarListVB = new VertexBuffer(typeof(CustomVertex.PositionColored),
                                          StarCount, drawArgs.device,
                                          Usage.Points | Usage.WriteOnly,
                                          CustomVertex.PositionColored.Format,
                                          Pool.Managed);
            CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[StarCount];

            // Create mesh for flares
            int vertIndex = 0;

            CustomVertex.PositionTextured pnt;
            Vector3 v;
            int     numVertices = 4 * FlareCount;
            int     numFaces    = 2 * FlareCount;

            FlareMesh = new Mesh(numFaces, numVertices, MeshFlags.Managed, CustomVertex.PositionTextured.Format, drawArgs.device);
            // Get the original mesh's vertex buffer.
            int [] ranks = new int[1];
            ranks[0] = FlareMesh.NumberVertices;
            System.Array arr = FlareMesh.VertexBuffer.Lock(0, typeof(CustomVertex.PositionTextured), LockFlags.None, ranks);

            // Now process star data and build vertex list and flare mesh
            double longitude = 0;
            double latitude  = 0;
            double maxVdec   = 0;
            double maxBVdec  = -99;
            double minBVdec  = 99;

            isData = 0;
            tr     = File.OpenText(Path.Combine(pluginPath, catalogFileName));
            while ((line = tr.ReadLine()) != null)
            {
                if (line.Length < 3)
                {
                    continue;
                }
                if (line.Substring(0, 1) == "#")
                {
                    continue;
                }
                if (isData == 1)                // Star data here
                {
                    // Data in ';' separated values
                    string[] starData = line.Split(';');
                    string   RAhms    = starData[idxRAhms];                     // Right Asc in H, min, sec     "00 01 35.85"
                    string   DEdms    = starData[idxDEdms];                     // Declinaison Degre min sec	"-77 03 55.1"
                    string   Vmag     = starData[idxVmag];                      // Aparent magnitude	" 4.78"
                    string   BV       = starData[idxBV];                        // B-V spectral color	" 1.254"
                    // compute RAhms into longitude
                    double RAh = Convert.ToDouble(RAhms.Substring(0, 2));
                    double RAm = Convert.ToDouble(RAhms.Substring(3, 2));
                    double RAs = Convert.ToDouble(RAhms.Substring(6, 5).Replace(".", DecSep));
                    longitude = (RAh * 15) + (RAm * .25) + (RAs * 0.0041666) - 180;
                    // compute DEdms into latitude
                    string DEsign = DEdms.Substring(0, 1);
                    double DEd    = Convert.ToDouble(DEdms.Substring(1, 2));
                    double DEm    = Convert.ToDouble(DEdms.Substring(4, 2));
                    double DEs    = Convert.ToDouble(DEdms.Substring(7, 4).Replace(".", DecSep));
                    latitude = DEd + (DEm / 60) + (DEs / 3600);
                    if (DEsign == "-")
                    {
                        latitude *= -1;
                    }
                    // compute aparent magnitude -1.5 - 10 to grayscale 0 - 255
                    double VM   = Convert.ToDouble(Vmag.Replace(".", DecSep));
                    double Vdec = 255 - ((VM + 1.5) * 255 / 10);
                    if (Vdec > maxVdec)
                    {
                        maxVdec = Vdec;
                    }
                    Vdec += 20;                     // boost luminosity
                    if (Vdec > 255)
                    {
                        Vdec = 255;
                    }
                    // convert B-V  -0.5 - 4 for rgb color select
                    double BVdec = 0;
                    try { BVdec = Convert.ToDouble(BV.Replace(".", DecSep)); }
                    catch { BVdec = 0; }
                    if (BVdec > maxBVdec)
                    {
                        maxBVdec = BVdec;
                    }
                    if (BVdec < minBVdec)
                    {
                        minBVdec = BVdec;
                    }

                    // Place vertex for point star
                    v = MathEngine.SphericalToCartesian(latitude, longitude, sphereRadius);
                    verts[idx].Position = new Vector3(v.X, v.Y, v.Z);
                    // color based on B-V
                    verts[idx].Color = Color.FromArgb(255, (int)Vdec, (int)Vdec, (int)Vdec).ToArgb();                     // gray scale default
                    if (BVdec < 4)
                    {
                        verts[idx].Color = Color.FromArgb(255, (int)(235 * Vdec / 255), (int)(96 * Vdec / 255), (int)(10 * Vdec / 255)).ToArgb();                     // redish
                    }
                    if (BVdec < 1.5)
                    {
                        verts[idx].Color = Color.FromArgb(255, (int)(246 * Vdec / 255), (int)(185 * Vdec / 255), (int)(20 * Vdec / 255)).ToArgb();                     // orange
                    }
                    if (BVdec < 1)
                    {
                        verts[idx].Color = Color.FromArgb(255, (int)(255 * Vdec / 255), (int)(251 * Vdec / 255), (int)(68 * Vdec / 255)).ToArgb();                     // yellow
                    }
                    if (BVdec < .5)
                    {
                        verts[idx].Color = Color.FromArgb(255, (int)(255 * Vdec / 255), (int)(255 * Vdec / 255), (int)(255 * Vdec / 255)).ToArgb();                     // white
                    }
                    if (BVdec < 0)
                    {
                        verts[idx].Color = Color.FromArgb(255, (int)(162 * Vdec / 255), (int)(195 * Vdec / 255), (int)(237 * Vdec / 255)).ToArgb();                     // light blue
                    }
                    // Next vertex
                    idx++;

                    // if flare add 4 vertex to mesh
                    if (VM < FlareMag)
                    {
                        double flareFactor = sphereRadius * 5 / drawArgs.device.Viewport.Width;
                        double l           = (VM + 1.5) / (FlareMag + 1.5) * flareFactor;               // Size of half flare texture in meter
                        // Calculate perp1 and perp2 so they form a plane perpendicular to the star vector and crossing earth center
                        Vector3 perp1 = Vector3.Cross(v, new Vector3(1, 1, 1));
                        Vector3 perp2 = Vector3.Cross(perp1, v);
                        perp1.Normalize();
                        perp2.Normalize();
                        perp1.Scale((float)l);
                        perp2.Scale((float)l);
                        Vector3 v1;

                        //v = MathEngine.SphericalToCartesian( latitude + l, longitude - l, sphereRadius);
                        v1           = v + perp1 - perp2;
                        pnt          = new CustomVertex.PositionTextured();
                        pnt.Position = new Vector3(v1.X, v1.Y, v1.Z);
                        pnt.Tu       = 0;
                        pnt.Tv       = 0;
                        arr.SetValue(pnt, vertIndex++);
                        //v = MathEngine.SphericalToCartesian( latitude + l, longitude + l, sphereRadius);
                        v1           = v + perp1 + perp2;
                        pnt          = new CustomVertex.PositionTextured();
                        pnt.Position = new Vector3(v1.X, v1.Y, v1.Z);
                        pnt.Tu       = 1;
                        pnt.Tv       = 0;
                        arr.SetValue(pnt, vertIndex++);
                        //v = MathEngine.SphericalToCartesian( latitude - l, longitude - l, sphereRadius);
                        v1           = v - perp1 - perp2;
                        pnt          = new CustomVertex.PositionTextured();
                        pnt.Position = new Vector3(v1.X, v1.Y, v1.Z);
                        pnt.Tu       = 0;
                        pnt.Tv       = 1;
                        arr.SetValue(pnt, vertIndex++);
                        //v = MathEngine.SphericalToCartesian( latitude - l, longitude + l, sphereRadius);
                        v1           = v - perp1 + perp2;
                        pnt          = new CustomVertex.PositionTextured();
                        pnt.Position = new Vector3(v1.X, v1.Y, v1.Z);
                        pnt.Tu       = 1;
                        pnt.Tv       = 1;
                        arr.SetValue(pnt, vertIndex++);
                    }
                }
                if (line.Substring(0, 3) == "---")
                {
                    isData = 1;
                }
            }
            tr.Close();
            //MessageBox.Show("FlareCount : " + FlareCount.ToString(), "Info", MessageBoxButtons.OK, MessageBoxIcon.Error );


            // Set vertex buffer for stars
            StarListVB.SetData(verts, 0, LockFlags.None);

            // Set flare mesh indices
            FlareMesh.VertexBuffer.Unlock();
            ranks[0]  = numFaces * 3;
            arr       = FlareMesh.LockIndexBuffer(typeof(short), LockFlags.None, ranks);
            vertIndex = 0;
            for (int flare = 0; flare < FlareCount; flare++)
            {
                short v1 = (short)(flare * 4);
                arr.SetValue(v1, vertIndex++);
                arr.SetValue((short)(v1 + 1), vertIndex++);
                arr.SetValue((short)(v1 + 2), vertIndex++);
                arr.SetValue((short)(v1 + 1), vertIndex++);
                arr.SetValue((short)(v1 + 3), vertIndex++);
                arr.SetValue((short)(v1 + 2), vertIndex++);
            }
            FlareMesh.IndexBuffer.SetData(arr, 0, LockFlags.None);
            FlareMesh.UnlockIndexBuffer();
        }
Пример #11
0
        private void RenderFlag(DrawArgs drawArgs, double offset)
        {
            if (m_effect == null)
            {
                string outerrors = "";

                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                Stream effectStream = assembly.GetManifestResourceStream("WorldWind.Shaders.flag.fx");

                m_effect =
                    Effect.FromStream(
                    drawArgs.device,
                    effectStream,
                    null,
                    null,
                    ShaderFlags.None,
                    null,
                    out outerrors);

                if (outerrors != null && outerrors.Length > 0)
                    Log.Write(Log.Levels.Error, outerrors);
            }

            if (m_vertexBuffer == null)
            {
                drawArgs.device.DeviceReset += new EventHandler(this.device_DeviceReset);
                this.device_DeviceReset(drawArgs.device, null);
            }

            if (m_flagPoleVertices == null)
            {
                CreateFlagPole(drawArgs.device);
            }

            Vector3 pos = MathEngine.SphericalToCartesian(this.m_latitude, this.m_longitude, this.World.EquatorialRadius + World.Settings.VerticalExaggeration * this.ScaleZ + offset);
            Vector3 surfacePos = MathEngine.SphericalToCartesian(this.m_latitude, this.m_longitude, this.World.EquatorialRadius + offset);

            Vector3 rc = new Vector3(
                (float)drawArgs.WorldCamera.ReferenceCenter.X,
                (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                (float)drawArgs.WorldCamera.ReferenceCenter.Z
                );

            drawArgs.device.SetTransform(TransformState.World, Matrix.Scaling(World.Settings.VerticalExaggeration * this.ScaleX * 0.01f, 
                World.Settings.VerticalExaggeration * this.ScaleY * 0.01f, -World.Settings.VerticalExaggeration * 2 * this.ScaleZ);
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationY((float)-MathEngine.DegreesToRadians(90));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationY((float)-MathEngine.DegreesToRadians(this.m_latitude));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.m_longitude));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.Translation(surfacePos - rc);

            drawArgs.device.VertexFormat = CustomVertex.PositionColored.Format;
            drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation , TextureOperation.SelectArg1);
            drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Diffuse);
            drawArgs.device.SetTextureStageState(0, TextureStage.AlphaArg1,TextureArgument.Diffuse);
            drawArgs.device.SetTextureStageState(0, TextureStage.AlphaOperation,  TextureOperation.SelectArg1);
            drawArgs.device.VertexShader = null;
            drawArgs.device.PixelShader = null;
            drawArgs.device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 
                0, m_flagPoleVertices.Length, m_flagPoleIndices.Length / 3, m_flagPoleIndices, 
                Format.Index16, m_flagPoleVertices);
            drawArgs.device.DrawIndexedUserPrimitives(PrimitiveType.LineList, 0, 
                m_outlineFlagPoleVertices.Length, m_outlineFlagPoleIndices.Length / 2, 
                m_outlineFlagPoleIndices, Format.Index16, m_outlineFlagPoleVertices);
            drawArgs.device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
            drawArgs.device.VertexDeclaration = m_vertexDeclaration;
            this.m_angle += .04f;

            if (this.m_angle > 360) this.m_angle = 0;

            drawArgs.device.VertexFormat = CustomVertex.PositionNormalTextured.Format;

            drawArgs.device.SetTransform(TransformState.World, Matrix.Scaling(World.Settings.VerticalExaggeration * this.ScaleX, 
                World.Settings.VerticalExaggeration * this.ScaleY, World.Settings.VerticalExaggeration * this.ScaleZ);
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationY((float)-MathEngine.DegreesToRadians(this.m_latitude)));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.m_longitude)));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.Translation(pos - rc);

            //Matrix worldViewProj = drawArgs.device.GetWorldViewProjMatrix();

            DateTime currentTime = TimeKeeper.CurrentTimeUtc;
            Point3d sunPosition = SunCalculator.GetGeocentricPosition(currentTime);

            Vector3 sunVector = new Vector3(
                (float)-sunPosition.X,
                (float)-sunPosition.Y,
                (float)-sunPosition.Z);

            m_effect.Technique = "VertexAndPixelShader";
            m_effect.SetValue("angle", (float) this.m_angle);
            m_effect.SetValue("attentuation", this.Attentuation);
            m_effect.SetValue("World", drawArgs.device.GetTransform(TransformState.World));
            m_effect.SetValue("View", drawArgs.device.GetTransform(TransformState.View));
            m_effect.SetValue("Projection", drawArgs.device.GetTransform(TransformState.Projection));
            m_effect.SetValue("Tex0", this.m_texture.NativePointer);
            m_effect.SetValue("lightDir", new Vector4(sunVector.X, sunVector.Y, sunVector.Z, 0));

            drawArgs.device.Indices = m_indexBuffer;
            drawArgs.device.SetStreamSource(0, m_vertexBuffer, 0, 0);
            int numPasses = m_effect.Begin(0);

            for (int i = 0; i < numPasses; i++)
            {
                m_effect.BeginPass(i);
                drawArgs.device.DrawIndexedPrimitive(
                    PrimitiveType.TriangleList, 0, 0, m_vertices.Length, 0,
                    m_indices.Length / 3);

                m_effect.EndPass();
            }
            m_effect.End();
            drawArgs.device.Indices = null;
            drawArgs.device.SetTransform(TransformState.World, drawArgs.WorldCamera.WorldMatrix);
            drawArgs.device.SetTransform(TransformState.View, drawArgs.WorldCamera.ViewMatrix);
        }
Пример #12
0
        public override void Render(DrawArgs drawArgs)
        {
            if (!this.isInitialized)
                return;

            if (this.m_polygonFeature == null || !drawArgs.WorldCamera.ViewFrustum.Intersects(this.m_polygonFeature.BoundingBox))
                return;
            try
            {
                double offset = 0;
                if (this.Bar3D != null && this.Bar3D.IsOn)
                {
                    this.Bar3D.Render(drawArgs);
                    offset = this.Bar3D.RenderedHeight;
                }
                Cull cull = drawArgs.device.GetRenderState<Cull>(RenderState.CullMode);
                drawArgs.device.SetRenderState(RenderState.CullMode , Cull.None);
                drawArgs.device.SetRenderState(RenderState.ZEnable , true);
                drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation , TextureOperation.SelectArg1);
                drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);

                Vector3 surfacePos = MathEngine.SphericalToCartesian(this.m_latitude, this.m_longitude, this.World.EquatorialRadius);

                Vector3 rc = new Vector3(
                    (float)drawArgs.WorldCamera.ReferenceCenter.X,
                    (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                    (float)drawArgs.WorldCamera.ReferenceCenter.Z
                    );

                Vector3 projectedPoint = drawArgs.WorldCamera.Project(surfacePos - rc);
                int mouseBuffer = 15;
                if (projectedPoint.X > DrawArgs.LastMousePosition.X - mouseBuffer &&
                        projectedPoint.X < DrawArgs.LastMousePosition.X + mouseBuffer &&
                        projectedPoint.Y > DrawArgs.LastMousePosition.Y - mouseBuffer &&
                        projectedPoint.Y < DrawArgs.LastMousePosition.Y + mouseBuffer)
                {
                    if (!this.m_isMouseInside)
                    {
                        this.m_isMouseInside = true;
                        if (this.OnMouseEnterEvent != null) this.OnMouseEnterEvent(this, null);
                    }
                }
                else
                {
                    if (this.m_isMouseInside)
                    {
                        this.m_isMouseInside = false;
                        if (this.OnMouseLeaveEvent != null) this.OnMouseLeaveEvent(this, null);
                    }
                }
                drawArgs.device.SetRenderState(RenderState.CullMode , Cull.None);

                if (this.ShowHighlight) this.renderHighlight(drawArgs);
                this.RenderFlag(drawArgs, offset);
                drawArgs.device.SetRenderState(RenderState.CullMode , cull);
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Пример #13
0
        private void renderHighlight(DrawArgs drawArgs)
        {
            bool lighting = drawArgs.device.GetRenderState<bool>(RenderState.Lighting);
            drawArgs.device.SetRenderState(RenderState.Lighting , false);

            if (m_highlightVertices == null)
            {
                m_highlightVertices = new CustomVertex.PositionColoredTextured[4];

                m_highlightVertices[0].X = -0.5f;
                m_highlightVertices[0].Y = 0.5f;
                m_highlightVertices[0].Z = 0.0f;
                m_highlightVertices[0].Tu = 0.0f;
                m_highlightVertices[0].Tv = 0.0f;

                m_highlightVertices[1].X = -0.5f;
                m_highlightVertices[1].Y = -0.5f;
                m_highlightVertices[1].Z = 0.0f;
                m_highlightVertices[1].Tu = 0.0f;
                m_highlightVertices[1].Tv = 1.0f;

                m_highlightVertices[2].X = 0.5f;
                m_highlightVertices[2].Y = 0.5f;
                m_highlightVertices[2].Z = 0.0f;
                m_highlightVertices[2].Tu = 1.0f;
                m_highlightVertices[2].Tv = 0.0f;

                m_highlightVertices[3].X = 0.5f;
                m_highlightVertices[3].Y = -0.5f;
                m_highlightVertices[3].Z = 0.0f;
                m_highlightVertices[3].Tu = 1.0f;
                m_highlightVertices[3].Tv = 1.0f;
            }

            if (HighlightTexture == null)
                HighlightTexture = ImageHelper.LoadTexture(this.highlightTexturePath);

            drawArgs.device.SetTransform(TransformState.World, Matrix.RotationY((float)MathEngine.DegreesToRadians(90));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.Scaling(World.Settings.VerticalExaggeration * this.ScaleX,
                World.Settings.VerticalExaggeration * this.ScaleY, World.Settings.VerticalExaggeration * this.ScaleZ);
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationY((float)-MathEngine.DegreesToRadians(this.m_latitude));
            drawArgs.device.SetTransform(TransformState.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(this.m_longitude));

            Vector3 surfacePos = MathEngine.SphericalToCartesian(this.m_latitude, this.m_longitude, this.World.EquatorialRadius);

            Vector3 rc = new Vector3(
                (float)drawArgs.WorldCamera.ReferenceCenter.X,
                (float)drawArgs.WorldCamera.ReferenceCenter.Y,
                (float)drawArgs.WorldCamera.ReferenceCenter.Z
                );

            drawArgs.device.SetTransform(TransformState.World *= Matrix.Translation(surfacePos - rc);
            drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation , TextureOperation.SelectArg1);
            drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
            drawArgs.device.SetTextureStageState(0, TextureStage.AlphaArg1,TextureArgument.Texture);
            drawArgs.device.SetTextureStageState(0, TextureStage.AlphaOperation,  TextureOperation.SelectArg1);
            drawArgs.device.SetRenderState(RenderState.ZEnable , false);
            drawArgs.device.SetTexture(0, HighlightTexture);
            drawArgs.device.VertexFormat = CustomVertex.PositionColoredTextured.Format;

            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, m_highlightVertices);
            drawArgs.device.SetRenderState(RenderState.ZEnable , true);
            drawArgs.device.SetRenderState(RenderState.Lighting , lighting);
        }
Пример #14
0
        public override void Render(DrawArgs drawArgs)
        {
            if (!isInitialized)
            {
                return;
            }



            if (m_polygonFeature == null || !drawArgs.WorldCamera.ViewFrustum.Intersects(m_polygonFeature.BoundingBox))
            {
                return;
            }



            try
            {
                double offset = 0;

                if (Bar3D != null && Bar3D.IsOn)
                {
                    Bar3D.Render(drawArgs);

                    offset = Bar3D.RenderedHeight;
                }



                Cull cull = drawArgs.device.RenderState.CullMode;

                drawArgs.device.RenderState.CullMode = Cull.None;

                drawArgs.device.RenderState.ZBufferEnable = true;

                drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

                drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;



                Vector3 surfacePos = MathEngine.SphericalToCartesian(m_latitude, m_longitude, World.EquatorialRadius);



                Vector3 rc = new Vector3(

                    (float)drawArgs.WorldCamera.ReferenceCenter.X,

                    (float)drawArgs.WorldCamera.ReferenceCenter.Y,

                    (float)drawArgs.WorldCamera.ReferenceCenter.Z

                    );



                Vector3 projectedPoint = drawArgs.WorldCamera.Project(surfacePos - rc);



                int mouseBuffer = 15;



                if (projectedPoint.X > DrawArgs.LastMousePosition.X - mouseBuffer &&

                    projectedPoint.X < DrawArgs.LastMousePosition.X + mouseBuffer &&

                    projectedPoint.Y > DrawArgs.LastMousePosition.Y - mouseBuffer &&

                    projectedPoint.Y < DrawArgs.LastMousePosition.Y + mouseBuffer)
                {
                    if (!m_isMouseInside)
                    {
                        m_isMouseInside = true;

                        if (OnMouseEnterEvent != null)
                        {
                            OnMouseEnterEvent(this, null);
                        }
                    }
                }

                else
                {
                    if (m_isMouseInside)
                    {
                        m_isMouseInside = false;

                        if (OnMouseLeaveEvent != null)
                        {
                            OnMouseLeaveEvent(this, null);
                        }
                    }
                }

                drawArgs.device.RenderState.CullMode = Cull.None;



                if (ShowHighlight)
                {
                    renderHighlight(drawArgs);
                }



                RenderFlag(drawArgs, offset);



                drawArgs.device.RenderState.CullMode = cull;
            }

            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }
Пример #15
0
        public override void Render(DrawArgs drawArgs)
        {
            if (errorMsg != null)
            {
                errorMsg      = null;
                IsOn          = false;
                isInitialized = false;
                return;
            }

            if (!IsVisible(drawArgs.WorldCamera))
            {
                // Mesh is not in view, unload it to save memory
                if (isInitialized)
                {
                    Dispose();
                }
                return;
            }

            if (!isInitialized)
            {
                return;
            }

            //Donot render for other planets
            if (!drawArgs.CurrentWorld.IsEarth)
            {
                return;
            }



            drawArgs.device.RenderState.CullMode         = Cull.None;
            drawArgs.device.RenderState.Lighting         = true;
            drawArgs.device.RenderState.AmbientColor     = 0x808080;
            drawArgs.device.RenderState.NormalizeNormals = true;

            drawArgs.device.Lights[0].Diffuse   = Color.FromArgb(255, 255, 255);
            drawArgs.device.Lights[0].Type      = LightType.Directional;
            drawArgs.device.Lights[0].Direction = new Vector3(1f, 1f, 1f);
            drawArgs.device.Lights[0].Enabled   = true;

            drawArgs.device.SamplerState[0].AddressU = TextureAddress.Wrap;
            drawArgs.device.SamplerState[0].AddressV = TextureAddress.Wrap;

            drawArgs.device.RenderState.AlphaBlendEnable   = true;
            drawArgs.device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;

            // Put the light somewhere up in space
            drawArgs.device.Lights[0].Position = new Vector3(
                (float)worldXyz.X * 2f,
                (float)worldXyz.Y * 1f,
                (float)worldXyz.Z * 1.5f);

            Matrix currentWorld = drawArgs.device.Transform.World;

            drawArgs.device.Transform.World  = Matrix.RotationX((float)MathEngine.DegreesToRadians(RotX));
            drawArgs.device.Transform.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(RotY));
            drawArgs.device.Transform.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(RotZ));
            drawArgs.device.Transform.World *= Matrix.Scaling(Scale, Scale, Scale);

            // Move the mesh to desired location on earth
            if (IsVertExaggerable)
            {
                vertExaggeration = World.Settings.VerticalExaggeration;
            }
            else
            {
                vertExaggeration = 1;
            }
            drawArgs.device.Transform.World *= Matrix.Translation(0, 0, (float)drawArgs.WorldCamera.WorldRadius + Altitude * vertExaggeration);
            drawArgs.device.Transform.World *= Matrix.RotationY((float)MathEngine.DegreesToRadians(90 - Latitude));
            drawArgs.device.Transform.World *= Matrix.RotationZ((float)MathEngine.DegreesToRadians(Longitude));


            drawArgs.device.Transform.World *= Matrix.Translation(
                (float)-drawArgs.WorldCamera.ReferenceCenter.X,
                (float)-drawArgs.WorldCamera.ReferenceCenter.Y,
                (float)-drawArgs.WorldCamera.ReferenceCenter.Z
                );

            Device device = drawArgs.device;

            // Draw the mesh with effect
            if (isBumpmapped)
            {
                setupBumpEffect(drawArgs);
            }
            else
            {
                setupReflectionEffect(drawArgs);
            }

            //render the effect
            bool alphastate = device.RenderState.AlphaBlendEnable;

            device.RenderState.AlphaBlendEnable = true;
            effect.Begin(0);
            effect.BeginPass(0);

            //drawArgs.device.SetTexture(0, texture);
            m_meshElems[0].mesh.DrawSubset(0);

            effect.EndPass();
            effect.End();
            device.RenderState.AlphaBlendEnable = alphastate;


            drawArgs.device.Transform.World      = currentWorld;
            drawArgs.device.RenderState.Lighting = false;
        }