示例#1
0
        public void DrawGoo()
        {
            float CurrTime = DXUtil.Timer(DirectXTimer.GetApplicationTime);
            float fTime    = (float)(((CurrTime % 180.0f) / 180.0f) * (2 * Math.PI));

            WorldMatrix = DirectX.Matrix.RotationYawPitchRoll((float)((CurrTime % 240) / 240 * Math.PI), 0, 0) * DirectX.Matrix.Translation(0, -45, -400);

            DirectX.Matrix WorldViewMatrix     = WorldMatrix * ViewMatrix;
            DirectX.Matrix WorldViewProjMatrix = WorldMatrix * ViewMatrix * ProjectionMatrix;

            GooEffect.SetValue("fMixTime", fTime);
            GooEffect.SetValue("WorldView", WorldViewMatrix);
            GooEffect.SetValue("WorldViewProjection", WorldViewProjMatrix);

            GameDevice.RenderState.AlphaBlendEnable = false;
            int numPasses = GooEffect.Begin(0);

            for (int i = 0; i < numPasses; i++)
            {
                GooEffect.BeginPass(i);
                GooMesh.DrawSubset(0);
                GooEffect.EndPass();
            }
            GooEffect.End();

            // Restore alpha blend setting
            GameDevice.RenderState.AlphaBlendEnable = true;
        }
 /// <summary>
 ///    Checks D3D matrix to see if it an identity matrix.
 /// </summary>
 /// <remarks>
 ///    For whatever reason, the equality operator overloads for the D3D Matrix
 ///    struct are extremely slow....
 /// </remarks>
 /// <param name="matrix"></param>
 /// <returns></returns>
 public static bool IsIdentity(ref Microsoft.DirectX.Matrix matrix)
 {
     if (matrix.M11 == 1.0f &&
         matrix.M12 == 0.0f &&
         matrix.M13 == 0.0f &&
         matrix.M14 == 0.0f &&
         matrix.M21 == 0.0f &&
         matrix.M22 == 1.0f &&
         matrix.M23 == 0.0f &&
         matrix.M24 == 0.0f &&
         matrix.M31 == 0.0f &&
         matrix.M32 == 0.0f &&
         matrix.M33 == 1.0f &&
         matrix.M34 == 0.0f &&
         matrix.M41 == 0.0f &&
         matrix.M42 == 0.0f &&
         matrix.M43 == 0.0f &&
         matrix.M44 == 1.0f)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
 private void SetupProjections(MechanismInfo mi)
 {
     mi.d3d.Lights[0].Enabled    = true;                 // Включаем нулевой источник освещения
     mi.d3d.Lights[0].Diffuse    = Color.White;          // Цвет источника освещения
     mi.d3d.Lights[0].Position   = new Vector3(0, 0, 0); // Задаем координаты
     mi.d3d.Transform.Projection = DirectMatrix.PerspectiveFovLH((float)Math.PI / 4, mi.Window.Width / mi.Window.Height, 1.0f, 50.0f);
 }
示例#4
0
        private static Matrix DXM2EM(Microsoft.DirectX.Matrix from)
        {
            Matrix to = new Matrix();

            to.element[0, 0] = from.M11;
            to.element[1, 0] = from.M12;
            to.element[2, 0] = from.M13;
            to.element[3, 0] = from.M14;

            to.element[0, 1] = from.M21;
            to.element[1, 1] = from.M22;
            to.element[2, 1] = from.M23;
            to.element[3, 1] = from.M24;

            to.element[0, 2] = from.M31;
            to.element[1, 2] = from.M32;
            to.element[2, 2] = from.M33;
            to.element[3, 2] = from.M34;

            to.element[0, 3] = from.M41;
            to.element[1, 3] = from.M42;
            to.element[2, 3] = from.M43;
            to.element[3, 3] = from.M44;

            return(to);
        }
示例#5
0
        public static void TransformMesh(Mesh mesh, Microsoft.DirectX.Matrix transform)
        {
            CustomVertex.PositionNormal[] tmp = new CustomVertex.PositionNormal[mesh.NumberVertices];
            Vector3 pos  = new Vector3();
            Vector3 norm = new Vector3();

            using (VertexBuffer vb = mesh.VertexBuffer)
            {
                GraphicsStream vertexData = vb.Lock(0, 0, LockFlags.None);
                BinaryReader   br         = new BinaryReader(vertexData);
                for (int v = 0; v < mesh.NumberVertices; v++)
                {
                    pos.X  = br.ReadSingle();
                    pos.Y  = br.ReadSingle();
                    pos.Z  = br.ReadSingle();
                    norm.X = br.ReadSingle();
                    norm.Y = br.ReadSingle();
                    norm.Z = br.ReadSingle();
                    pos.TransformCoordinate(transform);
                    norm.TransformNormal(transform);
                    tmp[v] = new CustomVertex.PositionNormal(pos.X, pos.Y, pos.Z, norm.X, norm.Y, norm.Z);
                }
                vb.Unlock();
            }

            mesh.SetVertexBufferData(tmp, LockFlags.None);
        }
示例#6
0
        private static Microsoft.DirectX.Matrix EM2DXM(Matrix from)
        {
            Microsoft.DirectX.Matrix to = new Microsoft.DirectX.Matrix();

            to.M11 = from.element[0, 0];
            to.M12 = from.element[1, 0];
            to.M13 = from.element[2, 0];
            to.M14 = from.element[3, 0];

            to.M21 = from.element[0, 1];
            to.M22 = from.element[1, 1];
            to.M23 = from.element[2, 1];
            to.M24 = from.element[3, 1];

            to.M31 = from.element[0, 2];
            to.M32 = from.element[1, 2];
            to.M33 = from.element[2, 2];
            to.M34 = from.element[3, 2];

            to.M41 = from.element[0, 3];
            to.M42 = from.element[1, 3];
            to.M43 = from.element[2, 3];
            to.M44 = from.element[3, 3];

            return(to);
        }
示例#7
0
        public void BuildMatrices(Device pID3DDevice)
        {
            matView = Camera.GetViewMatrix();

            pID3DDevice.Transform.View = matView;

            if (dynamic_znear)
            {
                Camera.GetDynamicZRange(zfar_ratio, out RenderZnear, out RenderZfar);
            }
            else
            {
                RenderZnear = znear;
                RenderZfar  = zfar;
            }

            float aspect = ((float)width) / ((float)height);

#if false
            Microsoft.DirectX.Matrix matrix = Microsoft.DirectX.Matrix.PerspectiveFovLH(Camera.Angle, aspect, RenderZnear, RenderZfar);
#else
            float ang = Camera.Angle;
            Microsoft.DirectX.Matrix matrix = Microsoft.DirectX.Matrix.OrthoLH(2 * ang * aspect, 2 * ang, -100, 100);
#endif
            pID3DDevice.Transform.Projection = matrix;
            matProj              = matrix;
            Viewport.X           = 0;
            Viewport.Y           = 0;
            Viewport.MinZ        = 0;
            Viewport.MaxZ        = 1;
            Viewport.Width       = width;
            Viewport.Height      = height;
            pID3DDevice.Viewport = Viewport;
        }
示例#8
0
 public Vector3  ProjectPoint(Vector3 pt, Microsoft.DirectX.Matrix world)
 {
     return(Vector3.Project(pt,
                            Viewport,
                            matProj,
                            matView,
                            world));
 }
示例#9
0
文件: DXUtils.cs 项目: nanma80/MPUlt
        static public Microsoft.DirectX.Matrix CTrans2Matrix(CTrans ct)
        {
            Quaternion qRotation = new Quaternion();

            qRotation.X = (float)-ct.R.X; qRotation.Y = (float)ct.R.Y; qRotation.Z = (float)ct.R.Z;
            qRotation.W = (float)-ct.R.R;
            Microsoft.DirectX.Matrix M = Microsoft.DirectX.Matrix.RotationQuaternion(qRotation);
            M.M41 = (float)-ct.T.X; M.M42 = (float)ct.T.Y; M.M43 = (float)ct.T.Z;
            return(M);
        }
        public void DrawNodes()
        {
            float node_offset = 0.0f;

            if (nodeSphere == null)
            {
                nodeSphere = Mesh.Sphere(MdxRender.Dev, 0.01f, 6, 6);
            }

            if (nodeLocations == null)
            {
                nodeLocations = new CustomVertex.PositionOnly[2 * m_Model.m_Nodes.Length];
                for (int i = 0; i < 2 * m_Model.m_Nodes.Length; i++)
                {
                    nodeLocations[i] = new CustomVertex.PositionOnly();
                }
            }

            Microsoft.DirectX.Matrix mat = new Microsoft.DirectX.Matrix();
            MdxRender.SM.m_TextureManager.ActivateDefaultTexture();
            MdxRender.Dev.RenderState.ZBufferFunction = Compare.Always;

            int nc = 0;

            for (int i = 0; i < m_Model.m_Nodes.Length; i++)
            {
                mat = Microsoft.DirectX.Matrix.Identity;

                mat.Translate(m_Model.NodeTransforms[i].m_FinalNode[0] + node_offset,
                              m_Model.NodeTransforms[i].m_FinalNode[1],
                              m_Model.NodeTransforms[i].m_FinalNode[2]);

                MdxRender.Dev.Transform.World = mat;

                nodeSphere.DrawSubset(0);

                if (m_AniNodes[i].ParentNode != -1)
                {
                    nodeLocations[2 * nc].X = m_Model.NodeTransforms[i].m_FinalNode[0] + node_offset;
                    nodeLocations[2 * nc].Y = m_Model.NodeTransforms[i].m_FinalNode[1];
                    nodeLocations[2 * nc].Z = m_Model.NodeTransforms[i].m_FinalNode[2];

                    nodeLocations[2 * nc + 1].X = m_Model.NodeTransforms[m_AniNodes[i].ParentNode].m_FinalNode[0] + node_offset;
                    nodeLocations[2 * nc + 1].Y = m_Model.NodeTransforms[m_AniNodes[i].ParentNode].m_FinalNode[1];
                    nodeLocations[2 * nc + 1].Z = m_Model.NodeTransforms[m_AniNodes[i].ParentNode].m_FinalNode[2];
                    nc++;
                }
            }

            MdxRender.Dev.Transform.World = Microsoft.DirectX.Matrix.Identity;
            MdxRender.Dev.DrawUserPrimitives(PrimitiveType.LineList,
                                             nc,
                                             nodeLocations);
            MdxRender.Dev.RenderState.ZBufferFunction = Compare.LessEqual;
        }
示例#11
0
        private void Render(Microsoft.DirectX.Matrix pTerrainMatrix, Texture ptexture)
        {
            this.m_device.Transform.World = Microsoft.DirectX.Matrix.Translation((float)this.ShiftX, (float)this.ShiftY, 0f) * pTerrainMatrix;
            int num = this.meshTex.GetAttributeTable().Length;

            this.m_device.Material = this.material;
            this.m_device.SetTexture(0, ptexture);
            for (int i = 0; i < num; i++)
            {
                this.meshTex.DrawSubset(i);
            }
        }
示例#12
0
        public GooAccess(Direct3D.Device NewGameDevice,
                         GameEngine.ShaderLevel NewCardShaderLevel,
                         DirectX.Matrix NewViewMatrix,
                         DirectX.Matrix NewProjectionMatrix)
        {
            GameDevice       = NewGameDevice;
            CardShaderLevel  = NewCardShaderLevel;
            ViewMatrix       = NewViewMatrix;
            ProjectionMatrix = NewProjectionMatrix;

            // Load Shader Effect From File
            GooEffect = Direct3D.Effect.FromFile(GameDevice, GameConfig.Files.GooFx, null, null, Direct3D.ShaderFlags.None, null);

            // Choose shader technique based on shader level.
            if (CardShaderLevel == GameEngine.ShaderLevel.Pixel_3_0)
            {
                GooEffect.Technique = "Goo_Parallax_3_0";
            }
            else if (CardShaderLevel == GameEngine.ShaderLevel.Pixel_2_b)
            {
                GooEffect.Technique = "Goo_Parallax_2_b";
            }
            else if (CardShaderLevel == GameEngine.ShaderLevel.Pixel_2_0)
            {
                GooEffect.Technique = "Goo_Parallax_2";
            }
            else if (CardShaderLevel == GameEngine.ShaderLevel.Pixel_1_4)
            {
                GooEffect.Technique = "Goo_Bump_1_4";
            }

            // Load Mesh From File
            GooMesh = Direct3D.Mesh.FromFile(GameConfig.Files.GooMesh, Direct3D.MeshFlags.Managed, GameDevice);

            // Load Textures From File
            ColorTexture  = Direct3D.TextureLoader.FromFile(GameDevice, GameConfig.Files.GooColor);
            NormalTexture = Direct3D.TextureLoader.FromFile(GameDevice, GameConfig.Files.GooNormal);
            HeightTexture = Direct3D.TextureLoader.FromFile(GameDevice, GameConfig.Files.GooHeight);

            // Load Textures into Effect
            GooEffect.SetValue("ColorTexture", ColorTexture);
            GooEffect.SetValue("NormalsTexture", NormalTexture);
            GooEffect.SetValue("HeightTexture", HeightTexture);

            // Set Parallax and Bump Intensity
            GooEffect.SetValue("ParallaxAmount", .5f);
            GooEffect.SetValue("BumpAmount", 1.5f);
        }
示例#13
0
        public Microsoft.DirectX.Matrix GetEffectiveTransform()
        {
            if (this.Transform.IsAbsolute)
            {
                return(this.Transform);
            }

            Microsoft.DirectX.Matrix m = Microsoft.DirectX.Matrix.Identity;
            foreach (NodeBox nb in parents)
            {
                m.Multiply(nb.GetEffectiveTransform());
            }

            m.Multiply(this.Transform);
            return(m);
        }
示例#14
0
文件: DXUtils.cs 项目: nanma80/MPUlt
        static public CTrans Matrix2CTrans(Microsoft.DirectX.Matrix M)
        {
            RPoint T = new RPoint(
                -M.M41,
                M.M42,
                M.M43);

            M.M41 = M.M42 = M.M43 = 0;
            Quaternion qRotation = Quaternion.RotationMatrix(M);
            QPoint     R         = new QPoint(
                -qRotation.X,
                qRotation.Y,
                qRotation.Z,
                -qRotation.W);

            return(new CTrans(T, R));
        }
        public override void Draw(Microsoft.DirectX.Matrix worldTransform)
        {
            if (vertices == null)
            {
                return;
            }

            device.Transform.World = _Transform * worldTransform;

            if (texture != null)
            {
                device.Material = material;
                device.SetTexture(0, texture);
            }


            device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
            device.SetStreamSource(0, vb, 0);
            device.Indices = ib;
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
        }
示例#16
0
        public void Draw(DX.Matrix transform, int pickValue = 0)
        {
            D3D.Device device = Renderer.current.device;
            device.VertexDeclaration = Renderer.current.vtxDeclaration;
            device.SetStreamSource(0, vertexBuffer, 0);
            Renderer.current.SetValues(usedEffect, transform);
            usedEffect.SetValue(Renderer.EffectHandles.PickColor, Renderer.pickIndexToColor(pickValue));

            foreach (Subset sub in subsets)
            {
                float shiftTValue = sub.shiftT >= 11 ? (int)1 << (0x10 - sub.shiftT) : 1.0f / (1 << sub.shiftT);
                float shiftSValue = sub.shiftS >= 11 ? (int)1 << (0x10 - sub.shiftS) : 1.0f / (1 << sub.shiftS);
                usedEffect.SetValue(Renderer.EffectHandles.ShiftMul, new DX.Vector4(shiftTValue / (float)sub.texture.width, shiftSValue / (float)sub.texture.height, 0, 0));
                usedEffect.SetValue(Renderer.EffectHandles.Texture0, sub.texture0);
                usedEffect.SetValue(Renderer.EffectHandles.Texture1, sub.texture1);
                usedEffect.Begin(D3D.FX.None);
                usedEffect.BeginPass(0);
                device.Indices = sub.indexBuffer;
                device.DrawIndexedPrimitives(D3D.PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, sub.indices.Length / 3);
                usedEffect.EndPass();
                usedEffect.End();
            }
        }
示例#17
0
文件: Matrix.cs 项目: rbernon/monoDX
		public static Matrix TransposeMatrix (Matrix source)
		{
			throw new NotImplementedException ();
		}
示例#18
0
 public void Render(Microsoft.DirectX.Matrix pTerrainMatrix)
 {
     this.Render(pTerrainMatrix, this.renderTex);
 }
示例#19
0
 public virtual void Render2(DrawArgs drawArgs)
 {
     if (this.m_Visible)
     {
         if ((this.dblLatitude != double.MinValue) && ((drawArgs.WorldCamera.Altitude > 100.0) || (World.Settings.VerticalExaggeration >= 1f)))
         {
             try
             {
                 drawArgs.device.RenderState.ZBufferEnable = true;
                 Cull cullMode = drawArgs.device.RenderState.CullMode;
                 drawArgs.device.RenderState.CullMode           = Cull.None;
                 drawArgs.device.VertexFormat                   = VertexFormats.Diffuse | VertexFormats.Position;
                 drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                 Microsoft.DirectX.Matrix matrix = Microsoft.DirectX.Matrix.Translation((float)-drawArgs.WorldCamera.ReferenceCenter.X, (float)-drawArgs.WorldCamera.ReferenceCenter.Y, (float)-drawArgs.WorldCamera.ReferenceCenter.Z);
                 drawArgs.device.Transform.World = matrix;
                 Microsoft.DirectX.Vector3 vector  = MathEngine.SphericalToCartesian((double)this.dblLatitude, (double)this.dblLongitude, (this.ww.CurrentWorld.EquatorialRadius + (this.ww.CurrentWorld.TerrainAccessor.GetElevationAt((double)this.dblLatitude, (double)this.dblLongitude, 100.0) * World.Settings.VerticalExaggeration)) + this.dblAltitude);
                 Microsoft.DirectX.Vector3 vector2 = new Microsoft.DirectX.Vector3();
                 Microsoft.DirectX.Vector3 vector3 = new Microsoft.DirectX.Vector3();
                 vector2.X = this.m_Location.X + (((float)this.m_Size.Width) / 3f);
                 vector2.Y = (this.m_Location.Y + this.m_Size.Height) - 5;
                 vector2.Z = 0f;
                 vector2.Unproject(drawArgs.device.Viewport, drawArgs.WorldCamera.ProjectionMatrix, drawArgs.WorldCamera.ViewMatrix, drawArgs.device.Transform.World);
                 vector3.X = this.m_Location.X + (2f * (((float)this.m_Size.Width) / 3f));
                 vector3.Y = (this.m_Location.Y + this.m_Size.Height) - 5;
                 vector3.Z = 0f;
                 vector3.Unproject(drawArgs.device.Viewport, drawArgs.WorldCamera.ProjectionMatrix, drawArgs.WorldCamera.ViewMatrix, drawArgs.device.Transform.World);
                 CustomVertex.PositionColored[] vertexStreamZeroData = new CustomVertex.PositionColored[3];
                 vertexStreamZeroData[0].X     = vector.X;
                 vertexStreamZeroData[0].Y     = vector.Y;
                 vertexStreamZeroData[0].Z     = vector.Z;
                 vertexStreamZeroData[0].Color = this.m_BackgroundColor.ToArgb();
                 vertexStreamZeroData[1].X     = vector2.X;
                 vertexStreamZeroData[1].Y     = vector2.Y;
                 vertexStreamZeroData[1].Z     = vector2.Z;
                 vertexStreamZeroData[1].Color = this.m_BackgroundColor.ToArgb();
                 vertexStreamZeroData[2].X     = vector3.X;
                 vertexStreamZeroData[2].Y     = vector3.Y;
                 vertexStreamZeroData[2].Z     = vector3.Z;
                 vertexStreamZeroData[2].Color = this.m_BackgroundColor.ToArgb();
                 drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertexStreamZeroData.Length - 2, vertexStreamZeroData);
                 drawArgs.device.Transform.World                = drawArgs.WorldCamera.WorldMatrix;
                 drawArgs.device.RenderState.CullMode           = cullMode;
                 drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.Message);
             }
         }
         if (this.m_TextFont == null)
         {
             System.Drawing.Font font = new System.Drawing.Font("Arial", 12f, FontStyle.Italic | FontStyle.Bold);
             this.m_TextFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, font);
         }
         if (this.m_WorldWindDingsFont == null)
         {
             AddFontResource(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
             PrivateFontCollection fonts = new PrivateFontCollection();
             fonts.AddFontFile(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
             System.Drawing.Font font2 = new System.Drawing.Font(fonts.Families[0], 12f);
             this.m_WorldWindDingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, font2);
         }
         if (this.m_Resizeble)
         {
             if (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNWSE;
             }
             else if (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNESW;
             }
             else if (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNESW;
             }
             else if (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNWSE;
             }
             else if ((((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < (this.AbsoluteLocation.X + this.resizeBuffer))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))) || (((DrawArgs.LastMousePosition.X > ((this.AbsoluteLocation.X - this.resizeBuffer) + this.ClientSize.Width)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeWE;
             }
             else if ((((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > (this.AbsoluteLocation.Y - this.resizeBuffer)) && (DrawArgs.LastMousePosition.Y < (this.AbsoluteLocation.Y + this.resizeBuffer)))) || (((DrawArgs.LastMousePosition.X > (this.AbsoluteLocation.X - this.resizeBuffer)) && (DrawArgs.LastMousePosition.X < ((this.AbsoluteLocation.X + this.resizeBuffer) + this.ClientSize.Width))) && ((DrawArgs.LastMousePosition.Y > ((this.AbsoluteLocation.Y - this.resizeBuffer) + this.ClientSize.Height)) && (DrawArgs.LastMousePosition.Y < ((this.AbsoluteLocation.Y + this.resizeBuffer) + this.ClientSize.Height)))))
             {
                 DrawArgs.MouseCursor = CursorType.SizeNS;
             }
         }
         if (this.ClientSize.Height > drawArgs.parentControl.Height)
         {
             this.ClientSize = new Size(this.ClientSize.Width, drawArgs.parentControl.Height);
         }
         if (this.ClientSize.Width > drawArgs.parentControl.Width)
         {
             this.ClientSize = new Size(drawArgs.parentControl.Width, this.ClientSize.Height);
         }
         if (!this.m_AutoHideHeader || (((DrawArgs.LastMousePosition.X >= this.m_Location.X) && (DrawArgs.LastMousePosition.X <= (this.m_Location.X + this.m_Size.Width))) && ((DrawArgs.LastMousePosition.Y >= this.m_Location.Y) && (DrawArgs.LastMousePosition.Y <= (this.m_Location.Y + this.m_Size.Height)))))
         {
             Utilities.DrawBox(this.m_Location.X, this.m_Location.Y, this.m_Size.Width, this.m_HeaderHeight, 0f, this.m_HeaderColor.ToArgb(), drawArgs.device);
             this.m_WorldWindDingsFont.DrawText(null, "E", new Rectangle((this.m_Location.X + this.m_Size.Width) - 15, this.m_Location.Y + 2, this.m_Size.Width, this.m_Size.Height), DrawTextFormat.NoClip, Color.White.ToArgb());
             this.m_OutlineVertsHeader[0].X = this.AbsoluteLocation.X;
             this.m_OutlineVertsHeader[0].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
             this.m_OutlineVertsHeader[1].X = this.AbsoluteLocation.X;
             this.m_OutlineVertsHeader[1].Y = this.AbsoluteLocation.Y;
             this.m_OutlineVertsHeader[2].X = this.AbsoluteLocation.X + this.ClientSize.Width;
             this.m_OutlineVertsHeader[2].Y = this.AbsoluteLocation.Y;
             this.m_OutlineVertsHeader[3].X = this.AbsoluteLocation.X + this.ClientSize.Width;
             this.m_OutlineVertsHeader[3].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
             if (!this.m_HideBorder)
             {
                 Utilities.DrawLine(this.m_OutlineVertsHeader, this.m_BorderColor.ToArgb(), drawArgs.device);
             }
         }
         Utilities.DrawBox(this.m_Location.X, this.m_Location.Y + this.m_HeaderHeight, this.m_Size.Width, this.m_Size.Height - this.m_HeaderHeight, 0f, this.m_BackgroundColor.ToArgb(), drawArgs.device);
         for (int i = this.m_ChildWidgets.Count - 1; i >= 0; i--)
         {
             IWidget widget = this.m_ChildWidgets[i];
             if (widget != null)
             {
                 if ((widget.ParentWidget == null) || (widget.ParentWidget != this))
                 {
                     widget.ParentWidget = this;
                 }
                 widget.Render(drawArgs);
             }
         }
         this.m_OutlineVerts[0].X = this.AbsoluteLocation.X + this.ClientSize.Width;
         this.m_OutlineVerts[0].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
         this.m_OutlineVerts[1].X = this.AbsoluteLocation.X + this.ClientSize.Width;
         this.m_OutlineVerts[1].Y = this.AbsoluteLocation.Y + this.ClientSize.Height;
         this.m_OutlineVerts[2].X = this.AbsoluteLocation.X;
         this.m_OutlineVerts[2].Y = this.AbsoluteLocation.Y + this.ClientSize.Height;
         this.m_OutlineVerts[3].X = this.AbsoluteLocation.X;
         this.m_OutlineVerts[3].Y = this.AbsoluteLocation.Y + this.m_HeaderHeight;
         if (!this.m_HideBorder)
         {
             Utilities.DrawLine(this.m_OutlineVerts, this.m_BorderColor.ToArgb(), drawArgs.device);
         }
     }
 }
示例#20
0
文件: Matrix.cs 项目: rbernon/monoDX
		public void Transpose (Matrix source)
		{
			throw new NotImplementedException ();
		}
示例#21
0
 void Init()
 {
     m_ViewMatr = Microsoft.DirectX.Matrix.LookAtLH(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0));
     R          = R0;
     Trans      = new S4Trans(Dim);
 }
