Exemplo n.º 1
0
 /// <summary>
 /// Set a three-component vector that contains floating-point data.
 /// </summary>
 /// <param name="value">A reference to the first component. </param>
 /// <returns>Returns one of the following {{Direct3D 10 Return Codes}}. </returns>
 /// <unmanaged>HRESULT ID3D10EffectVectorVariable::SetFloatVector([In] float* pData)</unmanaged>
 public void Set(RawVector3 value)
 {
     unsafe
     {
         SetRawValue(new IntPtr(&value), 0, Utilities.SizeOf <RawVector3>());
     }
 }
Exemplo n.º 2
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Десереализация трехмерного вектора из строки
            /// </summary>
            /// <param name="data">Строка данных</param>
            /// <returns>Трехмерный вектор</returns>
            //---------------------------------------------------------------------------------------------------------
            public static RawVector3 Deserialize(String data)
            {
                RawVector3 vector = new RawVector3();

                String[] vector_data = data.Split(';');
                vector.X = (Single.Parse(vector_data[0].Replace(',', '.'), CultureInfo.InvariantCulture));
                vector.Y = (Single.Parse(vector_data[1].Replace(',', '.'), CultureInfo.InvariantCulture));
                vector.Z = (Single.Parse(vector_data[2].Replace(',', '.'), CultureInfo.InvariantCulture));
                return(vector);
            }
Exemplo n.º 3
0
 /// <summary>
 /// Gets an array of <see cref="RawVector3"/> from a <see cref="DataStream"/>.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="vertexCount">The vertex count.</param>
 /// <param name="stride">The stride.</param>
 /// <returns>An array of <see cref="RawVector3"/> </returns>
 public static RawVector3[] GetVectors(DataStream stream, int vertexCount, int stride)
 {
     unsafe
     {
         var results = new RawVector3[vertexCount];
         for (int i = 0; i < vertexCount; i++)
         {
             results[i]       = stream.Read <RawVector3>();
             stream.Position += stride - sizeof(RawVector3);
         }
         return(results);
     }
 }
Exemplo n.º 4
0
 public void Render()
 {
     context.ClearRenderTargetView(renderTargetView, new RawColor4(0, 128, 255, 255));
     context.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
     camPosRel  = new RawVector3((float)Math.Sin(CamRot) * CamDis, CamHeight, (float)Math.Cos(CamRot) * CamDis);
     camPosRel += CamPos;
     view       = Matrix.LookAtLH(camPosRel, CamPos, Vector3.UnitY);
     foreach (RenderObject ro in objects)
     {
         ro.Render(context, view, proj);
     }
     swapChain.Present(0, PresentFlags.None);
 }
        public void Render()
        {
            RawVector3 position = new Vector3(PositionX, PositionY, PositionZ);
            RawVector3 lookAt   = new Vector3(0, 0, 1);

            float     pitch          = RotationX * 0.0174532925f;
            float     yaw            = RotationY * 0.0174532925f;;
            float     roll           = RotationZ * 0.0174532925f;;
            RawMatrix rotationMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, roll);

            lookAt = Vector3.TransformCoordinate(lookAt, rotationMatrix);
            RawVector3 up = Vector3.TransformCoordinate(Vector3.UnitY, rotationMatrix);

            lookAt = Vector3.Add(position, lookAt);

            ViewMatrix = Matrix.LookAtLH(position, lookAt, up);
        }
Exemplo n.º 6
0
        public static void Render()
        {
            context.OutputMerger.SetRenderTargets(renderTargetView);
            context.ClearRenderTargetView(renderTargetView, new RawColor4(0, 128, 255, 255));
            camPos = new RawVector3((float)Math.Sin(CamRot) * CamDis, 0, (float)Math.Cos(CamRot) * CamDis);
            view   = Matrix.LookAtLH(camPos, Vector3.Zero, Vector3.UnitY);
            world  = Matrix.Identity * view * proj;
            world  = Matrix.Transpose(world);
            DataStream data;

            context.MapSubresource(constantBuffer, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out data);
            data.Write(world);
            context.UnmapSubresource(constantBuffer, 0);
            context.VertexShader.SetConstantBuffer(0, constantBuffer);
            foreach (RenderObject ro in objects)
            {
                ro.Render(context);
            }
            swapChain.Present(0, PresentFlags.None);
        }
