Example #1
0
        //protected CubeMapFace GetFace(int index)
        //{
        //    switch (index)
        //    {
        //        case 0: return CubeMapFace.PositiveX;
        //        case 1: return CubeMapFace.NegativeX;
        //        case 2: return CubeMapFace.PositiveY;
        //        case 3: return CubeMapFace.NegativeY;
        //        case 4: return CubeMapFace.PositiveZ;
        //        case 5: return CubeMapFace.NegativeZ;
        //    }

        //    throw new IndexOutOfRangeException();
        //}

        public void CommitChanges()
        {
            if (Zn != cameras[0].ZNear || Zf != cameras[0].ZFar)
            {
                for (int i = 0; i < cameras.Length; i++)
                {
                    cameras[i].ZNear = Zn;
                    cameras[i].ZFar  = Zf;
                    cameras[i].CommitChanges();
                }
            }
            if (RenderTarget.TargetFormat != format || RenderTarget.EdgeSize != size)
            {
                if (RenderTarget != null)
                {
                    RenderTarget.Dispose();
                }
                RenderTarget = new RenderTextureCube(size, format, Format.D16_UNORM);
                _rendered    = false;
            }
        }
Example #2
0
        public virtual void Initialize()
        {
            _rendered = false;
            Vector3 position = Vector3.Zero;

            cameras[0] = Camera.FromLookAt(null, Vector3.Zero, Vector3.UnitX, Vector3.UnitY, Zn, Zf);  //PositiveX
            cameras[1] = Camera.FromLookAt(null, Vector3.Zero, -Vector3.UnitX, Vector3.UnitY, Zn, Zf); //NegativeX

            cameras[2] = Camera.FromLookAt(null, position, Vector3.UnitY, -1 * Vector3.UnitZ, Zn, Zf); //PositiveY
            cameras[3] = Camera.FromLookAt(null, position, -Vector3.UnitY, Vector3.UnitZ, Zn, Zf);     //NegativeY

            cameras[4] = Camera.FromLookAt(null, position, Vector3.UnitZ, Vector3.UnitY, Zn, Zf);      //PositiveZ
            cameras[5] = Camera.FromLookAt(null, position, -Vector3.UnitZ, Vector3.UnitY, Zn, Zf);     //NegativeZ

            for (int i = 0; i < 6; i++)
            {
                cameras[i].AspectRatio = 1;
                cameras[i].FieldOfView = Numerics.PIover2;
                cameras[i].CommitChanges();
            }

            if (format == Format.UNKNOWN)
            {
                throw new InvalidOperationException("Invalid format");
            }
            if (size <= 0)
            {
                throw new InvalidOperationException("size less than 0");
            }

            if (RenderTarget != null)
            {
                RenderTarget.Dispose();
            }
            RenderTarget = new RenderTextureCube(size, format, GraphicDeviceFactory.Device.BackDepthBuffer.SurfaceFormat);
            _rendered    = false;
            _vp          = new ViewPort(0, 0, size, size);
        }