示例#22
0
 public void             SetupWorldMatrix(Microsoft.DirectX.Matrix matr)
 {
     m_pd3dDevice.SetTransform(TransformType.World, matr);
 }
        protected void RigidBody_Clone(AnimatTools.Framework.DataObject doOriginal, bool bCutData, AnimatTools.Framework.DataObject doRoot)
        {
            RigidBody_DX doOrigBody = (RigidBody_DX) doOriginal;

            m_d3dDevice = doOrigBody.m_d3dDevice;
            m_v3Rotation = new Microsoft.DirectX.Vector3(doOrigBody.m_v3Rotation.X, doOrigBody.m_v3Rotation.Y, doOrigBody.m_v3Rotation.Z);
            m_v3Direction = new Microsoft.DirectX.Vector3(doOrigBody.m_v3Direction.X, doOrigBody.m_v3Direction.Y, doOrigBody.m_v3Direction.Z);

            m_mtxOrientation = Util_DX.CloneMatrix(doOrigBody.m_mtxOrientation);
            m_mtxTranslation = Util_DX.CloneMatrix(doOrigBody.m_mtxTranslation);

            m_d3dMaterial.Ambient = doOrigBody.m_d3dMaterial.Ambient;
            m_d3dMaterial.Diffuse = doOrigBody.m_d3dMaterial.Diffuse;
            m_d3dTransparentMaterial.Ambient = doOrigBody.m_d3dTransparentMaterial.Ambient;
            m_d3dTransparentMaterial.Diffuse = doOrigBody.m_d3dTransparentMaterial.Diffuse;

            m_snXLocalLocation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snXLocalLocation.Clone(this, bCutData, doRoot);
            m_snYLocalLocation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snYLocalLocation.Clone(this, bCutData, doRoot);
            m_snZLocalLocation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snZLocalLocation.Clone(this, bCutData, doRoot);

            m_snXWorldLocation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snXWorldLocation.Clone(this, bCutData, doRoot);
            m_snYWorldLocation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snYWorldLocation.Clone(this, bCutData, doRoot);
            m_snZWorldLocation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snZWorldLocation.Clone(this, bCutData, doRoot);

            m_snXRotation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snXRotation.Clone(this, bCutData, doRoot);
            m_snYRotation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snYRotation.Clone(this, bCutData, doRoot);
            m_snZRotation = (AnimatTools.Framework.ScaledNumber) doOrigBody.m_snZRotation.Clone(this, bCutData, doRoot);
        }
