static int SceneCompareFunction(ForestElement elementA, ForestElement elementB, int axis)
        {
            Vector3 posA = elementA.Transform.GetPosition();
            float valueA = (axis == 0) ? posA.X : (axis == 1) ? posA.Y : posA.Z;

            Vector3 posB = elementB.Transform.GetPosition();
            float valueB = (axis == 0) ? posB.X : (axis == 1) ? posB.Y : posB.Z;

            if (valueA < valueB)
                return -1;
            if (valueA > valueB)
                return 1;

            return 0;
        }
 public override void OnAdd(Scene scene)
 {
     mesh = ResourceManager.Inst.GetMesh("Cecropia");
     base.OnAdd(scene);
     for(int i = 0; i < entityCount; i++)
     {
         Vector3 pos;
         Vector3 normal;
         scene.MainTerrain.GenerateRandomTransform(RandomHelper.RandomGen, out pos, out normal);
         ForestElement element = new ForestElement();
         element.Transform = new Transform();
         element.Transform.SetPosition(pos);
         element.Mesh = mesh;
         visibleMeshes.AddElement(element, false);
     }
     visibleMeshes.BuildTree();
     RecursivelyBuildBounds(visibleMeshes.GetRoot());
 }
Esempio n. 3
0
        public override void OnAdd(Scene scene)
        {
            base.OnAdd(scene);
            meshes = new Mesh[meshNames.Length];
            for(int i = 0; i < meshNames.Length; i++)
                meshes[i] = ResourceManager.Inst.GetMesh(meshNames[i]);

            List<TriangleGraph> availableTriangles = null;
            if (useRegion)
            {
                scene.MainTerrain.GetTrianglesInRegion(RandomHelper.RandomGen, out availableTriangles, region);
                if (availableTriangles.Count == 0)
                {
                    isEnabled = false;
                    return;
                }
            }
            for(int i = 0; i < entityCount; i++)
            {
                Vector3 pos;
                Vector3 normal;
                if (useRegion)
                {
                    int index = i % (availableTriangles.Count+1);
                    int randIndex = RandomHelper.RandomGen.Next(availableTriangles.Count);//index);
                    normal = availableTriangles[randIndex].Normal;
                    pos = availableTriangles[randIndex].GeneratePointInTriangle(RandomHelper.RandomGen);
                }
                else
                    scene.MainTerrain.GenerateRandomTransform(RandomHelper.RandomGen, out pos, out normal);
                ForestElement element = new ForestElement();
                element.Transform = (alignToSurface) ? new NormalTransform() : new Transform();
                if (alignToSurface)
                {
                    NormalTransform transform = (NormalTransform)element.Transform;
                    transform.ConformToNormal(normal);
                    if (randomizeOrientation)
                        transform.SetAngle((float)RandomHelper.RandomGen.NextDouble() * MathHelper.TwoPi);
                }
                else if(randomizeOrientation)
                        element.Transform.SetRotation(new Vector3(0, (float)RandomHelper.RandomGen.NextDouble() * MathHelper.TwoPi, 0));

                element.Transform.SetPosition(pos);
                int randMeshIndex = RandomHelper.RandomGen.Next(meshes.Length);//i % (meshes.Length+1));
                element.Mesh = meshes[randMeshIndex];
                element.Bounds = element.Transform.TransformBounds(element.Mesh.GetBounds()); //This is only temporary
                visibleMeshes.AddElement(element, false);
            }
            isEnabled = true;
            visibleMeshes.BuildTree();
            RecursivelyBuildBounds(visibleMeshes.GetRoot());

            KDNode<ForestElement> root = visibleMeshes.GetRoot();
            root.bounds.Min -= Vector3.One * 1.15f;
            root.bounds.Max += Vector3.One * 1.15f;
        }
Esempio n. 4
0
        static int SceneCompareFunction(ForestElement elementA, ForestElement elementB, int axis)
        {
            BoundingBox boundsA = elementA.Bounds;//.Transform.TransformBounds(elementA.Mesh.GetBounds());

            Vector3 posA = (boundsA.Max + boundsA.Min) * 0.5f;// elementA.Transform.GetPosition();
            float valueA = (axis == 0) ? posA.X : (axis == 1) ? posA.Y : posA.Z;

            BoundingBox boundsB = elementB.Bounds;//.Transform.TransformBounds(elementB.Mesh.GetBounds());

            Vector3 posB = (boundsB.Max + boundsB.Min) * 0.5f;//elementB.Transform.GetPosition();
            float valueB = (axis == 0) ? posB.X : (axis == 1) ? posB.Y : posB.Z;

            if (valueA < valueB)
                return -1;
            if (valueA > valueB)
                return 1;

            return 0;
        }
Esempio n. 5
0
 static Vector2 SceneBoundsFunction(ForestElement element, int axis)
 {
     BoundingBox bounds = element.Bounds;//.Transform.TransformBounds(element.Mesh.GetBounds());
     return (axis == 0) ? new Vector2(bounds.Min.X, bounds.Max.X) : ((axis == 1) ? new Vector2(bounds.Min.Y, bounds.Max.Y) : new Vector2(bounds.Min.Z, bounds.Max.Z));
 }
Esempio n. 6
0
 static BoundingBox SceneBoundsEval(ForestElement element)
 {
     return element.Bounds;
 }