Exemplo n.º 7
0
        private void BuildSpriteQuad(Sprite sprite, ref SpriteVertex[] vertex)
        {
            if (vertex.Length < 4)
            {
                throw new ArgumentException("Must have 4 sprite vertices", "v");
            }

            RawRectangle destinationRectangle = sprite.DestRectangle;
            RawRectangle sourceRectangle      = sprite.SourceRectangle;

            vertex[0].Position = this.PointToNdc(destinationRectangle.Left, destinationRectangle.Bottom, sprite.Z);
            vertex[1].Position = this.PointToNdc(destinationRectangle.Left, destinationRectangle.Top, sprite.Z);
            vertex[2].Position = this.PointToNdc(destinationRectangle.Right, destinationRectangle.Top, sprite.Z);
            vertex[3].Position = this.PointToNdc(destinationRectangle.Right, destinationRectangle.Bottom, sprite.Z);

            vertex[0].Tex = new RawVector2((Single)sourceRectangle.Left / this.TexWidth, (Single)sourceRectangle.Bottom / this.TexHeight);
            vertex[1].Tex = new RawVector2((Single)sourceRectangle.Left / this.TexWidth, (Single)sourceRectangle.Top / this.TexHeight);
            vertex[2].Tex = new RawVector2((Single)sourceRectangle.Right / this.TexWidth, (Single)sourceRectangle.Top / this.TexHeight);
            vertex[3].Tex = new RawVector2((Single)sourceRectangle.Right / this.TexWidth, (Single)sourceRectangle.Bottom / this.TexHeight);

            vertex[0].Color = sprite.Color;
            vertex[1].Color = sprite.Color;
            vertex[2].Color = sprite.Color;
            vertex[3].Color = sprite.Color;

            Single tx = 0.5f * (vertex[0].Position.X + vertex[3].Position.X);
            Single ty = 0.5f * (vertex[0].Position.Y + vertex[1].Position.Y);

            RawVector2 origin      = new RawVector2(tx, ty);
            RawVector2 translation = new RawVector2(0.0f, 0.0f);

            //// RawMatrix Transformation = RawMatrix.AffineTransformation2D(sprite.Scale, origin, Sprite.Angle, translation);

            for (Int32 index = 0; index < 4; ++index)
            {
                RawVector3 position = vertex[index].Position;
                //// RawVector3 position = RawVector3.TransformCoordinate(position, Transformation);
                vertex[index].Position = position;
            }
        }
