コード例 #1
0
 public void FreeAll()
 {
     mMatLib.FreeAll();
     if (mVB != null)
     {
         mVB.Dispose();
     }
     if (mLMPlane != null)
     {
         mLMPlane.Free();
     }
     if (mTexU != null)
     {
         mTexU.Free();
     }
     if (mTexV != null)
     {
         mTexV.Free();
     }
 }
コード例 #2
0
ファイル: GameLoop.cs プロジェクト: Kharzette/GrogTools
        internal void TBuild(int gridSize, int chunkSize, float medianHeight,
                             float variance, int polySize, int tilingIterations, float borderSize,
                             int smoothPasses, int seed, int erosionIterations,
                             float rainFall, float solubility, float evaporation, int threads)
        {
            mFracFact = new FractalFactory(variance, medianHeight, gridSize + 1, gridSize + 1);

            mNumStreamThreads = threads;

            float   [,] fract = mFracFact.CreateFractal(seed);

            for (int i = 0; i < smoothPasses; i++)
            {
                FractalFactory.SmoothPass(fract);
            }

            for (int i = 0; i < tilingIterations; i++)
            {
                float borderSlice = borderSize / tilingIterations;

                FractalFactory.MakeTiled(fract, borderSlice * (i + 1));
            }

            if (erosionIterations > 0)
            {
                int realIterations = FractalFactory.Erode(fract, mRand,
                                                          erosionIterations, rainFall, solubility, evaporation);

                //redo tiling if eroded
                for (int i = 0; i < tilingIterations; i++)
                {
                    float borderSlice = borderSize / tilingIterations;

                    FractalFactory.MakeTiled(fract, borderSlice * (i + 1));
                }
            }

            Vector3 [,] norms = mFracFact.BuildNormals(fract, polySize);

            if (mTModel != null)
            {
                mTModel.FreeAll();
            }
            mTModel = new TerrainModel(fract, polySize, gridSize);

            mCellGridMax = gridSize / chunkSize;

            List <HeightMap.TexData> tdata = new List <HeightMap.TexData>();

            float transHeight = 0f;

            if (mTerrain != null)
            {
                //grab a copy of the old texture data if any
                List <HeightMap.TexData> texOld = mTerrain.GetTextureData(out transHeight);

                //clone it because it is about to all get nuked
                foreach (HeightMap.TexData td in texOld)
                {
                    HeightMap.TexData td2 = new HeightMap.TexData(td);
                    tdata.Add(td2);
                }
                mTerrain.FreeAll();
            }
            mTerrain = new Terrain(fract, norms, polySize, chunkSize, mCellGridMax);

            mTerrain.SetTextureData(tdata, transHeight);

            mBoundary = chunkSize * polySize;

            WrapGridCoordinates();

            mTerrain.SetCellCoord(mGridCoordinate);

            mTerrain.BuildGrid(mGD, mChunkRange, mNumStreamThreads);

            mPos.Y = mTModel.GetHeight(mPos) + 200f;

            mTerrain.UpdatePosition(mPos, mTerMats);

            //clamp box heights
            mTModel.FixBoxHeights();

            //clear existing
            if (mQTreeBoxes != null)
            {
                mQTreeBoxes.Free();
            }

            //turn on to debug quadtree
            //careful about big map sizes
//			List<BoundingBox>	boxes	=mTModel.GetAllBoxes();
//			mQTreeBoxes	=PrimFactory.CreateCubes(mGD.GD, boxes);
        }
コード例 #3
0
ファイル: DrawRays.cs プロジェクト: Kharzette/GrogTest
        internal void BuildRayDrawInfo(List <Vector3> rays, List <Vector3> hits, float polySize)
        {
            if (mVBRays != null)
            {
                mVBRays.Dispose();
            }
            if (mIBRays != null)
            {
                mIBRays.Dispose();
            }

            if (mHits != null)
            {
                mHits.Free();
            }

            if (rays.Count < 2)
            {
                return;
            }

            VPosNormCol0    [] segVerts = new VPosNormCol0[rays.Count * 3];
            VPosNormCol0    [] hitVerts = new VPosNormCol0[hits.Count * 8];

            UInt32        index   = 0;
            List <UInt32> indexes = new List <UInt32>();

            for (int i = 0; i < rays.Count; i += 2)
            {
                Color col = Mathery.RandomColor(mRand);

                //endpoint
                segVerts[index].Position = rays[i + 1];

                Vector3 lineVec = rays[i + 1] - rays[i];

                //get a perpindicular axis to the a to b axis
                //so the back side of the connection can flare out a bit
                Vector3 crossVec = Vector3.Cross(lineVec, Vector3.UnitY);

                crossVec.Normalize();

                Vector3 normVec = Vector3.Cross(crossVec, lineVec);

                normVec.Normalize();

                //crossVec	*=.2f;

                segVerts[index + 1].Position = rays[i] - crossVec;
                segVerts[index + 2].Position = rays[i] + crossVec;


                //scale up to visible
                segVerts[index].Position.X     *= polySize;
                segVerts[index].Position.Z     *= polySize;
                segVerts[index + 1].Position.X *= polySize;
                segVerts[index + 1].Position.Z *= polySize;
                segVerts[index + 2].Position.X *= polySize;
                segVerts[index + 2].Position.Z *= polySize;

                //upside down tri
                segVerts[index + 3].Position = segVerts[index + 2].Position;
                segVerts[index + 4].Position = segVerts[index + 1].Position;
                segVerts[index + 5].Position = segVerts[index].Position;

                segVerts[index].Color0     = col;
                segVerts[index + 1].Color0 = col;
                segVerts[index + 2].Color0 = col;
                segVerts[index + 3].Color0 = col;
                segVerts[index + 4].Color0 = col;
                segVerts[index + 5].Color0 = col;

                Half4 norm;
                norm.X = normVec.X;
                norm.Y = normVec.Y;
                norm.Z = normVec.Z;
                norm.W = 1f;
                segVerts[index].Normal     = norm;
                segVerts[index + 1].Normal = norm;
                segVerts[index + 2].Normal = norm;

                norm.X = -normVec.X;
                norm.Y = -normVec.Y;
                norm.Z = -normVec.Z;
                segVerts[index + 3].Normal = norm;
                segVerts[index + 4].Normal = norm;
                segVerts[index + 5].Normal = norm;

                indexes.Add(index);
                indexes.Add(index + 1);
                indexes.Add(index + 2);
                indexes.Add(index + 3);
                indexes.Add(index + 4);
                indexes.Add(index + 5);

                index += 6;
            }

            mVBRays  = VertexTypes.BuildABuffer(mGD.GD, segVerts, VertexTypes.GetIndex(segVerts[0].GetType()));
            mIBRays  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBRays = VertexTypes.BuildAVBB(VertexTypes.GetIndex(segVerts[0].GetType()), mVBRays);

            mRaysIndexCount = indexes.Count;

            indexes.Clear();

            mHits = PrimFactory.CreateCubes(mGD.GD, hits, 5f);
        }