Ejemplo n.º 1
0
        //build a full tree
        public SamplerNode(int sub, Vector3 center, Vector2 size, Vector2 uv, Vector2 uvstep)
        {
            mVertex          = new SampleVertexData();
            mVertex.Position = center;
            mVertex.UV       = uv;
            Vector2 subsize   = 0.5f * size;
            Vector2 subuvstep = 0.5f * uvstep;

            if (sub > 1)
            {
                Children[0] = new SamplerNode(sub - 1,
                                              new Vector3(center.x - 0.5f * subsize.x, center.y, center.z - 0.5f * subsize.y), subsize,
                                              new Vector2(uv.x - 0.5f * subuvstep.x, uv.y - 0.5f * subuvstep.y), subuvstep);
                Children[1] = new SamplerNode(sub - 1,
                                              new Vector3(center.x + 0.5f * subsize.x, center.y, center.z - 0.5f * subsize.y), subsize,
                                              new Vector2(uv.x + 0.5f * subuvstep.x, uv.y - 0.5f * subuvstep.y), subuvstep);
                Children[2] = new SamplerNode(sub - 1,
                                              new Vector3(center.x - 0.5f * subsize.x, center.y, center.z + 0.5f * subsize.y), subsize,
                                              new Vector2(uv.x - 0.5f * subuvstep.x, uv.y + 0.5f * subuvstep.y), subuvstep);
                Children[3] = new SamplerNode(sub - 1,
                                              new Vector3(center.x + 0.5f * subsize.x, center.y, center.z + 0.5f * subsize.y), subsize,
                                              new Vector2(uv.x + 0.5f * subuvstep.x, uv.y + 0.5f * subuvstep.y), subuvstep);
            }
            else
            {
                Children[0] = new SamplerLeaf(new Vector3(center.x - 0.5f * subsize.x, center.y, center.z - 0.5f * subsize.y),
                                              new Vector2(uv.x - 0.5f * subuvstep.x, uv.y - 0.5f * subuvstep.y));
                Children[1] = new SamplerLeaf(new Vector3(center.x + 0.5f * subsize.x, center.y, center.z - 0.5f * subsize.y),
                                              new Vector2(uv.x + 0.5f * subuvstep.x, uv.y - 0.5f * subuvstep.y));
                Children[2] = new SamplerLeaf(new Vector3(center.x - 0.5f * subsize.x, center.y, center.z + 0.5f * subsize.y),
                                              new Vector2(uv.x - 0.5f * subuvstep.x, uv.y + 0.5f * subuvstep.y));
                Children[3] = new SamplerLeaf(new Vector3(center.x + 0.5f * subsize.x, center.y, center.z + 0.5f * subsize.y),
                                              new Vector2(uv.x + 0.5f * subuvstep.x, uv.y + 0.5f * subuvstep.y));
            }
        }
Ejemplo n.º 2
0
 public void AddBoundary(int subdivision, int x, int z, byte bk, SampleVertexData vert)
 {
     if (mNode is SamplerNode)
     {
         SamplerNode node = (SamplerNode)mNode;
         node.AddBoundary(subdivision, x, z, bk, vert);
     }
 }
Ejemplo n.º 3
0
        public override void AddBoundary(int subdivision, int x, int z, byte bk, SampleVertexData point)
        {
            //first grade
            int u    = x >> subdivision; // x / power(2, subdivision);
            int v    = z >> subdivision;
            int subx = x - u * (1 << subdivision);
            int subz = z - v * (1 << subdivision);

            --subdivision;
            int idx = (subz >> subdivision) * 2 + (subx >> subdivision);

            Children[idx].AddBoundary(subdivision, subx, subz, bk, point);
        }
Ejemplo n.º 4
0
        private void RayCastBoundary(float fx, float fz, int x, int z, byte bk, SamplerTree sampler)
        {
            Vector3    top = vCheckTop + fx * Vector3.right + fz * Vector3.forward;
            RaycastHit hit = new RaycastHit();

            if (Physics.Raycast(top, Vector3.down, out hit, CheckRayLen))
            {
                SampleVertexData vert = new SampleVertexData();
                vert.Position = hit.point;
                vert.Normal   = hit.normal;
                vert.UV       = new Vector2(fx / maxX / gridSize[0], fz / maxZ / gridSize[1]);
                sampler.AddBoundary(subdivision, x, z, bk, vert);
            }
            else
            {
                MTLog.LogError("RayCastBoundary didn't hit terrain");
            }
        }
Ejemplo n.º 5
0
 public override void AddBoundary(int subdivision, int x, int z, byte bk, SampleVertexData vert)
 {
     Boundaries.Add(bk, vert);
 }
Ejemplo n.º 6
0
 public SamplerLeaf(SampleVertexData vert)
 {
     mVertex = vert;
 }
Ejemplo n.º 7
0
 public SamplerLeaf(Vector3 center, Vector2 uv)
 {
     mVertex          = new SampleVertexData();
     mVertex.Position = center;
     mVertex.UV       = uv;
 }
Ejemplo n.º 8
0
 public abstract void AddBoundary(int subdivision, int x, int z, byte bk, SampleVertexData vert);
Ejemplo n.º 9
0
 public void Merge(SampleVertexData other)
 {
     Position = 0.5f * (Position + other.Position);
     Normal   = 0.5f * (Normal + other.Normal);
     UV       = 0.5f * (UV + other.UV);
 }