Exemplo n.º 8
0
        private void DrawProgresBar(int progressSize)
        {
            _progressBarSprite.Begin(SpriteFlags.AlphaBlend);

            var backgroundstream = BackgroundImage.ToStream(ImageFormat.Bmp);
            var foregroundstream = ForegroundImage.ToStream(ImageFormat.Bmp);

            var backgroundTexture = Texture.FromStream(Device, backgroundstream, 100, 16, 0,
                                                       Usage.None,
                                                       Format.A8B8G8R8, Pool.Default, Filter.Default, Filter.Default, 0);

            var foregroundTexture = Texture.FromStream(Device, foregroundstream,
                                                       progressSize, 16, 0,
                                                       Usage.None,
                                                       Format.A8B8G8R8, Pool.Default, Filter.Default, Filter.Default, 0);

            var color = new RawColorBGRA()
            {
                R = 255, A = 255, B = 255, G = 255
            };
            var pos = new RawVector3
            {
                X = 5, Y = 5, Z = 0
            };

            _progressBarSprite.Draw(backgroundTexture, color, null, null, pos);

            if (progressSize > 0)
            {
                _progressBarSprite.Draw(foregroundTexture, color, null, null, pos);
            }

            _progressBarSprite.End();
            backgroundstream.Dispose();
            foregroundstream.Dispose();
            backgroundTexture.Dispose();
            foregroundTexture.Dispose();
        }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 public void RenderMatrix()
 {
     var up = new RawVector3(0.0f, 1.0f, 0.0f);
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rotation"></param>
 public void RotateCameraTo(RawVector3 rotation)
 {
     _rotation = new RawVector3(rotation.X, rotation.Y, rotation.Z);
 }
        public void Render(GameInfo game, Device d3d9Device, LiveSplitHelper liveSplitHelper)
        {
            if (game.State.Old != GameState.InEndScreen && game.State.Current == GameState.InEndScreen)
            {
                _prevLevelInfo = game.GetGameInfoSnapShot();
                GenerateLiveSplitSprite(d3d9Device, liveSplitHelper);
            }

            if (game.State.Old != GameState.InLoadScreen &&
                game.State.Current == GameState.InLoadScreen)
            {
                GenerateLiveSplitSprite(d3d9Device, liveSplitHelper);
            }

            var y = 0;

            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.Level)}: {_prevLevelInfo.Level.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.AreaCode)}: {_prevLevelInfo.AreaCode.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.NumberOfPlayers)}: {_prevLevelInfo.NumberOfPlayers.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.State)}: {_prevLevelInfo.State.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.GameTime)}: {_prevLevelInfo.GameTime.Current.ToTimerString()}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.ValidVSyncSettings)}: {_prevLevelInfo.ValidVSyncSettings.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(_prevLevelInfo.HasControl)}: {_prevLevelInfo.HasControl.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));

            y += 36;
            Text.DrawText(d3d9Device, $"------------------", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;

            Text.DrawText(d3d9Device, $"{nameof(game.Level)}: {game.Level.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(game.AreaCode)}: {game.AreaCode.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(game.NumberOfPlayers)}: {game.NumberOfPlayers.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(game.State)}: {game.State.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(game.GameTime)}: {game.GameTime.Current.ToTimerString()}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(game.ValidVSyncSettings)}: {game.ValidVSyncSettings.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));
            y += 36;
            Text.DrawText(d3d9Device, $"{nameof(game.HasControl)}: {game.HasControl.Current}", 34, 0, y, new RawColorBGRA(255, 255, 255, 255));

            if (_liveSplitSprite != null && _liveSplitTexture != null)
            {
                _liveSplitSprite.Begin();

                var w = d3d9Device.Viewport.Width;
                var h = d3d9Device.Viewport.Height;

                var pos   = new RawVector3(w - _liveSplitRectangle.Width, h - _liveSplitRectangle.Height, 0);
                var color = new RawColorBGRA(255, 255, 255, 255);

                _liveSplitSprite.Draw(_liveSplitTexture, color, null, null, pos);

                _liveSplitSprite.End();
            }
        }
Exemplo n.º 12
0
        private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = toolStripComboBox1.SelectedIndex;

            byte[] id  = mesh.lods[n].chunkID;
            string sid = Helpers.ByteArrayToHexString(id);

            rawLodBuffer     = null;
            hb2.ByteProvider = new DynamicByteProvider(new byte[0]);
            LoadRawLodBuffer(mesh, n);
            if (rawLodBuffer != null)
            {
                hb2.ByteProvider = new DynamicByteProvider(rawLodBuffer);
                mesh.lods[n].LoadVertexData(new MemoryStream(rawLodBuffer));
                timer1.Enabled = false;
                List <RawVector3> verts = new List <RawVector3>();
                for (int i = 0; i < mesh.lods[n].sections.Count; i++)
                {
                    MeshLodSection sec = mesh.lods[n].sections[i];
                    foreach (ushort idx in sec.indicies)
                    {
                        Vertex v = sec.vertices[idx];
                        if (v.position.members.Length == 3)
                        {
                            verts.Add(new RawVector3(v.position.members[0], v.position.members[1], v.position.members[2]));
                        }
                    }
                }
                RawVector3 min = new RawVector3(10000, 10000, 10000);
                RawVector3 max = new RawVector3(-10000, -10000, -10000);
                foreach (RawVector3 v in verts)
                {
                    if (v.X < min.X)
                    {
                        min.X = v.X;
                    }
                    if (v.Y < min.Y)
                    {
                        min.Y = v.Y;
                    }
                    if (v.Z < min.Z)
                    {
                        min.Z = v.Z;
                    }
                    if (v.X > max.X)
                    {
                        max.X = v.X;
                    }
                    if (v.Y > max.Y)
                    {
                        max.Y = v.Y;
                    }
                    if (v.Z > max.Z)
                    {
                        max.Z = v.Z;
                    }
                }
                mid             = new RawVector3((min.X + max.X) / 2f, (min.Y + max.Y) / 2f, (min.Z + max.Z) / 2f);
                DXHelper.CamDis = (float)Math.Sqrt(Math.Pow(max.X - mid.X, 2) + Math.Pow(max.Y - mid.Y, 2) + Math.Pow(max.Z - mid.Z, 2)) * 1.5f;
                if (DXHelper.CamDis < 1f)
                {
                    DXHelper.CamDis = 1f;
                }
                for (int i = 0; i < verts.Count; i++)
                {
                    RawVector3 v = verts[i];
                    v.X     -= mid.X;
                    v.Y     -= mid.Y;
                    v.Z     -= mid.Z;
                    verts[i] = v;
                }
                RenderObject ro = new RenderObject(DXHelper.device, RenderObject.RenderType.TriListWire, DXHelper.pixelShader);
                ro.vertices = verts.ToArray();
                ro.InitGeometry();
                DXHelper.objects = new List <RenderObject>();
                DXHelper.objects.Add(ro);
                if (skeleton != null)
                {
                    RenderObject skel = MakeSkeletonMesh(skeleton);
                    for (int i = 0; i < skel.vertices.Length; i++)
                    {
                        skel.vertices[i].X -= mid.X;
                        skel.vertices[i].Y -= mid.Y;
                        skel.vertices[i].Z -= mid.Z;
                    }
                    skel.InitGeometry();
                    DXHelper.objects.Add(skel);
                }
                timer1.Enabled = true;
            }
        }