示例#24
0
        private void Draw_8_3D(MechanismInfo mi)
        {
            Material kolesoMaterial = new Material();

            kolesoMaterial.Diffuse           = Color.Purple;
            kolesoMaterial.Specular          = Color.Yellow;
            kolesoMaterial.SpecularSharpness = 1;


            if (mi.Number != -1 && mi.Window != null)
            {
                int koef = mi.zoom;

                Mechanism_8 mechanism = (Mechanism_8)mi.mechanism;
                mechanism.ReturnState(mi.Timems * 0.01);

                //for static ball

                //for rope moving block
                float x = (float)(mechanism.R1 + mechanism.r2);
                float y = (float)(((mechanism.l - mechanism.R1) / 2 - Math.PI * mechanism.r2 / 2));
                //for ropes
                float xx = (float)(x + 2 * mechanism.r2);
                //for block
                int    lv = 100;
                double yb = mechanism.R1 + lv - mi.Timems * mechanism.v_block * 0.01;

                if ((yb < (mechanism.R1 / 2) || (y + mechanism.State.deltaO2) < 0.01) && mi.Timems != 0 && mi.Timer.Enabled)
                {
                    mi.Timer.Stop(); return;
                }



                DirectMatrix displace = DirectMatrix.Translation(-(float)(mechanism.R1 * 2) / koef, -(float)(mechanism.R1 * 2) / koef, 0);



                mi.d3d.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Wheat, 1.0f, 0);
                mi.d3d.BeginScene();

                SetupProjections(mi);

                mi.d3d.RenderState.FillMode = (mi.XRay)? Microsoft.DirectX.Direct3D.FillMode.Solid : Microsoft.DirectX.Direct3D.FillMode.WireFrame;
                mi.d3d.RenderState.Lighting = true;

                Mechanism_8 m8 = mi.mechanism as Mechanism_8;

                //Большое неподвижное колесо
                Mesh static_wheel = Mesh.Cylinder(mi.d3d, (float)m8.R1 / koef, (float)m8.R1 / koef, 0.1f, 50, 10);

                mi.d3d.Material        = kolesoMaterial;
                mi.d3d.Transform.World = DirectMatrix.RotationZ((float)mechanism.State.rot1) * displace *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                static_wheel.DrawSubset(0);

                //Вращающееся колесо
                Mesh nonstatic_wheel = Mesh.Cylinder(mi.d3d, (float)m8.r2 / koef, (float)m8.r2 / koef, 0.1f, 50, 10);

                mi.d3d.Transform.World = DirectMatrix.RotationZ(-(float)mechanism.State.rot2) * displace *

                                         DirectMatrix.Translation(x / koef, (float)(y + mechanism.State.deltaO2) / koef, 0) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180))
                                         * DirectMatrix.Translation(0, 0, 6f);
                nonstatic_wheel.DrawSubset(0);

                //Маленькое неподвижное колесо
                Mesh static_wheel1 = Mesh.Cylinder(mi.d3d, (float)m8.r1 / (koef), (float)m8.r1 / koef, 0.1f, 50, 10);
                kolesoMaterial.Diffuse = Color.Tomato;
                mi.d3d.Material        = kolesoMaterial;
                mi.d3d.Transform.World = DirectMatrix.RotationZ((float)mechanism.State.rot1) * displace * DirectMatrix.Translation(0, 0, 0.1f) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180))
                                         * DirectMatrix.Translation(0, 0, 6f);

                static_wheel1.DrawSubset(0);



                float len = (float)(y + mechanism.State.deltaO2);
                if (len < 0)
                {
                    len = -len;
                }

                kolesoMaterial.Diffuse = Color.DimGray;
                mi.d3d.Material        = kolesoMaterial;
                Mesh rope_left = Mesh.Cylinder(mi.d3d, 0.01f, 0.01f,
                                               len / koef, 50, 10
                                               );
                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(mechanism.R1) / koef, len / (2 * koef), 0) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                rope_left.DrawSubset(0);

                Mesh rope_right = Mesh.Cylinder(mi.d3d, 0.01f, 0.01f,
                                                len / koef, 50, 10
                                                );
                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(mechanism.R1 + 2 * mechanism.r2) / koef, len / (2 * koef), 0) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                rope_right.DrawSubset(0);

                Mesh rope_block = Mesh.Cylinder(mi.d3d, 0.01f, 0.01f,
                                                (float)yb / koef, 50, 10
                                                );
                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(-mechanism.r1) / koef, (float)yb / (2 * koef), 0.08f) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                rope_block.DrawSubset(0);


                //грузик
                kolesoMaterial.Diffuse = Color.ForestGreen;
                mi.d3d.Material        = kolesoMaterial;
                Mesh block = Mesh.Box(mi.d3d, 0.1f, 0.05f, 0.2f);

                mi.d3d.Transform.World =
                    DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                    DirectMatrix.Translation((float)(-mechanism.r1) / koef, (float)(yb + 0.05f) / koef, 0.08f) *
                    DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                    DirectMatrix.Translation(0, 0, 6f);
                block.DrawSubset(0);

                kolesoMaterial.Diffuse = Color.PapayaWhip;
                mi.d3d.Material        = kolesoMaterial;
                Mesh ball1 = Mesh.Sphere(mi.d3d, (float)mechanism.r1 / (3 * koef), 50, 20);
                mi.d3d.Transform.World = displace *
                                         DirectMatrix.Translation(0, 0, -0.05f) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                ball1.DrawSubset(0);

                Mesh ball2 = Mesh.Sphere(mi.d3d, (float)mechanism.r1 / (3 * koef), 50, 20);
                mi.d3d.Transform.World = displace *
                                         DirectMatrix.Translation(0, 0, 0.15f) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                ball2.DrawSubset(0);

                mi.d3d.RenderState.CullMode = Cull.None;
                kolesoMaterial.Diffuse      = Color.Purple;
                mi.d3d.Material             = kolesoMaterial;

                Mesh platform = Mesh.Polygon(mi.d3d, (float)mechanism.r2 / koef, 6);
                mi.d3d.Transform.World = DirectMatrix.RotationX((float)Math.PI / 2) * displace *
                                         DirectMatrix.Translation((float)(mechanism.R1 + 2 * mechanism.r2) / koef, 0, 0) *
                                         DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                         DirectMatrix.Translation(0, 0, 6f);
                platform.DrawSubset(0);



                if (mi.choise != Dots.None)
                {
                    DrawTrajectory(mi.mechanism.ID, mi.Timems == 0);
                }

                mi.d3d.EndScene();
                mi.d3d.Present();


                if (mi.Timer.Enabled)
                {
                    mi.Timems += mi.Timer.Interval;
                }
                static_wheel.Dispose();
                static_wheel1.Dispose();
                nonstatic_wheel.Dispose();
                rope_left.Dispose();
                rope_right.Dispose();
                rope_block.Dispose();
                block.Dispose();
                ball1.Dispose();
                ball2.Dispose();
                platform.Dispose();
            }
        }
