Example #1
0
        static public void GetMidPoint(Faces faces, out Vector3D ptMidPoint)
        {
            Vector3D ptMin, ptMax;

            FaceUtils.GetExtents(faces, out ptMin, out ptMax);
            ptMidPoint = (ptMin + ptMax) * 0.5f;
        }
Example #2
0
        //-----------------------------------------------------------------------------

        public int Render(RenderSettings settings)
        {
            int polygonCount = 0;

            GL.glErrorCheck();
            if ((settings.Background == true) &&
                (this.SkyBox != null))
            {
                polygonCount += this.SkyBox.Render(this, settings);
            }
            GL.glErrorCheck();

            Faces visibleFaces = BSPTreeVizOperator.GetVisibleFaces(this.Camera.Translation, this.BSPTreeRoot);

            ExoEngine.Viewer.Renderer.Render(this, visibleFaces, settings);
            polygonCount += visibleFaces.Count;
            GL.glErrorCheck();

            foreach (Entity entity in this.Entities)
            {
                polygonCount += entity.Render(this, settings);
            }
            GL.glErrorCheck();

            return(polygonCount);
        }
Example #3
0
 static public void GetExtents(Faces faces, out Vector3D ptMin, out Vector3D ptMax)
 {
     ptMin = new Vector3D(float.MaxValue, float.MaxValue, float.MaxValue);
     ptMax = new Vector3D(-float.MaxValue, -float.MaxValue, -float.MaxValue);
     foreach (Face face in faces)
     {
         foreach (Vector3D pt in face.Points)
         {
             ptMin = Vector3D.MinXYZ(ptMin, pt);
             ptMax = Vector3D.MaxXYZ(ptMax, pt);
         }
     }
 }
Example #4
0
        public override int Render(World world, RenderSettings settings)
        {
            Faces    facesVisible   = new Faces();
            Vector3D cameraLocation = world.Camera.Translation;

            foreach (Face face in this.Faces)
            {
                if (face.Plane.GetSign(cameraLocation) >= 0)
                {
                    facesVisible.Add(face);
                }
            }
            this.Renderer.Render(world, facesVisible, settings);

            return(facesVisible.Count);
        }
Example #5
0
        static public void OptimizeFaces(Faces faces)
        {
            int   removalCount   = 0;
            Faces facesOptimized = new Faces();

            facesOptimized.AddRange(faces);
            for (int i = 0; i < faces.Count; i++)
            {
                bool bNotRemoved = true;
                Face face        = faces[i];
                for (int j = 0; j < facesOptimized.Count && bNotRemoved == true; j++)
                {
                    Face facePossibleContainer = facesOptimized[j];
                    if (facePossibleContainer == face)
                    {
                        continue;
                    }
                    if (Vector3D.Dot(facePossibleContainer.GetNormal(), face.GetNormal()) < -0.9999)
                    {
                        Vector3D midPoint = face.GetMidPoint();
                        if (facePossibleContainer.IsContained(midPoint) == true &&
                            facePossibleContainer.GetPlane().GetSign(midPoint) == 0)
                        {
                            int containedPoints = 0;
                            for (int p = 0; p < face.Points.Count; p++)
                            {
                                if (facePossibleContainer.IsContained(face.Points[p]))
                                {
                                    containedPoints++;
                                }
                            }
                            if (containedPoints == face.Points.Count)
                            {
                                facesOptimized.Remove(face);
                                //Debug.Write( "." );
                                bNotRemoved = false;
                                removalCount++;
                            }
                        }
                    }
                }
            }
            faces.Clear();
            faces.AddRange(facesOptimized);
        }
Example #6
0
        //-----------------------------------------------------------------------------

        static public World  FromWorldcraftMap(WorldcraftMap wm)
        {
            // create new world
            World world = new World();

            world.Textures = wm.Textures;
            world.SkyBox   = new SkyBox("redSky");
            world.FileName = Path.Combine(ExoEngine.sWorldPath, Path.ChangeExtension(Path.GetFileName(wm.FileName), ExoEngine.sWorldExtension));
            world.Dirty    = true;


            // find the starting location
            WorldcraftObject woStartPosition = wm.Objects.FindByClassName("StartPosition");

            if (woStartPosition == null)
            {
                return(null);
            }

            Vector3D ptStartPosition;

            FaceUtils.GetMidPoint(woStartPosition.Faces, out ptStartPosition);
            world.StartPosition    = ptStartPosition;
            world.StartOrientation = woStartPosition.GetPropertyInteger("orientation", 0);

            // find the main light
            WorldcraftObject woLight = wm.Objects.FindByClassName("Light");

            if (woLight == null)
            {
                return(null);
            }

            Vector3D ptLight;

            FaceUtils.GetMidPoint(woLight.Faces, out ptLight);
            world.Light = ptLight;

            // find "Default" group... it is the static world
            WorldcraftObject woDefault = wm.Objects.FindByClassName("Default");

            if (woDefault == null)
            {
                return(null);
            }

            // setup BSP tree
            Faces faces = new Faces();

            // handle the other objects
            foreach (WorldcraftObject wo in wm.Objects)
            {
                if (wo.ClassName == "Water")
                {
                    Vector3D ptMin, ptMax;
                    FaceUtils.GetExtents(wo.Faces, out ptMin, out ptMax);
                    Water water = new Water(ptMin, ptMax, wo.GetPropertyFloat("waveHeight", 100));
                    water.Color = wo.GetPropertyColor("color", Color.Azure);
                    world.Entities.Add(water);
                }
                else if (wo.ClassName == "Duck")
                {
                    Vector3D ptMin, ptMax;
                    FaceUtils.GetExtents(wo.Faces, out ptMin, out ptMax);
                    Duck duck = new Duck(ptMin, ptMax);
                    duck.LoadDataSet(Path.Combine(ExoEngine.sSpritePath, "duck.odf"), wo.GetPropertyColor("color", Color.Yellow));
                    world.Entities.Add(duck);

                    foreach (Face face in wo.Faces)
                    {
                        face.Visible = false;
                    }
                    faces.AddRange(wo.Faces);
                }
            }

            world.Entities.SortByPriority();

            faces.AddRange(woDefault.Faces);
            FaceUtils.OptimizeFaces(faces);
            world.BSPTreeRoot = BSPTreeNode.FromFaces(faces);

            return(world);
        }