Example #1
0
        private void DrawAxis(DrawArgs drawArgs)
        {
            CustomVertex.PositionColored[] axis = new CustomVertex.PositionColored[2];
            Vector3 topV = MathEngine.SphericalToCartesian(90, 0, 1.15f * this.EquatorialRadius);

            axis[0].X = topV.X;
            axis[0].Y = topV.Y;
            axis[0].Z = topV.Z;

            axis[0].Color = Color.Pink.ToArgb();

            Vector3 botV = MathEngine.SphericalToCartesian(-90, 0, 1.15f * this.EquatorialRadius);

            axis[1].X     = botV.X;
            axis[1].Y     = botV.Y;
            axis[1].Z     = botV.Z;
            axis[1].Color = Color.Pink.ToArgb();

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

            drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, 1, axis);
            drawArgs.Device.Transform.World = drawArgs.WorldCamera.WorldMatrix;
        }
Example #2
0
        public override void Update(DrawArgs drawArgs)
        {
            try
            {
                if (!drawArgs.WorldCamera.ViewFrustum.Intersects(this.boundingBox))
                {
                    this.Dispose();
                    return;
                }

                if (!this.isLoaded)
                {
                    this.Load();
                }

                if (this.linePoints != null)
                {
                    if ((this.lastUpdatedPosition - drawArgs.WorldCamera.Position).LengthSquared() < 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;
                        }
                    }
                }

                this.verticalExaggeration = World.Settings.VerticalExaggeration;

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

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

                for (int i = 0; i < this.sphericalCoordinates.Count; i++)
                {
                    double altitude = 0;
                    if (this._parentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 3000000)
                    {
                        altitude = this._terrainAccessor.GetElevationAt(this.sphericalCoordinates[i].X, this.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;

                this.lastUpdatedPosition = drawArgs.WorldCamera.Position;
                System.Threading.Thread.Sleep(1);
            }
            catch
            {
            }
        }
Example #3
0
        public void AddPointToPath(float latitude, float longitude, bool terrainMapped, float heightAboveSurface)
        {
/*			if(terrainMapped)
 *                      {
 *                              heightAboveSurface += this.terrainManager.GetHeightAt(latitude, longitude) * this.verticalExaggeration;
 *                      }*/
            //Always add first coordinate

            Vector3[] newPoints = null;

            if (this.sphericalCoordinates.Length > 0)
            {
                float startLatitude  = this.sphericalCoordinates[this.sphericalCoordinates.Length - 1].X;
                float startLongitude = this.sphericalCoordinates[this.sphericalCoordinates.Length - 1].Y;
                newPoints = this.BuildSegment(Angle.FromDegrees(startLatitude), Angle.FromDegrees(startLongitude),
                                              Angle.FromDegrees(latitude), Angle.FromDegrees(longitude),
                                              heightAboveSurface);
            }


            Vector3[] newCoords = new Vector3[this.sphericalCoordinates.Length + 1];

            this.sphericalCoordinates.CopyTo(newCoords, 0);

            newCoords[newCoords.Length - 1].X = latitude;
            newCoords[newCoords.Length - 1].Y = longitude;
            newCoords[newCoords.Length - 1].Z = heightAboveSurface;

            this.sphericalCoordinates = newCoords;

            //TODO: HACK work fix this
            if (newPoints == null)
            {
                CustomVertex.PositionColored[] newLine = new CustomVertex.PositionColored[this.linePoints.Length + 1];
                this.linePoints.CopyTo(newLine, 0);


                Vector3 newPoint = MathEngine.SphericalToCartesian(latitude, longitude, this._parentWorld.EquatorialRadius + this.verticalExaggeration * heightAboveSurface);
                newLine[newLine.Length - 1] = new PositionColored(newPoint.X, newPoint.Y, newPoint.Z, this.lineColor);

                //Need to build path if points are spread too far apart

                lock (this.linePoints.SyncRoot)
                {
                    this.linePoints = newLine;
                }
            }
            else
            {
                foreach (Vector3 newPoint in newPoints)
                {
                    CustomVertex.PositionColored[] newLine = new CustomVertex.PositionColored[this.linePoints.Length + 1];
                    this.linePoints.CopyTo(newLine, 0);


                    //Vector3 newPoint = MathEngine.SphericalToCartesian(latitude, longitude, this._parentWorld.EquatorialRadius + this.verticalExaggeration * heightAboveSurface );
                    newLine[newLine.Length - 1] = new PositionColored(newPoint.X, newPoint.Y, newPoint.Z, this.lineColor);

                    //Need to build path if points are spread too far apart

                    lock (this.linePoints.SyncRoot)
                    {
                        this.linePoints = newLine;
                    }
                }
            }
            if (this.linePoints.Length == 1)
            {
                this.north = latitude;
                this.south = latitude;
                this.west  = longitude;
                this.east  = longitude;
            }
            else
            {
                if (latitude > this.north)
                {
                    this.north = latitude;
                }
                if (latitude < this.south)
                {
                    this.south = latitude;
                }
                if (longitude < this.west)
                {
                    this.west = longitude;
                }
                if (longitude > this.east)
                {
                    this.east = longitude;
                }
            }
        }