void initCamera() { if (ConfigFile->getVar("HMDEnable").asBool()) { std::vector<NL3D::CStereoDeviceInfo> devices; IStereoDisplay::listDevices(devices); for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it) { std::stringstream name; name << std::string("[") << it->Serial << "] [" << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName << "]"; nlinfo("Stereo Display: %s", name.str().c_str()); } CStereoDeviceInfo *deviceInfo = NULL; std::string hmdDeviceCfg = ConfigFile->getVar("HMDDevice").asString(); if (hmdDeviceCfg == std::string("Auto") && devices.begin() != devices.end()) { for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it) { if (it->AllowAuto) { deviceInfo = &devices[0]; } } } else { std::string hmdDeviceId = ConfigFile->getVar("HMDDeviceId").asString(); for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it) { std::stringstream name; name << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName; if (name.str() == hmdDeviceCfg) deviceInfo = &(*it); if (hmdDeviceId == it->Serial) break; } } if (deviceInfo) { nlinfo("Create VR stereo display device"); StereoDisplay = IStereoDisplay::createDevice(*deviceInfo); if (StereoDisplay) { if (deviceInfo->Class == CStereoDeviceInfo::StereoHMD) { nlinfo("Stereo display device is a HMD"); StereoHMD = static_cast<IStereoHMD *>(StereoDisplay); StereoHMD->setScale(3.0f); // snowballs is about 4 units per meter } StereoDisplay->setDriver(Driver); // move after driver creation, move stereodisplay before driver creation StereoDisplay->attachToDisplay(); } } } IStereoDisplay::releaseUnusedLibraries(); // Set up directly the camera Camera = Scene->getCam(); Camera.setTransformMode (UTransformable::DirectMatrix); Camera.setPerspective((float)Pi/2.f, ConfigFile->getVar("ScreenWidth").asFloat() / ConfigFile->getVar("ScreenHeight").asFloat(), 0.1f, 1000.f); Camera.lookAt (CVector(ConfigFile->getVar("StartPoint").asFloat(0), ConfigFile->getVar("StartPoint").asFloat(1), ConfigFile->getVar("StartPoint").asFloat(2)), CVectorD (0,0,0)); CamCollisionEntity = VisualCollisionManager->createEntity(); CamCollisionEntity->setCeilMode(true); // Create the snowing particle system Snow = Scene->createInstance("snow.ps"); // And setup it Snow.setTransformMode (UTransformable::DirectMatrix); // // Setup the sky scene // // -- -- not sure what the sky has to do with the camera SkyScene = Driver->createScene(false); SkyCamera = SkyScene->getCam (); SkyCamera.setTransformMode (UTransformable::DirectMatrix); // Set the very same frustum as the main camera SkyCamera.setFrustum (Camera.getFrustum ()); Sky = SkyScene->createInstance("sky.shape"); Sky.setTransformMode (UTransformable::DirectMatrix); Sky.setMatrix(CMatrix::Identity); }
//*************************************************************** std::string CToolCreateEntity::cloneEntityIntoScenario(CEntityCL *clonee, const NLMISC::CVector &createPosition, float createAngle, bool newAction, bool createGhost ) { //H_AUTO(R2_CToolCreateEntity_cloneEntityIntoScenario) if (!clonee) return ""; std::string instanceId; bool isBotObject = isBotObjectSheet(clonee->sheetId()); if (!getEditor().verifyRoomLeft(isBotObject ? 0 : 1, isBotObject ? 1 : 0)) { return ""; } std::string className; // if class is given in the palette node, then use it. Default to 'Npc' else CObject *paletteNode = getDMC().getPaletteElement(_PaletteId); if (paletteNode && paletteNode->findIndex("Class") != -1) { className = getString(paletteNode, "Class"); } if (className.empty()) { className = "Npc"; } ucstring readableName; // retrieve name from the palette id CLuaState &ls = getEditor().getLua(); getEditor().getEnv()["PaletteIdToTranslation"][_PaletteId].push(); if (ls.isString(-1)) { readableName.fromUtf8(ls.toString(-1)); } if (readableName.empty()) { // if no name found then give a default one readableName = CI18N::get(isBotObject ? "uiR2EDNameBotObject" : "uiR2EDNameNPC"); } // except for creatures, posfix the name with a number std::string creaturePaletteRoot = "palette.entities.creatures"; if (_PaletteId.substr(0, creaturePaletteRoot.size()) != creaturePaletteRoot) { readableName = getEditor().genInstanceName(readableName); } else { className = "NpcCreature"; // is Plant std::string sheetClient = getString(paletteNode, "SheetClient"); getEditor().getLua().push(sheetClient); if (getEditor().getEnv().callMethodByNameNoThrow("isNPCPlant", 1, 1)) { CLuaObject result(getEditor().getLua()); bool isPlant = result.toBoolean(); if (isPlant) className = "NpcPlant"; } } if (newAction) { getDMC().newAction(NLMISC::CI18N::get("uiR2EDCreateAction") + readableName); } // send network commands to create entity on server std::auto_ptr<CObject> desc(getDMC().newComponent(className)); if (desc.get()) { // TMP FIX : if the created entity is a custom npc, then retrieve look from the clonee visual properties if (className == "NpcCustom") { SPropVisualA vA; SPropVisualB vB; SPropVisualC vC; const string propNameA = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPA); const string propNameB = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPB); const string propNameC = toString("SERVER:Entities:E%d:P%d", clonee->slot(), CLFECOMMON::PROPERTY_VPC); CCDBNodeLeaf *leafA = CInterfaceManager::getInstance()->getDbProp(propNameA); CCDBNodeLeaf *leafB = CInterfaceManager::getInstance()->getDbProp(propNameB); CCDBNodeLeaf *leafC = CInterfaceManager::getInstance()->getDbProp(propNameC); if (!leafA) { nlwarning("Can't find DB leaf %s", propNameA.c_str()); return ""; } if (!leafB) { nlwarning("Can't find DB leaf %s", propNameB.c_str()); return ""; } if (!leafC) { nlwarning("Can't find DB leaf %s", propNameC.c_str()); return ""; } vA.PropertyA = leafA->getValue64(); vB.PropertyB = leafB->getValue64(); vC.PropertyC = leafC->getValue64(); nlassert(desc->isTable()); CObjectTable *props = (CObjectTable *) desc.get(); props->set("GabaritHeight", (double)vC.PropertySubData.CharacterHeight); props->set("GabaritTorsoWidth", (double)vC.PropertySubData.TorsoWidth); props->set("GabaritArmsWidth", (double)vC.PropertySubData.ArmsWidth); props->set("GabaritLegsWidth", (double)vC.PropertySubData.LegsWidth); props->set("GabaritBreastSize", (double)vC.PropertySubData.BreastSize); props->set("HairColor", (double)vA.PropertySubData.HatColor); props->set("Tattoo", (double)vC.PropertySubData.Tattoo); props->set("EyesColor", (double)vC.PropertySubData.EyesColor); props->set("MorphTarget1", (double)vC.PropertySubData.MorphTarget1); props->set("MorphTarget2", (double)vC.PropertySubData.MorphTarget2); props->set("MorphTarget3", (double)vC.PropertySubData.MorphTarget3); props->set("MorphTarget4", (double)vC.PropertySubData.MorphTarget4); props->set("MorphTarget5", (double)vC.PropertySubData.MorphTarget5); props->set("MorphTarget6", (double)vC.PropertySubData.MorphTarget6); props->set("MorphTarget7", (double)vC.PropertySubData.MorphTarget7); props->set("MorphTarget8", (double)vC.PropertySubData.MorphTarget8); props->set("Sex", (double)vA.PropertySubData.Sex); CVisualSlotManager * vsManager = CVisualSlotManager::getInstance(); NLMISC::CSheetId * sheetId = NULL; if(vA.PropertySubData.HatModel == 0) { props->set("HatModel", 0); } else { sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.HatModel, SLOTTYPE::HEAD_SLOT); if (sheetId) { props->set("HairType", (double)sheetId->asInt()); } } if(vA.PropertySubData.JacketModel == 0) { props->set("JacketModel", 0); } else { sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.JacketModel, SLOTTYPE::CHEST_SLOT); if (sheetId) { props->set("JacketModel", (double)sheetId->asInt()); } } if(vA.PropertySubData.TrouserModel == 0) { props->set("TrouserModel", 0); } else { sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.TrouserModel, SLOTTYPE::LEGS_SLOT); if (sheetId) { props->set("TrouserModel", (double)sheetId->asInt()); } } if(vB.PropertySubData.FeetModel == 0) { props->set("FeetModel", 0); } else { sheetId = vsManager->index2Sheet((uint32)vB.PropertySubData.FeetModel, SLOTTYPE::FEET_SLOT); if (sheetId) { props->set("FeetModel", (double)sheetId->asInt()); } } if(vB.PropertySubData.HandsModel == 0) { props->set("HandsModel", 0); } else { sheetId = vsManager->index2Sheet((uint32)vB.PropertySubData.HandsModel, SLOTTYPE::HANDS_SLOT); if (sheetId) { props->set("HandsModel", (double)sheetId->asInt()); } } if(vA.PropertySubData.ArmModel == 0) { props->set("ArmModel", 0); } else { sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.ArmModel, SLOTTYPE::ARMS_SLOT); if (sheetId) { props->set("ArmModel", (double)sheetId->asInt()); } } double weaponRH=0, weaponLH=0; if(vA.PropertySubData.WeaponRightHand == 0) { props->set("WeaponRightHand", 0); } else { sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.WeaponRightHand, SLOTTYPE::RIGHT_HAND_SLOT); if (sheetId) { weaponRH = (double)sheetId->asInt(); } props->set("WeaponRightHand", weaponRH); } if(vA.PropertySubData.WeaponLeftHand == 0) { props->set("WeaponLeftHand", 0); } else { sheetId = vsManager->index2Sheet((uint32)vA.PropertySubData.WeaponLeftHand, SLOTTYPE::LEFT_HAND_SLOT); if (sheetId) { weaponLH = (double)sheetId->asInt(); } props->set("WeaponLeftHand", weaponLH); } props->set("JacketColor", (double)vA.PropertySubData.JacketColor); props->set("TrouserColor", (double)vA.PropertySubData.TrouserColor); props->set("FeetColor", (double)vB.PropertySubData.FeetColor); props->set("HandsColor", (double)vB.PropertySubData.HandsColor); props->set("ArmColor", (double)vA.PropertySubData.ArmColor); CPlayerR2CL * player = (CPlayerR2CL*)dynamic_cast<CPlayerR2CL*>(clonee); if(player != NULL) { std::string race, gender, sheetClient; switch(player->people()) { case EGSPD::CPeople::Fyros: sheetClient = "basic_fyros_"; race = "Fyros"; break; case EGSPD::CPeople::Matis: sheetClient = "basic_matis_"; race = "Matis"; break; case EGSPD::CPeople::Tryker: sheetClient = "basic_tryker_"; race = "Tryker"; break; case EGSPD::CPeople::Zorai: sheetClient = "basic_zorai_"; race = "Zorai"; break; default: nlwarning("CToolCreateEntity::commit unknown people"); } switch(player->getGender()) { case GSGENDER::female: sheetClient = sheetClient+"female.creature"; gender = "female"; break; case GSGENDER::male: sheetClient = sheetClient+"male.creature"; gender = "male"; break; default: nlwarning("CToolCreateEntity::commit unknown gender"); } props->set("SheetClient", sheetClient); // random name getEditor().getLua().push(race); getEditor().getLua().push(gender); if (getEditor().getEnv().callMethodByNameNoThrow("randomNPCName", 2, 1)) { CLuaObject result(getEditor().getLua()); std::string name = result.toString(); props->set("Name", name); } } getEditor().getLua().push(getString(paletteNode, "Equipment")); getEditor().getLua().push(weaponRH); getEditor().getLua().push(weaponLH); getEditor().getLua().push(getString(paletteNode, "Sheet")); getEditor().getLua().push(getString(paletteNode, "SheetModel")); if (getEditor().getEnv().callMethodByNameNoThrow("searchSheet", 5, 1)) { CLuaObject result(getEditor().getLua()); std::string sheet = result.toString(); props->set("Sheet", sheet); } else { nlwarning("SearchSheet failed : Palette Id = %s", _PaletteId.c_str()); return ""; } } else { desc->set("Name", readableName.toUtf8()); } desc->set("Base", _PaletteId); desc->setObject("Position", buildVector(CVectorD(createPosition))); desc->set("Angle", createAngle); //desc->set("Name", readableName.toUtf8()); instanceId = getString(desc.get(), "InstanceId"); if (!instanceId.empty()) { if (!createGhost) { // selection asked when instance is created getEditor().setCookie(instanceId, "Select", true); } else { getEditor().setCookie(instanceId, "GhostDuplicate", true); } } // send creation command // tmp : static npc counter // add in component list of default feature if (getEditor().getDefaultFeature()) { std::string targetInstanceId; // if object is a bot object, it is considered to be permanent content // and should be created in the base act CInstance *targetAct = isBotObject ? getEditor().getBaseAct() : getEditor().getCurrentAct(); if (!targetAct) { nlwarning("Can't find act when creating an entity"); } else { if (_AutoGroup.getGroupingCandidate()) { nlassert(!createGhost); // either autogroup or arraymode, both at the same time not supported _AutoGroup.group(desc.get(), createPosition); } else { // create standalone desc->setGhost(createGhost); getDMC().requestInsertNode(getEditor().getDefaultFeature(targetAct)->getId(), "Components", -1, "", desc.get()); } } } } return instanceId; }