protected override void Awake() { Collider = Owner.GetComponent <Collider>(); if (Collider == null) { Logger.Log(DebugChannel.Warning, "No Rigid body attached", 10); } GameObject dbg = Owner.Scene.GetChildWithName("Console"); if (dbg != null) { DebugConsoleComponent console = dbg.GetComponent <DebugConsoleComponent>(); if (console != null) { console.AddCommand("preset", cmdResetPlayer); console.AddCommand("pcdamp", cmdChangeDamp); console.AddCommand("pcmove", cmdChangeForce); console.AddCommand("pcforce", cmdBulletForce); console.AddCommand("pcbrate", cmdBulletPerSecond); console.AddCommand("pcbmass", cmdBulletMass); console.AddCommand("pcbphys", cmdToggleBulletPhysics); } } lastEnemySpawn = (int)Owner.LocalPosition.Z; }
protected override void Awake() { enemiesAlive++; target = Owner.Scene.GetChildWithName("Player"); if (target == null) { throw new GameException("Target is Null"); } Collider = Owner.GetComponent <Collider>(); if (Collider == null) { Logger.Log(DebugChannel.Warning, "No Rigid body attached", 10); } GameObject dbg = Owner.Scene.GetChildWithName("Console"); if (dbg != null) { DebugConsoleComponent console = dbg.GetComponent <DebugConsoleComponent>(); if (console != null) { console.AddCommand("ereset", cmdResetPlayer); console.AddCommand("ecdamp", cmdChangeDamp); console.AddCommand("ecmove", cmdChangeForce); console.AddCommand("ecforce", cmdBulletForce); console.AddCommand("ecbrate", cmdBulletPerSecond); console.AddCommand("eactive", cmdActivate); console.AddCommand("pcbmass", cmdBulletMass); console.AddCommand("pcbphys", cmdToggleBulletPhysics); } } }
private void LoadTestScene(BasicCamera c) { camera = c; GameEngine.Instance.CurrentScene.Add(camera); GameEngine.Instance.CurrentScene.SetCamera(camera); DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>(); dbg.AddCommand("reload", cmd_ReLoadScene); dbg.AddCommand("mov", cmd_Move); dbg.AddCommand("rot", cmd_Rotate); GameEngine.Instance.CurrentScene.Add(dbg.Owner); WFCMapGenerator preview = WFCMapGenerator .CreateWFCPreview(Vector3.Zero, "assets/WFCTiles", false, (input) => CreateMap(input, DefaultFilepaths.DefaultLitShader)) .GetComponent <WFCMapGenerator>(); preview.Height = 256; preview.Width = 32; int tries = 1; Add(preview.Owner); preview.Generate(1); while (!preview.Success) { Logger.Log(DebugChannel.Log | DebugChannel.Game, "Generating map Try " + tries, 8); preview.Generate(1); tries++; } }
/// <summary> /// Overridden Awake method for setting up the Interpreter and add the commands to the console /// </summary> protected override void Awake() { Tex = TextureLoader.ParameterToTexture(width, height, "FLGeneratorMainTexture"); SpecularTex = TextureLoader.ParameterToTexture(width, height, "FLGeneratorSpecularTexture"); SpecularTex.TexType = TextureType.Specular; for (int i = 0; i < previews.Count; i++) { previews[i].Textures[0] = Tex; previews[i].Textures[1] = SpecularTex; } if (multiThread) { flRunner = new FlMultiThreadScriptRunner(null, DataVectorTypes.Uchar1, "assets/kernel/"); } else { flRunner = new FLScriptRunner(CLAPI.MainThread, DataVectorTypes.Uchar1, "assets/kernel/"); } DebugConsoleComponent console = Owner.Scene.GetChildWithName("Console").GetComponent <DebugConsoleComponent>(); console?.AddCommand("runfl", cmd_RunFL); console?.AddCommand("r", cmd_FLReset); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.Zero); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box"); //Creating a new Empty GameObject LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component DefaultFilepaths.DefaultLitShader, //The OpenGL Shader used(Unlit and Lit shaders are provided) Prefabs.Cube, //The Mesh that is going to be used by the MeshRenderer TextureLoader.ColorToTexture(Color.Red), //Diffuse Texture to put on the mesh 1); //Render Mask (UI = 1 << 30) box.AddComponent(lmr); //Attaching the Renderer to the GameObject box.AddComponent(new RotateSelfComponent()); //Adding a component that rotates the Object on the Y-Axis Add(box); //Adding the Object to the Scene. }
protected override void InitializeScene() { TextureGenerator.Initialize(true); 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_menu.xml", ref mc); Add(mainCamera); SetCamera(mainCamera); menubg = GenerateMenuBackground(); UiImageRendererComponent bg = new UiImageRendererComponent(menubg.Copy(), false, 1, DefaultFilepaths.DefaultUiImageShader); GameObject bgobj = new GameObject("BG"); bgobj.AddComponent(new BackgroundMover()); bgobj.AddComponent(bg); Add(bgobj); //Positions are wrong(0.5 => 5) out of the screen because the correct positions are defined in CreateButtonAnimation. CreateButton("assets/textures/btn/btn", "Start Game", new Vector2(-5f, 0.5f), new Vector2(0.2f, 0.1f), CreateButtonAnimation(new Vector2(-0.5f, 0.5f), 0), btnStartGame); CreateButton("assets/textures/btn/btn", "Credits", new Vector2(-5f, 0.25f), new Vector2(0.2f, 0.1f), CreateButtonAnimation(new Vector2(-0.5f, 0.25f), 0.2f)); CreateButton("assets/textures/btn/btn", "Exit", new Vector2(-5f, 0.0f), new Vector2(0.2f, 0.1f), CreateButtonAnimation(new Vector2(-0.5f, 0.0f), 0.4f), btnExit); DebugConsoleComponent c = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>(); Add(c.Owner); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.Zero); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. int texWidth = 128; //Width of the input texture int texHeight = 128; //Height of the input texture MemoryBuffer buffer = //Creating the Input Buffer Clapi.CreateEmpty <byte>( Clapi.MainThread, //We use the Main thread instance texWidth * texHeight * 4, //The image size in bytes MemoryFlag.ReadWrite); //We want to read and write to the texture Interpreter i = new Interpreter( //Creating an interpreter instance Clapi.MainThread, //We use the main thread "assets/filter/red.fl", //The file to execute DataTypes.Uchar1, //The Data type of our input buffer buffer, //The buffer texWidth, //Width texHeight, //Height 1, //Depth, for images always 1 4, //Channel count(BGRA) "assets/kernel/", //Directory for all kernels true); //the "brk" statement is ignored. do { i.Step(); //Step through the Instructions one by one until the script terminated. } while (!i.Terminated); //Create a texture from the output. Texture tex = TextureLoader.BytesToTexture(i.GetResult <byte>(), texWidth, texHeight); GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box"); //Creating a new Empty GameObject LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component DefaultFilepaths.DefaultLitShader, //The OpenGL Shader used(Unlit and Lit shaders are provided) Prefabs.Cube, //The Mesh that is going to be used by the MeshRenderer tex, //Diffuse Texture to put on the mesh 1); //Render Mask (UI = 1 << 30) box.AddComponent(lmr); //Attaching the Renderer to the GameObject box.AddComponent(new RotatingComponent()); //Adding a component that rotates the Object on the Y-Axis Add(box); //Adding the Object to the Scene. }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); BasicCamera bc = new BasicCamera( Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), 16 / 9f, 0.1f, 1000f), new Vector3(0, 5, 7)); //Creating a Basic Camera SetCamera(bc); Add(bc); bc.AddComponent(new MouseTrackerComponent()); GameObject box = new GameObject(Vector3.UnitX * 3, "Box"); LitMeshRendererComponent boxlmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.Red), 1); box.AddComponent(boxlmr); Add(box); GameObject box2 = new GameObject(Vector3.UnitX * -3, "Box"); LitMeshRendererComponent box2lmr = new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, TextureLoader.ColorToTexture(Color.Red), 1); box2.AddComponent(box2lmr); Add(box2); //Creating the Collider Shapes Entity boxShape = new Box( Physics.BEPUutilities.Vector3.Zero, 2f, 2f, 2f); Entity box2Shape = new Box( Physics.BEPUutilities.Vector3.Zero, 2f, 2f, 2f); //Creating A physics layer to be able to control which objects are meant to collide with each other int raycastLayerID = LayerManager.RegisterLayer("raycast", 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, raycastLayerID); Collider box2Collider = new Collider(box2Shape, LayerManager.LayerToName(raycastLayerID)); //Adding the Components box.AddComponent(boxCollider); box2.AddComponent(box2Collider); //Making the Camera LookAt the origin bc.LookAt(Vector3.Zero); }
protected override void Awake() { base.Awake(); DebugConsoleComponent comp = Owner.Scene.GetChildWithName("Console") .GetComponent <DebugConsoleComponent>(); comp?.AddCommand("rain", cmd_SpawnColliders); comp?.AddCommand("gravity", cmd_SetGravity); comp?.AddCommand("reset", cmd_ResetCollider); }
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); }
protected override void Awake() { //Physics.AddBoxStatic(System.Numerics.Vector3.UnitY * -4, new System.Numerics.Vector3(50, 10, 50), 1, 3); base.Awake(); DebugConsoleComponent comp = Owner.Scene.GetChildWithName("Console") .GetComponent <DebugConsoleComponent>(); comp?.AddCommand("rain", cmd_SpawnColliders); comp?.AddCommand("gravity", cmd_SetGravity); comp?.AddCommand("reset", cmd_ResetCollider); }
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); Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.Zero); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box"); //Creating a new Empty GameObject LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component DefaultFilepaths.DefaultLitShader, //The OpenGL Shader used(Unlit and Lit shaders are provided) Prefabs.Cube, //The Mesh that is going to be used by the MeshRenderer tex, //Diffuse Texture to put on the mesh 1); //Render Mask (UI = 1 << 30) box.AddComponent(lmr); //Attaching the Renderer to the GameObject box.AddComponent(new RotateSelfComponent()); //Adding a component that rotates the Object on the Y-Axis Add(box); //Adding the Object to the Scene. FLBuffer buffer = new FLBuffer(TextureLoader.TextureToMemoryBuffer(CLAPI.MainThread, tex, "BufferForFLProgram"), 128, 128); FLProgram program = parser.Process(new FLParserInput("assets/filter/red.fl")).Initialize(iset); program.Run(CLAPI.MainThread, buffer, true); FLBuffer result = program.GetActiveBuffer(false); byte[] dat = CLAPI.ReadBuffer <byte>(CLAPI.MainThread, result.Buffer, (int)result.Buffer.Size); //Create a texture from the output. TextureLoader.Update(tex, dat, 128, 128); result.Dispose(); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.UnitY * 7); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. }
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()); LayerManager.RegisterLayer("raycast", new Layer(1, 1)); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.UnitY * 15); bc.Rotate(Vector3.UnitX, MathHelper.DegreesToRadians(-90)); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. bc.AddComponent(new AStarTest()); //Adding the AStar Test Component to the Camera }
/// <summary> /// Overridden Awake method for setting up the Interpreter and add the commands to the console /// </summary> protected override void Awake() { Tex = TextureLoader.ParameterToTexture(width, height); for (int i = 0; i < _previews.Count; i++) { _previews[i].Texture = Tex; } DebugConsoleComponent console = Owner.Scene.GetChildWithName("Console").GetComponent <DebugConsoleComponent>(); console?.AddCommand("runfl", cmd_RunFL); console?.AddCommand("dbgfl", cmd_RunFLStepped); console?.AddCommand("step", cmd_FLStep); console?.AddCommand("r", cmd_FLReset); console?.AddCommand("dbgstop", cmd_FLStop); _db = new KernelDatabase("kernel/", OpenCL.TypeEnums.DataTypes.UCHAR1); }
protected override void Awake() { DebugConsoleComponent console = Owner.Scene.GetChildWithName("Console").GetComponent <DebugConsoleComponent>(); console.AddCommand("n", cmd_N); console.AddCommand("ground", cmd_Ground); console.AddCommand("height", cmd_Height); console.AddCommand("limit", cmd_Limit); console.AddCommand("seed", cmd_Seed); console.AddCommand("useseed", cmd_UseSeed); console.AddCommand("width", cmd_Width); console.AddCommand("symmetry", cmd_Symmetry); console.AddCommand("pin", cmd_PeriodicInput); console.AddCommand("pout", cmd_PeriodicOutput); console.AddCommand("run", cmd_Run); console.AddCommand("reload", cmd_Reload); console.AddCommand("list", cmd_List); renderer = Owner.GetComponent <MeshRendererComponent>(); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.UnitY * 7); bc.Rotate(Vector3.UnitX, MathHelper.DegreesToRadians(-90)); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. bc.AddComponent(new AudioListener()); GameObject boxContainer = new GameObject("Container"); //Empty Container at origin GameObject box = new GameObject(-Vector3.UnitZ * 6, "Box"); //Creating a new Empty GameObject LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component DefaultFilepaths.DefaultLitShader, //The OpenGL Shader used(Unlit and Lit shaders are provided) Prefabs.Cube, //The Mesh that is going to be used by the MeshRenderer TextureLoader.ColorToTexture(Color.Red), //Diffuse Texture to put on the mesh 1); //Render Mask (UI = 1 << 30) box.AddComponent(lmr); //Attaching the Renderer to the GameObject AudioSourceComponent asc = new AudioSourceComponent(); AudioLoader.TryLoad("assets/sound.wav", out AudioFile file); asc.Clip = file; asc.Looping = true; asc.Play(); asc.UpdatePosition = true; //Enable 3D Tracking the Gameobjects movements and apply it to the audio source asc.Gain = 0.6f; box.AddComponent(asc); boxContainer.AddComponent(new RotatingComponent()); boxContainer.Add(box); //Adding the Object to the Scene. Add(boxContainer); }
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); }
protected override void InitializeScene() { Add(DebugConsoleComponent.CreateConsole()); 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(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(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 RotateKineticBodyComponent()); Add(kinetic); //A Large sphere that will act as a ground GameObject ground = new GameObject(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 = Physics.BEPUutilities.Vector3.UnitY * -25; //Creating the Collider Shapes Entity boxShape = new Box( Physics.BEPUutilities.Vector3.Zero, 2f, 2f, 2f, 1f); Entity kineticShape = new Box( 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() { Add(DebugConsoleComponent.CreateConsole()); Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView( MathHelper.DegreesToRadians(75f), //Field of View Vertical 16f / 9f, //Aspect Ratio 0.1f, //Near Plane 1000f); //Far Plane BasicCamera bc = new BasicCamera(proj, Vector3.Zero); Add(bc); //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events SetCamera(bc); //Sets the Camera as the "active" camera that the scene will be rendered from. //Image size in bytes(Width * Height * ChannelCount) int imageSize = 512 * 512 * 4; //Creating a Kernel Database that will load all the Kernels contained in the asset directory KernelDatabase db = new KernelDatabase(Clapi.MainThread, "assets/test_kernel/", DataTypes.Uchar1); //We try to get the kernel_red from the file assets/test_kernel/red.cl db.TryGetClKernel("kernel_red", out CLKernel redKernel); //Creating a MemoryBuffer with size of the image. //We are using the CLAPI instance of the main thread and specify that we`d like to read/write from the buffer MemoryBuffer imageBuffer = Clapi.CreateEmpty <byte>(Clapi.MainThread, imageSize, MemoryFlag.ReadWrite); //With plain OpenCL you would need to Set the Arguments/Buffers by their argument index/types/size/yada yads, //thanks to the CL abstraction for the engine, we can just specify the argument name how we do in OpenGL Shaders(But Faster). redKernel.SetBuffer("imageData", imageBuffer); //Set Arg has the capabilities to automatically cast the value that is passed to the right type, //however this is not really fast and can be avoided by specifying the correct type directly. redKernel.SetArg("strength", 0.5f); //We directly pass a float, no casting required //When We pass something as byte(uchar in cl), we need to cast it. //If we dont the Engine OpenCL Wrapper will automatically convert the integer into a byte, but it will apply rescaling // This takes over automatic type conversion from float(opengl) to byte(System.Bitmap/opencl) // Calculation when not passed: (4 / Int32.MaxSize) * byte.MaxValue. redKernel.SetArg("channelCount", (byte)4); //This Line runs the kernel. Clapi.Run(Clapi.MainThread, redKernel, imageSize); //After the kernel ran, we can read the buffer we have passed to the kernel and Convert it into a OpenGL Texture. Texture tex = TextureLoader.BytesToTexture(Clapi.ReadBuffer <byte>(Clapi.MainThread, imageBuffer, imageSize), 512, 512); GameObject box = new GameObject(-Vector3.UnitZ * 4, "Box"); //Creating a new Empty GameObject LitMeshRendererComponent lmr = new LitMeshRendererComponent( //Creating a Renderer Component DefaultFilepaths.DefaultLitShader, //The OpenGL Shader used(Unlit and Lit shaders are provided) Prefabs.Cube, //The Mesh that is going to be used by the MeshRenderer tex, //Diffuse Texture to put on the mesh 1); //Render Mask (UI = 1 << 30) box.AddComponent(lmr); //Attaching the Renderer to the GameObject box.AddComponent(new RotatingComponent()); //Adding a component that rotates the Object on the Y-Axis Add(box); //Adding the Object to the Scene. }
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); 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_astardemo.xml", ref mc); GameObject sourceCube = new GameObject(new Vector3(0, 0, 0), "Light Source"); GameObject hackCube = new GameObject(new Vector3(0, 8, -50), "Workaround"); Add(sourceCube); Add(hackCube); sourceCube.AddComponent(new LightComponent()); mainCamera.AddComponent(new CameraRaycaster(sourceCube, hackCube)); GameObject bgObj = new GameObject(new Vector3(0, -3, -32), "BG") { Scale = new Vector3(32, 1, 32) }; Collider groundCol = new Collider(new Box(Vector3.Zero, 64, 1, 64), hybLayer); Texture bgTex = TextureLoader.ColorToTexture(Color.Yellow); bgTex.TexType = TextureType.Diffuse; bgObj.AddComponent(groundCol); tex = TextureLoader.ColorToTexture(Color.Green); beginTex = TextureLoader.ColorToTexture(Color.Blue); endTex = TextureLoader.ColorToTexture(Color.Red); blockTex = TextureLoader.ColorToTexture(Color.DarkMagenta); tex.TexType = beginTex.TexType = endTex.TexType = blockTex.TexType = TextureType.Diffuse; DebugConsoleComponent c = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>(); c.AddCommand("repath", ResetPaths); c.AddCommand("rp", ResetPaths); Add(c.Owner); bgObj.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Cube, bgTex, 1)); Add(bgObj); Add(mainCamera); SetCamera(mainCamera); Random rnd = new Random(); nodes = GenerateNodeGraph(64, 64); for (int i = 0; i < nodes.GetLength(0); i++) { for (int j = 0; j < nodes.GetLength(1); j++) { if (rnd.Next(0, 6) == 0) { nodes[i, j].Walkable = false; nodes[i, j].Owner .AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, Prefabs.Sphere, blockTex, 1)); } nodes[i, j].Owner.Scale *= 0.3f; Add(nodes[i, j].Owner); } } }
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); }