예제 #1
0
        public FreeCamera(float aspectRatio, float fov)
        {
            float fovdegree = 90;
            Cam = new Camera(new Vector3(0, 5, 0), new Vector3(0, 0, 1), Vector3.UnitY, aspectRatio, MathHelper.DegreesToRadians(fovdegree), 0.1f, 10000.0f);
            Camera.MainDisplayCamera = Cam;

            Game.OnBeforeDraw += UpdateSterring;
            Game.OnMouseMove += OnMouseMove;

            Game.OnKeyUp += (o, e) =>
            {
                if(e.Key == OpenTK.Input.Key.M)
                {
                    fovdegree += 5f;
                    if(fovdegree >= 179)
                        fovdegree = 179;
                    Matrix4 a = Matrix4.Zero;
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(fovdegree), aspectRatio, 0.1f, 10000.0f, out a);
                    Cam.SetProjectionMatrix(a);
                    Camera.Current.FocalLength = (float)(43.266f / (2.0f * Math.Tan(Math.PI * fovdegree / 360.0f))) / 1.5f;
                }
                if(e.Key == OpenTK.Input.Key.N)
                {
                    fovdegree -= 5f;
                    if(fovdegree <= 10)
                        fovdegree = 10;
                    Matrix4 a = Matrix4.Zero;
                    Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(fovdegree), aspectRatio, 0.1f, 10000.0f, out a);
                    Cam.SetProjectionMatrix(a);
                    Camera.Current.FocalLength = (float)(43.266f / (2.0f * Math.Tan(Math.PI * fovdegree / 360.0f))) / 1.5f;
                }
            };
        }
예제 #2
0
 public ProjectionLight(Vector3 position, Quaternion rotation, int mapwidth, int mapheight, float fov, float near, float far)
 {
     camera = new Camera(position, Vector3.Zero, Vector3.UnitY, mapwidth / mapheight, fov, near, far);
     camera.LookAt(Vector3.Zero);
     FBO = new Framebuffer(mapwidth, mapheight, true);
     FBO.DepthInternalFormat = PixelInternalFormat.DepthComponent32f;
     FBO.DepthPixelFormat = PixelFormat.DepthComponent;
     FBO.DepthPixelType = PixelType.Float;
 }
예제 #3
0
 public ProjectionLight(Vector3 position, Quaternion rotation, int mapwidth, int mapheight, float fov, float near, float far)
 {
     FarPlane = far;
     camera = new Camera(position, Vector3.Zero, mapwidth / mapheight, fov, near, far);
     camera.LookAt(Vector3.Zero);
     FBO = new Framebuffer(mapwidth, mapheight, true);
     //FBO.ColorInternalFormat = PixelInternalFormat.Rgba8;
     //FBO.ColorPixelFormat = PixelFormat.Rgba;
     //FBO.ColorPixelType = PixelType.UnsignedByte;
     Shader = GenericMaterial.FromName("ConeLight");
     ViewPort = new Size(mapwidth, mapheight);
 }
예제 #4
0
파일: Camera.cs 프로젝트: whztt07/vengine
 public Camera(Vector3 position, Vector3 lookAt, Vector2 size, float near, float far)
 {
     Transformation = new TransformationManager(position, Quaternion.Identity, 1.0f);
     Far = far;
     //ViewMatrix = Matrix4.LookAt(position, lookAt, new Vector3(0, 1, 0));
     Matrix4.CreateOrthographic(size.X, size.Y, near, far, out ProjectionMatrix);
     if(Current == null)
         Current = this;
     Pitch = 0.0f;
     Roll = 0.0f;
     Update();
 }
예제 #5
0
파일: Camera.cs 프로젝트: whztt07/vengine
 public Camera(Vector3 position, Vector3 lookAt, Vector3 up, float aspectRatio, float fov, float near, float far)
 {
     Transformation = new TransformationManager(position, Quaternion.Identity, 1.0f);
     Matrix4.CreatePerspectiveFieldOfView(fov, aspectRatio, near, far, out ProjectionMatrix);
     Far = far;
     if(Current == null)
         Current = this;
     if(MainDisplayCamera == null)
         MainDisplayCamera = this;
     Pitch = 0.0f;
     Roll = 0.0f;
     Transformation.SetOrientation(Matrix4.LookAt(Vector3.Zero, lookAt, up).ExtractRotation().Inverted());
     Update();
 }
