Пример #1
0
void PCamera::setViewport(pfloat32 x, pfloat32 y, pfloat32 width, pfloat32 height)
{
    m_viewport = pVector4(x, y, width, height);

    switch (m_projection.projection())
    {
        case P_PROJECTION_PERSPECTIVE:
            {
                pfloat32 aspect = width / height;
                m_projection.perspective(m_projection.fov(), 
                                         aspect, 
                                         m_projection.zNear(), 
                                         m_projection.zFar());
            }
            break;
        case P_PROJECTION_ORTHOGONAL:
            {
                pfloat32 aspect = width / height;
                m_projection.orthogonal(aspect, 
                                        m_projection.zNear(), 
                                        m_projection.zFar());
            }
            break;
        case P_PROJECTION_WINDOW:
            m_projection.window(width, height);
            break;
        default:
            PASSERT_NOTREACHABLE("Unknown projection type.");
            break;
    }
}
Пример #2
0
PBackground::PBackground(const pchar *name, PScene *scene)
    : PDrawable(name, scene, P_DRAWABLE_PRIORITY_DRAWLAST)
{
    P_OBJECT_INITIALIZE_PROPERTY(PDrawable)
    
    PResourceManager *resourceManager = scene->context()->module<PResourceManager>("resource-manager");

    m_texture  = P_NULL;

    setGeometry(PNEW(PGeometryPlane(resourceManager)));
    setMaterial(PNEW(PMaterial("internal/background.pmt", PBACKGROUND_PMT, false, resourceManager)));

    m_textureInfo = pVector4(1, 1, 0, 0);
    m_sizeInfo    = pVector4(1, 1, 0, 0);
    m_layout      = (LAYOUT_CENTER | LAYOUT_MIDDLE);  
    m_dirty       = true;
}
Пример #3
0
void PCamera::oblique(const PPlane &plane)
{
    PMatrix4x4 inversedProjection = m_projection.toInversedMatrix4x4();
    PVector4 q = inversedProjection * pVector4(pSign(plane.A()), pSign(plane.B()), 1.0f, 1.0f);
    PVector4 c = plane.toVector4() * 2.0f * (1.0f / (plane.toVector4().dot(q)));

    // New projection matrix.
    PMatrix4x4 proj = m_projection.toMatrix4x4();

    proj.m_m[2]  = c[0] - proj.m_m[3];
    proj.m_m[6]  = c[1] - proj.m_m[7];
    proj.m_m[10] = c[2] - proj.m_m[11];
    proj.m_m[14] = c[3] - proj.m_m[15];

    m_projection.setMatrix4x4(proj.m_m);
}