Exemplo n.º 13
0
 public Camera(float x         = 0.0f, float y = 0.0f, float z = 0.0f,
               float xRotation = 0.0f, float yRotation = 0.0f, float zRotation = 0.0f)
 {
     _position = new RawVector3(x, y, z);
     _rotation = new RawVector3(xRotation, yRotation, zRotation);
 }
Exemplo n.º 14
0
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Сериализация трехмерного вектора в строку
 /// </summary>
 /// <param name="vector">Трехмерный вектор</param>
 /// <returns>Строка данных</returns>
 //---------------------------------------------------------------------------------------------------------
 public static String Serialize(this RawVector3 vector)
 {
     return(String.Format("{0};{1};{2}", vector.X, vector.Y, vector.Z));
 }
Exemplo n.º 15
0
 public VertexPositionColor(RawVector3 position, RawColor4 color)
 {
     Position = position;
     Color    = color;
 }
Exemplo n.º 16
0
 public Camera(RawVector3 position, RawVector3 rotation)
 {
     _position = position;
     _rotation = rotation;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Sets the named property to the given value.
 /// </summary>
 /// <param name="index">Index of the property</param>
 /// <param name="value">Value of the property</param>
 /// <unmanaged>HRESULT ID2D1Properties::SetValue([In] const wchar_t* name,[In] D2D1_PROPERTY_TYPE type,[In, Buffer] const void* data,[In] unsigned int dataSize)</unmanaged>
 public unsafe void SetValue(int index, RawVector3 value)
 {
     SetValue(index, PropertyType.Vector3, new IntPtr(&value), sizeof(RawVector3));
 }
Exemplo n.º 18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="position"></param>
 public void MoveCameraTo(RawVector3 position)
 {
     _position = new RawVector3(position.X, position.Y, position.Z);
 }
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Запись данных трехмерного вектора в формат атрибутов
 /// </summary>
 /// <param name="xml_writer">Средство записи данных в формат XML</param>
 /// <param name="name">Имя атрибута</param>
 /// <param name="vector">Двухмерный вектор</param>
 //---------------------------------------------------------------------------------------------------------
 public static void WriteVector3ToAttribute(this XmlWriter xml_writer, String name, RawVector3 vector)
 {
     xml_writer.WriteStartAttribute(name);
     xml_writer.WriteValue(vector.Serialize());
     xml_writer.WriteEndAttribute();
 }
Exemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        public static RawVector3 TransformCoord(this RawMatrix m, RawVector3 v)
        {
            var v2 = Multiply(m, v.X, v.Y, v.Z, 1);

            return(new RawVector3(v2.X, v2.Y, v2.Z));
        }