Example #1
0
        private PolygonIntegrals GetPolygonIntegrals(int polyNumber, int a, int b, int c)
        {
            ProjectionIntegrals pi = GetProjectionIntegrals(polyNumber, a, b);

            Vector3 n  = _polygons[polyNumber].Normal;
            float   w  = -_polygons[polyNumber].Distance;
            float   k1 = 1.0f / n.Get(c);
            float   k2 = k1 * k1;
            float   k3 = k2 * k1;
            float   k4 = k3 * k1;

            PolygonIntegrals integrals = new PolygonIntegrals();

            integrals.Fa = k1 * pi.Pa;
            integrals.Fb = k1 * pi.Pb;
            integrals.Fc = -k2 * (n.Get(a) * pi.Pa + n.Get(b) * pi.Pb + w * pi.P1);

            integrals.Faa = k1 * pi.Paa;
            integrals.Fbb = k1 * pi.Pbb;
            integrals.Fcc = k3 * (idMath.Square(n.Get(a)) * pi.Paa + 2 * n.Get(a) * n.Get(b) * pi.Pab + idMath.Square(n.Get(b)) * pi.Pbb
                                  + w * (2 * (n.Get(a) * pi.Pa + n.Get(b) * pi.Pb) + w * pi.P1));

            integrals.Faaa = k1 * pi.Paaa;
            integrals.Fbbb = k1 * pi.Pbbb;
            integrals.Fccc = -k4 * (idMath.Cube(n.Get(a)) * pi.Paaa + 3 * idMath.Square(n.Get(a)) * n.Get(b) * pi.Paab
                                    + 3 * n.Get(a) * idMath.Square(n.Get(b)) * pi.Pabb + idMath.Cube(n.Get(b)) * pi.Pbbb
                                    + 3 * w * (idMath.Square(n.Get(a)) * pi.Paa + 2 * n.Get(a) * n.Get(b) * pi.Pab + idMath.Square(n.Get(b)) * pi.Pbb)
                                    + w * w * (3 * (n.Get(a) * pi.Pa + n.Get(b) * pi.Pb) + w * pi.P1));

            integrals.Faab = k1 * pi.Paab;
            integrals.Fbbc = -k2 * (n.Get(a) * pi.Pabb + n.Get(b) * pi.Pbbb + w * pi.Pbb);
            integrals.Fcca = k3 * (idMath.Square(n.Get(a)) * pi.Paaa + 2 * n.Get(a) * n.Get(b) * pi.Paab + idMath.Square(n.Get(b)) * pi.Pabb
                                   + w * (2 * (n.Get(a) * pi.Paa + n.Get(b) * pi.Pab) + w * pi.Pa));

            return(integrals);
        }
Example #2
0
		private PolygonIntegrals GetPolygonIntegrals(int polyNumber, int a, int b, int c)
		{
			ProjectionIntegrals pi = GetProjectionIntegrals(polyNumber, a, b);

			Vector3 n = _polygons[polyNumber].Normal;
			float w = -_polygons[polyNumber].Distance;
			float k1 = 1.0f / n.Get(c);
			float k2 = k1 * k1;
			float k3 = k2 * k1;
			float k4 = k3 * k1;

			PolygonIntegrals integrals = new PolygonIntegrals();
			integrals.Fa = k1 * pi.Pa;
			integrals.Fb = k1 * pi.Pb;
			integrals.Fc = -k2 * (n.Get(a) * pi.Pa + n.Get(b) * pi.Pb + w * pi.P1);
			
			integrals.Faa = k1 * pi.Paa;
			integrals.Fbb = k1 * pi.Pbb;
			integrals.Fcc = k3 * (idMath.Square(n.Get(a)) * pi.Paa + 2 * n.Get(a) * n.Get(b) * pi.Pab + idMath.Square(n.Get(b)) * pi.Pbb
				+ w * (2 * (n.Get(a) * pi.Pa + n.Get(b) * pi.Pb) + w * pi.P1));

			integrals.Faaa = k1 * pi.Paaa;
			integrals.Fbbb = k1 * pi.Pbbb;
			integrals.Fccc = -k4 * (idMath.Cube(n.Get(a)) * pi.Paaa + 3 * idMath.Square(n.Get(a)) * n.Get(b) * pi.Paab
					+ 3 * n.Get(a) * idMath.Square(n.Get(b)) * pi.Pabb + idMath.Cube(n.Get(b)) * pi.Pbbb
					+ 3 * w * (idMath.Square(n.Get(a)) * pi.Paa + 2 * n.Get(a) * n.Get(b) * pi.Pab + idMath.Square(n.Get(b)) * pi.Pbb)
					+ w * w * (3 * (n.Get(a) * pi.Pa + n.Get(b) * pi.Pb) + w * pi.P1));

			integrals.Faab = k1 * pi.Paab;
			integrals.Fbbc = -k2 * (n.Get(a) * pi.Pabb + n.Get(b) * pi.Pbbb + w * pi.Pbb);
			integrals.Fcca = k3 * (idMath.Square(n.Get(a)) * pi.Paaa + 2 * n.Get(a) * n.Get(b) * pi.Paab + idMath.Square(n.Get(b)) * pi.Pabb
					+ w * (2 * (n.Get(a) * pi.Paa + n.Get(b) * pi.Pab) + w * pi.Pa));

			return integrals;
		}
