コード例 #1
0
 void CollisionShapeManager::SaveShapesToBinaryFile(const String& FileName, ShapeVector& ShapesToSave)
 {
     btDefaultSerializer* BulletSerializer = new btDefaultSerializer(1024*1024*5);
     BulletSerializer->startSerialization();
     for( ShapeVectorIterator it = ShapesToSave.begin() ; it != ShapesToSave.end() ; it++ )
     {
         Physics::CollisionShape* Shape = (*it);
         BulletSerializer->registerNameForPointer((void*)Shape->_GetInternalShape(),(*it)->GetName().c_str());
         int len = Shape->_GetInternalShape()->calculateSerializeBufferSize();
         btChunk* chunk = BulletSerializer->allocate(len,1);
         const char* structType = Shape->_GetInternalShape()->serialize(chunk->m_oldPtr, BulletSerializer);
         BulletSerializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,Shape->_GetInternalShape());
     }
     BulletSerializer->finishSerialization();
     FILE* f2 = fopen(FileName.c_str(),"wb");
     fwrite(BulletSerializer->getBufferPointer(),BulletSerializer->getCurrentBufferSize(),1,f2);
     fclose(f2);
 }
コード例 #2
0
        void CollisionShapeManager::SaveShapesToXMLFile(const String& FileName, ShapeVector& ShapesToSave)
        {
            XML::Document ShapesDoc;
            XML::Node DeclNode = ShapesDoc.AppendChild(XML::NodeDeclaration);
            XML::Attribute VerAttrib = DeclNode.AppendAttribute("version");

            if( DeclNode.SetName("xml") && VerAttrib.SetValue("1.0") ) {
                XML::Node ShapesRoot = ShapesDoc.AppendChild( "ShapesRoot" );
                for( ShapeVectorIterator ShapeIt = ShapesToSave.begin() ; ShapeIt != ShapesToSave.end() ; ++ShapeIt )
                {
                    (*ShapeIt)->ProtoSerialize( ShapesRoot );
                }

                /// @todo Replace this stack allocated stream for one initialized from the Resource Manager, after the system is ready.
                Resource::FileStream SettingsStream(FileName,".",Resource::SF_Truncate | Resource::SF_Write);
                ShapesDoc.Save(SettingsStream,"\t",XML::FormatIndent);
            }else{
                MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"Failed to create XML document declaration for file \"" + FileName + "\".");
            }
        }
コード例 #3
0
ファイル: raytracer.cpp プロジェクト: tkohlman/rad-raytracing
Intersection *Raytracer::get_closest_intersection(Scene *scene, const Ray &ray)
{
    ShapeVector *shapes = scene->shapes();
    ShapeIterator iter = shapes->begin();
    Intersection *closest_intersection = nullptr;

    for (; iter != shapes->end(); ++iter)
    {
        // Calculate the intersection with this shape
        Ray *intersection = (*iter)->intersect(ray);

        if (intersection != nullptr)
        {
            // Check if this intersection is closer
            if ((closest_intersection == nullptr) ||
                (distance_between(ray.vertex(),
                                 intersection->vertex()) <
                 distance_between(ray.vertex(),
                                 closest_intersection->intersection_point())))
            {
                // Latest intersection is closer
                if (closest_intersection != nullptr)
                    delete closest_intersection;

                closest_intersection = new Intersection(
                                            intersection->vertex(),
                                            intersection->direction(),
                                            *iter);
            }
            delete intersection;
            intersection = nullptr;
        }
    }

    return closest_intersection;
}