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 MouseTracker()); GameObject box = new GameObject(OpenTK.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(OpenTK.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( Engine.Physics.BEPUutilities.Vector3.Zero, 2f, 2f, 2f); Entity box2Shape = new Box( Engine.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); }
public void SetDefaultWorldCamera(Vector3 target) { // Do a little trigonometry, we want to look at our target from a distance of 1500 units at an angle of 70deg var distance = 2000; var angle = MathHelper.DegreesToRadians(60); var location = target + new Vector3(0, -distance * (float)Math.Cos(angle), distance * (float)Math.Sin(angle)); var cameraMatrix = Matrix4.CreateRotationY(angle) * Matrix4.CreateRotationZ(MathHelper.PiOver2) * Matrix4.CreateTranslation(location); // Set camera ActiveCamera = new Camera(cameraMatrix, "worldspawn"); }
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 }
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); }