void PositionMap::MarkAreaUsed (const AreaID& area, const float radius, const float xpos, const float zpos) { // Don't bother with very small radii if (radius < SMALL_EPSILON) return; size_t b = area.first; size_t areaIndex = area.second; Bucket& bucket = buckets[b]; Bucket::Area freeArea (buckets[b].freeAreas[areaIndex]); csBox2 box (*(freeArea.box)); Bucket::Area replaceArea = bucket.freeAreas.Pop (); BubbleAreaIncrease (bucket, bucket.freeAreas.GetSize(), -replaceArea.area); if (bucket.freeAreas.GetSize() > areaIndex) { BubbleAreaIncrease (bucket, areaIndex, replaceArea.area - freeArea.area); bucket.freeAreas[areaIndex] = replaceArea; } GetBoxAlloc()->Free (freeArea.box); InsertNewArea (csBox2 (box.MinX(), box.MinY(), xpos+radius, zpos-radius)); InsertNewArea (csBox2 (xpos+radius, box.MinY(), box.MaxX(), zpos+radius)); InsertNewArea (csBox2 (xpos-radius, zpos+radius, box.MaxX(), box.MaxY())); InsertNewArea (csBox2 (box.MinX(), zpos-radius, xpos-radius, box.MaxY())); }
csBox2 csBox3::GetSide (int side) const { switch (side) { case CS_BOX_SIDE_x: case CS_BOX_SIDE_X: return csBox2 (MinY (), MinZ (), MaxY (), MaxZ ()); case CS_BOX_SIDE_y: case CS_BOX_SIDE_Y: return csBox2 (MinX (), MinZ (), MaxX (), MaxZ ()); case CS_BOX_SIDE_z: case CS_BOX_SIDE_Z: return csBox2 (MinX (), MinY (), MaxX (), MaxY ()); } return csBox2 (); }
csBox2 operator * (const csBox2 &box1, const csBox2 &box2) { return csBox2 ( MAX (box1.minbox.x, box2.minbox.x), MAX (box1.minbox.y, box2.minbox.y), MIN (box1.maxbox.x, box2.maxbox.x), MIN (box1.maxbox.y, box2.maxbox.y)); }
csBox2 operator+ (const csBox2 &box, const csVector2 &point) { return csBox2 ( MIN (box.minbox.x, point.x), MIN (box.minbox.y, point.y), MAX (box.maxbox.x, point.x), MAX (box.maxbox.y, point.y)); }
void csTerraFormerCollider::UpdateOPCODEModel (const csVector3 &other_pos, float res) { if (ceil (res) > resolution) { resolution = (unsigned int)ceil (res); InitOPCODEModel (); } csRef<iTerraSampler> sampler = former->GetSampler ( csBox2 (other_pos.x - resolution, other_pos.z - resolution, other_pos.x + resolution, other_pos.z + resolution), resolution, resolution); const csVector3 *v = sampler->SampleVector3 (stringVertices); int index = 0; for (unsigned int y = 0 ; y < resolution ; y++) { for (unsigned int x = 0 ; x < resolution ; x++) { vertices[index].Set (v[index].x,v[index].y,v[index].z); index++; } } int i = 0; for (unsigned int y = 0 ; y < resolution-1 ; y++) { int yr = y * resolution; for (unsigned int x = 0 ; x < resolution-1 ; x++) { indexholder[i++] = yr + x; indexholder[i++] = yr+resolution + x; indexholder[i++] = yr + x+1; indexholder[i++] = yr + x+1; indexholder[i++] = yr+resolution + x; indexholder[i++] = yr+resolution + x+1; } } opcode_model->Build (OPCC); }
csPtr<iBase> csTerrainFactoryLoader::Parse (iDocumentNode* node, iStreamSource*, iLoaderContext* /*ldr_context*/, iBase* /*context*/) { csRef<iPluginManager> plugin_mgr = csQueryRegistry<iPluginManager> (object_reg); csRef<iMeshObjectFactory> fact; csRef<iTerrainFactoryState> state; csRef<iDocumentNodeIterator> it = node->GetNodes (); while (it->HasNext()) { csRef<iDocumentNode> child = it->Next (); if (child->GetType () != CS_NODE_ELEMENT) continue; const char* value = child->GetValue (); csStringID id = xmltokens.Request (value); switch (id) { case XMLTOKEN_PLUGIN: { const char* pluginname = child->GetContentsValue (); csRef<iMeshObjectType> type = csLoadPluginCheck<iMeshObjectType> ( plugin_mgr, pluginname); if (!type) { synldr->ReportError ("crystalspace.terrain.loader.factory", node, "Could not load %s!", pluginname); return 0; } fact = type->NewFactory (); if (!fact) { synldr->ReportError ("crystalspace.terrain.loader.factory", node, "Could not create a factory from %s", pluginname); } state = scfQueryInterface<iTerrainFactoryState> (fact); if (!state) { synldr->ReportError ("crystalspace.terrain.loader.factory", node, "Could not query iTerrainFactoryState from %s", pluginname); } break; } case XMLTOKEN_TERRAFORMER: { const char* name = child->GetContentsValue (); csRef<iTerraFormer> form = csQueryRegistryTagInterface<iTerraFormer> (object_reg, name); if (form == 0) { synldr->ReportError ("crystalspace.terrain.factory.loader", child, "Unable to find TerraFormer %s", name); return 0; } state->SetTerraFormer (form); break; } case XMLTOKEN_SAMPLEREGION: { csBox3 box; if (!synldr->ParseBox (child, box)) { synldr->ReportError ("crystalspace.terrain.factory.loader", child, "Unable to parse sampleregion"); return 0; } state->SetSamplerRegion (csBox2(box.MinX(), box.MinY(), box.MaxX(), box.MaxY())); break; } default: synldr->ReportError ("crystalspace.terrain.factory.loader", child, "Unknown token!"); } } return csPtr<iBase> (fact); }