Esempio n. 1
0
        public bool UpdateInput()
        {
            bool  bCameraUpdated = false;
            float Multiplier     = ToolkitSettings.CameraSpeed;

            if (Input.IsKeyDown(Keys.ShiftKey))
            {
                Multiplier *= 2.0f;
            }

            float speed = Profile.DeltaTime * Multiplier;

            if (Input.IsKeyDown(Keys.A))
            {
                Camera.Position -= Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(0), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.D))
            {
                Camera.Position += Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(0), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.W))
            {
                Camera.Position -= Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(2), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.S))
            {
                Camera.Position += Vector3Utils.FromVector4(Vector4.Multiply(Camera.ViewMatrix.GetColumn(2), speed));
                bCameraUpdated   = true;
            }

            if (Input.IsKeyDown(Keys.Q))
            {
                Camera.Position.Z += speed;
                bCameraUpdated     = true;
            }

            if (Input.IsKeyDown(Keys.E))
            {
                Camera.Position.Z -= speed;
                bCameraUpdated     = true;
            }

            return(bCameraUpdated);
        }
        /*
         * Position.X = 2 Bytes / Half;
         * Position.Y = 2 Bytes / Half;
         * Position.Z = 2 Bytes / Half;
         * Position.W = 2 Bytes / Half;
         *  Also
         *      Tangent.X = 1 Bytes (1st Bytes of Position.W)
         *      Tangent.Y = 1 Bytes (2nd Bytes of Position.W)
         * Normal.X = 1 Bytes / Byte.
         * Normal.Y = 1 Bytes / Byte.
         * Normal.Z = 1 Bytes / Byte.
         * Normal.W = 1 Bytes / Bytes.
         *
         *  Also
         *      Tangent.W = 1 Bytes (1st Bytes of Normal.W)
         *
         *
         * */
        public static Vertex DecompressVertex(byte[] data, VertexFlags declaration, Vector3 offset, float scale, Dictionary <VertexFlags, ResourceTypes.FrameResource.FrameLOD.VertexOffset> offsets)
        {
            Vertex vertex = new Vertex();

            if (declaration.HasFlag(VertexFlags.Position))
            {
                int startIndex = offsets[VertexFlags.Position].Offset;
                var output     = ReadPositionDataFromVB(data, startIndex, scale, offset);
                vertex.Position = Vector3Utils.FromVector4(output);
                vertex.Binormal = new Vector3(output.W);
            }

            if (declaration.HasFlag(VertexFlags.Tangent))
            {
                int startIndex = offsets[VertexFlags.Position].Offset;
                vertex.Tangent = ReadTangentDataFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.Normals))
            {
                int startIndex = offsets[VertexFlags.Normals].Offset;
                vertex.Normal = ReadNormalDataFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.Skin))
            {
                int startIndex = offsets[VertexFlags.Skin].Offset;
                vertex.BoneWeights = ReadWeightsFromVB(data, startIndex);
                vertex.BoneIDs     = ReadBonesFromVB(data, startIndex + 4);
            }

            if (declaration.HasFlag(VertexFlags.Color))
            {
                int startIndex = offsets[VertexFlags.Color].Offset;
                vertex.Color0 = ReadColorFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.Color1))
            {
                int startIndex = offsets[VertexFlags.Color1].Offset;
                vertex.Color1 = ReadColorFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.TexCoords0))
            {
                int startIndex = offsets[VertexFlags.TexCoords0].Offset;
                vertex.UVs[0] = ReadTexcoordFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.TexCoords1))
            {
                int startIndex = offsets[VertexFlags.TexCoords1].Offset;
                vertex.UVs[1] = ReadTexcoordFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.TexCoords2))
            {
                int startIndex = offsets[VertexFlags.TexCoords2].Offset;
                vertex.UVs[2] = ReadTexcoordFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.ShadowTexture))
            {
                int startIndex = offsets[VertexFlags.ShadowTexture].Offset;
                vertex.UVs[3] = ReadTexcoordFromVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.BBCoeffs))
            {
                int startIndex = offsets[VertexFlags.BBCoeffs].Offset;
                vertex.BBCoeffs = ReadBBCoeffsVB(data, startIndex);
            }

            if (declaration.HasFlag(VertexFlags.DamageGroup))
            {
                int startIndex = offsets[VertexFlags.DamageGroup].Offset;
                vertex.DamageGroup = ReadDamageGroupFromVB(data, startIndex);
            }

            // We only try to calculate binormal vector if we have the correct tangent space data so far..
            if (declaration.HasFlag(VertexFlags.Normals) && declaration.HasFlag(VertexFlags.Tangent))
            {
                Vector4 positionW = new Vector4(vertex.Position, vertex.Binormal.X);
                vertex.Binormal = CalculateBinormal(positionW, vertex.Tangent, vertex.Normal);
            }
            return(vertex);
        }