コード例 #1
0
        // Get the transformation matrices at a time
        private Frame GetTransformsAtTime(float time)
        {
            // Calculate the index of the current frame
            var frameIndex = (int)(time * Fps) % FrameCount;
            var t          = ((time * Fps) - frameIndex) % 1;

            // Get current and next frame
            var frame1 = Frames[frameIndex];
            var frame2 = Frames[(frameIndex + 1) % FrameCount];

            // Create output frame
            var frame = new Frame();

            var length = FrameCount / Fps;

            // Interpolate bone positions and angles
            foreach (var bonePair in frame1.Bones)
            {
                var position = Vector3.Lerp(frame1.Bones[bonePair.Key].Position, frame2.Bones[bonePair.Key].Position, t);
                var angle    = Quaternion.Slerp(frame1.Bones[bonePair.Key].Angle, frame2.Bones[bonePair.Key].Angle, t);
                frame.Bones[bonePair.Key] = new FrameBone(position, angle);
            }

            return(frame);
        }
コード例 #2
0
        public override void Render(float partialTicks)
        {
            Vector3 partialPos = Vector3.Lerp(LastPos, Pos, partialTicks);
            Vector3 partialRot = Vector3.Lerp(_lastRot, _rot, partialTicks);

            float partialScale = LastParticleScale + (ParticleScale - LastParticleScale) * partialTicks;
            float partialAlpha = LastParticleAlpha + (ParticleAlpha - LastParticleAlpha) * partialTicks;

            partialPos.Y += partialScale / 2.0f;

            ModelBaked model = ParticleRenderer.ParticleModel;

            model.Shader.SetMatrix4("transformationMatrix", MatrixHelper.CreateTransformationMatrix(partialPos, partialRot, partialScale));
            model.Shader.SetVector2("UVmin", UVmin);
            model.Shader.SetVector2("UVmax", UVmax);
            model.Shader.SetFloat("alpha", partialAlpha);

            GL.BindTexture(TextureTarget.Texture2D, TextureId);
            model.RawModel.Render();
        }