예제 #1
0
파일: Face.cs 프로젝트: kevincos/Vexed
        public Face(Vector3 normal, Vector3 center)
        {
            this.normal = normal;
            this.center = center;

            blocks = new List<Block>();
            Block b = new Block();

            Vector3 xDir = Vector3.UnitX;
            if(Vector3.Cross(xDir, normal).Equals(Vector3.Zero))
               xDir = Vector3.UnitZ;
            Vector3 yDir = Vector3.Cross(normal, xDir);
            yDir.Normalize();
            xDir.Normalize();

            b.edges.Add(new Edge(center,center+xDir*2));
            b.edges.Add(new Edge(center+xDir*2,center+xDir*2+yDir*2));
            b.edges.Add(new Edge(center+xDir*2+yDir*2,center+yDir*2));
            b.edges.Add(new Edge(center + yDir * 2, center));
            b.Init();
            blocks.Add(b);

            doodads = new List<Doodad>();
            monsters = new List<Monster>();
        }
예제 #2
0
파일: Block.cs 프로젝트: kevincos/Vexed
 public Block(Block b)
 {
     id = b.id;
     name = b.name;
     color = b.color;
     edges = new List<Edge>();
     behaviors = new List<Behavior>();
     foreach (Edge e in b.edges)
     {
         edges.Add(new Edge(e));
     }
     foreach (Behavior be in b.behaviors)
     {
         behaviors.Add(new Behavior(be));
     }
 }
예제 #3
0
파일: Face.cs 프로젝트: kevincos/Vexed
 public bool IsBlockValid(Block b)
 {
     Vector3 result;
     Vector3 prevResult = Vector3.Zero;
     foreach (Edge e in b.edges)
     {
         for (int i = 0; i < 4; i++)
         {
             Vector3 v1 = vertices[i] - vertices[(i + 1) % 4];
             Vector3 v2 = e.start - vertices[(i + 1) % 4];
             result = Vector3.Cross(v1, v2);
             if (i > 0 && Vector3.Dot(result, prevResult) < 0)
                 return false;
             prevResult = result;
         }
     }
     return true;
 }
예제 #4
0
파일: Face.cs 프로젝트: kevincos/Vexed
        public VertexPositionColor[] GetTemplate(Vector3 position, Vector3 templatePosition)
        {
            Color templateColor = Color.White;
            Block b = null;
            VertexPositionColor[] vList = new VertexPositionColor[8];

            Vector3 xDir = Vector3.UnitX;
            if (Vector3.Cross(xDir, normal).Equals(Vector3.Zero))
                xDir = Vector3.UnitZ;
            Vector3 yDir = Vector3.Cross(normal, xDir);
            yDir.Normalize();
            xDir.Normalize();
            xDir = 2f * xDir;
            yDir = 2f * yDir;

            b = GetHoverBlock(position);
            if (b == null)
            {
                templateColor = Color.Black;
                b = new Block();
                b.edges.Add(new Edge(templatePosition, templatePosition + xDir));
                b.edges.Add(new Edge(templatePosition + xDir, templatePosition + xDir + yDir));
                b.edges.Add(new Edge(templatePosition + xDir + yDir, templatePosition + yDir));
                b.edges.Add(new Edge(templatePosition + yDir, templatePosition));
            }

            if(IsBlockValid(b))
            {
                vList[0] = new VertexPositionColor(b.edges[0].start + .2f*normal, templateColor);
                vList[1] = new VertexPositionColor(b.edges[0].end + .2f * normal, templateColor);
                vList[2] = new VertexPositionColor(b.edges[1].start + .2f * normal, templateColor);
                vList[3] = new VertexPositionColor(b.edges[1].end + .2f * normal, templateColor);
                vList[4] = new VertexPositionColor(b.edges[2].start + .2f * normal, templateColor);
                vList[5] = new VertexPositionColor(b.edges[2].end + .2f * normal, templateColor);
                vList[6] = new VertexPositionColor(b.edges[3].start + .2f * normal, templateColor);
                vList[7] = new VertexPositionColor(b.edges[3].end + .2f * normal, templateColor);
                return vList;
            }
            return null;
        }
예제 #5
0
파일: Face.cs 프로젝트: kevincos/Vexed
        public VertexPositionColor[] GetSelectedMonsterHighlight(Vector3 position)
        {
            VertexPositionColor[] vList = null;
            Monster m = GetHoverMonster(position);
            if (m == null)
            {
                Color templateColor = Color.Yellow;
                Vector3 lockPosition = new Vector3((int)position.X, (int)position.Y, (int)position.Z);
                Vector3 up = .5f * MainForm.currentUp;
                Vector3 left = .5f * Vector3.Cross(MainForm.currentUp, normal);
                lockPosition += up + left + .4f * normal;

                Block testBlock = new Block();
                testBlock.edges.Add(new Edge(lockPosition - up, lockPosition + left));
                testBlock.edges.Add(new Edge(lockPosition + left, lockPosition + up));
                testBlock.edges.Add(new Edge(lockPosition + up, lockPosition - left));
                testBlock.edges.Add(new Edge(lockPosition - left, lockPosition - up));
                if (IsBlockValid(testBlock))
                {
                    vList = new VertexPositionColor[6];
                    vList[0] = new VertexPositionColor(lockPosition - up - left, templateColor);
                    vList[1] = new VertexPositionColor(lockPosition + up + left, templateColor);
                    vList[2] = new VertexPositionColor(lockPosition - up + left, templateColor);
                    vList[3] = new VertexPositionColor(lockPosition + up - left, templateColor);
                    vList[4] = new VertexPositionColor(lockPosition + up, templateColor);
                    vList[5] = new VertexPositionColor(lockPosition, templateColor);

                }

            }

            return vList;
        }
예제 #6
0
파일: Face.cs 프로젝트: kevincos/Vexed
        public void AddBlock(Vector3 position)
        {
            Block b = new Block();

            Vector3 xDir = Vector3.UnitX;
            if (Vector3.Cross(xDir, normal).Equals(Vector3.Zero))
                xDir = Vector3.UnitZ;
            Vector3 yDir = Vector3.Cross(normal, xDir);
            yDir.Normalize();
            xDir.Normalize();
            xDir = 2f * xDir;
            yDir = 2f * yDir;

            b.edges.Add(new Edge(position, position + xDir));
            b.edges.Add(new Edge(position + xDir, position + xDir + yDir));
            b.edges.Add(new Edge(position + xDir + yDir, position + yDir));
            b.edges.Add(new Edge(position + yDir, position));

            bool blockOK = IsBlockValid(b);
            if (blockOK)
            {
                b.Init();
                blocks.Add(b);
            }
        }