void Muzzleflasher::updateMuzzleflash(IPointableObject *unit, VisualObject *muzzleflash, const std::string &name, const std::string &helper, const VC3 &pos, const VC3 &scale) { game::Unit *u = (game::Unit *)unit; VisualObject *vo = u->getVisualObject(); if (vo == NULL || vo->getStormModel() == NULL) { return; } IStorm3D_Model_Object *object = vo->getStormModel()->SearchObject(name.c_str()); if(object == NULL) { // didn't find it - add it createMuzzleflash(unit, muzzleflash, name, helper); object = vo->getStormModel()->SearchObject(name.c_str()); if(object == NULL) { return; } } object->SetPosition(pos); object->SetScale(scale); //object->SetRotation(rot); }
void BuildingAdder::addBuilding(Game *game, const VC3 &position, const char *filename, GamePhysics *gamePhysics) { Building *b = new Building(filename); game->buildings->addBuilding(b); createVisualForBuilding(game, b); //VC2I mapPos = b->getMapPosition(); //float x = gameMap->configToScaledX(mapPos.x); //float y = gameMap->configToScaledY(mapPos.y); //b->setPosition(VC3(x, gameMap->getScaledHeightAt(x, y), y)); VC3 pos = position; b->setPosition(pos); game->getGameScene()->addBuildingObstacle(b, buildingadder_enableterraincut); VisualObject *vo = b->getVisualObject(); if (vo != NULL) { // Damn, should change the buidlinghandler to use the // visual object instead of storm models... // Add to building handler too game->gameUI->buildingHandler.addBuilding(vo->model); b->addPhysics(gamePhysics); // NOTE: these resources should be freed. (but cannot be, because we might be in physics simulation/because // the actual mesh cooking is done at next sync, not right now... (applies to PhysX) // NOTE: also, ODE physics will pose same kind of problems (possibly even more due to multithreaded cooking) // MOVED THIS LATER ON... #ifdef PHYSICS_NONE if(vo->getStormModel()) { vo->getStormModel()->FreeMemoryResources(); } #endif } // TODO: not an optimal solution doing this after every single // building! game->gameMap->applyObstacleHeightChanges(); }
bool Muzzleflasher::getMuzzleflash(IPointableObject *unit, VisualObject *muzzleflash, const std::string &name, const std::string &helper, VC3 &pos, VC3 &scale, QUAT &rot) { game::Unit *u = (game::Unit *)unit; VisualObject *vo = u->getVisualObject(); if (vo == NULL || vo->getStormModel() == NULL) { return false; } IStorm3D_Model_Object *object = vo->getStormModel()->SearchObject(name.c_str()); if(object == NULL) { return false; } pos = object->GetPosition(); scale = object->GetScale(); rot = object->GetRotation(); return true; }
void BuildingAdder::createVisualForBuilding(Game *game, Building *building) { // another quick haxor // maybe should check that the visual does not already exist //VisualObjectModel *vom = new VisualObjectModel(building->getModelFilename()); VisualObjectModel *vom = game->visualObjectModelStorage->getVisualObjectModel(building->getModelFilename()); VisualObject *vo = vom->getNewObjectInstance(); building->setVisualObject(vo); vo->setInScene(true); vo->setDataObject(building); // disable collision to "firethrough" collision layer... IStorm3D_Model *model = vo->getStormModel(); if(model) { const VC3 &sunDir = game->getGameUI()->getTerrain()->getSunDirection(); model->SetDirectional(sunDir, 1.f); } Iterator<IStorm3D_Model_Object *> *objectIterator; for(objectIterator = model->ITObject->Begin(); !objectIterator->IsEnd(); objectIterator->Next()) { IStorm3D_Model_Object *object = objectIterator->GetCurrent(); const char *name = object->GetName(); if (strstr(name, "FireThrough") != NULL) { object->SetNoCollision(true); } } delete objectIterator; // add building for self-illum (lightmap brightness) changes... game->gameUI->getLightManager()->getSelfIlluminationChanger()->addModel(vo->getStormModel()); }