Beispiel #1
0
bool CCharShape::CheckPolyhedronCollision (TCharNode *node, TMatrix modelMatrix, 
		TMatrix invModelMatrix, TPolyhedron ph) {

    TMatrix newModelMatrix, newInvModelMatrix;
    TCharNode *child;
    TPolyhedron newph;
    bool hit = false;

    MultiplyMatrices (newModelMatrix, modelMatrix, node->trans);
    MultiplyMatrices (newInvModelMatrix, node->invtrans, invModelMatrix);

    if  (node->visible) {
        newph = CopyPolyhedron (ph);
        TransPolyhedron (newInvModelMatrix, newph);
        hit = IntersectPolyhedron (newph);
        FreePolyhedron (newph);
    } 

    if (hit == true) return hit;
    child = node->child;
    while (child != NULL) {
        hit = CheckPolyhedronCollision (child, newModelMatrix, newInvModelMatrix, ph);
        if  (hit == true) return hit;
        child = child->next;
    } 
    return false;
}
bool CCharShape::CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4, 4>& modelMatrix,
        const TMatrix<4, 4>& invModelMatrix, const TPolyhedron& ph) {
	bool hit = false;

	TMatrix<4, 4> newModelMatrix = modelMatrix * node->trans;
	TMatrix<4, 4> newInvModelMatrix = node->invtrans * invModelMatrix;

	if (node->visible) {
		TPolyhedron newph = ph;
		TransPolyhedron (newInvModelMatrix, newph);
		hit = IntersectPolyhedron (newph);
	}

	if (hit == true) return hit;
	const TCharNode *child = node->child;
	while (child != NULL) {
		hit = CheckPolyhedronCollision (child, newModelMatrix, newInvModelMatrix, ph);
		if (hit == true) return hit;
		child = child->next;
	}
	return false;
}