Example #3
0
        private VolumeIntegrals GetVolumeIntegrals()
        {
            VolumeIntegrals integrals = new VolumeIntegrals();
            int             polyCount = _polygons.Length;

            for (int i = 0; i < polyCount; i++)
            {
                TraceModelPolygon poly = _polygons[i];

                float nx = idMath.Abs(poly.Normal.X);
                float ny = idMath.Abs(poly.Normal.Y);
                float nz = idMath.Abs(poly.Normal.Z);
                int   c  = 0;

                if ((nx > ny) && (nx > nz))
                {
                    c = 0;
                }
                else
                {
                    c = (ny > nz) ? 1 : 2;
                }

                int a = (c + 1) % 3;
                int b = (a + 1) % 3;

                PolygonIntegrals pi = GetPolygonIntegrals(i, a, b, c);

                integrals.T0 += poly.Normal.X * ((a == 0) ? pi.Fa : ((b == 0) ? pi.Fb : pi.Fc));

                if (a == 0)
                {
                    integrals.T1.X += poly.Normal.X * pi.Faa;
                    integrals.T2.X += poly.Normal.X * pi.Faaa;
                    integrals.TP.X += poly.Normal.X * pi.Faab;
                }
                else if (a == 1)
                {
                    integrals.T1.Y += poly.Normal.Y * pi.Faa;
                    integrals.T2.Y += poly.Normal.Y * pi.Faaa;
                    integrals.TP.Y += poly.Normal.Y * pi.Faab;
                }
                else if (a == 2)
                {
                    integrals.T1.Z += poly.Normal.Z * pi.Faa;
                    integrals.T2.Z += poly.Normal.Z * pi.Faaa;
                    integrals.TP.Z += poly.Normal.Z * pi.Faab;
                }

                if (b == 0)
                {
                    integrals.T1.X += poly.Normal.X * pi.Fbb;
                    integrals.T2.X += poly.Normal.X * pi.Fbbb;
                    integrals.TP.X += poly.Normal.X * pi.Fbbc;
                }
                else if (b == 1)
                {
                    integrals.T1.Y += poly.Normal.Y * pi.Fbb;
                    integrals.T2.Y += poly.Normal.Y * pi.Fbbb;
                    integrals.TP.Y += poly.Normal.Y * pi.Fbbc;
                }
                else if (b == 2)
                {
                    integrals.T1.Z += poly.Normal.Z * pi.Fbb;
                    integrals.T2.Z += poly.Normal.Z * pi.Fbbb;
                    integrals.TP.Z += poly.Normal.Z * pi.Fbbc;
                }

                if (c == 0)
                {
                    integrals.T1.X += poly.Normal.X * pi.Fcc;
                    integrals.T2.X += poly.Normal.X * pi.Fccc;
                    integrals.TP.X += poly.Normal.X * pi.Fcca;
                }
                else if (c == 1)
                {
                    integrals.T1.Y += poly.Normal.Y * pi.Fcc;
                    integrals.T2.Y += poly.Normal.Y * pi.Fccc;
                    integrals.TP.Y += poly.Normal.Y * pi.Fcca;
                }
                else if (c == 2)
                {
                    integrals.T1.Z += poly.Normal.Z * pi.Fcc;
                    integrals.T2.Z += poly.Normal.Z * pi.Fccc;
                    integrals.TP.Z += poly.Normal.Z * pi.Fcca;
                }
            }

            integrals.T1 *= 0.5f;
            integrals.T2 *= (1.0f / 3.0f);
            integrals.TP *= 0.5f;

            return(integrals);
        }