예제 #1
0
// Gets some vector d and finds the furthest point of shape along that direction using projection method
Util::Point SteerLib::GJK_EPA::getFurthestPointinDirection(const std::vector<Util::Vector>& _shape, const Util::Vector & d)
{
	Util::Point furthestPoint(0, 0, 0);
	float greatestProjectionMagnitude = 0;

	// Finds Furthest Point By iterating through the list
	for (std::vector<Util::Vector>::const_iterator it = _shape.begin(); it != _shape.end(); ++it)
	{
		//compute the dot product, whhich gets the projection of the shape vector onto 
		float magnitude = ((*it) * d);

		if (magnitude > greatestProjectionMagnitude)
		{
			greatestProjectionMagnitude = magnitude;
			furthestPoint = Util::Point((*it).x, (*it).y, (*it).z);
		}
	}
	return furthestPoint;
}
예제 #2
0
Util::Vector SteerLib::GJK_EPA::Minkowski_Helper(const std::vector<Util::Vector>& shape, const Util::Vector& direction) {
    
    Util::Vector furthestPoint(0, 0, 0);
    float farthestDistance = dot(shape[0], direction);
    int farthestIndex = 0;

    int i = 1;
    while (i < shape.size()) {
        float dotProduct = dot(shape[i], direction);
        if (dotProduct > farthestDistance) {
            farthestDistance = dotProduct;
            farthestIndex = i;
        }
        i++;
    }
    
    furthestPoint[0] = shape[farthestIndex][0];
    furthestPoint[1] = shape[farthestIndex][1];
    furthestPoint[2] = shape[farthestIndex][2];
    
    return furthestPoint;
}