Example #1
0
		public void DrawBoundingBox(BoundingBox box, DMatrix transform)
		{
			var corners			= box.GetCorners();
			var worldCorners	= corners.Select(x => DVector3.TransformCoordinate(new DVector3(x.X, x.Y, x.Z), transform)).ToArray();

			//foreach (var corner in worldCorners)
			//{
			//	DrawPoint(corner, 0.1f);
			//}
			

			DrawLine(worldCorners[0], worldCorners[1], Color.Green);
			DrawLine(worldCorners[0], worldCorners[4], Color.Green);
			DrawLine(worldCorners[0], worldCorners[3], Color.Green);

			DrawLine(worldCorners[7], worldCorners[6], Color.Red);
			DrawLine(worldCorners[7], worldCorners[3], Color.Red);
			DrawLine(worldCorners[7], worldCorners[4], Color.Red);

			DrawLine(worldCorners[5], worldCorners[1], Color.Yellow);
			DrawLine(worldCorners[5], worldCorners[4], Color.Yellow);
			DrawLine(worldCorners[5], worldCorners[6], Color.Yellow);

			DrawLine(worldCorners[2], worldCorners[1], Color.WhiteSmoke);
			DrawLine(worldCorners[2], worldCorners[3], Color.WhiteSmoke);
			DrawLine(worldCorners[2], worldCorners[6], Color.WhiteSmoke);
		}
        public GameObject(string MeshName)
        {
            Position = new DVector3();

            MMC = ContentManager.LoadMultiMesh(MeshName);
            LocalAABBMin = Conversion.ToDoubleVector(MMC.LocalAABBMin);
            LocalAABBMax = Conversion.ToDoubleVector(MMC.LocalAABBMax);

            Transformation =  DMatrix.CreateScale(1d)*DMatrix.CreateTranslation(Position) * DMatrix.CreateFromYawPitchRoll(0, 0, 0);

            RecalcAABB();

            InitObj();
            Lens = ContentManager.LoadTexture2D("Content/Textures/Lens");
        }
 public static DMatrix ToDoubleMatrix(JMatrix matrix)
 {
     DMatrix TM = new DMatrix();
     TM.M11 = (float)matrix.M11;
     TM.M12 = (float)matrix.M12;
     TM.M13 = (float)matrix.M13;
     //TM.M14 = 0.0f;
     TM.M21 = (float)matrix.M21;
     TM.M22 = (float)matrix.M22;
     TM.M23 = (float)matrix.M23;
     //TM.M24 = 0.0f;
     TM.M31 = (float)matrix.M31;
     TM.M32 = (float)matrix.M32;
     TM.M33 = (float)matrix.M33;
     //TM.M34 = 0.0f;
     //TM.M41 = 0.0f;
     //TM.M42 = 0.0f;
     //TM.M43 = 0.0f;
     TM.M44 = 1.0f;
     return TM;
 }
 public static DMatrix ToDoubleMatrix(Matrix matrix)
 {
     DMatrix TM = new DMatrix();
     TM.M11 = matrix.M11;
     TM.M12 = matrix.M12;
     TM.M13 = matrix.M13;
     TM.M14 = matrix.M14;
     TM.M21 = matrix.M21;
     TM.M22 = matrix.M22;
     TM.M23 = matrix.M23;
     TM.M24 = matrix.M24;
     TM.M31 = matrix.M31;
     TM.M32 = matrix.M32;
     TM.M33 = matrix.M33;
     TM.M34 = matrix.M34;
     TM.M41 = matrix.M41;
     TM.M42 = matrix.M42;
     TM.M43 = matrix.M43;
     TM.M44 = matrix.M44;
     return TM;
 }
