Beispiel #1
0
        internal void Draw(ITransformation camera, Vector3 cameraPos)
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            shader.Activate();
            shader.Uniform(nameof(cameraPos), cameraPos);
            shader.Uniform(nameof(camera), camera);

            void SetJointMatrices(Matrix4x4[] jointTransformations) => GL.UniformMatrix4(locJoints, jointTransformations.Length, false, jointTransformations.ToFloatArray());

            model.UpdateAnimations((float)time.Elapsed.TotalSeconds, SetJointMatrices);

            void SetWorld(ITransformation transform) => shader.Uniform("world", transform);

            if (model.IsSkinned)
            {
                var joints = model.CalculateJointTransforms();
                SetJointMatrices(joints);
                SetWorld(Transformation.Identity);
                model.Draw((m) => { });
            }
            else
            {
                //initialize joint matrices with identity
                var ident = new Matrix4x4[100];
                for (int i = 0; i < ident.Length; ++i)
                {
                    ident[i] = Matrix4x4.Identity;
                }
                float[] buffer = ident.ToFloatArray();
                SetJointMatrices(ident);
                model.Draw(SetWorld);
            }

            shader.Deactivate();

            if (time.ElapsedMilliseconds > 5000)
            {
                time.Restart();
            }
        }
Beispiel #2
0
        internal void Draw(ITransformation camera, Vector3 cameraPos)
        {
            void SetWorld(ITransformation transform) => shader.Uniform("world", transform);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            shader.Activate();
            shader.Uniform(nameof(cameraPos), cameraPos);
            shader.Uniform(nameof(camera), camera);
            model.Draw((float)time.Elapsed.TotalSeconds, SetWorld);
            shader.Deactivate();

            if (time.ElapsedMilliseconds > 5000)
            {
                time.Restart();
            }
        }