예제 #6
0
파일: Camera.cs 프로젝트: yanko/vengine
 public Camera(Vector3 position, Vector3 lookAt, float aspectRatio, float fov, float near, float far)
 {
     Transformation = new TransformationManager(position, Quaternion.Identity, 1.0f);
     //ViewMatrix = Matrix4.LookAt(position, lookAt, new Vector3(0, 1, 0));
     Matrix4.CreatePerspectiveFieldOfView(fov, aspectRatio, near, far, out ProjectionMatrix);
     Far = far;
     if(Current == null)
         Current = this;
     if(MainDisplayCamera == null)
         MainDisplayCamera = this;
     Pitch = 0.0f;
     Roll = 0.0f;
     Update();
 }
예제 #7
0
파일: FreeCamera.cs 프로젝트: yanko/vengine
 public FreeCamera(float aspectRatio, float fov)
 {
     Cam = new Camera(new Vector3(20, 20, 20), new Vector3(0, 2, 0), aspectRatio, fov, 1.0f, 10000.0f);
     collisionShape = new SphereShape(0.8f);
     //collisionShape.LinearDamping = 0.5f;
     rigidBody = World.Root.CreateRigidBody(0.01f, Matrix4.CreateTranslation(Cam.Transformation.GetPosition()), collisionShape, null);
     rigidBody.SetSleepingThresholds(0, 0);
     rigidBody.ContactProcessingThreshold = 0;
     rigidBody.CcdMotionThreshold = 0;
     World.Root.PhysicalWorld.AddRigidBody(rigidBody);
     rigidBody.Gravity = Vector3.Zero;
     rigidBody.ApplyGravity();
     rigidBody.SetDamping(0.5f, 0.01f);
     GLThread.OnUpdate += UpdateSterring;
     GLThread.OnMouseMove += OnMouseMove;
 }
예제 #8
0
파일: FreeCamera.cs 프로젝트: yanko/vengine
 public FreeCamera(float aspectRatio, float fov)
 {
     Cam = new Camera(new Vector3(20, 20, 20), new Vector3(0, 2, 0), aspectRatio, fov, 0.1f, 10000.0f);
     Camera.MainDisplayCamera = Cam;
     collisionShape = new SphereShape(0.8f);
     //collisionShape.LinearDamping = 0.5f;
     rigidBody = World.Root.CreateRigidBody(0.01f, Matrix4.CreateTranslation(Cam.Transformation.GetPosition()), collisionShape, null);
     rigidBody.SetSleepingThresholds(0, 0);
     rigidBody.ContactProcessingThreshold = 0;
     rigidBody.CcdMotionThreshold = 0;
     World.Root.PhysicalWorld.AddRigidBody(rigidBody);
     rigidBody.Gravity = Vector3.Zero;
     rigidBody.ApplyGravity();
     rigidBody.SetDamping(0.5f, 0.01f);
     GLThread.OnUpdate += UpdateSterring;
     GLThread.OnMouseMove += OnMouseMove;
     GLThread.OnKeyUp += (o, e) =>
     {
         if(e.Key == OpenTK.Input.Key.P)
         {
             GravityEnabled = !GravityEnabled;
             if(GravityEnabled)
             {
                 rigidBody.Gravity = new Vector3(0, -9.81f, 0);
                 rigidBody.ApplyGravity();
                 rigidBody.SetDamping(0.8f, 0.01f);
             }
             else
             {
                 rigidBody.Gravity = Vector3.Zero;
                 rigidBody.ApplyGravity();
                 rigidBody.SetDamping(0.5f, 0.01f);
             }
         }
     };
 }
예제 #9
0
 public void UpdateCameraFocus(Camera camera)
 {
     GLThread.Invoke(() => camera.CurrentDepthFocus = (camera.CurrentDepthFocus * 4.0f + SmallFrameBuffer.GetDepth(0.5f, 0.5f)) / 5.0f);
 }
예제 #10
0
 public void UpdateCameraBrightness(Camera camera)
 {
     if(!SmallFrameBuffer.Generated)
         return;
     GLThread.Invoke(() =>
     {
         var pixels = SmallFrameBuffer.GetColorBuffer();
         GLThread.RunAsync(() =>
         {
             float average = 0.0f;
             for(int i = 0; i < pixels.Length; i += 4)
             {
                 var l = pixels[i].ToVector3().LengthFast;
                 average += l / pixels.Length;
             }
             camera.Brightness = (camera.Brightness * 7.0f + (1.5f - average * 8.0f)) / 8.0f;
             if(camera.Brightness < 0.6f)
                 camera.Brightness = 0.6f;
             if(camera.Brightness > 1.0f)
                 camera.Brightness = 1.0f;
         });
     });
 }
