Exemplo n.º 1
0
/**
 * Take the rotation from a 4x4 transformation matrix, and return it as an axis and an angle (in radians)
 * returns the output axis.
 */
kmVec3* kmMat4RotationToAxisAngle(kmVec3* pAxis, kmScalar* radians, const kmMat4* pIn)
{
    /*Surely not this easy?*/
    kmQuaternion temp;
    kmMat3 rotation;
    kmMat4ExtractRotationMat3(pIn, &rotation);
    kmQuaternionRotationMatrix(&temp, &rotation);
    kmQuaternionToAxisAngle(&temp, pAxis, radians);
    return pAxis;
}
Exemplo n.º 2
0
kmQuaternion* kmQuaternionLookRotation(kmQuaternion* pOut, const kmVec3* direction, const kmVec3* upDirection) {
    kmMat4 lookAt;
    kmMat3 rot;
    kmMat4LookAt(&lookAt, &KM_VEC3_ZERO, direction, upDirection);

    kmMat4ExtractRotationMat3(&lookAt, &rot);

    kmQuaternionRotationMatrix(pOut, &rot);
    kmQuaternionNormalize(pOut, pOut);
    return pOut;
}
Exemplo n.º 3
0
/*
 * FIXME: Stupid argument ordering
 */
void GenericRenderer::set_auto_uniforms_on_shader(GPUProgram& program,
    CameraID camera,
    Renderable &subactor) {

    //Calculate the modelview-projection matrix
    Mat4 modelview_projection;
    Mat4 modelview;

    const Mat4 model = subactor.final_transformation();
    const Mat4& view = window().camera(camera)->view_matrix();
    const Mat4& projection = window().camera(camera)->projection_matrix();

    kmMat4Multiply(&modelview, &view, &model);
    kmMat4Multiply(&modelview_projection, &projection, &modelview);

    if(program.uniforms().uses_auto(SP_AUTO_VIEW_MATRIX)) {
        program.uniforms().set_mat4x4(
            program.uniforms().auto_variable_name(SP_AUTO_VIEW_MATRIX),
            view
        );
    }

    if(program.uniforms().uses_auto(SP_AUTO_MODELVIEW_PROJECTION_MATRIX)) {
        program.uniforms().set_mat4x4(
            program.uniforms().auto_variable_name(SP_AUTO_MODELVIEW_PROJECTION_MATRIX),
            modelview_projection
        );
    }

    if(program.uniforms().uses_auto(SP_AUTO_MODELVIEW_MATRIX)) {
        program.uniforms().set_mat4x4(
            program.uniforms().auto_variable_name(SP_AUTO_MODELVIEW_MATRIX),
            modelview
        );
    }

    if(program.uniforms().uses_auto(SP_AUTO_PROJECTION_MATRIX)) {
        program.uniforms().set_mat4x4(
            program.uniforms().auto_variable_name(SP_AUTO_PROJECTION_MATRIX),
            projection
        );
    }

    if(program.uniforms().uses_auto(SP_AUTO_INVERSE_TRANSPOSE_MODELVIEW_MATRIX)) {
        Mat3 inverse_transpose_modelview;

        kmMat4ExtractRotationMat3(&modelview, &inverse_transpose_modelview);
        kmMat3Inverse(&inverse_transpose_modelview, &inverse_transpose_modelview);
        kmMat3Transpose(&inverse_transpose_modelview, &inverse_transpose_modelview);

        program.uniforms().set_mat3x3(
            program.uniforms().auto_variable_name(SP_AUTO_INVERSE_TRANSPOSE_MODELVIEW_MATRIX),
            inverse_transpose_modelview
        );
    }
/*
    if(pass.uses_auto_uniform(SP_AUTO_MATERIAL_AMBIENT)) {
        pass.program()->uniforms().set_colour(
            pass.auto_uniform_variable_name(SP_AUTO_MATERIAL_AMBIENT),
            pass.ambient()
        );
    }

    if(pass.uses_auto_uniform(SP_AUTO_MATERIAL_DIFFUSE)) {
        pass.program()->uniforms().set_colour(
            pass.auto_uniform_variable_name(SP_AUTO_MATERIAL_DIFFUSE),
            pass.diffuse()
        );
    }

    if(pass.uses_auto_uniform(SP_AUTO_MATERIAL_SPECULAR)) {
        pass.program()->uniforms().set_colour(
            pass.auto_uniform_variable_name(SP_AUTO_MATERIAL_SPECULAR),
            pass.specular()
        );
    }

    if(pass.uses_auto_uniform(SP_AUTO_MATERIAL_SHININESS)) {
        pass.program()->uniforms().set_float(
            pass.auto_uniform_variable_name(SP_AUTO_MATERIAL_SHININESS),
            pass.shininess()
        );
    }

    if(pass.uses_auto_uniform(SP_AUTO_MATERIAL_ACTIVE_TEXTURE_UNITS)) {
        pass.program()->uniforms().set_int(
            pass.auto_uniform_variable_name(SP_AUTO_MATERIAL_ACTIVE_TEXTURE_UNITS),
            pass.texture_unit_count()
        );
    }*/
}