Пример #1
0
QJsonObject HeadData::toJson() const {
    QJsonObject headJson;
    const auto& blendshapeLookupMap = getBlendshapesLookupMap();
    QJsonObject blendshapesJson;
    for (auto name : blendshapeLookupMap.keys()) {
        auto index = blendshapeLookupMap[name];
        if (index >= _blendshapeCoefficients.size()) {
            continue;
        }
        auto value = _blendshapeCoefficients[index];
        if (value == 0.0f) {
            continue;
        }
        blendshapesJson[name] = value;
    }
    if (!blendshapesJson.isEmpty()) {
        headJson[JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS] = blendshapesJson;
    }
    if (getRawOrientation() != quat()) {
        headJson[JSON_AVATAR_HEAD_ROTATION] = toJsonValue(getRawOrientation());
    }
    if (getLeanForward() != 0.0f) {
        headJson[JSON_AVATAR_HEAD_LEAN_FORWARD] = getLeanForward();
    }
    if (getLeanSideways() != 0.0f) {
        headJson[JSON_AVATAR_HEAD_LEAN_SIDEWAYS] = getLeanSideways();
    }
    auto lookat = getLookAtPosition();
    if (lookat != vec3()) {
        vec3 relativeLookAt = glm::inverse(_owningAvatar->getOrientation()) *
            (getLookAtPosition() - _owningAvatar->getPosition());
        headJson[JSON_AVATAR_HEAD_LOOKAT] = toJsonValue(relativeLookAt);
    }
    return headJson;
}
Пример #2
0
QJsonObject HeadData::toJson() const {
    QJsonObject headJson;
    const auto& blendshapeLookupMap = getBlendshapesLookupMap();
    QJsonObject blendshapesJson;
    for (auto name : blendshapeLookupMap.keys()) {
        auto index = blendshapeLookupMap[name];
        float value = 0.0f;
        if (index < _blendshapeCoefficients.size()) {
            value += _blendshapeCoefficients[index];
        }
        if (index < _transientBlendshapeCoefficients.size()) {
            value += _transientBlendshapeCoefficients[index];
        }
        if (value != 0.0f) {
            blendshapesJson[name] = value;
        }
    }
    if (!blendshapesJson.isEmpty()) {
        headJson[JSON_AVATAR_HEAD_BLENDSHAPE_COEFFICIENTS] = blendshapesJson;
    }
    if (getRawOrientation() != quat()) {
        headJson[JSON_AVATAR_HEAD_ROTATION] = toJsonValue(getRawOrientation());
    }
    auto lookat = getLookAtPosition();
    if (lookat != vec3()) {
        vec3 relativeLookAt = glm::inverse(_owningAvatar->getOrientation()) *
            (getLookAtPosition() - _owningAvatar->getPosition());
        headJson[JSON_AVATAR_HEAD_LOOKAT] = toJsonValue(relativeLookAt);
    }
    return headJson;
}
Пример #3
0
// -------------------------------------------------------------------------------------------------------- 
void KPerspectiveProjection::rotate ( const GLfloat x, const GLfloat y, const GLfloat z )
{
    KVector savePos = getLookAtPosition();
    translate(-getPosition());
        
    KVector up   = getYVector();
    KVector look = getZVector();

    KMatrix rotxz; rotxz.rotate (x, 0.0, z);
    KMatrix roty;  roty.rotate  (0.0, y, 0.0);

    KVector yunit(0.0, 1.0, 0.0), zunit (0.0, 0.0, 1.0);

    KVector lookperp = look.perpendicular (yunit); // y-axis rotation    
    if (lookperp.length() > 0)
    {
        look = roty * lookperp + look.parallel(yunit);
        up   = roty * up.perpendicular(yunit) + up.parallel(yunit);
    }
    
    // x & z-axis rotation 
    KMatrix transmat(up.cross(look), up, look);
    
    KVector uprotxz   = rotxz * yunit;
    KVector lookrotxz = rotxz * zunit;

    up   = transmat * uprotxz;
    look = transmat * lookrotxz;
    
    *((KMatrix*)this) = KMatrix(up.cross(look), up, look);
    
    setPosition( savePos + eye_distance * getZVector());
}
void LookAtTransformationElement::calcMatrix(Matrix &result) const
{
    MatrixLookAt(result, 
                 getEyePosition(), 
                 getLookAtPosition(), 
                 getUpDirection()   );
}
Пример #5
0
// --------------------------------------------------------------------------------------------------------
void KPerspectiveProjection::apply ()
{
    glViewport(vp[0], vp[1], vp[2], vp[3]);
    
    gluPerspective (fov, getCurrentAspectRatio(), znear, zfar);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    KVector lookAt = getLookAtPosition();

    gluLookAt(	matrix[TX], matrix[TY], matrix[TZ],
                lookAt[X], lookAt[Y], lookAt[Z],
                matrix[4], matrix[5], matrix[6]);
}
Пример #6
0
// --------------------------------------------------------------------------------------------------------
void KPerspectiveProjection::setEyeDistance ( GLfloat ed )
{
    KVector lookAtPos = getLookAtPosition();
    eye_distance = kMin( kMax(znear, ed), 0.9 * zfar );
    setPosition(lookAtPos + eye_distance * getZVector());
}