예제 #11
0
파일: CarCamera.cs 프로젝트: yanko/vengine
 public CarCamera(float aspectRatio, float fov)
 {
     Cam = new Camera(new Vector3(20, 20, 20), new Vector3(0, 2, 0), aspectRatio, fov, 1.0f, 10000.0f);
     GLThread.OnMouseMove += OnMouseMove;
     GLThread.OnUpdate += GLThread_OnUpdate;
 }
예제 #12
0
        public Voxel3dTextureWriter(int gridsizeX, int gridsizeY, int gridsizeZ, Vector3 boxsize, Vector3 staticPosition)
        {
            GridSizeX             = gridsizeX;
            GridSizeY             = gridsizeY;
            GridSizeZ             = gridsizeZ;
            MapPosition           = staticPosition;
            BoxSize               = boxsize;
            TextureResolverShader = new ComputeShader("Texture3DResolve.compute.glsl");
            //TextureResolverNormalShader = new ComputeShader("Texture3DResolveNormal.compute.glsl");
            TextureMipmapShader = new ComputeShader("Texture3DMipmap.compute.glsl");

            TextureRed   = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);
            TextureGreen = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);
            TextureBlue  = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);

            /*
             * TextureNormalX = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.R32i,
             *  ColorPixelFormat = PixelFormat.RedInteger,
             *  ColorPixelType = PixelType.Int
             * };
             * TextureNormalY = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.R32i,
             *  ColorPixelFormat = PixelFormat.RedInteger,
             *  ColorPixelType = PixelType.Int
             * };
             * TextureNormalZ = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.R32i,
             *  ColorPixelFormat = PixelFormat.RedInteger,
             *  ColorPixelType = PixelType.Int
             * };
             * TextureNormalResolved = new Texture3D(gridsize, gridsize, gridsize)
             * {
             *  ColorInternalFormat = PixelInternalFormat.Rgba16f,
             *  ColorPixelFormat = PixelFormat.Rgba,
             *  ColorPixelType = PixelType.HalfFloat
             * };
             */
            TextureCount = new Texture3D(gridsizeX, gridsizeY, gridsizeZ);

            /*
             * TEXTURE LAYOUT:
             * 1 - Initial - RES / 1 - 256
             * 2 - Blurred 2 PX 1 res / 2 128
             * 3 - Blurred 2 PX 2 res / 2 64
             * 4 - Blurred 2 PX 3 res / 2 32
             */

            TextureResolvedMipMaps = new List <Texture3D>();
            int szx = gridsizeX;
            int szy = gridsizeY;
            int szz = gridsizeZ;

            //while(szx > 8 && szy > 8 && szz > 8)
            for (int i = 0; i < 4; i++)
            {
                TextureResolvedMipMaps.Add(new Texture3D(szx, szy, szz)
                {
                    ColorInternalFormat = PixelInternalFormat.Rgba16f,
                    ColorPixelFormat    = PixelFormat.Rgba,
                    ColorPixelType      = PixelType.HalfFloat
                });
                szx = szx / 2;
                szy = szy / 2;
                szz = szz / 2;
            }

            FBO = new Framebuffer(512, 512, true)
            {
            };

            XForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitX, Vector3.UnitY).ExtractRotation();
            YForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitY, Vector3.UnitZ).ExtractRotation();
            ZForward = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY).ExtractRotation();

            Vector3 boxhalf = boxsize * 0.5f;


            RenderingCameraX = new Camera();
            RenderingCameraX.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Y, boxhalf.Y, boxhalf.Z, -boxhalf.Z);
            RenderingCameraX.SetOrientation(XForward);
            RenderingCameraX.SetPosition(MapPosition);
            RenderingCameraX.Update();

            RenderingCameraY = new Camera();
            RenderingCameraY.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Z, boxhalf.Z, boxhalf.Y, -boxhalf.Y);
            RenderingCameraY.SetOrientation(YForward);
            RenderingCameraY.SetPosition(MapPosition);
            RenderingCameraY.Update();

            RenderingCameraZ = new Camera();
            RenderingCameraZ.UpdatePerspectiveOrtho(-boxhalf.X, boxhalf.X, -boxhalf.Y, boxhalf.Y, boxhalf.Z, -boxhalf.Z);
            RenderingCameraZ.SetOrientation(ZForward);
            RenderingCameraZ.SetPosition(MapPosition);
            RenderingCameraZ.Update();

            Shader = new ShaderPool.ShaderPack("Voxel3dTextureWriter.fragment.glsl");
        }