/// <summary>
        /// Determines if the object is culled; if it isn't, it renders the object
        /// with the appropriate translation and rotation transform.
        /// </summary>
        public void Render()
        {
            //perform cull test on bounding sphere based on translation
            if (m_bCulled == false)
            {
                MdxRender.Dev.RenderState.CullMode = Cull.None;

                float dist = MdxRender.Camera.GetObjectDistance(m_Translation.X, m_Translation.Y, m_Translation.Z);

                eLOD lod;
                if (dist > 5)
                {
                    lod = eLOD.SUPER_LOW;
                }
                else if (dist > 4)
                {
                    lod = eLOD.LOW;
                }
                else if (dist > 3)
                {
                    lod = eLOD.MEDIUM;
                }
                else if (dist > 2)
                {
                    lod = eLOD.HIGH;
                }
                else if (dist > 1)
                {
                    lod = eLOD.SUPER_HIGH;
                }
                else
                {
                    lod = eLOD.CAUSES_FIRES;
                }

                //Trace.WriteLine("obj dist = " + dist.ToString());

                //max lod for screens
                lod = eLOD.CAUSES_FIRES;
                MdxRender.Dev.Material = objectColor;
                //        if(m_SelectTool.m_Mode == EditMode.NotSelected)
                //          MdxRender.Dev.Material = objectColor;
                //        else

                if (bBillboardMode)
                {
                    if (true)//dist < 30)
                    {
                        if (m_SelectTool.m_Mode != EditMode.NotSelected)
                        {
                            MdxRender.Dev.Transform.World = m_Matrix;
                            m_Model.Render();
                        }

                        m_BillboardMatrix     = MdxRender.Camera.InverseView;
                        m_BillboardMatrix.M41 = m_Translation.X;
                        m_BillboardMatrix.M42 = m_Translation.Y;
                        m_BillboardMatrix.M43 = m_Translation.Z;

                        MdxRender.Dev.Transform.World = m_BillboardMatrix;
                        billboard.Render();
                    }
                }
                else if (bDecalMode)
                {
                    MdxRender.Dev.Transform.World = m_Matrix;
                    decal.Render();
                }
                else
                {
                    MdxRender.Dev.Transform.World = m_Matrix;
                    m_Model.LevelOfDetail         = lod;
                    m_Model.Render();

                    if (m_SelectTool.m_Mode != EditMode.NotSelected)
                    {
                        if (m_Model.m_BoundingBox != null)
                        {
                            if (this.m_SelectTool.m_Mode == EditMode.Selected)
                            {
                                m_Model.m_BoundingBox.RenderBoundingBox();
                            }
                        }
                    }
                }

                m_SelectTool.Render(m_Matrix, m_bEditActive);
            }
        }
        public void DrawScene()
        {
            if (m_ready)
            {
                m_FPS.BeginFrame();

                if (MdxRender.DeviceInfo.bDeviceLost)
                {
                    AttemptRecovery();
                }
                else
                {
                    try
                    {
                        MdxRender.Dev.Clear(ClearFlags.ZBuffer | ClearFlags.Target, ClearColor, 1.0f, 0);
                        MdxRender.Dev.Transform.View  = Camera.GetViewMatrix();
                        MdxRender.Dev.Transform.World = Matrix.Identity;

                        //todo: preview vs bsp mode
                        if (PreviewManager.Mode != PreviewMode.ProjectMode)
                        {
                            MdxRender.SetZbufRange(0.01f, 300.0f);
                            UpdateViewTransform();
                        }
                        else
                        {
                            SetZbufRange(30.0f, 100000.0f);
                            UpdateViewTransform();
                        }

                        MdxRender.Dev.BeginScene();

                        if (!m_isPaused)
                        {
                            MdxRender.Dev.Material = whiteMaterial;
                            //The beef of the matter
                            if (PreviewManager.Mode != PreviewMode.ProjectMode)
                            {
                                PreviewManager.RenderActivePreview();
                                //mapViewButton.DrawButton(true);
                            }
                            else
                            {
                                #region DrawProject
                                MdxRender.Dev.Material = whiteMaterial;
                                MdxRender.Dev.RenderState.DiffuseMaterialSource  = ColorSource.Material;
                                MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material;
                                MdxRender.Dev.RenderState.SpecularEnable         = false;

                                //Render the skybox if we are in map view mode
                                if (MdxRender.SkyBox != null)
                                {
                                    //turn lighting off for skybox
                                    //MdxRender.Dev.RenderState.Lighting = false;

                                    //turn off fog or you won't be able to see the skybox through it
                                    if (MdxRender.FogEnabled)
                                    {
                                        MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false);
                                    }

                                    //disable z-writing for the skybox since it is behind everything
                                    //and to get rid of that stupid clipping artifact
                                    MdxRender.Dev.RenderState.ZBufferWriteEnable = false;
                                    SkyBox.Render();
                                    MdxRender.Dev.RenderState.ZBufferWriteEnable = true;

                                    //turn fog back on
                                    if (MdxRender.FogEnabled)
                                    {
                                        MdxRender.Dev.SetRenderState(RenderStates.FogEnable, true);
                                    }
                                }
                                else
                                {
                                    //turn off fog when we are in model preview mode
                                    MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false);
                                }

                                //draw the map BSP
                                if (Halo1_Bsp != null)
                                {
                                    MdxRender.Dev.RenderState.Lighting = true;
                                    Halo1_Bsp.DrawBsp();
                                    TagBsp.Debug_RenderNearestNeighborVerts();
                                    MdxRender.lightmapDebugger.Render();
                                    //Halo1_Bsp.DrawWireframeBsp();
                                    //MdxRender.Dev.RenderState.FillMode = FillMode.Solid;
                                }

                                //turn on lighting for scenery
                                MdxRender.Dev.RenderState.Lighting = true;
                                MdxRender.SM.DisableBlend(); //this necessary?

                                //draw all ye map objects
                                //MdxRender.Dev.RenderState.DiffuseMaterialSource = ColorSource.Material;
                                //MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material;
                                //MdxRender.Dev.RenderState.SpecularEnable = true;
                                ProjectManager.MapSpawns.Render();
                                #endregion


                                if (m_showFPS)
                                {
                                    DrawFPS();
                                }
                            }
                        }
                        else
                        {
                            m_fontFPS.DrawText(null, "Rendering Paused", 3, 3, Color.White);
                            Thread.Sleep(250);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("Error during DrawScene(): " + e.Message);
                    }
                    finally
                    {
                        try
                        {
                            MdxRender.Dev.EndScene();
                            MdxRender.Dev.Present();
                            //SwapChain sc = MdxRender.Dev.GetSwapChain(0);
                            //sc.Present(Present.LinearContent);
                        }
                        catch (DeviceLostException)
                        {
                            MdxRender.DeviceInfo.bDeviceLost = true;
                            Trace.WriteLine("Device was lost.");
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine("Error during Device.Present(): " + e.Message);
                        }
                    }
                }
                m_FPS.EndFrame();
            }
        }