Ejemplo n.º 1
0
// virtual
void SkeletonModel::renderJointCollisionShapes(float alpha) { 
    if (!_ragdoll) {
        return;
    }
    glPushMatrix();
    Application::getInstance()->loadTranslatedViewMatrix(_translation);
    glm::vec3 simulationTranslation = _ragdoll->getTranslationInSimulationFrame();
    for (int i = 0; i < _shapes.size(); i++) { 
        Shape* shape = _shapes[i];
        if (!shape) { 
            continue;
        } 

        auto geometryCache = DependencyManager::get<GeometryCache>();

        glPushMatrix();
        // shapes are stored in simulation-frame but we want position to be model-relative
        if (shape->getType() == SPHERE_SHAPE) { 
            glm::vec3 position = shape->getTranslation() - simulationTranslation;
            glTranslatef(position.x, position.y, position.z);
            // draw a grey sphere at shape position
            geometryCache->renderSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.75f, 0.75f, 0.75f, alpha));
        } else if (shape->getType() == CAPSULE_SHAPE) {
            CapsuleShape* capsule = static_cast<CapsuleShape*>(shape);

            // draw a blue sphere at the capsule endpoint                                         
            glm::vec3 endPoint;
            capsule->getEndPoint(endPoint);
            endPoint = endPoint - simulationTranslation;
            glTranslatef(endPoint.x, endPoint.y, endPoint.z);                                     
            geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.6f, 0.6f, 0.8f, alpha));

            // draw a yellow sphere at the capsule startpoint
            glm::vec3 startPoint;
            capsule->getStartPoint(startPoint);
            startPoint = startPoint - simulationTranslation;
            glm::vec3 axis = endPoint - startPoint;
            glTranslatef(-axis.x, -axis.y, -axis.z);
            geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.8f, 0.8f, 0.6f, alpha));

            // draw a green cylinder between the two points
            glm::vec3 origin(0.0f);
            Avatar::renderJointConnectingCone( origin, axis, capsule->getRadius(), capsule->getRadius(), glm::vec4(0.6f, 0.8f, 0.6f, alpha));
        }
        glPopMatrix();
    }
    glPopMatrix();
}