示例#1
0
        public TriangleShape(PosVector position, PosVector vb, PosVector vc, BaseMaterial frontMaterial,
                             BaseMaterial backMaterial) : base(position)
        {
            VB             = vb;
            VC             = vc;
            _frontMaterial = frontMaterial;
            _backMaterial  = backMaterial;

            EdgeAb = VB - VA;
            EdgeBc = VC - VB;
            EdgeCa = VA - VC;

            Normal    = EdgeAb.Dot(EdgeBc) < EdgeBc.Dot(EdgeCa) ? EdgeAb.Cross(EdgeBc) : EdgeBc.Cross(EdgeCa);
            Magnitude = Normal.Magnitude();
            if (Magnitude > 0.0)
            {
                Normal = Normal / Magnitude; // unit vector to triangle plane
            }

            PlaneCoefficient = Normal.Dot(VA); // same coeff for all three vertices

            var a    = EdgeAb.MagnitudeSquared();
            var b    = EdgeAb.Dot(EdgeCa);
            var c    = EdgeCa.MagnitudeSquared();
            var dinv = 1.0 / (a * c - b * b);

            a = a * dinv;
            b = b * dinv;
            c = c * dinv;

            Ubeta  = (EdgeAb * c).AddScaled(EdgeCa, -b);
            Ugamma = (EdgeCa * -a).AddScaled(EdgeAb, b);
        }
示例#2
0
 public SphereShape(PosVector position, double radius, BaseMaterial material) : base(position)
 {
     Radius    = radius;
     _material = material;
 }