示例#25
0
        private void Render()
        {
            //I had to draw the scene twice here as I could not figure out how to draw the sprite behind the mesh
            //Must be a better way to do this but this works and I quite like the flicker it causes as you can see through the mesh for a moment which is good for alignment.

            if (device == null)
            {
                return;
            }

            //using try{} stops application error on exit when device is disposed before Thread closed
            try
            {
                //Clear the backbuffer to a solid color and clears the zbuffer so the mesh renders each face with the correct overlapping
                device.Clear(
                    ClearFlags.Target | ClearFlags.ZBuffer,
                    backgroundColour, //Black is good to target later when removing borders
                    1.0f,
                    0);



                //******************* Sprite ********************



                //This showRefImage should disable drawing the character images while converting the Directx panel to the final .lib images
                if (showRefImage)
                {
                    _selectedRefImage    = _refLibrary.GetMImage((int)nud_frame.Value);
                    textBox_OffSetX.Text = _selectedRefImage.X.ToString();
                    textBox_OffSetY.Text = _selectedRefImage.Y.ToString();
                    if (_selectedRefImage.Image != null)
                    {
                        //Begin the scene for the sprite images
                        device.BeginScene();

                        //draw 2d Character Image behind the mesh
                        sprite = new Sprite(device);
                        sprite.Begin(SpriteFlags.AlphaBlend);

                        Texture character = Texture.FromBitmap(device, _selectedRefImage.Image, Usage.None, Pool.Managed);
                        sprite.Draw2D(
                            character,
                            new Rectangle(0, 0, _selectedRefImage.Width, _selectedRefImage.Height),
                            new Size(_selectedRefImage.Width, _selectedRefImage.Height),
                            new Point(characterGlobalOffsetX + _selectedRefImage.X, characterGlobalOffsetY + _selectedRefImage.Y),
                            Color.White);



                        sprite.End();
                        sprite.Dispose();

                        device.EndScene();     //end scene here so images are saved to the backbuffer and drawn behind the mesh
                        device.Present();

                        //only clear ZBuffer here so it keeps the sprite on the screen as the background
                        device.Clear(
                            ClearFlags.ZBuffer,
                            backgroundColour,
                            1.0f,
                            0);
                    }
                }



                //******************* Hands ********************



                if (_handLibrary != null && (showHandImage == true || blankHandImage == true))
                {
                    _selectedHandImage = _handLibrary.GetMImage((int)nud_frame.Value);
                    if (_selectedHandImage.Image != null)
                    {
                        //Begin the scene for the sprite images (hands)
                        device.BeginScene();

                        //draw 2d Character hands Image infront of the mesh
                        sprite = new Sprite(device);
                        sprite.Begin(SpriteFlags.AlphaBlend);

                        //if blankHands checkbox selected turn the hand image black so it gets removed when rendered
                        Bitmap TempHandBMP = new Bitmap(_selectedHandImage.Image); //create a new bitmap to store image (this way the original wont be updated and we can switch back at any time)
                        if (blankHandImage)
                        {
                            unsafe
                            {
                                BitmapData bitmapdata =
                                    TempHandBMP.LockBits(new Rectangle(0, 0, TempHandBMP.Width, TempHandBMP.Height),
                                                         ImageLockMode.ReadWrite, TempHandBMP.PixelFormat);

                                int bytesPerPixel  = System.Drawing.Bitmap.GetPixelFormatSize(TempHandBMP.PixelFormat) / 8;
                                int heightInPixels = bitmapdata.Height;
                                int widthInBytes   = bitmapdata.Width * bytesPerPixel;

                                byte *ptrFirstPixel = (byte *)bitmapdata.Scan0;

                                Parallel.For(0, heightInPixels, y =>
                                {
                                    byte *currentLine = ptrFirstPixel + (y * bitmapdata.Stride);

                                    for (int x = 0; x < widthInBytes; x = x + bytesPerPixel)
                                    {
                                        //GET (not needed for this)
                                        //int oldBlue = currentLine[x];
                                        //int oldGreen = currentLine[x + 1];
                                        //int oldRed = currentLine[x + 2];
                                        //int oldAlpha = currentLine[x + 3];

                                        //checks for alpha value
                                        if (currentLine[x + 3] != 0)
                                        {
                                            //SET
                                            //set this pixel to Black so it won't show up later
                                            currentLine[x]     = 0;   //blue
                                            currentLine[x + 1] = 0;   //green
                                            currentLine[x + 2] = 0;   //red
                                            currentLine[x + 3] = 255; //alpha
                                        }
                                    }
                                });
                                TempHandBMP.UnlockBits(bitmapdata);
                            }
                        }

                        // if the BlankHands checkbox is not selected it will have skipped the code to change the colours to pure black and the image will be unedited normal hands drawn on top of the mesh
                        // otherwise the image will be black and be removed from the black background when we capture the backbuffer
                        Texture hand = Texture.FromBitmap(device, TempHandBMP, Usage.None, Pool.Managed);
                        sprite.Draw2D(
                            hand,
                            new Rectangle(0, 0, _selectedHandImage.Width, _selectedHandImage.Height),
                            new Size(_selectedHandImage.Width, _selectedHandImage.Height),
                            new Point(characterGlobalOffsetX + _selectedHandImage.X, characterGlobalOffsetY + _selectedHandImage.Y),
                            Color.White);

                        TempHandBMP.Dispose(); // don't need this anymore

                        sprite.End();
                        sprite.Dispose();

                        device.EndScene(); //end scene here so images are saved to the backbuffer and drawn behind the mesh
                        device.Present();
                    }
                }



                //******************* Mesh ********************



                //begin the scene for drawing the mesh
                device.BeginScene();

                //draw mesh
                if (meshLoaded)
                {
                    for (int i = 0; i < meshMaterials.Length; i++)
                    {
                        // Set the material and texture for this subset.
                        device.Material = meshMaterials[i];
                        device.SetTexture(0, meshTextures[i]);

                        Microsoft.DirectX.Matrix mat1 = new Microsoft.DirectX.Matrix();
                        mat1 = Microsoft.DirectX.Matrix.Multiply(Microsoft.DirectX.Matrix.RotationX((float)(_selectedRefImage.RotationX * (6.28 / 360))), Microsoft.DirectX.Matrix.RotationY((float)(_selectedRefImage.RotationY * (6.28 / 360))));
                        mat1 = Microsoft.DirectX.Matrix.Multiply(mat1, Microsoft.DirectX.Matrix.RotationZ((float)(_selectedRefImage.RotationZ * (6.28 / 360))));
                        mat1 = Microsoft.DirectX.Matrix.Multiply(mat1, Microsoft.DirectX.Matrix.Translation(_selectedRefImage.MoveX, _selectedRefImage.MoveY, 0));
                        device.Transform.World = mat1;

                        // Draw the mesh subset.
                        mesh.DrawSubset(i);
                    }
                }
                //End the scene
                device.EndScene();
                device.Present();
            }
            catch
            {
            }
        }
        public static void Present()
        {
            lock (Renderlock)
            {
                DXNative.FontEnginePresentTexturesSync();
                foreach (GUIFont font in ListFonts)
                {
                    font.Present();
                }

                if (_spriteUsed)
                {
                    if (_sprite == null)
                    {
                        _sprite = new Sprite(GUIGraphicsContext.DX9Device);
                    }
                    _sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture);
                    Viewport orgView = GUIGraphicsContext.DX9Device.Viewport;
                    Matrix   orgProj = GUIGraphicsContext.DX9Device.Transform.View;
                    Matrix   projm   = orgProj;

                    foreach (FontManagerDrawText draw in _listDrawText)
                    {
                        Matrix finalm;
                        finalm.M11        = draw.Matrix[0, 0];
                        finalm.M21        = draw.Matrix[0, 1];
                        finalm.M31        = draw.Matrix[0, 2];
                        finalm.M41        = draw.Matrix[0, 3];
                        finalm.M12        = draw.Matrix[1, 0];
                        finalm.M22        = draw.Matrix[1, 1];
                        finalm.M32        = draw.Matrix[1, 2];
                        finalm.M42        = draw.Matrix[1, 3];
                        finalm.M13        = draw.Matrix[2, 0];
                        finalm.M23        = draw.Matrix[2, 1];
                        finalm.M33        = draw.Matrix[2, 2];
                        finalm.M43        = draw.Matrix[2, 3];
                        finalm.M14        = 0;
                        finalm.M24        = 0;
                        finalm.M34        = 0;
                        finalm.M44        = 1.0f;
                        _sprite.Transform = finalm;
                        GUIGraphicsContext.DX9Device.Viewport = draw.Viewport;
                        float wfactor = (float)orgView.Width / draw.Viewport.Width;
                        float hfactor = (float)orgView.Height / draw.Viewport.Height;
                        float xoffset = (float)orgView.X - draw.Viewport.X;
                        float yoffset = (float)orgView.Y - draw.Viewport.Y;
                        projm.M11 = (orgProj.M11 + orgProj.M14 * xoffset) * wfactor;
                        projm.M21 = (orgProj.M21 + orgProj.M24 * xoffset) * wfactor;
                        projm.M31 = (orgProj.M31 + orgProj.M34 * xoffset) * wfactor;
                        projm.M41 = (orgProj.M41 + orgProj.M44 * xoffset) * wfactor;
                        projm.M12 = (orgProj.M12 + orgProj.M14 * yoffset) * hfactor;
                        projm.M22 = (orgProj.M22 + orgProj.M24 * yoffset) * hfactor;
                        projm.M32 = (orgProj.M32 + orgProj.M34 * yoffset) * hfactor;
                        projm.M42 = (orgProj.M42 + orgProj.M44 * yoffset) * hfactor;
                        GUIGraphicsContext.DX9Device.Transform.View = projm;
                        if (GUIGraphicsContext.IsDirectX9ExUsed())
                        {
                            DrawTextUsingTexture(draw, draw.FontHeight);
                        }
                        else
                        {
                            draw.Fnt.DrawText(_sprite, draw.Text, new Rectangle((int)draw.Xpos,
                                                                                (int)draw.Ypos, 0, 0), DrawTextFormat.NoClip,
                                              draw.Color);
                        }

                        _sprite.Flush();
                    }

                    GUIGraphicsContext.DX9Device.Viewport       = orgView;
                    GUIGraphicsContext.DX9Device.Transform.View = orgProj;
                    _sprite.End();
                    _listDrawText = new List <FontManagerDrawText>();
                    _spriteUsed   = false;
                }
            }
        }
        private DX.Matrix MakeD3DMatrix(Axiom.MathLib.Matrix4 matrix)
        {
            DX.Matrix dxMat = new DX.Matrix();

            // set it to a transposed matrix since DX uses row vectors
            dxMat.M11 = matrix.m00;
            dxMat.M12 = matrix.m10;
            dxMat.M13 = matrix.m20;
            dxMat.M14 = matrix.m30;
            dxMat.M21 = matrix.m01;
            dxMat.M22 = matrix.m11;
            dxMat.M23 = matrix.m21;
            dxMat.M24 = matrix.m31;
            dxMat.M31 = matrix.m02;
            dxMat.M32 = matrix.m12;
            dxMat.M33 = matrix.m22;
            dxMat.M34 = matrix.m32;
            dxMat.M41 = matrix.m03;
            dxMat.M42 = matrix.m13;
            dxMat.M43 = matrix.m23;
            dxMat.M44 = matrix.m33;

            return dxMat;
        }
