/// <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(); } }
public void ApplyTransformation() { if (_dynamicPhysicsObject == null) { RotationMatrix = Matrix.CreateRotationX((float)AngleX) * Matrix.CreateRotationY((float)AngleY) * Matrix.CreateRotationZ((float)AngleZ); Matrix scaleMatrix = Matrix.CreateScale(Scale); _worldOldMatrix = scaleMatrix * RotationMatrix * Matrix.CreateTranslation(Position); WorldTransform.Scale = Scale; WorldTransform.World = _worldOldMatrix; if (StaticPhysicsObject != null) { AffineTransform change = new AffineTransform( new BEPUutilities.Vector3(Scale.X, Scale.Y, Scale.Z), Quaternion.CreateFromRotationMatrix(MathConverter.Convert(RotationMatrix)), MathConverter.Convert(Position)); if (!MathConverter.Equals(change.Matrix, StaticPhysicsObject.WorldTransform.Matrix)) { //StaticPhysicsMatrix = MathConverter.Copy(Change.Matrix); StaticPhysicsObject.WorldTransform = change; } } } else { //Has something changed? WorldTransform.Scale = Scale; _worldOldMatrix = Extensions.CopyFromBepuMatrix(_worldOldMatrix, _dynamicPhysicsObject.WorldTransform); Matrix scaleMatrix = Matrix.CreateScale(Scale); //WorldOldMatrix = Matrix.CreateScale(Scale)*WorldOldMatrix; WorldTransform.World = scaleMatrix * _worldOldMatrix; } }
public static Matrix CreateTranslation(Vector3 pos) { return(new Matrix(Matrix4x4.CreateTranslation(pos))); }