Beispiel #1
0
        /// <summary>
        /// Renders the given <see cref="Komodo.Core.ECS.Components.Drawable3DComponent"/>.
        /// </summary>
        /// <param name="component"><see cref="Komodo.Core.ECS.Components.Drawable3DComponent"/> to render.</param>
        private void DrawComponent(Drawable3DComponent component)
        {
            var position           = component.WorldPosition;
            var rotationQuaternion = component.RotationQuaternion;
            var scale = component.Scale;

            if (ActiveCamera != null)
            {
                var bounds = component.BoundingBox;
                if (ActiveCamera.BoundingFrustum.Contains(bounds) == ContainmentType.Disjoint)
                {
                    return;
                }
            }
            var positionMatrix = Matrix.CreateTranslation(position.MonoGameVector);

            foreach (var mesh in component.ModelData.MonoGameModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.Texture        = component.Texture?.MonoGameTexture;
                    effect.TextureEnabled = effect.Texture != null;
                    effect.DiffuseColor   = component.DiffuseColor.ToVector3();

                    effect.Projection = ActiveCamera != null ? ActiveCamera.Projection : Matrix.Identity;
                    effect.View       = ActiveCamera != null ? ActiveCamera.ViewMatrix : Matrix.Identity;
                    effect.World      = (
                        Matrix.CreateScale(scale.MonoGameVector)
                        * Matrix.CreateFromQuaternion(rotationQuaternion)
                        * positionMatrix
                        );
                }

                mesh.Draw();
            }
        }
Beispiel #2
0
        public void SetLocalTransform(AnimatableProperty <XNAV3> s, AnimatableProperty <XNAQUAT> r, AnimatableProperty <XNAV3> t)
        {
            var ss = s != null && s.IsAnimated;
            var rr = r != null && r.IsAnimated;
            var tt = t != null && t.IsAnimated;

            if (!(ss || rr || tt))
            {
                _UseAnimatedTransforms = false;
                _LocalScale            = null;
                _LocalRotation         = null;
                _LocalTranslation      = null;
                return;
            }

            _UseAnimatedTransforms = true;
            _LocalScale            = s;
            _LocalRotation         = r;
            _LocalTranslation      = t;

            var m = XNAMAT.Identity;

            if (s != null)
            {
                m *= XNAMAT.CreateScale(s.Value);
            }
            if (r != null)
            {
                m *= XNAMAT.CreateFromQuaternion(r.Value);
            }
            if (t != null)
            {
                m.Translation = t.Value;
            }
            _LocalMatrix = m;
        }
 public static Matrix CreateFromQuaterion(Quaterion q)
 {
     return(new Matrix(Matrix4x4.CreateFromQuaternion(q)));
 }