示例#28
0
文件: Matrix.cs 项目: rbernon/monoDX
		public unsafe static Matrix PerspectiveFovLH (float fieldOfViewY, float aspectRatio, float znearPlane, float zfarPlane)
		{
			Matrix result = new Matrix();
			D3DXMatrixPerspectiveFovLH(&result, fieldOfViewY, aspectRatio, znearPlane, zfarPlane);
			return result;
		}
示例#29
0
        public Form1()
        {
            InitializeComponent();

            PureQuadTree tree = new PureQuadTree(new Vector2(), new Vector2(256, 256));

            tree.Fork(1, false);
            tree.Children[3].Fork(1, false);
            tree.Children[1].Fork(1, false);
            //tree.Children[3].Children[3].Fork(1, false);
            //tree.Children[1].Fork(2, false);
            ////tree.Children[2].Fork(1, false);
            //tree.Children[3].Children[1].Fork(1, false);

            //leafPatches = new Dictionary<ulong, byte>();
            //patchLevels = new Dictionary<ulong, ushort[]>();
            //foreach (PureQuadTreeNode leaf in tree)
            //{
            //    if (leaf.Level > 0)
            //    {
            //        TraceLeaf(leaf);
            //    }
            //}

            qTree   = tree;// new PureQuadTree(new Vector2(), new Vector2(256, 256));
            viewPos = new Vector2(200, 300);
            viewDir = Vector2.Normalize(new Vector2(128, 128) - viewPos);
            falloff = 250;

            Vector3    viewDir3 = new Vector3(viewDir.X, 0, viewDir.Y);
            Quaternion q        = Quaternion.RotationAxis(new Vector3(0, 1, 0), (float)Math.PI / 8);
            Matrix     rot      = Matrix.RotationQuaternion(q);
            Vector4    temp     = Vector3.Transform(viewDir3, rot);

            viewFOVp1 = new Vector2(temp.X, temp.Z);
            viewFOVp1.Normalize();
            viewFOVp1 = new Vector2(viewPos.X + (viewFOVp1 * falloff).X, viewPos.Y + (viewFOVp1 * falloff).Y);

            q         = Quaternion.RotationAxis(new Vector3(0, 1, 0), -(float)Math.PI / 8);
            rot       = Matrix.RotationQuaternion(q);
            temp      = Vector3.Transform(viewDir3, rot);
            viewFOVp2 = new Vector2(temp.X, temp.Z);
            viewFOVp2.Normalize();
            viewFOVp2 = new Vector2(viewPos.X + (viewFOVp2 * falloff).X, viewPos.Y + (viewFOVp2 * falloff).Y);

            Vector3 viewPos3 = new Vector3(viewPos.X, 0, viewPos.Y);

            q    = Quaternion.RotationAxis(new Vector3(0, 1, 0), ((float)Math.PI / 8) + ((float)Math.PI / 2));
            rot  = Matrix.RotationQuaternion(q);
            temp = Vector3.Transform(viewDir3, rot);
            Vector3 v3 = new Vector3(-temp.X, 0, -temp.Z);

            v3.Normalize();

            viewFOVpl1 = Plane.FromPointNormal(viewPos3, v3);

            q    = Quaternion.RotationAxis(new Vector3(0, 1, 0), -((float)Math.PI / 8) - ((float)Math.PI / 2));
            rot  = Matrix.RotationQuaternion(q);
            temp = Vector3.Transform(viewDir3, rot);
            v3   = new Vector3(-temp.X, 0, -temp.Z);
            v3.Normalize();

            viewFOVpl2 = Plane.FromPointNormal(viewPos3, v3);
            //Plane.FromPoints(viewDir3, new Vector3(viewDir3.X, 1, viewDir3.Z), new Vector3(viewDir3.X + viewFOVp2.X, 0, viewDir3.Z + viewFOVp2.Y));

            leafDetail = new Dictionary <ulong, short>();

            BuildTree();
        }
