Beispiel #1
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
const ShaderInstance ForceField::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    for (element = element->FirstChildElement(); element != 0; element = element->NextSiblingElement())
    {
        unsigned int typeHash = hashString(element->Value());
        if (Material::m_hash == typeHash)
        {
            shaderInstance.getMaterial().deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), element);
            shaderInstance.getMaterial().setBlendState(true);
        }
        else if (Vector3::m_hash == typeHash)
        {
            m_position.deserialise(element);
            translate(m_world, m_position.x(), m_position.y(), m_position.z());
        }
    }

    return shaderInstance;
}
Beispiel #2
0
void GunTurret::fireLaser()
{
    ShaderInstance shaderInstance;
    shaderInstance.setMaterial(Material(0.0f, Color::black(), Color::black(), Color::red(), Color::red()));
    shaderInstance.getMaterial().setBlendState(true);
    shaderInstance.getMaterial().setEffect(getGameResource().getEffectCache().getEffect("laser_effect.xml"));

    getWriteableGameResource().getLaserManager().addInstance(m_position + Vector3(0.0f, 3.0f, 0.0f), m_direction, shaderInstance);
}
Beispiel #3
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
const ShaderInstance GunTurret::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    Matrix44 scaleTransform, translation, rotation;
    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement())
    {
        unsigned int childElementHash = hashString(childElement->Value());
        if (childElementHash == Vector3::m_hash)
        {
            const tinyxml2::XMLAttribute* nameAttribute = childElement->FindAttribute("name"); //This material needs a name to distinguish between normal and glowing versions of the material
            if (nameAttribute)
            {
                if (strICmp(nameAttribute->Value(), "position"))
                {
                    m_position.deserialise(childElement);
                    
                    scale(scaleTransform, 5.0f, 5.0f, 5.0f);
                    translate(translation, m_position);  
                }
                else if( strICmp(nameAttribute->Value(), "direction") )
                {
                    m_direction.deserialise(childElement);
                    m_direction.normalize();
                    rotation = rotationFromDirection(m_direction);
                }
            }
        }
        if (childElementHash == hashString("Model"))
        {
            attribute = childElement->FindAttribute("file");
            if (attribute != nullptr)
            {
                //Heavily relies on the shader instance existing before we load the model, might be better to put the model construction in initialise instead
                m_drawableObject = getWriteableGameResource().getModelManager().LoadModel(m_resource, shaderInstance, attribute->Value());
                m_drawableObject->setDirty();
            }
        }
        if (childElementHash == Material::m_hash)
        {
            shaderInstance.getMaterial().deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement );
        }
    }

    m_world = rotation * scaleTransform * translation;

    return shaderInstance;
}
Beispiel #4
0
//-------------------------------------------------------------------------
// @brief 
//-------------------------------------------------------------------------
const ShaderInstance Core::deserialise( const tinyxml2::XMLElement* element)
{
    ShaderInstance shaderInstance;
    
    const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name");
    if (attribute != nullptr)
    {
        m_name = attribute->Value();
    }

    for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement())
    {
        unsigned int childElementHash = hashString(childElement->Value());
        if (childElementHash == Material::m_hash)
        {
            const tinyxml2::XMLAttribute* nameAttribute = childElement->FindAttribute("name"); //This material needs a name to distinguish between normal and glowing versions of the material
            if (nameAttribute)
            {
                if (strICmp(nameAttribute->Value(), "CoreMaterialNormal"))
                {
                    m_forcefieldmatnormal.deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                    shaderInstance.getMaterial().deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                    shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString("cube_player_forcefield"), Material::TextureSlotMapping::Diffuse0));
                }
                else if( strICmp(nameAttribute->Value(), "CoreMaterialNormalGlow") )
                {
                    m_forcefieldmatglowing.deserialise(m_resource, getGameResource().getDeviceManager(), getGameResource().getTextureManager(), getGameResource().getLightManager(), childElement);
                }
            }
        }
        else if (childElementHash == hashString("Model"))
        {
            attribute = childElement->FindAttribute("file_name");
            if (attribute != nullptr)
            {
                //Heavily relies on the shader instance existing before we load the model, might be better to put the model construction in initialise instead
                m_drawableObject = getWriteableGameResource().getModelManager().LoadModel(m_resource, shaderInstance, attribute->Value());
                m_drawableObject->setDirty();
            }
        }
    }

    //Get texture strings and load textures
    const SettingsManager& sm = getGameResource().getSettingsManager();
    TextureManager& tm = getWriteableGameResource().getTextureManager();
    const ISetting<std::string>* textureString = sm.getSetting<std::string>("Core");
    if (textureString)
    {
        tm.addLoad(getGameResource().getDeviceManager(), textureString->getData());
        shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString(getTextureNameFromFileName(textureString->getData())), Material::TextureSlotMapping::Diffuse0));
    }
    textureString = sm.getSetting<std::string>("ForceFieldCore");
    if (textureString)
    {
        tm.addLoad(getGameResource().getDeviceManager(), textureString->getData());
        shaderInstance.getMaterial().addTextureReference(Material::TextureSlotMapping(hashString(getTextureNameFromFileName(textureString->getData())), Material::TextureSlotMapping::Diffuse0));
    }

    return shaderInstance;
}
Beispiel #5
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void GunTurret::initialise(const ShaderInstance& shaderInstance)
{
    UNUSEDPARAM(shaderInstance);

    const SettingsManager& sm = getGameResource().getSettingsManager();
    const ISetting<std::string>* modelString = sm.getSetting<std::string>("Guns");
    if (modelString)
    {
        m_drawableObject = getWriteableGameResource().getModelManager().LoadModel(m_resource, shaderInstance, modelString->getData());
    }

    Super::initialise(shaderInstance);
}