2020-08-26 21:58:01 +00:00
|
|
|
using System.Collections.Immutable;
|
2020-08-05 19:21:42 +00:00
|
|
|
using System.IO;
|
|
|
|
using Encompass;
|
|
|
|
using KavTest.Components;
|
2020-08-05 20:57:15 +00:00
|
|
|
using KavTest.Engines;
|
2020-08-26 23:07:31 +00:00
|
|
|
using KavTest.Extensions;
|
2020-08-05 19:21:42 +00:00
|
|
|
using KavTest.Messages;
|
|
|
|
using KavTest.Renderers;
|
|
|
|
using KavTest.Spawners;
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2020-08-26 21:58:01 +00:00
|
|
|
using MoonTools.Curve;
|
2020-08-05 19:21:42 +00:00
|
|
|
|
|
|
|
namespace KavTest
|
|
|
|
{
|
|
|
|
class KavTestGame : Game
|
|
|
|
{
|
|
|
|
GraphicsDeviceManager graphics;
|
|
|
|
|
|
|
|
WorldBuilder WorldBuilder { get; } = new WorldBuilder();
|
|
|
|
World World { get; set; }
|
|
|
|
|
|
|
|
public KavTestGame()
|
|
|
|
{
|
|
|
|
graphics = new GraphicsDeviceManager(this);
|
|
|
|
graphics.PreferredBackBufferWidth = 1280;
|
|
|
|
graphics.PreferredBackBufferHeight = 720;
|
|
|
|
graphics.PreferMultiSampling = true;
|
|
|
|
Content.RootDirectory = "Content";
|
|
|
|
|
|
|
|
Window.AllowUserResizing = true;
|
|
|
|
IsMouseVisible = true;
|
2020-08-06 23:22:24 +00:00
|
|
|
|
|
|
|
Microsoft.Xna.Framework.Input.Mouse.IsRelativeMouseModeEXT = true;
|
2020-08-05 19:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadContent()
|
|
|
|
{
|
2020-08-06 23:54:42 +00:00
|
|
|
base.LoadContent();
|
2020-08-06 22:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UnloadContent()
|
|
|
|
{
|
|
|
|
base.UnloadContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Initialize()
|
|
|
|
{
|
|
|
|
base.Initialize();
|
|
|
|
|
2020-08-06 07:10:54 +00:00
|
|
|
var rustyBallModel = Kav.ModelLoader.Load(
|
2020-08-05 19:21:42 +00:00
|
|
|
GraphicsDevice,
|
2020-08-06 07:00:02 +00:00
|
|
|
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/rustysphere.glb"))
|
2020-08-05 19:21:42 +00:00
|
|
|
);
|
|
|
|
|
2020-08-26 21:58:01 +00:00
|
|
|
var lightBulbModel = Kav.ModelLoader.Load(
|
|
|
|
GraphicsDevice,
|
|
|
|
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/cube.glb"))
|
|
|
|
);
|
|
|
|
|
2020-09-16 19:59:31 +00:00
|
|
|
var floorModel = Kav.ModelLoader.Load(
|
|
|
|
GraphicsDevice,
|
|
|
|
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/floor.glb"))
|
|
|
|
);
|
|
|
|
|
2020-08-06 23:28:47 +00:00
|
|
|
WorldBuilder.AddEngine(new InputEngine(this));
|
2020-08-06 07:00:02 +00:00
|
|
|
WorldBuilder.AddEngine(new AngularVelocityEngine());
|
2020-08-26 21:58:01 +00:00
|
|
|
WorldBuilder.AddEngine(new MoveAlongCurve3DEngine());
|
2020-08-06 07:00:02 +00:00
|
|
|
WorldBuilder.AddEngine(new MotionEngine());
|
|
|
|
WorldBuilder.AddEngine(new CameraEngine());
|
2020-08-05 19:21:42 +00:00
|
|
|
WorldBuilder.AddEngine(new RustyBallSpawner(rustyBallModel));
|
2020-08-26 21:58:01 +00:00
|
|
|
WorldBuilder.AddEngine(new LightBulbSpawner(lightBulbModel));
|
2020-09-16 19:59:31 +00:00
|
|
|
WorldBuilder.AddEngine(new StaticModelSpawner());
|
|
|
|
WorldBuilder.AddEngine(new DirectionalLightSpawner());
|
2020-08-05 19:21:42 +00:00
|
|
|
WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0);
|
|
|
|
|
|
|
|
WorldBuilder.SendMessage(new RustyBallSpawnMessage(
|
2020-08-05 22:10:04 +00:00
|
|
|
new Transform3D(new Vector3(0, 0, 0)),
|
|
|
|
new Vector3(1, 1, -1)
|
2020-08-05 19:21:42 +00:00
|
|
|
));
|
2020-08-05 22:10:04 +00:00
|
|
|
|
|
|
|
WorldBuilder.SendMessage(new RustyBallSpawnMessage(
|
2020-08-06 07:00:02 +00:00
|
|
|
new Transform3D(new Vector3(-3, 0, 0)),
|
2020-08-05 22:10:04 +00:00
|
|
|
new Vector3(-1, 1, -1)
|
|
|
|
));
|
|
|
|
|
|
|
|
WorldBuilder.SendMessage(new RustyBallSpawnMessage(
|
2020-08-06 07:00:02 +00:00
|
|
|
new Transform3D(new Vector3(3, 0, 0)),
|
2020-08-05 22:10:04 +00:00
|
|
|
new Vector3(-1, 1, 1)
|
|
|
|
));
|
|
|
|
|
2020-09-16 19:59:31 +00:00
|
|
|
WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
|
|
|
new Transform3D(new Vector3(0, -3, 0), Quaternion.Identity, new Vector3(10f, 1f, 10f)),
|
|
|
|
floorModel
|
|
|
|
));
|
|
|
|
|
2020-08-27 00:03:02 +00:00
|
|
|
for (var i = 0; i < 1; i++)
|
2020-08-26 23:07:31 +00:00
|
|
|
{
|
|
|
|
var start = RandomHelper.RandomVector3(-5, 5);
|
|
|
|
|
|
|
|
WorldBuilder.SendMessage(new LightBulbSpawnMessage(
|
|
|
|
new Transform3D(start.ToXNAVector(), Quaternion.Identity, new Vector3(0.1f, 0.1f, 0.1f)),
|
|
|
|
RandomHelper.RandomColor(),
|
2020-08-27 00:03:02 +00:00
|
|
|
10f,
|
2020-08-26 23:07:31 +00:00
|
|
|
RandomHelper.RandomLoop(start, -15, 15, 3, 10)
|
|
|
|
));
|
|
|
|
}
|
2020-08-23 01:31:59 +00:00
|
|
|
|
2020-09-16 19:59:31 +00:00
|
|
|
WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
|
|
|
|
Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver2 + 0.1f),
|
|
|
|
Color.GhostWhite,
|
|
|
|
0.1f
|
2020-08-07 08:13:20 +00:00
|
|
|
));
|
|
|
|
|
2020-09-16 19:59:31 +00:00
|
|
|
// WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
|
|
|
|
// Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver4),
|
|
|
|
// Color.GhostWhite,
|
|
|
|
// 0.1f
|
|
|
|
// ));
|
|
|
|
|
|
|
|
// WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
|
|
|
|
// Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver2 + Microsoft.Xna.Framework.MathHelper.PiOver4),
|
|
|
|
// Color.GhostWhite,
|
|
|
|
// 0.1f
|
|
|
|
// ));
|
|
|
|
|
2020-08-05 19:21:42 +00:00
|
|
|
var cameraEntity = WorldBuilder.CreateEntity();
|
2020-08-06 21:21:34 +00:00
|
|
|
WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent(
|
|
|
|
new ArcballTransform(
|
|
|
|
new Vector3(0, 0, -10),
|
2020-08-06 23:37:24 +00:00
|
|
|
Microsoft.Xna.Framework.MathHelper.Pi,
|
2020-08-06 21:21:34 +00:00
|
|
|
0
|
|
|
|
)
|
2020-08-06 07:00:02 +00:00
|
|
|
));
|
2020-08-05 19:21:42 +00:00
|
|
|
WorldBuilder.SetComponent(cameraEntity, new CameraComponent(
|
2020-08-06 07:00:02 +00:00
|
|
|
Matrix.CreatePerspectiveFieldOfView(
|
2020-08-06 23:37:24 +00:00
|
|
|
Microsoft.Xna.Framework.MathHelper.PiOver4,
|
2020-08-06 07:00:02 +00:00
|
|
|
16f / 9f,
|
|
|
|
0.1f,
|
2020-09-16 19:59:31 +00:00
|
|
|
100f
|
2020-08-05 19:21:42 +00:00
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
World = WorldBuilder.Build();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
|
{
|
|
|
|
World.Update(gameTime.ElapsedGameTime.TotalSeconds);
|
|
|
|
|
|
|
|
base.Update(gameTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
|
|
{
|
|
|
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
|
|
|
|
|
|
|
World.Draw();
|
|
|
|
|
|
|
|
base.Draw(gameTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|