void CollisionMesh::Initialise(bool createmesh, Geometry::Shape shape, const D3DXVECTOR3& minScale, const D3DXVECTOR3& maxScale, int divisions) { if(createmesh) { m_geometry.reset(new Geometry(m_engine->device(), m_engine->getShader(ShaderManager::BOUNDS_SHADER), shape, divisions)); } m_worldVertices.clear(); m_worldVertices.resize(m_geometry->GetVertices().size()); D3DXVECTOR3 scale(minScale); if(m_parent) { // If parental, scale the mesh from min-max depending on the parent scale m_minLocalScale = minScale; m_maxLocalScale = maxScale; scale = FindLocalScale(); } LoadCollisionModel(scale); }
void CollisionMesh::FullUpdate() { assert(m_parent); // Modify the scale of the collision mesh // depending on the parent scale D3DXVECTOR3 scale(FindLocalScale()); D3DXVECTOR3 localScale(m_localWorld.GetScale()); if(scale != localScale) { LoadCollisionModel(scale); } //DirectX: World = LocalWorld * ParentWorld m_positionDelta += m_parent->Position() - m_world.Position(); m_world.Set(m_localWorld.GetMatrix()*m_parent->GetMatrix()); m_position = m_world.Position(); m_requiresFullUpdate = true; }
static RwStream* ReadCollisionFromClump( RwStream *stream, size_t size ) { // We do not wanna load if we are not requesting a collision. if ( !g_clumpLoaderCOLAcquisition ) return stream; // We should not load invalid sized collisions if ( size < sizeof(ColModelFileHeader) ) return stream; // Allocate the required buffer for the COL data char *buf = new char[size]; // Read the collision from the RenderWare stream block if ( RwStreamReadBlocks( stream, buf, size ) != size ) { delete buf; return NULL; } ColModelFileHeader& header = *(ColModelFileHeader*)buf; CColModelSAInterface *colModel = new CColModelSAInterface; // Load according to version switch( header.checksum ) { case 'LLOC': LoadCollisionModel( buf + sizeof(ColModelFileHeader), colModel, NULL ); break; case '2LOC': LoadCollisionModelVer2( buf + sizeof(ColModelFileHeader), header.size - 0x18, colModel, NULL ); break; case '3LOC': LoadCollisionModelVer3( buf + sizeof(ColModelFileHeader), header.size - 0x18, colModel, NULL ); break; case '4LOC': LoadCollisionModelVer4( buf + sizeof(ColModelFileHeader), header.size - 0x18, colModel, NULL ); break; default: // Invalid checksum; maybe invalid version or bad chunk // Happens for RC CAM vehicle; by returning NULL we disabled this model. delete [] buf; delete colModel; return NULL; } // Unsegmentize the data. colModel->UnsegmentizeData(); delete [] buf; // Update the request. // The_GTA: Made the collision assignment logic request based; original loader at // CStreamingSA.utils.cpp - LoadClumpFilePersistent. g_clumpLoaderCOLAcquisition->SetCollision( colModel ); return stream; }