示例#30
0
        private void DrawTrajectory(int ID, bool f)
        {
            MechanismInfo mi = FindMechanismInfo(ID);

            if (mi.Number == 8)
            {
                Dots        choise    = mi.choise;
                Mechanism_8 mechanism = (Mechanism_8)mi.mechanism;

                Point _O2 = new Point((int)(mechanism.R1 + mechanism.r2), (int)(((mechanism.l - mechanism.R1) / 2 - Math.PI * mechanism.r2 / 2) + mechanism.State.deltaO2));
                Point _A  = new Point((int)(_O2.X + mechanism.r2 * 3 * Math.Cos(mechanism.State.rot2) / 4),
                                      (int)(_O2.Y - mechanism.r2 * 3 * Math.Sin(mechanism.State.rot2) / 4));

                Point _B = new Point((int)(_O2.X + mechanism.r2 * Math.Cos(mechanism.State.rot2 + 3 * Math.PI / 4)),
                                     (int)(_O2.Y - mechanism.r2 * Math.Sin(mechanism.State.rot2 + 3 * Math.PI / 4)));

                CustomVertex.PositionColored A = new CustomVertex.PositionColored(new Vector3((float)_A.X, (float)_A.Y, 0), Color.Blue.ToArgb());
                A.Color = Color.Blue.ToArgb();

                CustomVertex.PositionColored B = new CustomVertex.PositionColored(new Vector3((float)_B.X, (float)_B.Y, 0), Color.Silver.ToArgb());
                B.Color = Color.Red.ToArgb();

                if (trajectories_vertex.Count < 2)
                {
                    trajectories_vertex.Add(new List <CustomVertex.PositionColored>());
                    trajectories_vertex.Add(new List <CustomVertex.PositionColored>());

                    trajectories_vertex[0].Add(A);
                    trajectories_vertex[1].Add(B);
                }
                if (f)
                {
                    trajectories_vertex[0].Clear();
                    trajectories_vertex[1].Clear();
                }
                trajectories_vertex[0].Add(A);
                trajectories_vertex[1].Add(B);

                //РИСОВАНИЕ КУРВ 3D


                List <CustomVertex.PositionColored> real_trajectoriesA = new List <CustomVertex.PositionColored>();
                List <CustomVertex.PositionColored> real_trajectoriesB = new List <CustomVertex.PositionColored>();

                for (int i = 0; i < trajectories_vertex[0].Count; i++)
                {
                    real_trajectoriesA.Add(new CustomVertex.PositionColored(new Vector3(trajectories_vertex[0][i].X / mi.zoom, trajectories_vertex[0][i].Y / mi.zoom, 0), trajectories_vertex[0][i].Color));
                    real_trajectoriesB.Add(new CustomVertex.PositionColored(new Vector3(trajectories_vertex[1][i].X / mi.zoom, trajectories_vertex[1][i].Y / mi.zoom, 0), trajectories_vertex[1][i].Color));
                }


                mi.d3d.VertexFormat = CustomVertex.PositionColored.Format;
                DirectMatrix displace = DirectMatrix.Translation(-(float)(mechanism.R1 * 2) / mi.zoom, -(float)(mechanism.R1 * 2) / mi.zoom, 0);

                Material kolesoMaterial = new Material();
                kolesoMaterial.Diffuse = Color.Blue;

                mi.d3d.RenderState.Lighting = true;

                if ((choise == Dots.A) || (choise == Dots.Both))
                {
                    mi.d3d.Material = kolesoMaterial;

                    Mesh ball2 = Mesh.Sphere(mi.d3d, (float)mechanism.r2 / (4 * mi.zoom), 50, 20);
                    mi.d3d.Transform.World = displace *
                                             DirectMatrix.Translation((float)(_A.X) / mi.zoom, (float)(_A.Y) / mi.zoom, 0) *
                                             DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                             DirectMatrix.Translation(0, 0, 6f);
                    ball2.DrawSubset(0);
                    ball2.Dispose();


                    mi.d3d.Transform.World = displace * DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) * DirectMatrix.Translation(0, 0, 6f);
                    mi.d3d.DrawUserPrimitives(PrimitiveType.LineStrip, real_trajectoriesA.Count - 1, real_trajectoriesA.ToArray());
                }
                if ((choise == Dots.B) || (choise == Dots.Both))
                {
                    kolesoMaterial.Diffuse = Color.Red;
                    mi.d3d.Material        = kolesoMaterial;

                    Mesh ball2 = Mesh.Sphere(mi.d3d, (float)mechanism.r2 / (4 * mi.zoom), 50, 20);
                    mi.d3d.Transform.World = displace *
                                             DirectMatrix.Translation((float)(_B.X) / mi.zoom, (float)(_B.Y) / mi.zoom, 0) *
                                             DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) *
                                             DirectMatrix.Translation(0, 0, 6f);
                    ball2.DrawSubset(0);
                    ball2.Dispose();

                    mi.d3d.Transform.World = displace * DirectMatrix.RotationX((float)(mi.rotateY * Math.PI / 180)) * DirectMatrix.RotationY((float)(mi.rotateZ * Math.PI / 180)) * DirectMatrix.Translation(0, 0, 6f);
                    mi.d3d.DrawUserPrimitives(PrimitiveType.LineStrip, real_trajectoriesB.Count - 1, real_trajectoriesB.ToArray());
                }
            }
        }
        public override void LoadData(ref AnimatTools.DataObjects.Simulation dsSim, ref AnimatTools.DataObjects.Physical.PhysicalStructure doStructure, ref AnimatTools.Interfaces.StdXml oXml)
        {
            base.LoadData (ref dsSim, ref doStructure, ref oXml);
            oXml.IntoElem();

            //get the color of the body
            if(oXml.FindChildElement("Color"))
            {
                System.Drawing.Color oColor = Util.LoadColor(ref oXml, "Color");

                this.Alpha = oColor.A;
                this.Color = oColor;
            }

            if(oXml.FindChildElement("Direction",false))
            {
                this.m_v3Direction = new Vector3();
                Vec3d vDirection = Util.LoadVec3d(ref oXml, "Direction", this);
                m_v3Direction.X = (float)vDirection.X;
                m_v3Direction.Y = (float)vDirection.Y;
                m_v3Direction.Z = (float)vDirection.Z;
            }

            if(oXml.FindChildElement("OrientationMatrix", false))
            {
                m_mtxOrientation = Util_DX.LoadMatrix(ref oXml, "OrientationMatrix");
                m_v3Rotation = Util_DX.DecomposeXYZRotationMatrix(Orientation);
            }

            if(oXml.FindChildElement("TranslationMatrix",false))
                m_mtxTranslation = Util_DX.LoadMatrix(ref oXml,"TranslationMatrix");

            oXml.OutOfElem();
        }
        public static Microsoft.DirectX.Matrix CloneMatrix(Microsoft.DirectX.Matrix aryMatrix)
        {
            Microsoft.DirectX.Matrix aryNewMatrix = new Microsoft.DirectX.Matrix();
            aryNewMatrix.M11 = aryMatrix.M11;
            aryNewMatrix.M12 = aryMatrix.M12;
            aryNewMatrix.M13 = aryMatrix.M13;
            aryNewMatrix.M14 = aryMatrix.M14;

            aryNewMatrix.M21 = aryMatrix.M21;
            aryNewMatrix.M22 = aryMatrix.M22;
            aryNewMatrix.M23 = aryMatrix.M23;
            aryNewMatrix.M24 = aryMatrix.M24;

            aryNewMatrix.M31 = aryMatrix.M31;
            aryNewMatrix.M32 = aryMatrix.M32;
            aryNewMatrix.M33 = aryMatrix.M33;
            aryNewMatrix.M34 = aryMatrix.M34;

            aryNewMatrix.M41 = aryMatrix.M41;
            aryNewMatrix.M42 = aryMatrix.M42;
            aryNewMatrix.M43 = aryMatrix.M43;
            aryNewMatrix.M44 = aryMatrix.M44;

            return aryNewMatrix;
        }
