コード例 #1
0
        private void ParseBrushes(idLexer lexer, CollisionModel model)
        {
            idToken             token = lexer.CheckTokenType(TokenType.Number, 0);
            int                 planeCount;
            CollisionModelBrush b;

            float[] tmp;

            lexer.ExpectTokenString("{");

            while (lexer.CheckTokenString("}") == false)
            {
                // parse brush
                planeCount = lexer.ParseInt();

                b          = new CollisionModelBrush();
                b.Contents = ContentFlags.All;
                b.Material = _traceModelMaterial;
                b.Planes   = new Plane[planeCount];

                lexer.ExpectTokenString("{");

                for (int i = 0; i < planeCount; i++)
                {
                    tmp = lexer.Parse1DMatrix(3);

                    b.Planes[i].Normal = new Vector3(tmp[0], tmp[1], tmp[2]);
                    b.Planes[i].D      = lexer.ParseFloat();
                }

                lexer.ExpectTokenString("}");

                tmp          = lexer.Parse1DMatrix(3);
                b.Bounds.Min = new Vector3(tmp[0], tmp[1], tmp[2]);

                tmp          = lexer.Parse1DMatrix(3);
                b.Bounds.Max = new Vector3(tmp[0], tmp[1], tmp[2]);

                token = lexer.ReadToken();

                if (token.Type == TokenType.Number)
                {
                    b.Contents = (ContentFlags)token.ToInt32();                      // old .cm files use a single integer
                }
                else
                {
                    b.Contents = ContentsFromString(token.ToString());
                }

                b.CheckCount     = 0;
                b.PrimitiveCount = 0;

                // filter brush into tree
                FilterBrushIntoTree(model, model.Node, b);
            }
        }
コード例 #2
0
		private void ParseBrushes(idLexer lexer, CollisionModel model)
		{
			idToken token = lexer.CheckTokenType(TokenType.Number, 0);
			int planeCount;
			CollisionModelBrush b;
			float[] tmp;

			lexer.ExpectTokenString("{");

			while(lexer.CheckTokenString("}") == false)
			{
				// parse brush
				planeCount = lexer.ParseInt();

				b = new CollisionModelBrush();
				b.Contents = ContentFlags.All;
				b.Material = _traceModelMaterial;
				b.Planes = new Plane[planeCount];

				lexer.ExpectTokenString("{");

				for(int i = 0; i < planeCount; i++)
				{
					tmp = lexer.Parse1DMatrix(3);

					b.Planes[i].Normal = new Vector3(tmp[0], tmp[1], tmp[2]);
					b.Planes[i].D = lexer.ParseFloat();
				}

				lexer.ExpectTokenString("}");

				tmp = lexer.Parse1DMatrix(3);
				b.Bounds.Min = new Vector3(tmp[0], tmp[1], tmp[2]);

				tmp = lexer.Parse1DMatrix(3);
				b.Bounds.Max = new Vector3(tmp[0], tmp[1], tmp[2]);

				token = lexer.ReadToken();

				if(token.Type == TokenType.Number)
				{
					b.Contents = (ContentFlags) token.ToInt32(); // old .cm files use a single integer
				}
				else
				{
					b.Contents = ContentsFromString(token.ToString());
				}

				b.CheckCount = 0;
				b.PrimitiveCount = 0;

				// filter brush into tree
				FilterBrushIntoTree(model, model.Node, b);
			}
		}
コード例 #3
0
        private void FilterBrushIntoTree(CollisionModel model, CollisionModelNode node, CollisionModelBrush b)
        {
            while (node.PlaneType != -1)
            {
                if (InsideAllChildren(node, b.Bounds) == true)
                {
                    break;
                }

                float v  = (node.PlaneType == 0) ? b.Bounds.Min.X : (node.PlaneType == 1) ? b.Bounds.Min.Y : b.Bounds.Min.Z;
                float v2 = (node.PlaneType == 0) ? b.Bounds.Max.X : (node.PlaneType == 1) ? b.Bounds.Max.Y : b.Bounds.Max.Z;

                if (v >= node.PlaneDistance)
                {
                    node = node.Children[0];
                }
                else if (v2 <= node.PlaneDistance)
                {
                    node = node.Children[1];
                }
                else
                {
                    FilterBrushIntoTree(model, node.Children[1], b);
                    node = node.Children[0];
                }
            }

            node.Brushes.Add(b);
        }
コード例 #4
0
		private void FilterBrushIntoTree(CollisionModel model, CollisionModelNode node, CollisionModelBrush b)
		{
			while(node.PlaneType != -1)
			{
				if(InsideAllChildren(node, b.Bounds) == true)
				{
					break;
				}

				float v = (node.PlaneType == 0) ? b.Bounds.Min.X : (node.PlaneType == 1) ? b.Bounds.Min.Y : b.Bounds.Min.Z;
				float v2 = (node.PlaneType == 0) ? b.Bounds.Max.X : (node.PlaneType == 1) ? b.Bounds.Max.Y : b.Bounds.Max.Z;

				if(v >= node.PlaneDistance)
				{
					node = node.Children[0];
				}
				else if(v2 <= node.PlaneDistance)
				{
					node = node.Children[1];
				}
				else
				{
					FilterBrushIntoTree(model, node.Children[1], b);
					node = node.Children[0];
				}
			}

			node.Brushes.Add(b);
		}