Ejemplo n.º 1
0
        //Mutators

        public void fixCenterAndRadius()
        {
            //Calculate the centroid
            /* We plan to divide by vertCount, so don't allow it to be zero. */
            if (vertCount() == 0)
            {
                return;
            }
            cVector3 centroid = new cVector3(); //Default constuctor starts at zeroVector.

            foreach (cVector3 v in _vectorvert)
            {
                centroid.addassign(_vectorvert.ElementAt());
            }
            centroid.divassign(vertCount()); // We already made sure this divisor isn't zero.
            //Move the centroid to the origin
            foreach (cVector3 v in _vectorvert)
            {
                _vectorvert.ElementAt().subassign(centroid);
            }
            //Fix Radius as furthest vertex from the origin.
            float distance = 0.0f; //Start with this and look for the biggest one.
            float testdistance;

            foreach (cVector3 v in _vectorvert)
            {
                testdistance = v.Magnitude;
                if (testdistance > distance)
                {
                    distance = testdistance;
                }
            }
            _radius = distance; //_radius is a raw number.
            _fixConvex();
        }
Ejemplo n.º 2
0
        public cDistanceAndDirection distanceAndDirection(cCritter pa, cCritter pb)
        {
            cVector3 dir      = pb.Position.sub(pa.Position);
            float    distance = dir.Magnitude;

            if (distance > 0.00001f)
            {
                dir.divassign(distance);
            }
            else
            {
                dir = new cVector3(1.0f, 0.0f);                   //default unit vector
            }
            return(new cDistanceAndDirection(distance, dir));
        }