private string cmd_Move(string[] args) { if (args.Length < 3) { return("Not Enough arguments"); } if (!int.TryParse(args[0], out int X)) { return("Could not parse X"); } if (!int.TryParse(args[1], out int Y)) { return("Could not parse Y"); } if (!int.TryParse(args[2], out int Z)) { return("Could not parse Z"); } camera.Translate(new Vector3(X, Y, Z)); return("Done"); }
protected override void InitializeScene() { int rayLayer = LayerManager.RegisterLayer("raycast", new Layer(1, 2)); int hybLayer = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2)); int physicsLayer = LayerManager.RegisterLayer("physics", new Layer(1, 1)); LayerManager.DisableCollisions(rayLayer, physicsLayer); PhysicsDemoComponent phys = new PhysicsDemoComponent(); AddComponent(phys); //Adding Physics Component to world. Add(DebugConsoleComponent.CreateConsole()); GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG"); bgObj.Scale = new Vector3(250, 1, 250); bgObj.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.Brown), 1)); Collider groundCol = new Collider(new Box(Vector3.Zero, 500, 1, 500), hybLayer); bgObj.AddComponent(groundCol); Add(bgObj); GameObject boxO = new GameObject(Vector3.UnitY * 3, "Box"); boxO.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.DarkMagenta), 1)); boxO.AddComponent(new Collider(new Box(Vector3.Zero, 1, 1, 1), physicsLayer)); boxO.Translate(new Vector3(55, 0, 35)); Add(boxO); GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG"); mouseTarget.Scale = new Vector3(1, 1, 1); mouseTarget.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Sphere, TextureLoader.ColorToTexture(Color.GreenYellow), 1)); Add(mouseTarget); BasicCamera c = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); c.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(-25)); c.Translate(new Vector3(1, 30, 45)); c.AddComponent(new CameraRaycaster(mouseTarget, boxO)); GameEngine.Instance.CurrentScene.Add(c); GameEngine.Instance.CurrentScene.SetCamera(c); }
private void LoadGameScene(BasicCamera c) { c.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(-75)); c.Translate(new Vector3(0, 75, 15)); Add(CreateGoal(FindGoalSpawn(-(map.GetLength(1) + 6)))); GameObject[] objs = PlayerController.CreatePlayer(FindPlayerSpawn(map), c); for (int i = 0; i < objs.Length; i++) { GameEngine.Instance.CurrentScene.Add(objs[i]); } //EnemyComponent.CreateEnemies(new Vector2(30, 500), map, 5,0); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG"); bgObj.Scale = new Vector3(25, 1, 25); bgObj.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.MediumPurple), 1)); Add(bgObj); BasicCamera c = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); c.Translate(new Vector3(0, 4, 0)); camLookCommandComponent = new LookAtComponent(); c.AddComponent(camLookCommandComponent); sourceCube = new GameObject(Vector3.UnitZ * -5, "Audio Source"); AudioSourceComponent source = new AudioSourceComponent(); sourceCube.AddComponent(source); sourceCube.AddComponent(new RotateAroundComponent()); sourceCube.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube, DefaultFilepaths.DefaultTexture, 1)); if (!AudioLoader.TryLoad("assets/sounds/test_mono_16.wav", out AudioFile clip)) { Console.ReadLine(); } source.Clip = clip; source.Looping = true; source.Play(); Add(sourceCube); AudioListener listener = new AudioListener(); c.AddComponent(listener); Add(c); SetCamera(c); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); BasicCamera inPicCam = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); inPicCam.Rotate(Vector3.UnitX, MathHelper.DegreesToRadians(-90f)); inPicCam.Translate(Vector3.UnitY * 25); Add(inPicCam); splitCam = new RenderTarget(inPicCam, 1, Color.FromArgb(0, 0, 0, 0)) { MergeType = RenderTargetMergeType.Additive, ViewPort = new Rectangle(0, 0, (int)(GameEngine.Instance.Width * 0.3f), (int)(GameEngine.Instance.Height * 0.3f)) }; GameEngine.Instance.AddRenderTarget(splitCam); BasicCamera bc = new BasicCamera(Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), 16 / 9f, 0.1f, 1000f), new Vector3(0, 5, 30)); //Creating a Basic Camera SetCamera(bc); Add(bc); //Creating a Box that is meant to fall down on the kinetic box GameObject box = new GameObject(OpenTK.Vector3.UnitZ * -3 + Vector3.UnitY * 2, "Box"); LitMeshRendererComponent lmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.Red), 1); box.AddComponent(lmr); Add(box); //Creating a Kinetic Box that will rotate slowly GameObject kinetic = new GameObject(OpenTK.Vector3.UnitZ * -3 + Vector3.UnitY * -2, "Box"); LitMeshRendererComponent kineticlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.Green), 1); kinetic.AddComponent(kineticlmr); kinetic.AddComponent(new RotatingComponent()); Add(kinetic); //A Large sphere that will act as a ground GameObject ground = new GameObject(OpenTK.Vector3.UnitZ * -3 + Vector3.UnitY * -1, "Box"); LitMeshRendererComponent groundlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Sphere, TextureLoader.ColorToTexture(Color.Blue), 1); ground.AddComponent(groundlmr); Add(ground); ground.Scale = new Vector3(20, 20, 20); ground.LocalPosition = Engine.Physics.BEPUutilities.Vector3.UnitY * -25; //Creating the Collider Shapes Entity boxShape = new Box( Engine.Physics.BEPUutilities.Vector3.Zero, 2f, 2f, 2f, 1f); Entity kineticShape = new Box( Engine.Physics.BEPUutilities.Vector3.Zero, 2f, 2f, 2f, 1f); Entity groundShape = new Sphere( Vector3.Zero, 20f); //Note: Not specifying the mass when creating makes the shape a static shape that is really cheap computatinally //Ground(Sphere) and the falling box is going to have 0 friction and maximum bounciness. Material groundPhysicsMaterial = new Material(0, 0, 1f); Material boxPhysicsMaterial = new Material(0, 0, 1f); //Creating A physics layer to be able to control which objects are meant to collide with each other int physicsLayerID = LayerManager.RegisterLayer("physics", new Layer(1, 1)); //Creating the Components for the Physics Engine //Note: There are different ways to get the LayerID than storing it. Collider boxCollider = new Collider(boxShape, physicsLayerID); Collider groundCollider = new Collider(groundShape, "physics"); Collider kineticCollider = new Collider(kineticShape, LayerManager.LayerToName(physicsLayerID)); //Final Collider Setup //Kinetic becomes Kinetic kineticCollider.PhysicsCollider.BecomeKinematic(); //Adding the Physics Materials boxCollider.PhysicsCollider.Material = boxPhysicsMaterial; groundCollider.PhysicsCollider.Material = groundPhysicsMaterial; //Adding the Components box.AddComponent(boxCollider); kinetic.AddComponent(kineticCollider); ground.AddComponent(groundCollider); //Making the Camera LookAt the origin bc.LookAt(Vector3.Zero); }
protected override void InitializeScene() { Mesh bgBox = MeshLoader.FileToMesh("models/cube_flat.obj"); ShaderProgram.TryCreate(new Dictionary <ShaderType, string> { { ShaderType.FragmentShader, "shader/UITextRender.fs" }, { ShaderType.VertexShader, "shader/UIRender.vs" } }, out ShaderProgram textShader); ShaderProgram.TryCreate(new Dictionary <ShaderType, string> { { ShaderType.FragmentShader, "shader/texture.fs" }, { ShaderType.VertexShader, "shader/texture.vs" } }, out ShaderProgram shader); DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>(); dbg.AddCommand("mov", cmd_ChangeCameraPos); dbg.AddCommand("rot", cmd_ChangeCameraRot); dbg.AddCommand("reload", cmd_ReLoadScene); dbg.AddCommand("next", cmd_NextScene); dbg.AddCommand("lookat", cmd_LookAtAudioSource); GameEngine.Instance.CurrentScene.Add(dbg.Owner); GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG"); bgObj.Scale = new Vector3(25, 1, 25); bgObj.AddComponent(new MeshRendererComponent(shader, bgBox, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); GameEngine.Instance.CurrentScene.Add(bgObj); BasicCamera c = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); c.Translate(new Vector3(0, 4, 0)); _camLookCommandComponent = new LookAtComponent(); c.AddComponent(_camLookCommandComponent); _sourceCube = new GameObject(Vector3.UnitZ * -5, "Audio Source"); Mesh sourceCube = MeshLoader.FileToMesh("models/cube_flat.obj"); AudioSourceComponent source = new AudioSourceComponent(); _sourceCube.AddComponent(source); _sourceCube.AddComponent(new RotateAroundComponent()); _sourceCube.AddComponent(new MeshRendererComponent(shader, sourceCube, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); if (!AudioLoader.TryLoad("sounds/test_mono_16.wav", out AudioFile clip)) { Console.ReadLine(); } source.Clip = clip; source.Looping = true; source.Play(); GameEngine.Instance.CurrentScene.Add(_sourceCube); AudioListener listener = new AudioListener(); c.AddComponent(listener); GameEngine.Instance.CurrentScene.Add(c); GameEngine.Instance.CurrentScene.SetCamera(c); }
protected override void InitializeScene() { creator = BufferCreator.CreateWithBuiltInTypes(); iset = FLInstructionSet.CreateWithBuiltInTypes(CLAPI.MainThread, "assets/kernel/"); checkPipeline = FLProgramCheckBuilder.CreateDefaultCheckBuilder(iset, creator); parser = new FLParser(iset, creator); checkPipeline.Attach(parser, true); Mesh plane = MeshLoader.FileToMesh("assets/models/plane.obj"); Texture texQuad = TextureLoader.ParameterToTexture(1024, 1024, "FLDisplayTextureQuad"); Texture texSphere = TextureLoader.ParameterToTexture(1024, 1024, "FLDisplayTextureSphere"); GameObject objSphere = new GameObject(new Vector3(1, 1, 0), "SphereDisplay"); LitMeshRendererComponent sphereLmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Sphere, texSphere, 1); objSphere.AddComponent(sphereLmr); sphereLmr.Textures = new[] { sphereLmr.Textures[0], DefaultFilepaths.DefaultTexture }; objSphere.AddComponent(new RotatingComponent()); GameObject objQuad = new GameObject(new Vector3(-1, 1, 0), "QuadDisplay"); LitMeshRendererComponent quadLmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, plane, texQuad, 1); objQuad.AddComponent(quadLmr); quadLmr.Textures = new[] { quadLmr.Textures[0], DefaultFilepaths.DefaultTexture }; objQuad.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(45)); GameObject sourceCube = new GameObject(new Vector3(0, 10, 10), "Light Source"); sourceCube.AddComponent(new LightComponent()); sourceCube.AddComponent(new RotateAroundComponent { Slow = 0.15f }); sourceCube.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.White), 1)); GameObject uiText = new GameObject(new Vector3(0), "UIText"); uiText.AddComponent(new FlGeneratorComponent(new List <LitMeshRendererComponent> { sphereLmr, quadLmr }, 512, 512, true)); Add(sourceCube); Add(uiText); Add(DebugConsoleComponent.CreateConsole()); Add(objSphere); Add(objQuad); GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG") { Scale = new Vector3(25, 1, 25) }; bgObj.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, GenerateGroundTexture(), 1)); Add(bgObj); BasicCamera mainCamera = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); object mc = mainCamera; EngineConfig.LoadConfig("assets/configs/camera_fldemo.xml", ref mc); Add(mainCamera); SetCamera(mainCamera); GameObject camContainer = new GameObject("CamContainer"); BasicCamera inPicCam = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); inPicCam.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(0)); inPicCam.Translate(new Vector3(0, 2, 4)); inPicCam.AddComponent(new RotateAroundComponent()); GameObject zeroPoint = new GameObject("Zero"); Add(zeroPoint); LookAtComponent comp = new LookAtComponent(); comp.SetTarget(zeroPoint); inPicCam.AddComponent(comp); Add(inPicCam); splitCam = new RenderTarget(inPicCam, 1, Color.FromArgb(0, 0, 0, 0)) { MergeType = RenderTargetMergeType.Additive, ViewPort = new Rectangle(0, 0, (int)(GameEngine.Instance.Width * 0.3f), (int)(GameEngine.Instance.Height * 0.3f)) }; Add(camContainer); GameEngine.Instance.AddRenderTarget(splitCam); }
protected override void InitializeScene() { Mesh sphere = MeshLoader.FileToMesh("models/sphere_smooth.obj"); Mesh plane = MeshLoader.FileToMesh("models/plane.obj"); Mesh bgBox = MeshLoader.FileToMesh("models/cube_flat.obj"); ShaderProgram.TryCreate(new Dictionary <ShaderType, string> { { ShaderType.FragmentShader, "shader/UITextRender.fs" }, { ShaderType.VertexShader, "shader/UITextRender.vs" } }, out ShaderProgram textShader); ShaderProgram.TryCreate(new Dictionary <ShaderType, string> { { ShaderType.FragmentShader, "shader/texture.fs" }, { ShaderType.VertexShader, "shader/texture.vs" } }, out ShaderProgram shader); GameObject objSphere = new GameObject(new Vector3(1, 1, 0), "SphereDisplay"); objSphere.AddComponent(new MeshRendererComponent(shader, sphere, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); objSphere.AddComponent(new RotatingComponent()); GameObject objQuad = new GameObject(new Vector3(-1, 1, 0), "QuadDisplay"); objQuad.AddComponent(new MeshRendererComponent(shader, plane, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); objQuad.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(90)); GameObject uiText = new GameObject(new Vector3(0), "UIText"); uiText.AddComponent(new FLGeneratorComponent(new List <MeshRendererComponent> { objSphere.GetComponent <MeshRendererComponent>(), objQuad.GetComponent <MeshRendererComponent>() }, 512, 512)); GameEngine.Instance.CurrentScene.Add(uiText); DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>(); dbg.AddCommand("mov", cmd_ChangeCameraPos); dbg.AddCommand("rot", cmd_ChangeCameraRot); dbg.AddCommand("reload", cmd_ReLoadScene); dbg.AddCommand("next", cmd_NextScene); GameEngine.Instance.CurrentScene.Add(dbg.Owner); GameEngine.Instance.CurrentScene.Add(objSphere); GameEngine.Instance.CurrentScene.Add(objQuad); GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG"); bgObj.Scale = new Vector3(25, 1, 25); Texture bgTex = TextureLoader.FileToTexture("textures/ground4k.png"); //BufferOperations.GetRegion<byte>(buf, new int3(), ) bgObj.AddComponent(new MeshRendererComponent(shader, bgBox, bgTex, 1)); GameEngine.Instance.CurrentScene.Add(bgObj); BasicCamera mainCamera = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); object mc = mainCamera; EngineConfig.LoadConfig("configs/camera_fldemo.xml", ref mc); GameEngine.Instance.CurrentScene.Add(mainCamera); GameEngine.Instance.CurrentScene.SetCamera(mainCamera); GameObject camContainer = new GameObject("CamContainer"); BasicCamera inPicCam = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); inPicCam.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(0)); inPicCam.Translate(new Vector3(0, 2, 4)); inPicCam.AddComponent(new RotateAroundComponent()); GameObject zeroPoint = new GameObject("Zero"); GameEngine.Instance.CurrentScene.Add(zeroPoint); LookAtComponent comp = new LookAtComponent(); comp.SetTarget(zeroPoint); inPicCam.AddComponent(comp); GameEngine.Instance.CurrentScene.Add(inPicCam); splitCam = new RenderTarget(inPicCam, 1, new Color(0, 0, 0, 0)) { MergeType = RenderTargetMergeType.Additive, ViewPort = new Rectangle(0, 0, (int)(GameEngine.Instance.Width * 0.3f), (int)(GameEngine.Instance.Height * 0.3f)) }; GameEngine.Instance.CurrentScene.Add(camContainer); GameEngine.Instance.AddRenderTarget(splitCam); }
protected override void InitializeScene() { Texture test = TextureLoader.FileToTexture("textures/ground4k.png"); int rayLayer = LayerManager.RegisterLayer("raycast", new Layer(1, 2)); int hybLayer = LayerManager.RegisterLayer("hybrid", new Layer(1, 1 | 2)); int physicsLayer = LayerManager.RegisterLayer("physics", new Layer(1, 1)); LayerManager.DisableCollisions(rayLayer, physicsLayer); Mesh bgBox = MeshLoader.FileToMesh("models/cube_flat.obj"); Mesh box = MeshLoader.FileToMesh("models/cube_flat.obj"); Mesh sphere = MeshLoader.FileToMesh("models/sphere_smooth.obj"); ShaderProgram.TryCreate(new Dictionary <ShaderType, string> { { ShaderType.FragmentShader, "shader/UITextRender.fs" }, { ShaderType.VertexShader, "shader/UIRender.vs" } }, out ShaderProgram textShader); ShaderProgram.TryCreate(new Dictionary <ShaderType, string> { { ShaderType.FragmentShader, "shader/texture.fs" }, { ShaderType.VertexShader, "shader/texture.vs" } }, out ShaderProgram shader); PhysicsDemoComponent phys = new PhysicsDemoComponent(); GameEngine.Instance.CurrentScene.AddComponent(phys); //Adding Physics Component to world. DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>(); dbg.AddCommand("mov", cmd_ChangeCameraPos); dbg.AddCommand("rot", cmd_ChangeCameraRot); dbg.AddCommand("reload", cmd_ReLoadScene); dbg.AddCommand("next", cmd_NextScene); GameEngine.Instance.CurrentScene.Add(dbg.Owner); GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG"); bgObj.Scale = new Vector3(250, 1, 250); bgObj.AddComponent(new MeshRendererComponent(shader, bgBox, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); Collider groundCol = new Collider(new Box(Vector3.Zero, 500, 1, 500), hybLayer); bgObj.AddComponent(groundCol); GameEngine.Instance.CurrentScene.Add(bgObj); GameObject boxO = new GameObject(Vector3.UnitY * 3, "Box"); boxO.AddComponent(new MeshRendererComponent(shader, bgBox, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); boxO.AddComponent(new Collider(new Box(Vector3.Zero, 1, 1, 1), physicsLayer)); boxO.Translate(new Vector3(55, 0, 35)); GameEngine.Instance.CurrentScene.Add(boxO); GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG"); mouseTarget.Scale = new Vector3(1, 1, 1); mouseTarget.AddComponent(new MeshRendererComponent(shader, sphere, TextureLoader.FileToTexture("textures/ground4k.png"), 1)); GameEngine.Instance.CurrentScene.Add(mouseTarget); BasicCamera c = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f), GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero); c.Rotate(new Vector3(1, 0, 0), MathHelper.DegreesToRadians(-25)); c.Translate(new Vector3(1, 30, 45)); c.AddComponent(new CameraRaycaster(mouseTarget, 3, boxO)); GameEngine.Instance.CurrentScene.Add(c); GameEngine.Instance.CurrentScene.SetCamera(c); }