/// <summary> /// Initializes a new instance of the <see cref="nginz.Camera"/> class. /// </summary> /// <param name="fieldOfView">Field of view.</param> /// <param name="resolution">Resolution.</param> /// <param name="near">Near plane.</param> /// <param name="far">Far plane.</param> /// <param name="radians">Whether radians should be used instead of degrees.</param> /// <param name="type">The camera type.</param> public Camera(float fieldOfView, Resolution resolution, float near, float far, bool radians = false, ProjectionType type = ProjectionType.Perspective) { // Calculate the field of view FieldOfView = radians ? fieldOfView : MathHelper.DegreesToRadians (fieldOfView); // Set the resolution Resolution = resolution; // Set the near plane Near = near; // Set the far plane Far = far; // Initialize the position Position = Vector3.Zero; // Initialize the orientation Orientation = Quaternion.Identity; // Set the camera projection type ProjectionType = type; // Calculate the projection graphics ProjectionMatrix = type == ProjectionType.Orthographic ? Matrix4.CreateOrthographicOffCenter (0, Resolution.Width, Resolution.Height, 0, Near, Far) : Matrix4.CreatePerspectiveFieldOfView (FieldOfView, AspectRatio, Near, Far); }
protected override void Initialize() { GL.ClearColor (.25f, .30f, .35f, 1f); Mouse.ShouldCenterMouse = true; Mouse.CursorVisible = false; GL.CullFace (CullFaceMode.Back); GL.Enable (EnableCap.CullFace); testTexture = Content.Load<Texture2D> ("testWoodDiffuse.jpg", TextureConfiguration.Linear); var normal = Content.Load<Texture2D> ("testWoodNormal.jpg", TextureConfiguration.Linear); var res = new Resolution { Width = Configuration.Width, Height = Configuration.Height }; camera = new FPSCamera (60f, res, Mouse, Keyboard); camera.Camera.SetAbsolutePosition (new Vector3 (0, 0, 2)); camera.MouseRotation.X = MathHelper.DegreesToRadians (180); var obj = Content.LoadMultiple<Geometry> ("plane.obj"); var rand = new Random (); foreach (Geometry geom in obj) { //geom.Material = new Material (new Color4((byte) rand.Next(0, 255), (byte) rand.Next (0, 255), (byte) rand.Next (0, 255), 255), testTexture, normal, 32, 16); geom.Material = new Material (Color4.White, null, null, 32, 16); models.Add (new Model (geom)); } /*this.RenderingPipeline.AddDirectionalLight (new DirectionalLight { @base = new BaseLight { Color = new Vector3 (1f), Intensity = 1f, }, direction = new Vector3 (0, 1, -1) });*/ Func<Random, float, float, float> randPos = (rnd, min, max) => min + (float) rnd.NextDouble() * (max - min); for (int i = 0; i < 64; i++) { this.RenderingPipeline.AddPointLight (new PointLight { @base = new BaseLight { Color = new Vector3 ((float) rand.NextDouble(), (float) rand.NextDouble (), (float) rand.NextDouble ()), Intensity = .25f }, atten = new Attenuation { constant = 2f, exponent = .5f, linear = 1f, }, position = new Vector3 (randPos (rand, -5, 5), randPos(rand, .125f, .75f), randPos (rand, -5, 5)), }); } base.Initialize (); }
/// <summary> /// Initializes a new instance of the <see cref="nginz.FPSCamera"/> class. /// </summary> /// <param name="fieldOfView">Field of view.</param> /// <param name="resolution">Resolution.</param> /// <param name="mouse">Mouse.</param> /// <param name="keyboard">Keyboard.</param> public FPSCamera(float fieldOfView, Resolution resolution, MouseBuffer mouse, KeyboardBuffer keyboard) { // Create the base camera Camera = new Camera (fieldOfView, resolution, 0.01f, 256f); // Set the mouse and the keyboard Mouse = mouse; Keyboard = keyboard; // Initialize the mouse sensitivity MouseXSensitivity = .1f; MouseYSensitivity = .1f; // Initialize the actor speed Speed = 5f; }
/// <summary> /// Update the resolution. /// </summary> void UpdateResolution() { Resolution = new Resolution { Width = window.Width, Height = window.Height }; }
/// <summary> /// Update the camera matrix. /// </summary> /// <param name="resolution">Resolution.</param> public void UpdateCameraMatrix(Resolution resolution) { // Set the resolution Resolution = resolution; // Resize the projection matrix ProjectionMatrix = ProjectionType == ProjectionType.Orthographic ? Matrix4.CreateOrthographic (Resolution.Width, Resolution.Height, Near, Far) : Matrix4.CreatePerspectiveFieldOfView (FieldOfView, AspectRatio, Near, Far); }