Exemplo n.º 1
0
        internal void BuildDrawInfo(PathGraph graph)
        {
            FreeVBs();

            List <Vector3> verts      = new List <Vector3>();
            List <Vector3> norms      = new List <Vector3>();
            List <UInt32>  indexes    = new List <UInt32>();
            List <int>     vertCounts = new List <int>();

            graph.GetNodePolys(verts, indexes, norms, vertCounts);

            if (verts.Count == 0)
            {
                return;
            }

            VPosNormCol0    [] nodeVerts = new VPosNormCol0[verts.Count];
            for (int i = 0; i < nodeVerts.Length; i++)
            {
                nodeVerts[i].Position = verts[i] + Vector3.UnitY;                       //boost up 1
                nodeVerts[i].Normal.X = norms[i].X;
                nodeVerts[i].Normal.Y = norms[i].Y;
                nodeVerts[i].Normal.Z = norms[i].Z;
                nodeVerts[i].Normal.W = 1f;
            }

            int idx = 0;

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

                for (int j = 0; j < vertCounts[i]; j++)
                {
                    nodeVerts[idx + j].Color0 = col;
                }
                idx += vertCounts[i];
            }

            mVBNodes  = VertexTypes.BuildABuffer(mGD.GD, nodeVerts, VertexTypes.GetIndex(nodeVerts[0].GetType()));
            mIBNodes  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBNodes = VertexTypes.BuildAVBB(VertexTypes.GetIndex(nodeVerts[0].GetType()), mVBNodes);

            mNodeIndexCount = indexes.Count;

            //connexions
            List <PathGraph.LineSeg> segz = graph.GetNodeConnections();

            if (segz.Count <= 0)
            {
                return;
            }
            VPosNormCol0    [] segVerts = new VPosNormCol0[segz.Count * 3];

            UInt32 index = 0;

            indexes.Clear();
            foreach (PathGraph.LineSeg seg in segz)
            {
                Color col = Mathery.RandomColor(mRand);

                //endpoint
                segVerts[index].Position = seg.mB;

                Vector3 lineVec = seg.mB - seg.mA;

                //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 = seg.mA - crossVec + Mathery.RandomDirectionXZ(mRand);
                segVerts[index + 2].Position = seg.mA + crossVec + Mathery.RandomDirectionXZ(mRand);

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

                //adjust up
                segVerts[index].Position     += Vector3.UnitY * 2f;
                segVerts[index + 1].Position += Vector3.UnitY * 1.7f;
                segVerts[index + 2].Position += Vector3.UnitY * 1.7f;

                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;

                indexes.Add(index);
                indexes.Add(index + 1);
                indexes.Add(index + 2);

                index += 3;
            }

            mVBCons  = VertexTypes.BuildABuffer(mGD.GD, segVerts, VertexTypes.GetIndex(segVerts[0].GetType()));
            mIBCons  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBCons = VertexTypes.BuildAVBB(VertexTypes.GetIndex(segVerts[0].GetType()), mVBCons);

            mConIndexCount = indexes.Count;
        }
Exemplo n.º 2
0
        public void MakeDrawStuff(Device dev,
                                  Vector3         [] facePoints,
                                  bool            [] inSolid,
                                  GFXPlane facePlane,
                                  int numSamples)
        {
            if (facePoints.Length <= 0)
            {
                return;
            }

            //free existing if any
            if (mVB != null)
            {
                mVB.Dispose();
            }

            VPosNormCol0    [] vpc = new VPosNormCol0[facePoints.Length * 2];

            int sampIdx     = 0;
            int j           = 0;
            int sampPoints  = facePoints.Length / numSamples;
            int sampCounter = 0;

            for (int i = 0; i < facePoints.Length; i++)
            {
                vpc[j].Position = facePoints[i];
                vpc[j].Normal.X = facePlane.mNormal.X;
                vpc[j].Normal.Y = facePlane.mNormal.Y;
                vpc[j].Normal.Z = facePlane.mNormal.Z;
                vpc[j].Normal.W = 1f;

                if (sampIdx == 0)
                {
                    vpc[j++].Color0 = inSolid[i]?    Color.Red : Color.Green;
                    vpc[j].Position = facePoints[i] + facePlane.mNormal * 3f;
                    vpc[j].Color0   = inSolid[i]?    Color.Red : Color.Green;
                }
                else
                {
                    vpc[j++].Color0 = Color.Blue;
                    vpc[j].Position = facePoints[i] + facePlane.mNormal * 1f;
                    vpc[j].Color0   = inSolid[i]?    Color.Red : Color.Blue;
                }

                vpc[j].Normal.X   = facePlane.mNormal.X;
                vpc[j].Normal.Y   = facePlane.mNormal.Y;
                vpc[j].Normal.Z   = facePlane.mNormal.Z;
                vpc[j++].Normal.W = 1f;

                sampCounter++;

                if (sampCounter >= sampPoints)
                {
                    sampIdx++;
                    sampCounter = 0;
                }
            }

            mVertCount = j;
            mVB        = VertexTypes.BuildABuffer(dev, vpc, vpc[0].GetType());
            mVBBinding = VertexTypes.BuildAVBB(VertexTypes.GetIndex(vpc[0].GetType()), mVB);
        }
Exemplo n.º 3
0
        internal void BuildPathDrawInfo(List <Vector3> path, Vector3 boxMiddleOffset)
        {
            if (mVBPath != null)
            {
                mVBPath.Dispose();
            }
            if (mIBPath != null)
            {
                mIBPath.Dispose();
            }

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

            VPosNormCol0    [] segVerts = new VPosNormCol0[(path.Count - 1) * 3];

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

            for (int i = 0; i < (path.Count - 1); i++)
            {
                Color col = Mathery.RandomColor(mRand);

                col = Color.Red;

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

                Vector3 lineVec = path[i + 1] - path[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 = path[i] - crossVec + Mathery.RandomDirectionXZ(mRand);
                segVerts[index + 2].Position = path[i] + crossVec + Mathery.RandomDirectionXZ(mRand);

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

                //adjust up
                segVerts[index].Position     += boxMiddleOffset;
                segVerts[index + 1].Position += boxMiddleOffset;
                segVerts[index + 2].Position += boxMiddleOffset;

                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;

                indexes.Add(index);
                indexes.Add(index + 1);
                indexes.Add(index + 2);

                index += 3;
            }

            mVBPath  = VertexTypes.BuildABuffer(mGD.GD, segVerts, VertexTypes.GetIndex(segVerts[0].GetType()));
            mIBPath  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBPath = VertexTypes.BuildAVBB(VertexTypes.GetIndex(segVerts[0].GetType()), mVBPath);

            mPathIndexCount = indexes.Count;
        }
Exemplo n.º 4
0
        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);
        }