예제 #1
0
        public void PlaceInstances(Vector3d Anchorpoint)
        {
            //DistanceThreshold = tile.DistanceThreshold;
            this.transform.Position = Anchorpoint;

            Random ran = new Random(1234);

            Matrix4d TreeRotation = Matrix4d.CreateFromQuaternion(Globals.LocalUpRotation());

            int i = 0;

            for (int z = 0; z < 30; z++)
            {
                for (int x = 0; x < 30; x++)
                {
                    if (i >= MaxInstances)
                    {
                        break;
                    }

                    //Vector3d pos = new Vector3d(1000 * ran.NextDouble(), 200 * ran.NextDouble(), 1000 * ran.NextDouble());
                    Vector3d pos = MassiveTools.RandomPointInSphere(Vector3d.Zero, 1000, ran);
                    //Vector3d PlantingPos = planet.GetNearestPointOnSphere(SeedPos + Treepos, 0) - SeedPos;
                    double   scale     = MinSize + ran.NextDouble() * (MaxSize - MinSize);
                    Matrix4d TreeScale = Matrix4d.Scale(scale, scale, scale);

                    Matrix4d TreePosition = Matrix4d.CreateTranslation(pos);
                    TreeRotation = Matrix4d.CreateFromQuaternion(
                        Quaterniond.FromEulerAngles(
                            ran.NextDouble(),
                            ran.NextDouble(),
                            ran.NextDouble()));
                    //find point at y with raycast
                    Matrix4 final = MTransform.GetFloatMatrix(TreeScale * TreeRotation * TreePosition);
                    mats[i] = final;
                    i++;
                }
            }

            TotalInstances = i;

            //null out the remainder
            for (int j = TotalInstances; j < MaxInstances; j++)
            {
                Matrix4 final = Matrix4.Identity;
                mats[j] = final;
            }

            Planted = false;
        }