/// <summary>
        /// 
        /// </summary>
        public sceneviewer()
        {
            Graphics = new GraphicsDeviceManager(this);
            Graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0;
            Graphics.PreferMultiSampling = false;
            Graphics.SynchronizeWithVerticalRetrace = false;

            Content = new ContentManager(Services);

            KeysPressedThisFrame = new List<Keys>();
            KeysReleasedThisFrame = new List<Keys>();
            Prims = new Dictionary<uint, PrimVisual>();
            Client = new SecondLife();

            this.IsMouseVisible = true;
            Window.AllowUserResizing = true;

            CurrentKeyboardState = Keyboard.GetState();
            CurrentMouseState = Mouse.GetState();
            KeysHeldDown = Keyboard.GetState().GetPressedKeys();

            Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged);
            this.Exiting += new EventHandler(sceneviewer_Exiting);

            Camera = new Camera(this.Window, new Vector3(-10, -10, 40), new Vector3(255, 255, 40));
        }
        public WaterSurface(GraphicsDevice device, Camera camera, Vector3 normal, float position, int sizeX, int sizeY)
        {
            Vector3 x;

            Device = device;
            Camera = camera;
            Normal = normal;
            Position = position;
            Plane = new Plane(normal, position);
            NoiseMaker = new NoiseMaker(Device, GridSizeX, GridSizeY);
            PlaneWithinFrustum = false;

            // Set the initial water color
            WaterColor = Color.Aquamarine;

            // Calculate the U and V vectors
            if (Math.Abs(Vector3.Dot(Vector3.UnitX, normal)) < Math.Abs(Vector3.Dot(Vector3.UnitY, normal)))
            {
                x = Vector3.UnitX;
            }
            else
            {
                x = Vector3.UnitY;
            }

            U = x - normal * Vector3.Dot(normal, x);
            U = Vector3.Normalize(U);

            // Get V (cross)
            V = Vector3.Cross(U, normal);

            GridSizeX = sizeX + 1;
            GridSizeY = sizeY + 1;

            SetDisplacementAmplitude(0);

            if (!InitializeBuffers())
            {
                return;
            }

            // Load the textures
            if ((Fresnel = Texture2D.FromFile(Device, "textures/fresnel_water_linear.bmp")) == null)
            {
                return;
            }
            if ((XYNoise = Texture2D.FromFile(Device, "textures/xynoise.png")) == null)
            {
                return;
            }

            // Initialize the reflection and refraction textures, and the depth stencil
            Reflection = new Texture2D(Device, REFLREFRDETAIL, REFLREFRDETAIL, 1, ResourceUsage.RenderTarget,
                SurfaceFormat.Color, ResourcePool.Default);
            Refraction = new Texture2D(Device, REFLREFRDETAIL, REFLREFRDETAIL, 1, ResourceUsage.RenderTarget,
                SurfaceFormat.Color, ResourcePool.Default);
            DepthStencil = Device.CreateDepthStencilSurface(REFLREFRDETAIL, REFLREFRDETAIL, DepthFormat.Depth24Stencil8,
                MultiSampleType.None, 0, true);

            // Load the effect
            CompiledEffect water = Effect.CompileEffectFromFile("shaders/watereffect.fx", null, null,
                CompilerOptions.Debug | CompilerOptions.SkipOptimization, TargetPlatform.Windows);
            if (!water.Success)
            {
                return;
            }
            else
            {
                WaterEffect = new Effect(Device, water.GetShaderCode(), CompilerOptions.None, null);
            }

            Initialized = true;
        }