pbool PPropertyColor::unpack(const pchar *value)
{
    const pchar *p = value;

    pfloat32 r;
    pfloat32 g;
    pfloat32 b;
    pfloat32 a;

    if ((p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
        (p = pStringUnpackFloat(p, &r)) != P_NULL &&
        (p = pStringUnpackFloat(p, &g)) != P_NULL &&
        (p = pStringUnpackFloat(p, &b)) != P_NULL &&
        (p = pStringUnpackFloat(p, &a)) != P_NULL)
    {
        m_r = r;
        m_g = g;
        m_b = b;
        m_a = a;

        return true;
    }
        
    PLOG_ERROR("Failed to unpack a color property called %s", name());
    return false;
}
pbool PPropertyTransform::unpack(const pchar *value)
{
    const pchar *p = value;
    pfloat32 sx, sy, sz;
    pfloat32 rx, ry, rz;
    pfloat32 tx, ty, tz;

    if ((p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
            (p = pStringUnpackFloat(p, &sx)) != P_NULL &&
            (p = pStringUnpackFloat(p, &sy)) != P_NULL &&
            (p = pStringUnpackFloat(p, &sz)) != P_NULL &&
            (p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
            (p = pStringUnpackFloat(p, &rx)) != P_NULL &&
            (p = pStringUnpackFloat(p, &ry)) != P_NULL &&
            (p = pStringUnpackFloat(p, &rz)) != P_NULL &&
            (p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
            (p = pStringUnpackFloat(p, &tx)) != P_NULL &&
            (p = pStringUnpackFloat(p, &ty)) != P_NULL &&
            (p = pStringUnpackFloat(p, &tz)) != P_NULL)
    {
        m_translationx = tx;
        m_translationy = ty;
        m_translationz = tz;

        m_scalingx = sx;
        m_scalingy = sy;
        m_scalingz = sz;

        m_rotationx = rx;
        m_rotationy = ry;
        m_rotationz = rz;

        m_dirty = true;

        return true;
    }

    PLOG_ERROR("Failed to unpack a transform property called %s", name());
    return false;
}
示例#3
0
pbool PCamera::unpack(const PXmlElement* xmlElement)
{
    if (PNode::unpack(xmlElement))
    {
        // When the aspect, width or height of the projection is left to be default value,
        // we need to explicitly set them.
        const puint32 *rect = scene()->viewport();
        if (m_projection.projection() == P_PROJECTION_ORTHOGONAL)
        {
            if (m_projection.aspect() < 0)
            {
                pfloat32 aspect = ((pfloat32)rect[2] / (pfloat32)rect[3]);
                m_projection.orthogonal(aspect, m_projection.zNear(), m_projection.zFar());
            }
        }
        else if (m_projection.projection() == P_PROJECTION_PERSPECTIVE)
        {
            if (m_projection.aspect() < 0)
            {
                pfloat32 aspect = ((pfloat32)rect[2] / (pfloat32)rect[3]);
                m_projection.perspective(m_projection.fov(), aspect, m_projection.zNear(), m_projection.zFar());
            }
        }
        else if (m_projection.projection() == P_PROJECTION_WINDOW)
        {
            if (m_projection.width() < 0 || m_projection.height())
            {
                m_projection.window((pfloat32)rect[2], (pfloat32)rect[3]);
            }
        }
        else
        {
            PASSERT_NOTREACHABLE("Unknown projection type.");
        }

        // See if there is any lookat attribute and the transform attribute is not used.
        // In this case, the lookat property will be used to set the transform the camera.
        const pchar *lookatValue = xmlElement->attribute("lookat");
        const pchar *transformValue = xmlElement->attribute("transform");
        if (lookatValue != P_NULL && transformValue == P_NULL)
        {
            const pchar *p = lookatValue;

            pfloat32 eyex, eyey, eyez;
            pfloat32 centerx, centery, centerz;
            pfloat32 upx, upy, upz;

            if ((p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
                (p = pStringUnpackFloat(p, &eyex)) != P_NULL &&
                (p = pStringUnpackFloat(p, &eyey)) != P_NULL &&
                (p = pStringUnpackFloat(p, &eyez)) != P_NULL &&
                (p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
                (p = pStringUnpackFloat(p, &centerx)) != P_NULL &&
                (p = pStringUnpackFloat(p, &centery)) != P_NULL &&
                (p = pStringUnpackFloat(p, &centerz)) != P_NULL &&
                (p = pStringUnpackTrimAnnotation(p)) != P_NULL &&
                (p = pStringUnpackFloat(p, &upx)) != P_NULL &&
                (p = pStringUnpackFloat(p, &upy)) != P_NULL &&
                (p = pStringUnpackFloat(p, &upz)) != P_NULL)
            {
                m_localTransform.setLookAt(eyex, eyey, eyez,
                                           centerx, centery, centerz,
                                           upx, upy, upz);
            }
            else
            {
                PLOG_ERROR("The camera %s has a valid lookat property in the xml node.", m_name.toString().c_str());
            }
        }

        return true;
    }

    return false;
}