const OgreNewt::MaterialID* PhysicsManager::createMaterialID(const Ogre::String& materialname) { const OgreNewt::MaterialID* materialid = NULL; if ((materialid = getMaterialID(materialname)) == NULL) { materialid = new OgreNewt::MaterialID(mWorld); mMaterials.insert( MaterialMapPair(materialname, materialid) ); } return materialid; }
void writeRectangle(rectangle_struct* rec, FILE* f) { if(!rec || !f)return; writeVect(rec->position,f); writeVect(rec->size,f); writeVect(rec->normal,f); fwrite(&rec->portalable,sizeof(bool),1,f); u16 mid=getMaterialID(rec->material); fwrite(&mid,sizeof(u16),1,f); }
void PhysicsManager::addLevelGeometry( Ogre::Entity* levelEntity, const std::vector<OgreNewt::CollisionPtr> &collisions) { RlAssert1(levelEntity); RlAssert1(levelEntity->getParentSceneNode()); SceneNode* node = levelEntity->getParentSceneNode(); //Level entity has to be attached to a scene node. // try one compound collision for the entity if there are several collisions OgreNewt::CollisionPtr collision; switch( collisions.size() ) { case 0: break; case 1: collision = collisions[0]; break; default: collision = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::CompoundCollision(mWorld, collisions, 0)); break; } if( collision ) { OgreNewt::Body* body = new OgreNewt::Body(mWorld, collision ); body->attachNode(node); body->setPositionOrientation(node->_getDerivedPosition(), node->_getDerivedOrientation()); body->setMaterialGroupID(getMaterialID("level")); mLevelBodiesQuadTree.add(body); //mLevelBodies.push_back(body); } // adjust worldAABB Vector3 minV(mWorldAABB.getMinimum()); Vector3 maxV(mWorldAABB.getMaximum()); AxisAlignedBox entityAABB = levelEntity->getWorldBoundingBox(true); minV.makeFloor(entityAABB.getMinimum()); maxV.makeCeil(entityAABB.getMaximum()); mWorldAABB.setMinimum(minV - Vector3(50, 50, 50)); mWorldAABB.setMaximum(maxV + Vector3(50, 50, 50)); mWorld->setWorldSize(mWorldAABB); }
PhysicsManager::PhysicsManager( ) : mEnabled(false), mPhysicalThings(), mDebugMode(0), mGravity(0, -9.81, 0), mTimeFactor(1.0f), mWorldAABB(Vector3(-100, -100, -100), Vector3(100, 100, 100)), mElapsed(0.0f), mMinTimestep(1.0f/600.0f), mMaxTimestep(1.0f/30.0f), mGenericCallback(), mPhysicsCollisionFactory(new PhysicsCollisionFactory()) { mWorld = new OgreNewt::World(); mWorld->setFrictionModel(OgreNewt::World::FM_ADAPTIVE); mWorld->setSolverModel(OgreNewt::World::SM_ADAPTIVE); //mWorld->setSolverModel(4); // setup materials: default<->default const OgreNewt::MaterialID* defaultID = mWorld->getDefaultMaterialID(); mMaterials.insert(MaterialMapPair("default", defaultID)); OgreNewt::MaterialPair* mDefaultPair = createMaterialPair( defaultID, defaultID ); mGenericCallback = new PhysicsGenericContactCallback(); mDefaultPair->setContactCallback(mGenericCallback); mDefaultPair->setDefaultFriction(0.85f, 0.80f); // setup level material createMaterialID("level"); mWorld->getDebugger().setMaterialColor(getMaterialID("level"), Ogre::ColourValue::Blue); // below here starts 'old' stale fix code that should be removed // setup level quadtree extents mLevelBodiesQuadTree.setMaxData(20); mLevelBodiesQuadTree.setMaxDepth(10); mLevelBodiesQuadTree.setLoosenessFactor(0.5f); mLevelBodiesQuadTree.setExtents(Ogre::Vector2(-100,-100), Ogre::Vector2(100,100)); }
void Renderer::visitRenderQueue(const RenderQueue& queue) { ssize_t size = queue.size(); for (ssize_t index = 0; index < size; ++index) { auto command = queue[index]; auto commandType = command->getType(); if(RenderCommand::Type::QUAD_COMMAND == commandType) { flush3D(); auto cmd = static_cast<QuadCommand*>(command); //Batch quads if(_numQuads + cmd->getQuadCount() > VBO_SIZE) { CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() < VBO_SIZE, "VBO is not big enough for quad data, please break the quad data down or use customized render command"); //Draw batched quads if VBO is full drawBatchedQuads(); } _batchedQuadCommands.push_back(cmd); memcpy(_quads + _numQuads, cmd->getQuads(), sizeof(V3F_C4B_T2F_Quad) * cmd->getQuadCount()); convertToWorldCoordinates(_quads + _numQuads, cmd->getQuadCount(), cmd->getModelView()); _numQuads += cmd->getQuadCount(); } else if(RenderCommand::Type::GROUP_COMMAND == commandType) { flush(); int renderQueueID = ((GroupCommand*) command)->getRenderQueueID(); visitRenderQueue(_renderGroups[renderQueueID]); } else if(RenderCommand::Type::CUSTOM_COMMAND == commandType) { flush(); auto cmd = static_cast<CustomCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::BATCH_COMMAND == commandType) { flush(); auto cmd = static_cast<BatchCommand*>(command); cmd->execute(); } else if (RenderCommand::Type::MESH_COMMAND == commandType) { flush2D(); auto cmd = static_cast<MeshCommand*>(command); if (_lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID()) { flush3D(); cmd->preBatchDraw(); cmd->batchDraw(); _lastBatchedMeshCommand = cmd; } else { cmd->batchDraw(); } } else { CCLOGERROR("Unknown commands in renderQueue"); } } }
void Renderer::processRenderCommand(RenderCommand* command) { auto commandType = command->getType(); if( RenderCommand::Type::TRIANGLES_COMMAND == commandType) { //Draw if we have batched other commands which are not triangle command flush3D(); flushQuads(); //Process triangle command auto cmd = static_cast<TrianglesCommand*>(command); //Draw batched Triangles if necessary if(cmd->isSkipBatching() || _filledVertex + cmd->getVertexCount() > VBO_SIZE || _filledIndex + cmd->getIndexCount() > INDEX_VBO_SIZE) { CCASSERT(cmd->getVertexCount()>= 0 && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); CCASSERT(cmd->getIndexCount()>= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command"); //Draw batched Triangles if VBO is full drawBatchedTriangles(); } //Batch Triangles _batchedCommands.push_back(cmd); fillVerticesAndIndices(cmd); if(cmd->isSkipBatching()) { drawBatchedTriangles(); } } else if ( RenderCommand::Type::QUAD_COMMAND == commandType ) { //Draw if we have batched other commands which are not quad command flush3D(); flushTriangles(); //Process quad command auto cmd = static_cast<QuadCommand*>(command); //Draw batched quads if necessary if(cmd->isSkipBatching()|| (_numberQuads + cmd->getQuadCount()) * 4 > VBO_SIZE ) { CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() * 4 < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); //Draw batched quads if VBO is full drawBatchedQuads(); } //Batch Quads _batchQuadCommands.push_back(cmd); fillQuads(cmd); if(cmd->isSkipBatching()) { drawBatchedQuads(); } } else if (RenderCommand::Type::MESH_COMMAND == commandType) { flush2D(); auto cmd = static_cast<MeshCommand*>(command); if (cmd->isSkipBatching() || _lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID()) { flush3D(); if(cmd->isSkipBatching()) { // XXX: execute() will call bind() and unbind() // but unbind() shouldn't be call if the next command is a MESH_COMMAND with Material. // Once most of cocos2d-x moves to Pass/StateBlock, only bind() should be used. cmd->execute(); } else { cmd->preBatchDraw(); cmd->batchDraw(); _lastBatchedMeshCommand = cmd; } } else { cmd->batchDraw(); } } else if(RenderCommand::Type::GROUP_COMMAND == commandType) { flush(); int renderQueueID = ((GroupCommand*) command)->getRenderQueueID(); visitRenderQueue(_renderGroups[renderQueueID]); } else if(RenderCommand::Type::CUSTOM_COMMAND == commandType) { flush(); auto cmd = static_cast<CustomCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::BATCH_COMMAND == commandType) { flush(); auto cmd = static_cast<BatchCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::PRIMITIVE_COMMAND == commandType) { flush(); auto cmd = static_cast<PrimitiveCommand*>(command); cmd->execute(); } else { CCLOGERROR("Unknown commands in renderQueue"); } }
void Renderer::processRenderCommand(RenderCommand* command) { auto commandType = command->getType(); if (RenderCommand::Type::ARBITRARY_VERTEX_COMMAND == commandType) { // TODO use FastVector _batchedArbitaryCommands.push_back(command); } else if (RenderCommand::Type::MESH_COMMAND == commandType) { flush2D(); auto cmd = static_cast<MeshCommand*>(command); if (cmd->isSkipBatching() || _lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID()) { flush3D(); if (cmd->isSkipBatching()) { // XXX: execute() will call bind() and unbind() // but unbind() shouldn't be call if the next command is a MESH_COMMAND with Material. // Once most of cocos2d-x moves to Pass/StateBlock, only bind() should be used. cmd->execute(); } else { cmd->preBatchDraw(); cmd->batchDraw(); _lastBatchedMeshCommand = cmd; } } else { cmd->batchDraw(); } } else if (RenderCommand::Type::CUSTOM_COMMAND == commandType) { flush(); auto cmd = static_cast<CustomCommand*>(command); cmd->execute(); } else if (RenderCommand::Type::BATCH_COMMAND == commandType) { flush(); auto cmd = static_cast<BatchCommand*>(command); cmd->execute(); } else if (RenderCommand::Type::PRIMITIVE_COMMAND == commandType) { flush(); auto cmd = static_cast<PrimitiveCommand*>(command); cmd->execute(); } else if ((RenderCommand::Type)QueueCommand::QUEUE_COMMAND == commandType) { flush(); auto cmd = static_cast<QueueCommand*>(command); (this->*cmd->func)(); } else { CCLOGERROR("Unknown commands in renderQueue"); } }
void Renderer::processRenderCommand(RenderCommand* command) { auto commandType = command->getType(); if( RenderCommand::Type::TRIANGLES_COMMAND == commandType) { //Draw if we have batched other commands which are not triangle command flush3D(); flushQuads(); //Process triangle command auto cmd = static_cast<TrianglesCommand*>(command); //Draw batched Triangles if necessary if(cmd->isSkipBatching() || _filledVertex + cmd->getVertexCount() > VBO_SIZE || _filledIndex + cmd->getIndexCount() > INDEX_VBO_SIZE) { CCASSERT(cmd->getVertexCount()>= 0 && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); CCASSERT(cmd->getIndexCount()>= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command"); //Draw batched Triangles if VBO is full drawBatchedTriangles(); } //Batch Triangles _batchedCommands.push_back(cmd); fillVerticesAndIndices(cmd); if(cmd->isSkipBatching()) { drawBatchedTriangles(); } } else if ( RenderCommand::Type::QUAD_COMMAND == commandType ) { //Draw if we have batched other commands which are not quad command flush3D(); flushTriangles(); //Process quad command auto cmd = static_cast<QuadCommand*>(command); //Draw batched quads if necessary if(cmd->isSkipBatching()|| (_numberQuads + cmd->getQuadCount()) * 4 > VBO_SIZE ) { CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() * 4 < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); //Draw batched quads if VBO is full drawBatchedQuads(); } //Batch Quads _batchQuadCommands.push_back(cmd); fillQuads(cmd); if(cmd->isSkipBatching()) { drawBatchedQuads(); } } else if (RenderCommand::Type::MESH_COMMAND == commandType) { flush2D(); auto cmd = static_cast<MeshCommand*>(command); if (cmd->isSkipBatching() || _lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID()) { flush3D(); if(cmd->isSkipBatching()) { cmd->execute(); } else { cmd->preBatchDraw(); cmd->batchDraw(); _lastBatchedMeshCommand = cmd; } } else { cmd->batchDraw(); } } else if(RenderCommand::Type::GROUP_COMMAND == commandType) { flush(); int renderQueueID = ((GroupCommand*) command)->getRenderQueueID(); visitRenderQueue(_renderGroups[renderQueueID]); } else if(RenderCommand::Type::CUSTOM_COMMAND == commandType) { flush(); auto cmd = static_cast<CustomCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::BATCH_COMMAND == commandType) { flush(); auto cmd = static_cast<BatchCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::BEGIN_SCISSOR_COMMAND == commandType) { flush(); command->execute<BeginScissorCommand>(); } else if(RenderCommand::Type::END_SCISSOR_COMMAND == commandType) { flush(); command->execute<EndScissorCommand>(); } else if(RenderCommand::Type::BEGIN_STENCIL_COMMAND == commandType) { flush(); command->execute<BeginStencilCommand>(); } else if(RenderCommand::Type::AFTER_STENCIL_COMMAND == commandType) { flush(); command->execute<AfterStencilCommand>(); } else if(RenderCommand::Type::END_STENCIL_COMMAND == commandType) { flush(); command->execute<EndStencilCommand>(); } else { CCLOGERROR("Unknown commands in renderQueue"); } }
void Renderer::visitRenderQueue(const RenderQueue& queue) { ssize_t size = queue.size(); for (ssize_t index = 0; index < size; ++index) { auto command = queue[index]; auto commandType = command->getType(); if( RenderCommand::Type::TRIANGLES_COMMAND == commandType) { flush3D(); if(_numberQuads > 0) { drawBatchedQuads(); _lastMaterialID = 0; } auto cmd = static_cast<TrianglesCommand*>(command); //Batch Triangles if( _filledVertex + cmd->getVertexCount() > VBO_SIZE || _filledIndex + cmd->getIndexCount() > INDEX_VBO_SIZE) { CCASSERT(cmd->getVertexCount()>= 0 && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); CCASSERT(cmd->getIndexCount()>= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command"); //Draw batched Triangles if VBO is full drawBatchedTriangles(); } _batchedCommands.push_back(cmd); fillVerticesAndIndices(cmd); } else if ( RenderCommand::Type::QUAD_COMMAND == commandType ) { flush3D(); if(_filledIndex > 0) { drawBatchedTriangles(); _lastMaterialID = 0; } auto cmd = static_cast<QuadCommand*>(command); //Batch quads if( (_numberQuads + cmd->getQuadCount()) * 4 > VBO_SIZE ) { CCASSERT(cmd->getQuadCount()>= 0 && cmd->getQuadCount() * 4 < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); //Draw batched quads if VBO is full drawBatchedQuads(); } _batchQuadCommands.push_back(cmd); fillQuads(cmd); } else if(RenderCommand::Type::GROUP_COMMAND == commandType) { flush(); int renderQueueID = ((GroupCommand*) command)->getRenderQueueID(); visitRenderQueue(_renderGroups[renderQueueID]); } else if(RenderCommand::Type::CUSTOM_COMMAND == commandType) { flush(); auto cmd = static_cast<CustomCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::BATCH_COMMAND == commandType) { flush(); auto cmd = static_cast<BatchCommand*>(command); cmd->execute(); } else if(RenderCommand::Type::PRIMITIVE_COMMAND == commandType) { flush(); auto cmd = static_cast<PrimitiveCommand*>(command); cmd->execute(); } else if (RenderCommand::Type::MESH_COMMAND == commandType) { flush2D(); auto cmd = static_cast<MeshCommand*>(command); if (_lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID()) { flush3D(); cmd->preBatchDraw(); cmd->batchDraw(); _lastBatchedMeshCommand = cmd; } else { cmd->batchDraw(); } } else { CCLOGERROR("Unknown commands in renderQueue"); } } }
MaterialLib::PorousMedium::Storage const& PorousMediaProperties::getSpecificStorage( double /*t*/, ProcessLib::SpatialPosition const& pos) const { return *_specific_storage_models[getMaterialID(pos)]; }
MaterialLib::PorousMedium::Permeability const& PorousMediaProperties::getIntrinsicPermeability( double /*t*/, ProcessLib::SpatialPosition const& pos) const { return *_intrinsic_permeability_models[getMaterialID(pos)]; }
MaterialLib::PorousMedium::Porosity const& PorousMediaProperties::getPorosity( double /*t*/, ProcessLib::SpatialPosition const& pos) const { return *_porosity_models[getMaterialID(pos)]; }
void Renderer::processRenderCommand(RenderCommand* command) { auto commandType = command->getType(); if( RenderCommand::Type::TRIANGLES_COMMAND == commandType) { // flush other queues flush3D(); auto cmd = static_cast<TrianglesCommand*>(command); // flush own queue when buffer is full if(_filledVertex + cmd->getVertexCount() > VBO_SIZE || _filledIndex + cmd->getIndexCount() > INDEX_VBO_SIZE) { CCASSERT(cmd->getVertexCount()>= 0 && cmd->getVertexCount() < VBO_SIZE, "VBO for vertex is not big enough, please break the data down or use customized render command"); CCASSERT(cmd->getIndexCount()>= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, "VBO for index is not big enough, please break the data down or use customized render command"); drawBatchedTriangles(); } // queue it _queuedTriangleCommands.push_back(cmd); _filledIndex += cmd->getIndexCount(); _filledVertex += cmd->getVertexCount(); } else if (RenderCommand::Type::MESH_COMMAND == commandType) { flush2D(); auto cmd = static_cast<MeshCommand*>(command); if (cmd->isSkipBatching() || _lastBatchedMeshCommand == nullptr || _lastBatchedMeshCommand->getMaterialID() != cmd->getMaterialID()) { flush3D(); CCGL_DEBUG_INSERT_EVENT_MARKER("RENDERER_MESH_COMMAND"); if(cmd->isSkipBatching()) { // XXX: execute() will call bind() and unbind() // but unbind() shouldn't be call if the next command is a MESH_COMMAND with Material. // Once most of cocos2d-x moves to Pass/StateBlock, only bind() should be used. cmd->execute(); } else { cmd->preBatchDraw(); cmd->batchDraw(); _lastBatchedMeshCommand = cmd; } } else { CCGL_DEBUG_INSERT_EVENT_MARKER("RENDERER_MESH_COMMAND"); cmd->batchDraw(); } } else if(RenderCommand::Type::GROUP_COMMAND == commandType) { flush(); int renderQueueID = ((GroupCommand*) command)->getRenderQueueID(); CCGL_DEBUG_PUSH_GROUP_MARKER("RENDERER_GROUP_COMMAND"); visitRenderQueue(_renderGroups[renderQueueID]); CCGL_DEBUG_POP_GROUP_MARKER(); } else if(RenderCommand::Type::CUSTOM_COMMAND == commandType) { flush(); auto cmd = static_cast<CustomCommand*>(command); CCGL_DEBUG_INSERT_EVENT_MARKER("RENDERER_CUSTOM_COMMAND"); cmd->execute(); } else if(RenderCommand::Type::BATCH_COMMAND == commandType) { flush(); auto cmd = static_cast<BatchCommand*>(command); CCGL_DEBUG_INSERT_EVENT_MARKER("RENDERER_BATCH_COMMAND"); cmd->execute(); } else if(RenderCommand::Type::PRIMITIVE_COMMAND == commandType) { flush(); auto cmd = static_cast<PrimitiveCommand*>(command); CCGL_DEBUG_INSERT_EVENT_MARKER("RENDERER_PRIMITIVE_COMMAND"); cmd->execute(); } else { CCLOGERROR("Unknown commands in renderQueue"); } }