Exemplo n.º 1
0
// temporary
bool OnLoadCustomShapeResource(ResourceBase* pRes, void* pData)
{
    CollisionShape* pShape = (CollisionShape*)pRes;

    if (strcmp(pShape->GetName(), "shape_floor") == 0)
    {
        pShape->AddBox(Vector(100.0f, 10.0f, 100.0f), MatrixIdentity());
    }
    else if (strcmp(pShape->GetName(), "shape_box") == 0)
    {
        pShape->AddBox(Vector(0.25f, 0.25f, 0.25f), MatrixIdentity());
    }
    else if (strcmp(pShape->GetName(), "shape_frame") == 0)
    {
        // Z axis
        pShape->AddBox(Vector(0.025f, 0.025f, 0.45f), MatrixTranslation3(Vector(-0.475f, -0.475f, 0.0f)));
        pShape->AddBox(Vector(0.025f, 0.025f, 0.45f), MatrixTranslation3(Vector(-0.475f, 0.475f, 0.0f)));
        pShape->AddBox(Vector(0.025f, 0.025f, 0.45f), MatrixTranslation3(Vector(0.475f, -0.475f, 0.0f)));
        pShape->AddBox(Vector(0.025f, 0.025f, 0.45f), MatrixTranslation3(Vector(0.475f, 0.475f, 0.0f)));

        // Y axis
        pShape->AddBox(Vector(0.025f, 0.5f, 0.025f), MatrixTranslation3(Vector(-0.475f, 0.0f, -0.475f)));
        pShape->AddBox(Vector(0.025f, 0.5f, 0.025f), MatrixTranslation3(Vector(-0.475f, 0.0f, 0.475f)));
        pShape->AddBox(Vector(0.025f, 0.5f, 0.025f), MatrixTranslation3(Vector(0.475f, 0.0f, -0.475f)));
        pShape->AddBox(Vector(0.025f, 0.5f, 0.025f), MatrixTranslation3(Vector(0.475f, 0.0f, 0.475f)));

        // X axis
        pShape->AddBox(Vector(0.5f, 0.025f, 0.025f), MatrixTranslation3(Vector(0.0f, -0.475f, -0.475f)));
        pShape->AddBox(Vector(0.5f, 0.025f, 0.025f), MatrixTranslation3(Vector(0.0f, -0.475f, 0.475f)));
        pShape->AddBox(Vector(0.5f, 0.025f, 0.025f), MatrixTranslation3(Vector(0.0f, 0.475f, -0.475f)));
        pShape->AddBox(Vector(0.5f, 0.025f, 0.025f), MatrixTranslation3(Vector(0.0f, 0.475f, 0.475f)));
    }
    else if (strcmp(pShape->GetName(), "shape_barrel") == 0)
    {
        pShape->AddCylinder(1.31f, 0.421f);
    }

    return true;
}
Exemplo n.º 2
0
        void CollisionShapeManager::LoadAllShapesFromXMLFile(const String& FileName, const String& Group)
        {
            /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready.
            Resource::FileStream ShapesStream( FileName, Resource::ResourceManager::GetSingletonPtr()->GetAssetPath(FileName,Group) );
            XML::Document ShapesDoc;
            XML::ParseResult DocResult = ShapesDoc.Load(ShapesStream);
            if( DocResult.Status != XML::StatusOk ) {
                MEZZ_EXCEPTION(ExceptionBase::SYNTAX_ERROR_EXCEPTION_XML,"Failed to parse XML file \"" + FileName + "\".");
            }
            XML::Node ShapesRoot = ShapesDoc.GetChild("InitializerRoot");
            if( ShapesRoot.Empty() ) {
                MEZZ_EXCEPTION(ExceptionBase::SYNTAX_ERROR_EXCEPTION_XML,"Failed to find expected Root node in \"" + FileName + "\".");
            }

            for( XML::NodeIterator ShapeIt = ShapesRoot.begin() ; ShapeIt != ShapesRoot.end() ; ++ShapeIt )
            {
                CollisionShape* DeSerializedShape = Physics::CreateShape( (*ShapeIt) );
                this->CollisionShapes.insert( std::pair<String,CollisionShape*>(DeSerializedShape->GetName(),DeSerializedShape) );
            }
        }