//    public static DenseD2Matrix64F convertToD2( DMatrixRMaj orig ) {
//        DenseD2Matrix64F ret = new DenseD2Matrix64F(orig.getNumRows(),orig.getNumCols());
//
//        copy(orig,ret);
//
//        return ret;
//    }

        public static bool isEquivalent(DMatrix a, DMatrix b, double tol)
        {
            if (a.getNumRows() != b.getNumRows() || a.getNumCols() != b.getNumCols())
            {
                return(false);
            }

            for (int i = 0; i < a.getNumRows(); i++)
            {
                for (int j = 0; j < a.getNumCols(); j++)
                {
                    double diff = Math.Abs(a.get(i, j) - b.get(i, j));

                    if (diff > tol)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public static void printFancy(DMatrix mat, int length)
        {
            // TODO print en consola

            /*
             * printTypeSize(out, mat);
             * DecimalFormat format = new DecimalFormat("#");
             *
             * final int cols = mat.getNumCols();
             *
             * for (int row = 0; row < mat.getNumRows(); row++)
             * {
             *  for (int col = 0; col < cols; col++)
             *  {
             *  out.print(fancyStringF(mat.get(row, col), format, length, 4));
             *      if (col != cols - 1)
             *      out.print(" ");
             *  }
             * out.println();
             * }
             */
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="observation"></param>
        /// <returns></returns>
        public ProbabilityPrediction PredictProbability(double[] observation)
        {
            var floatObservation = new float[][]
            {
                observation.ToFloat()
            };

            using (var data = new DMatrix(floatObservation))
            {
                var prediction = m_model.Predict(data);

                var numberOfClasses = prediction.Length;
                if (numberOfClasses >= 2)
                {
                    return(PredictMultiClassProbability(prediction));
                }
                else
                {
                    return(PredictSingleClassProbability(prediction));
                }
            }
        }
        /**
         * <p>
         * Checks to see if each element in the upper or lower triangular portion of the two matrices are within tolerance of
         * each other: tol &ge; |a<sub>ij</sub> - b<sub>ij</sub>|.
         * <p>
         *
         * <p>
         * NOTE: If any of the elements are not countable then false is returned.<br>
         * NOTE: If a tolerance of zero is passed in this is equivalent to calling
         * {@link #isEquals(DMatrixD1, DMatrixD1)}
         * </p>
         *
         * @param a A matrix. Not modified.
         * @param b A matrix. Not modified.
         * @param upper true of upper triangular and false for lower.
         * @param tol How close to being identical each element needs to be.
         * @return true if equals and false otherwise.
         */
        public static bool isEqualsTriangle(DMatrix a, DMatrix b, bool upper, double tol)
        {
            if (a.NumRows != b.NumRows || a.NumCols != b.NumCols)
            {
                return(false);
            }

            if (upper)
            {
                for (int i = 0; i < a.NumRows; i++)
                {
                    for (int j = i; j < a.NumCols; j++)
                    {
                        if (Math.Abs(a.get(i, j) - b.get(i, j)) > tol)
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < a.NumRows; i++)
                {
                    int end = Math.Min(i, a.NumCols - 1);

                    for (int j = 0; j <= end; j++)
                    {
                        if (Math.Abs(a.get(i, j) - b.get(i, j)) > tol)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Example #9
0
        public virtual void set(Matrix original)
        {
            DMatrix m = (DMatrix)original;

            if (m.getNumCols() == 1 && m.getNumRows() == 4)
            {
                a1 = m.get(0, 0);
                a2 = m.get(1, 0);
                a3 = m.get(2, 0);
                a4 = m.get(3, 0);
            }
            else if (m.getNumRows() == 1 && m.getNumCols() == 4)
            {
                a1 = m.get(0, 0);
                a2 = m.get(0, 1);
                a3 = m.get(0, 2);
                a4 = m.get(0, 3);
            }
            else
            {
                throw new ArgumentException("Incompatible shape");
            }
        }
Example #10
0
        public override void set(Matrix original)
        {
            DMatrix m = (DMatrix)original;

            reshape(original.getNumRows(), original.getNumCols());

            if (original is DMatrixRMaj)
            {
                // do a faster copy if its of type DMatrixRMaj
                Array.Copy(((DMatrixRMaj)m).data, 0, data, 0, numRows * numCols);
            }
            else
            {
                int index = 0;
                for (int i = 0; i < numRows; i++)
                {
                    for (int j = 0; j < numCols; j++)
                    {
                        data[index++] = m.get(i, j);
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void InputDeviceOnMouseDown(object sender, Frame.MouseEventArgs args)
        {
            if (args.Key != Keys.LeftButton)
            {
                return;
            }

            var w = viewportWidth;
            var h = viewportHeight;

            var pos = new Vector2(args.X, args.Y);

            var nearPoint = new DVector3(pos.X, pos.Y, frustumZNear);
            var farPoint  = new DVector3(pos.X, pos.Y, frustumZFar);

            var vm  = DMatrix.LookAtRH(cameraPosition, DVector3.Zero, DVector3.UnitY);
            var mVP = vm * projMatrix;

            var near = DVector3.Unproject(nearPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);
            var far  = DVector3.Unproject(farPoint, 0, 0, w, h, frustumZNear, frustumZFar, mVP);

            DVector3[] res;

            if (LineIntersection(near, far, Config.earthRadius, out res))
            {
                if (res.Length > 0)
                {
                    double lon, lat;

                    CartesianToSpherical(res[0], out lon, out lat);

                    var lonLat = new DVector2(DMathUtil.RadiansToDegrees(lon), DMathUtil.RadiansToDegrees(lat));

                    Console.WriteLine(lonLat);
                }
            }
        }
Example #12
0
 /**
  * Returns true if the provided matrix is has a value of 1 along the diagonal
  * elements and zero along all the other elements.
  *
  * @param a Matrix being inspected.
  * @param tol How close to zero or one each element needs to be.
  * @return If it is within tolerance to an identity matrix.
  */
 public static bool isIdentity(DMatrix a, double tol)
 {
     for (int i = 0; i < a.getNumRows(); i++)
     {
         for (int j = 0; j < a.getNumCols(); j++)
         {
             if (i == j)
             {
                 if (Math.Abs(a.get(i, j) - 1.0) > tol)
                 {
                     return(false);
                 }
             }
             else
             {
                 if (Math.Abs(a.get(i, j)) > tol)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
 public void TempSetPos(DVector3 Pos)
 {
     Position = Pos;
     Transformation = DMatrix.CreateScale(1d) * DMatrix.CreateTranslation(Position) * DMatrix.CreateFromYawPitchRoll(0, 0, 0);
     RecalcAABB();
 }
Example #14
0
 public static void TestBoosterBasic()
 {
     var checks      = new Checks("Test booster basic");
     var trainMatrix = new DMatrix("agaricus.txt.train");
     var testMatrix  = new DMatrix("agaricus.txt.test");
 }
Example #15
0
 public override void Translate(double tx, double ty)
 {
     if (tx != 0 || ty != 0)
     {
         DMatrix m = DMatrix.InitTranslateMatrix(tx, ty);
         ModifyWorldTransform(m);
         currentMatrix = currentMatrix.Multiply(m);
     }
 }
 public static Matrix ToMatrix(DMatrix matrix)
 {
     Matrix TM = new Matrix();
     TM.M11 = (float)matrix.M11;
     TM.M12 = (float)matrix.M12;
     TM.M13 = (float)matrix.M13;
     TM.M14 = (float)matrix.M14;
     TM.M21 = (float)matrix.M21;
     TM.M22 = (float)matrix.M22;
     TM.M23 = (float)matrix.M23;
     TM.M24 = (float)matrix.M24;
     TM.M31 = (float)matrix.M31;
     TM.M32 = (float)matrix.M32;
     TM.M33 = (float)matrix.M33;
     TM.M34 = (float)matrix.M34;
     TM.M41 = (float)matrix.M41;
     TM.M42 = (float)matrix.M42;
     TM.M43 = (float)matrix.M43;
     TM.M44 = (float)matrix.M44;
     return TM;
 }
 public static JMatrix ToJitterMatrix(DMatrix matrix)
 {
     JMatrix result;
     result.M11 = matrix.M11;
     result.M12 = matrix.M12;
     result.M13 = matrix.M13;
     result.M21 = matrix.M21;
     result.M22 = matrix.M22;
     result.M23 = matrix.M23;
     result.M31 = matrix.M31;
     result.M32 = matrix.M32;
     result.M33 = matrix.M33;
     return result;
 }
Example #18
0
 public override void LoadTransform(DMatrix matrix)
 {
     cr.Matrix = MakeMatrix(matrix);
 }
Example #19
0
 void ModifyWorldTransform(DMatrix m)
 {
     WriteRecordHeader(Emf.RecordType.EMR_MODIFYWORLDTRANSFORM, 36);
     Emf.XForm x = new Emf.XForm(m);
     byte[] data = RawSerialize(x);
     ms.Write(data, 0, data.Length);
     WriteUInt((uint)Emf.ModifyWorldTransformMode.MWT_LEFTMULTIPLY);
 }
Example #20
0
        public static void print(Stream output, DMatrix mat, int numChar, int precision)
        {
            string format = "%" + numChar + "." + precision + "f";

            print(output, mat, format);
        }
Example #21
0
 public static void print(Stream output, DMatrix mat)
 {
     print(output, mat, 6, 3);
 }
Example #22
0
 void SetWorldTransform(DMatrix m)
 {
     WriteRecordHeader(Emf.RecordType.EMR_SETWORLDTRANSFORM, 32);
     Emf.XForm x = new Emf.XForm(m);
     byte[] data = RawSerialize(x);
     ms.Write(data, 0, data.Length);
 }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        void DrawInternal(GameTime gameTime)
        {
            var dev = Game.GraphicsDevice;

            viewMatrix = DMatrix.LookAtRH(cameraPosition, DVector3.Zero, DVector3.UnitY);

            DMatrix vvvM = viewMatrix;

            viewMatrix.TranslationVector = DVector3.Zero;

            var camPos = cameraPosition;

            if (Game.InputDevice.IsKeyDown(Keys.LeftShift))
            {
                DVector3 cameraUp    = cameraPosition / cameraPosition.Length();
                DVector3 lookAtPoint = cameraUp * Config.earthRadius;

                double length = Config.CameraDistance - Config.earthRadius;

                var quat = DQuaternion.RotationAxis(DVector3.UnitY, FreeCamYaw) * DQuaternion.RotationAxis(DVector3.UnitX, FreeCamPitch);

                var qRot = DMatrix.RotationQuaternion(quat);
                var mat  = DMatrix.Identity;

                var xAxis = DVector3.TransformNormal(DVector3.UnitX, DMatrix.RotationAxis(DVector3.UnitY, Yaw));
                xAxis.Normalize();

                mat.Up      = cameraUp;
                mat.Right   = xAxis;
                mat.Forward = DVector3.Cross(xAxis, cameraUp);
                mat.Forward.Normalize();

                var matrix = qRot * mat;

                var c = DVector3.Transform(new DVector3(0, 0, length), matrix);

                var camPoint = new DVector3(c.X, c.Y, c.Z) + lookAtPoint;

                camPos = camPoint;

                viewMatrix = DMatrix.LookAtRH(camPoint, lookAtPoint, cameraUp);
                vvvM       = viewMatrix;
                viewMatrix.TranslationVector = DVector3.Zero;
            }

            viewMatrixFloat = DMatrix.ToFloatMatrix(viewMatrix);
            projMatrixFloat = DMatrix.ToFloatMatrix(projMatrix);

            var viewDir = cameraPosition / cameraPosition.Length();

            constBuffer.Data.ViewProj      = viewMatrixFloat * projMatrixFloat;
            constBuffer.Data.ViewPositionX = camPos.X;
            constBuffer.Data.ViewPositionY = camPos.Y;
            constBuffer.Data.ViewPositionZ = camPos.Z;
            constBuffer.Data.Temp          = new Vector4(0.0f, (float)Config.earthRadius, 0, 0);
            constBuffer.Data.ViewDir       = new Vector4((float)viewDir.X, (float)viewDir.Y, (float)viewDir.Z, 0);
            constBuffer.UpdateCBuffer();

            Game.GraphicsDevice.VertexShaderConstants[0] = constBuffer;

            Game.GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearClamp;
            Game.GraphicsDevice.PixelShaderResources[1] = frame;

            if (gridVertexBuffer != null)
            {
                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_TEXTURED | (Config.ShowFrames ? GlobeFlags.SHOW_FRAMES : GlobeFlags.NONE),
                    Primitive.TriangleList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullCW,
                    DepthStencilState.Readonly);

                Game.GraphicsDevice.PixelShaderResources[0] = gridTex;

                Game.GraphicsDevice.SetupVertexInput(gridVertexBuffer, gridIndexBuffer);
                dev.DrawIndexed(/*Primitive.TriangleList,*/ gridIndexBuffer.Capacity, 0, 0);
            }

            var rastState = Game.InputDevice.IsKeyDown(Keys.Tab) ? RasterizerState.Wireframe : RasterizerState.CullCW;

            Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_TEXTURED | (Config.ShowFrames ? GlobeFlags.SHOW_FRAMES : GlobeFlags.NONE),
                Primitive.TriangleList,
                BlendState.AlphaBlend,
                rastState,
                DepthStencilState.Default);

            foreach (var globeTile in tilesToRender)
            {
                var tex = Game.GetService <LayerService>().MapLayer.CurrentMapSource.GetTile(globeTile.Value.X, globeTile.Value.Y, globeTile.Value.Z).Tile;
                dev.PixelShaderResources[0] = tex;

                dev.SetupVertexInput(globeTile.Value.VertexBuf, globeTile.Value.IndexBuf);
                dev.DrawIndexed(globeTile.Value.IndexBuf.Capacity, 0, 0);
            }


            dotsBuf.Data.View = viewMatrixFloat;
            dotsBuf.Data.Proj = projMatrixFloat;
            dotsBuf.UpdateCBuffer();

            //// Draw simple railroads
            //if (simpleRailroadsVB != null && Config.ShowRailroads) {
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_SEGMENTED_LINES,
            //		Primitive.LineList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //	constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[1]	= dotsBuf;
            //	Game.GraphicsDevice.GeometryShaderConstants[1]	= dotsBuf;
            //	Game.GraphicsDevice.GeometryShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = railRoadsTex;
            //	Game.GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearWrap;
            //
            //	dev.SetupVertexInput(simpleRailroadsVB, null);
            //	dev.Draw(simpleRailroadsVB.Capacity, 0);
            //}


            //// Draw buildings
            //if (contourBuildingsVB != null && Config.ShowBuildingsContours) {
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_COLOR,
            //		Primitive.LineList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //
            //	constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	dev.SetupVertexInput(contourBuildingsVB, null);
            //	dev.Draw(contourBuildingsVB.Capacity, 0);
            //}

            // Draw Lines
            if (linesBatch.Count != 0 && Config.ShowRoads)
            {
                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_COLOR,
                    Primitive.LineList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);


                constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                constBuffer.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[0] = constBuffer;
                Game.GraphicsDevice.PixelShaderConstants[0]  = constBuffer;

                foreach (var vb in linesBatch)
                {
                    dev.SetupVertexInput(vb, null);
                    dev.Draw(vb.Capacity, 0);
                }
            }



            // Draw simple railroads
            if (linesPolyBatch.Count != 0 && Config.ShowRoads)
            {
                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_LINES,
                    Primitive.LineList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);

                constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                constBuffer.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;
                Game.GraphicsDevice.VertexShaderConstants[0]   = constBuffer;
                Game.GraphicsDevice.PixelShaderConstants[0]    = constBuffer;


                foreach (var vb in linesPolyBatch)
                {
                    dev.SetupVertexInput(vb, null);
                    dev.Draw(vb.Capacity, 0);
                }
            }



            if (Config.ShowPOI)
            {
                dotsBuf.Data.TexWHST = new Vector4(geoObjects.Width, geoObjects.Height, 164.0f, 0.05f);
                dotsBuf.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;

                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_DOTS | GlobeFlags.DOTS_WORLDSPACE,
                    Primitive.PointList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);

                Game.GraphicsDevice.PixelShaderResources[0] = geoObjects;
                Game.GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearClamp;

                dev.SetupVertexInput(dotsVB, null);
                dev.Draw(dotsVB.Capacity - geoObjectStart, geoObjectStart);
            }



            // Draw people
            if (Config.ShowPeople)
            {
                dotsBuf.Data.TexWHST = new Vector4(socioClasses.Width, socioClasses.Height, 64.0f, 0.025f);
                dotsBuf.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;

                Game.GraphicsDevice.PixelShaderResources[0] = socioClasses;
                Game.GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearClamp;

                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_DOTS | GlobeFlags.DOTS_WORLDSPACE,
                    Primitive.PointList,
                    BlendState.AlphaBlend,
                    RasterizerState.CullNone,
                    DepthStencilState.None);

                dev.SetupVertexInput(dotsVB, null);
                dev.Draw(geoObjectStart - 1, 0);
            }



            //// Draw heatmap
            //if (Config.ShowHeatMap && heatVB != null) {
            //	constBuffer.Data.Temp = new Vector4((float)Config.MaxHeatMapLevel, Config.HeatMapTransparency, HeatMapDim, 0);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_HEAT,
            //		Primitive.TriangleList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //
            //	Game.GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearClamp;
            //	Game.GraphicsDevice.PixelShaderSamplers[1] = SamplerState.AnisotropicClamp;
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = heatMap;
            //	Game.GraphicsDevice.PixelShaderResources[1] = heatMapPalette;
            //
            //	Game.GraphicsDevice.SetupVertexInput(heatVB, heatIB);
            //	Game.GraphicsDevice.DrawIndexed(heatIB.Capacity, 0, 0);
            //}

            //// Draw infection map
            //if (Config.ShowInfectHeatMap && heatVB != null) {
            //	constBuffer.Data.Temp = new Vector4((float)Config.MaxInfectLevel, 0.0f, HeatMapDim, 0);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_POLY | GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_HEAT,
            //		Primitive.TriangleList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //	Game.GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearClamp;
            //	Game.GraphicsDevice.PixelShaderSamplers[1] = SamplerState.AnisotropicClamp;
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = infectMap;
            //	Game.GraphicsDevice.PixelShaderResources[1] = heatMapPalette;
            //
            //	Game.GraphicsDevice.SetupVertexInput(heatVB, heatIB);
            //	Game.GraphicsDevice.DrawIndexed(/*Primitive.TriangleList,*/ heatIB.Capacity, 0, 0);
            //}


            ////Draw atmosphere
            //if (Config.ShowAtmosphere && atmosVB != null) {
            //	constBuffer.Data.Temp = new Vector4(atmosTime, Config.ArrowsScale, 0.0f, 0);
            //	constBuffer.UpdateCBuffer();
            //
            //	Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            //	Game.GraphicsDevice.PixelShaderConstants[0]		= constBuffer;
            //
            //
            //	Game.GraphicsDevice.PixelShaderResources[0] = atmosTexture;
            //	Game.GraphicsDevice.PixelShaderResources[1] = heatMapPalette;
            //	Game.GraphicsDevice.PixelShaderResources[2] = atmosNextTexture;
            //	Game.GraphicsDevice.PixelShaderResources[3] = arrowTex;
            //
            //
            //	Game.GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearClamp;
            //	Game.GraphicsDevice.PixelShaderSamplers[1] = SamplerState.AnisotropicClamp;
            //
            //	Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
            //		GlobeFlags.DRAW_VERTEX_POLY | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_ATMOSPHERE,
            //		Primitive.TriangleList,
            //		BlendState.AlphaBlend,
            //		RasterizerState.CullNone,
            //		DepthStencilState.None);
            //
            //	Game.GraphicsDevice.SetupVertexInput(atmosVB, atmosIB);
            //	Game.GraphicsDevice.DrawIndexed(atmosIB.Capacity, 0, 0);
            //}


            //Draw airlines
            if (airLinesVB != null && Config.ShowAirLines)
            {
                constBuffer.Data.Temp = new Vector4(1.0f, 0.0f, 0.0f, 0.0f);
                constBuffer.UpdateCBuffer();

                Game.GraphicsDevice.VertexShaderConstants[1]   = dotsBuf;
                Game.GraphicsDevice.GeometryShaderConstants[0] = constBuffer;
                Game.GraphicsDevice.GeometryShaderConstants[1] = dotsBuf;

                Game.GraphicsDevice.PipelineState = myMiniFactory.ProducePipelineState(
                    GlobeFlags.DRAW_VERTEX_LINES | GlobeFlags.USE_GEOCOORDS | GlobeFlags.VERTEX_SHADER | GlobeFlags.DRAW_ARCS,
                    Primitive.LineList,
                    BlendState.Additive,
                    RasterizerState.CullNone,
                    DepthStencilState.Readonly);

                dev.SetupVertexInput(airLinesVB, null);
                dev.Draw(/*Primitive.LineList,*/ airLinesVB.Capacity, 0);
            }

            DrawDebugLines();

            //Game.GetService<DebugStrings>().Add("Cam pos     : " + Game.GetService<Camera>().CameraMatrix.TranslationVector, Color.Red);
            //Game.GetService<DebugStrings>().Add("Radius      : " + Config.earthRadius, Color.Red);
            //Game.GetService<DebugStrings>().Add("Level       : " + CurrentLevel, Color.Green);
            //Game.GetService<DebugStrings>().Add("CamDistance : " + Config.CameraDistance, Color.Green);
            //Game.GetService<DebugStrings>().Add("Pitch : " + Pitch, Color.Green);
            //Game.GetService<DebugStrings>().Add("Width : " + Game.GraphicsDevice.Viewport.Width, Color.Green);
            Game.GetService <DebugStrings>().Add("Height : " + (Config.CameraDistance - Config.earthRadius) * 1000.0, Color.Green);
        }
Example #24
0
 public override void Rotate(double angle, DPoint center)
 {
     if (angle != 0)
     {
         Translate(center.X, center.Y);
         DMatrix m = DMatrix.InitRotateMatrix(angle);
         ModifyWorldTransform(m);
         currentMatrix = currentMatrix.Multiply(m);
         Translate(-center.X, -center.Y);
     }
 }
Example #25
0
 Matrix MakeMatrix(DMatrix matrix)
 {
     return new Matrix(matrix.A, matrix.B, matrix.C, matrix.D, matrix.E, matrix.F);
 }
Example #26
0
 public abstract void LoadTransform(DMatrix matrix);
Example #27
0
 public override void ResetTransform()
 {
     ResetWorldTransform();
     currentMatrix = DMatrix.Identity();
 }
Example #28
0
		void UpdateProjectionMatrix()
		{
			double aspect = Viewport.AspectRatio;

			double nearHeight	= Parameters.FrustumZNear * Math.Tan(DMathUtil.DegreesToRadians(Parameters.CameraFovDegrees / 2));
			double nearWidth	= nearHeight * aspect;

			Parameters.FrustumWidth		= nearWidth;
			Parameters.FrustumHeight	= nearHeight;

			ProjMatrix = DMatrix.PerspectiveOffCenterRH(-nearWidth / 2, nearWidth / 2, -nearHeight / 2, nearHeight / 2, Parameters.FrustumZNear, Parameters.FrustumZFar);
		}
Example #29
0
 public override void LoadTransform(DMatrix matrix)
 {
     if (!currentMatrix.Equals(matrix))
     {
         SetWorldTransform(matrix);
         currentMatrix = matrix;
     }
 }
Example #30
0
 public override void LoadTransform(DMatrix matrix)
 {
 }
Example #31
0
 public XForm(DMatrix m)
 {
     this.M11 = (float)m.A;
     this.M12 = (float)m.B;
     this.M21 = (float)m.C;
     this.M22 = (float)m.D;
     this.Dx = (float)m.E;
     this.Dy = (float)m.F;
 }
Example #32
0
 public override void Scale(double sx, double sy)
 {
     if (sx != 1 || sy != 1)
     {
         DMatrix m = DMatrix.InitScaleMatrix(sx, sy);
         ModifyWorldTransform(m);
         currentMatrix = currentMatrix.Multiply(m);
     }
 }
Example #33
0
		public void Update(GameTime gameTime)
		{
			UpdateProjectionMatrix();

			CameraPosition	= DVector3.Transform(new DVector3(0, 0, CameraDistance), Rotation);
			ViewMatrix		= DMatrix.LookAtRH(CameraPosition, DVector3.Zero, DVector3.UnitY);

			ViewMatrixWithTranslation		= ViewMatrix;
			ViewMatrix.TranslationVector	= DVector3.Zero;
			FinalCamPosition				= CameraPosition;


			if (CameraState == CameraStates.ViewToPoint) {
				var mat = CalculateBasisOnSurface();

				DVector3	lookAtPoint = mat.Up * EarthRadius;
				double		length		= CameraDistance - EarthRadius;

				var quat	= DQuaternion.RotationAxis(DVector3.UnitY, ViewToPointYaw) * DQuaternion.RotationAxis(DVector3.UnitX, ViewToPointPitch);
				var qRot	= DMatrix.RotationQuaternion(quat);
				var matrix	= qRot * mat;

				var pointOffset = DVector3.Transform(new DVector3(0, 0, length), matrix);
				var camPoint	= new DVector3(pointOffset.X, pointOffset.Y, pointOffset.Z) + lookAtPoint;

				FinalCamPosition = camPoint;

				ViewMatrix					= DMatrix.LookAtRH(camPoint, lookAtPoint, mat.Up);
				ViewMatrixWithTranslation	= ViewMatrix;

				ViewMatrix.TranslationVector = DVector3.Zero;
			} else if (CameraState == CameraStates.FreeSurface) {
				var mat = CalculateBasisOnSurface();
				
				#region Input
					// Update surface camera yaw and pitch
					//if (input.IsKeyDown(Keys.RightButton)) {
					//	FreeSurfaceYaw		+= input.RelativeMouseOffset.X*0.0003;
					//	FreeSurfacePitch	-= input.RelativeMouseOffset.Y*0.0003;
					//
					//	input.IsMouseCentered	= false;
					//	input.IsMouseHidden		= true;
					//}
					//else {
					//	input.IsMouseCentered	= false;
					//	input.IsMouseHidden		= false;
					//}


					//if (Game.Keyboard.IsKeyDown(Input.Keys.Left))		FreeSurfaceYaw		-= gameTime.ElapsedSec * 0.7;
					//if (Game.Keyboard.IsKeyDown(Input.Keys.Right))	FreeSurfaceYaw		+= gameTime.ElapsedSec * 0.7;
					//if (Game.Keyboard.IsKeyDown(Input.Keys.Up))		FreeSurfacePitch	-= gameTime.ElapsedSec * 0.7;
					//if (Game.Keyboard.IsKeyDown(Input.Keys.Down))		FreeSurfacePitch	+= gameTime.ElapsedSec * 0.7;


					//FreeSurfaceYaw = DMathUtil.Clamp(FreeSurfaceYaw, -DMathUtil.PiOverTwo, DMathUtil.PiOverTwo);
					if (FreeSurfaceYaw > DMathUtil.TwoPi)	FreeSurfaceYaw -= DMathUtil.TwoPi;
					if (FreeSurfaceYaw < -DMathUtil.TwoPi)	FreeSurfaceYaw += DMathUtil.TwoPi;

					// Calculate free cam rotation matrix

					if (!freezeFreeCamRotation)
						freeSurfaceRotation = DQuaternion.RotationAxis(DVector3.UnitY, FreeSurfaceYaw) * DQuaternion.RotationAxis(DVector3.UnitX, FreeSurfacePitch);

					var quat	= freeSurfaceRotation;
					var qRot	= DMatrix.RotationQuaternion(quat);
					var matrix	= qRot * mat;

					var velDir = matrix.Forward * velocityDirection.X + mat.Up * velocityDirection.Y + matrix.Right * velocityDirection.Z;

					if (velDir.Length() != 0) {
						velDir.Normalize();
					}
				
				#endregion

				double fac = ((CameraDistance - EarthRadius) - Parameters.MinDistVelocityThreshold) / (Parameters.MaxDistVelocityThreshold - Parameters.MinDistVelocityThreshold);
				fac = DMathUtil.Clamp(fac, 0.0, 1.0);

				FreeSurfaceVelocityMagnitude = DMathUtil.Lerp(Parameters.MinVelocityFreeSurfCam, Parameters.MaxVelocityFreeSurfCam, fac);

				// Update camera position
				FinalCamPosition	= FreeSurfacePosition = FreeSurfacePosition + velDir * FreeSurfaceVelocityMagnitude * gameTime.ElapsedSec;
				CameraPosition		= FinalCamPosition;


				velocityDirection = DVector3.Zero;


				//Calculate view matrix
				ViewMatrix = DMatrix.LookAtRH(FinalCamPosition, FinalCamPosition + matrix.Forward, matrix.Up);
				ViewMatrixWithTranslation		= ViewMatrix;
				ViewMatrix.TranslationVector	= DVector3.Zero;

				// Calculate new yaw and pitch
				CameraDistance = CameraPosition.Length();

				var newLonLat = GetCameraLonLat();
				Yaw		= newLonLat.X;
				Pitch	= -newLonLat.Y;
			}

			ViewMatrixFloat = DMatrix.ToFloatMatrix(ViewMatrix);
			ProjMatrixFloat = DMatrix.ToFloatMatrix(ProjMatrix);

			//var viewDir = CameraPosition / CameraPosition.Length();
		}
Example #34
0
 void WmfUpdateMaxtrix(DGraphics dg, DMatrix m)
 {
     // could not get this working... used wmfApplyTransforms to all points instead :(
     /*
     dg.LoadTransform(m);
     dg.Translate(X - winX, Y - winY);
     //int pW = placeable.Right - placeable.Left, pH = placeable.Bottom - placeable.Top;
     //dg.Scale(Width / pW, Height / pH);
     //if (winWidth != 0 && winHeight != 0)
     //    dg.Scale(pW / winWidth, pH / winHeight);
     if (winWidth != 0 && winHeight != 0)
         dg.Scale(Width / winWidth, Height / winHeight);
     */
 }
Example #35
0
		void GetEulerAngles(DMatrix q, out double yaw, out double pitch, out double roll)
		{
			yaw		= Math.Atan2(q.M32, q.M33);
			pitch	= Math.Atan2(-q.M31, Math.Sqrt(q.M32*q.M32 + q.M33*q.M33));
			roll	= Math.Atan2(q.M21, q.M11);
		}
Example #36
0
 private Matrix MakeMatrix(DMatrix matrix)
 {
     return new Matrix((float)matrix.A, (float)matrix.B, (float)matrix.C,
         (float)matrix.D, (float)matrix.E, (float)matrix.F);
 }