Skip to content

Commit

Permalink
Corrected Logo Sample (#85)
Browse files Browse the repository at this point in the history
Improved matrix handling in sample
  • Loading branch information
AVinitzca authored Aug 20, 2024
1 parent 32c04a5 commit 49bfa86
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions TGC.MonoGame.Samples/Samples/TGCLogoSample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TGC.MonoGame.Samples.Cameras;
Expand All @@ -11,6 +11,14 @@ namespace TGC.MonoGame.Samples.Samples
/// </summary>
public class TGCLogoSample : TGCSample
{
private Camera Camera { get; set; }

private Model Model { get; set; }

private Matrix World { get; set; }

private float Angle { get; set; }

/// <summary>
/// Default constructor.
/// </summary>
Expand All @@ -20,12 +28,7 @@ public TGCLogoSample(TGCViewer game) : base(game)
Name = GetType().Name;
Description = Description = "Time to explore the samples :)";
}

private Camera Camera { get; set; }
private Model Model { get; set; }
private Matrix ModelWorld { get; set; }
private float ModelRotation { get; set; }


/// <inheritdoc />
public override void Initialize()
{
Expand All @@ -42,15 +45,16 @@ protected override void LoadContent()
var modelEffect = (BasicEffect) Model.Meshes[0].Effects[0];
modelEffect.DiffuseColor = Color.DarkBlue.ToVector3();
modelEffect.EnableDefaultLighting();
ModelWorld = Matrix.CreateRotationY(MathHelper.Pi);
World = Matrix.Identity;

base.LoadContent();
}

/// <inheritdoc />
public override void Update(GameTime gameTime)
{
ModelRotation += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
Angle += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
World = Matrix.CreateRotationY(Angle);

Game.Gizmos.UpdateViewProjection(Camera.View, Camera.Projection);

Expand All @@ -63,9 +67,9 @@ public override void Draw(GameTime gameTime)
Game.Background = Color.Black;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

Model.Draw(ModelWorld * Matrix.CreateRotationY(ModelRotation), Camera.View, Camera.Projection);
Model.Draw(World, Camera.View, Camera.Projection);

base.Draw(gameTime);
}
}
}
}

0 comments on commit 49bfa86

Please sign in to comment.