示例#33
0
文件: Matrix.cs 项目: rbernon/monoDX
		public unsafe static Matrix LookAtLH (Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector)
		{
			Matrix result = new Matrix();
			D3DXMatrixLookAtLH(&result, &cameraPosition, &cameraTarget, &cameraUpVector);
			return result;
		}
示例#34
0
        public WallAccess(Direct3D.Device NewGameDevice,
                          GameEngine.ShaderLevel NewCardShaderLevel,
                          DirectX.Matrix NewViewMatrix,
                          DirectX.Matrix NewProjectionMatrix)
        {
            GameDevice       = NewGameDevice;
            CardShaderLevel  = NewCardShaderLevel;
            ViewMatrix       = NewViewMatrix;
            ProjectionMatrix = NewProjectionMatrix;

            // Load Shader Effects From Files
            WallEffect           = Direct3D.Effect.FromFile(GameDevice, GameConfig.Files.WallFx, null, null, Direct3D.ShaderFlags.None, null);
            WallEffect.Technique = "WallLight_1_1";

            PipeEffect           = Direct3D.Effect.FromFile(GameDevice, GameConfig.Files.PipeFx, null, null, Direct3D.ShaderFlags.None, null);
            PipeEffect.Technique = "PipeLight_1_1";

            // Load Mesh From File
            WallMesh = Direct3D.Mesh.FromFile(GameConfig.Files.WallMesh, Direct3D.MeshFlags.Managed, GameDevice, out WallMtrl);
            PipeMesh = Direct3D.Mesh.FromFile(GameConfig.Files.PipeMesh, Direct3D.MeshFlags.Managed, GameDevice, out PipeMtrl);

            // Load Wall Textures
            if ((WallMtrl != null) && (WallMtrl.Length > 0))
            {
                WallMaterials = new Direct3D.Material[WallMtrl.Length];
                WallTextures  = new Direct3D.Texture[WallMtrl.Length];

                for (int i = 0; i < WallMtrl.Length; i++)
                {
                    WallMaterials[i] = WallMtrl[i].Material3D;
                    if ((WallMtrl[i].TextureFilename != null) && (WallMtrl[i].TextureFilename != string.Empty))
                    {
                        WallTextures[i] = Direct3D.TextureLoader.FromFile(GameDevice, @"..\..\Resources\" + WallMtrl[i].TextureFilename);
                    }
                }
            }

            // Load Pipe Textures
            if ((PipeMtrl != null) && (PipeMtrl.Length > 0))
            {
                PipeMaterials = new Direct3D.Material[PipeMtrl.Length];
                PipeTextures  = new Direct3D.Texture[PipeMtrl.Length];

                for (int i = 0; i < PipeMtrl.Length; i++)
                {
                    PipeMaterials[i] = PipeMtrl[i].Material3D;
                    if ((PipeMtrl[i].TextureFilename != null) && (PipeMtrl[i].TextureFilename != string.Empty))
                    {
                        PipeTextures[i] = Direct3D.TextureLoader.FromFile(GameDevice, @"..\..\Resources\" + PipeMtrl[i].TextureFilename);
                    }
                }
            }

            // Set wall mesh location
            WallWorldMatrix = DirectX.Matrix.RotationYawPitchRoll(3.12f, 0.0f, 0.0f) * DirectX.Matrix.Translation(15, -75, -425);
            PipeWorldMatrix = DirectX.Matrix.RotationYawPitchRoll(3.20f, -0.1f, 0.0f) * DirectX.Matrix.Translation(-145, 15, -375);

            // Set Wall Shader Parameters
            DirectX.Matrix WorldViewProjMatrix = WallWorldMatrix * ViewMatrix * ProjectionMatrix;
            WallEffect.SetValue("WorldViewProj", WorldViewProjMatrix);
            WallEffect.SetValue("WorldMatrix", WallWorldMatrix);
            WallEffect.SetValue("DiffuseDirection", new DirectX.Vector4(1.0f, 1.0f, 1.0f, 0.0f));

            // Set Pipe Shader Parameters
            WorldViewProjMatrix = PipeWorldMatrix * ViewMatrix * ProjectionMatrix;
            PipeEffect.SetValue("WorldViewProj", WorldViewProjMatrix);
            PipeEffect.SetValue("WorldMatrix", PipeWorldMatrix);
            PipeEffect.SetValue("DiffuseDirection", new DirectX.Vector4(1.0f, 1.0f, 1.0f, 0.0f));
        }