void NativeGameLogic::load(WorldModel::WorldAccess *worldAccess) { worldAccess->clear(); createWall(worldAccess, geom::Point(.0, .0, -20.0), 20.0, 20.0, geom::Angle(M_PI), render::Color(1.0, .0, .0)); createWall(worldAccess, geom::Point(.0, .0, 20.0), 20.0, 20.0, geom::Angle(.0), render::Color(.0, 1.0, .0)); createWall(worldAccess, geom::Point(10.0, .0, .0), 40.0, 20.0, geom::Angle(M_PI_2), render::Color(.0, .0, 1.0)); createWall(worldAccess, geom::Point(-10.0, .0, .0), 40.0, 20.0, geom::Angle(-M_PI_2), render::Color(1.0, 1.0, .0)); createLight(worldAccess, geom::Point(5.0, 5.0, -10.0)); }
void Model::processLight(const aiScene* scene) { vector<Light> listPointLight; vector<Light> listSpotLight; vector<Light> listDirectionalLight; aiLight* light; Light myLight; /* listPointLight.push_back(createLight(aiVector3D(-50.0f, 10.0f, 0.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f), 1.0f, 0.009f, 0.0032f, 0.71f, 0.52f, aiVector3D(-1.0f, -1.0f, 1.0f))); */ listPointLight.push_back(createLight(aiVector3D(0.0f, 10.0f, 0.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f), 1.0f, 0.009f, 0.0032f, 0.71f, 0.52f, aiVector3D(-1.0f, -1.0f, 1.0f))); /* listPointLight.push_back(createLight(aiVector3D(50.0f, 10.0f, 0.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f), aiColor3D(1.0f, 1.0f, 1.0f), 1.0f, 0.009f, 0.0032f, 0.71f, 0.52f, aiVector3D(0.0f, -1.0f, 0.0f))); */ for(int i=0; scene->mNumLights; i++) { light = scene->mLights[i]; myLight = createLight(light->mPosition, light->mColorAmbient, light->mColorDiffuse, light->mColorSpecular, light->mAttenuationConstant, light->mAttenuationLinear, light->mAttenuationQuadratic, light->mAngleInnerCone, light->mAngleOuterCone, light->mDirection); if(light->mType == aiLightSourceType::aiLightSource_POINT) listPointLight.push_back(myLight); if(light->mType == aiLightSourceType::aiLightSource_SPOT) listSpotLight.push_back(myLight); if(light->mType == aiLightSourceType::aiLightSource_DIRECTIONAL) listDirectionalLight.push_back(myLight); } GLuint nbLights = listPointLight.size() + listSpotLight.size() + listDirectionalLight.size(); m_lightShaderStorageBuffer.create(sizeof(glm::ivec4) + sizeof(Light)*nbLights, GL_SHADER_STORAGE_BUFFER, GL_STATIC_DRAW); glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(glm::ivec4), glm::value_ptr(glm::ivec4(listPointLight.size(), listSpotLight.size(), listDirectionalLight.size(), 1))); glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(glm::ivec4), sizeof(Light)*listPointLight.size(), &listPointLight[0]); glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(glm::ivec4) + sizeof(Light)*listPointLight.size(), sizeof(Light)*listSpotLight.size(), &listSpotLight[0]); glBufferSubData(GL_SHADER_STORAGE_BUFFER, sizeof(glm::ivec4) + sizeof(Light)*listPointLight.size() + sizeof(Light)*listSpotLight.size(), sizeof(Light)*listDirectionalLight.size(), &listDirectionalLight[0]); m_lightShaderStorageBuffer.setBindingPoint(0); }
void SingleplayerGame::createScene(std::vector<std::string> partyNames){ auto scnMgr = mRenderer->mSceneManager; auto root = scnMgr->getRootSceneNode(); Ogre::Camera* camera = mRenderer->mCamera; mRoomRoot = root->createChildSceneNode(); scnMgr->setSkyBox(true, "Examples/MorningSkyBox", 5000, true); // Set ambient light scnMgr->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3)); scnMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); // Create a light mMainLight = scnMgr->createLight(BaseGame::mainLightName); mMainLight->setPosition(0, 500, 0); mMainLight->setType(Ogre::Light::LT_POINT); mMainLight->setDiffuseColour(.5, .5, .5); // Create ground plane ground = new Plane(scnMgr, mRoomRoot); // Add test objects Player* p = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo(partyNames[0]), Ogre::Vector3(500, 0, 200), mSoundBank); myParty.push_back(p); Player* p2 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo(partyNames[1]), Ogre::Vector3(500, 0, 0), mSoundBank); myParty.push_back(p2); Player* p3 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo(partyNames[2]), Ogre::Vector3(500, 0, -200), mSoundBank); myParty.push_back(p3); Player* p4 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo("Mecha-Scoot"), Ogre::Vector3(-500, 0, 200), mSoundBank); enemyParty.push_back(p4); Player* p5 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo("SSJVirginia"), Ogre::Vector3(-500, 0, 0), mSoundBank); enemyParty.push_back(p5); Player* p6 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo("Metal Scoot"), Ogre::Vector3(-500, 0, -200), mSoundBank); enemyParty.push_back(p6); // Set Camera Position cameraInitialPosition = Ogre::Vector3(1100, 250, 700); cameraInitialLookAt = Ogre::Vector3(0, 0, 0); camera->setPosition(cameraInitialPosition); camera->lookAt(cameraInitialLookAt); }
void CMenuState::enter(void) { FightClubApp::getSingletonPtr()->mLog->logMessage("正在进入菜单......"); mRoot=FightClubApp::getSingletonPtr()->mRoot; createLight(); FightClubApp::getSingletonPtr()->mLog->logMessage("创建灯光完毕......"); createCamera(); FightClubApp::getSingletonPtr()->mLog->logMessage("创建相机完毕......"); createScene(); }
//------------------------------ bool LightImporter::import() { addLight( *mLight ); LightObject* maxLight = createLight(mLight); handleObjectReferences(mLight, maxLight); return true; }
/* this method sets up a light at the origin. if enable is true, the light is created/turned on again. if enable is false, the light is deactivated */ void OgreDisplay::makeOriginLight(ColourValue col) { if (originLight == NULL) { originLight = createLight("point", Vector3(0,0,0), col, "origin_light"); } else { originLight->setDiffuseColour(col); originLight->setSpecularColour(col); } }
/* this method sets up a light that is centred at the camera. if enable is true, the light is created/turned on again. if enable is false, the light is deactivated */ void OgreDisplay::makeCameraLight(ColourValue col) { if (cameraLight == NULL) { cameraLight = createLight("point", camera->getPosition(), col, "camera_light"); } else { cameraLight->setDiffuseColour(col); cameraLight->setSpecularColour(col); } }
void Light::enterScene(Scene* scene) { VisualComponent::enterScene(scene); light = createLight(); setEnabled(isEnabled()); setDiffuseColour(getDiffuseColour()); setSpecularColour(getSpecularColour()); setAttenuation(getAttenuation()); getSceneNode()->attachObject(light); }
//------------------------------ void LightImporter::importLight ( const COLLADAFW::Light* light ) { // Check if the light is already imported. const COLLADAFW::UniqueId& lightId = light->getUniqueId (); if ( findMayaLightNode ( lightId ) != 0 ) return; // Get the transform nodes, which work with this light instance. VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter (); const UniqueIdVec* transformNodes = visualSceneImporter->findLightTransformIds ( lightId ); if ( transformNodes == 0 ) { std::cerr << "No transform node which implements this light!" << std::endl; return; } UniqueIdVec::const_iterator nodesIter = transformNodes->begin (); while ( nodesIter != transformNodes->end () ) { // Get the maya node of the current transform node. const COLLADAFW::UniqueId& transformNodeId = *nodesIter; MayaNodesList* mayaNodesList = visualSceneImporter->findMayaTransformNodes ( transformNodeId ); if ( mayaNodesList == 0 ) { std::cerr << "Cant find transform node!" << std::endl; return; } MayaNode* mayaTransformNode = (*mayaNodesList) [0]; String transformNodeName = mayaTransformNode->getName (); // Get the path to the parent transform node. String transformNodePath = mayaTransformNode->getNodePath (); // The first reference is a direct one, the others are instances. if ( nodesIter == transformNodes->begin() ) { // Create the current mesh node. createLight ( light, mayaTransformNode ); } else { // Get the path to the node. MayaNode* mayaLightNode = findMayaLightNode ( lightId ); String lightNodePath = mayaLightNode->getNodePath (); // parent -shape -noConnections -relative -addObject "|pCube1|pCubeShape1" "pCube2"; FILE* file = getDocumentImporter ()->getFile (); MayaDM::parentShape ( file, lightNodePath, transformNodePath, false, true, true, true ); } ++nodesIter; } }
void LightEngine::Initialise() { glEnable(GL_LIGHTING); GLfloat global_ambient[] = {0.3f, 0.3f, 0.3f, 0.3f, 1.0f}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); glShadeModel(GL_SMOOTH); for(int i=0;i<sizeof(lightArray);i++) { lightArray[i].clear = true; } //Setting up these lights is temp in here... would be usually done through scripting Vec3 spec(0.66f, 0.33f, 0.0f); Vec3 dir(0.0f, -1.0f, 0.0f); Vec3 pos(-135.0, 70.0f, 0.0f); createLight(spec, spec, spec, pos, dir, 60.0f); spec.setX(0.33f); spec.setY(0.66f); spec.setZ(0.0f); pos.setX(175); createLight(spec, spec, spec, pos, dir, 60.0f); pos.setZ(-175); createLight(spec, spec, spec, pos, dir, 60.0f); spec.setX(0.33f); spec.setY(0.0f); spec.setZ(0.66f); pos.setX(420); createLight(spec, spec, spec, pos, dir, 60.0f); pos.setZ(0); createLight(spec, spec, spec, pos, dir, 60.0f); }
int light_addRINT(const char * name){ lightcount++; for(; lightArrayFirstOpen < lightArraySize && lightlist[lightArrayFirstOpen].type; lightArrayFirstOpen++); if(lightArrayFirstOpen == lightArraySize){ //resize lightArraySize++; lightlist = realloc(lightlist, lightArraySize * sizeof(light_t)); } lightlist[lightArrayFirstOpen] = createLight(name); int returnid = (lightcount << 16) | lightArrayFirstOpen; lightlist[lightArrayFirstOpen].myid = returnid; addToHashTable(lightlist[lightArrayFirstOpen].name, returnid, lighthashtable); if(lightArrayLastTaken < lightArrayFirstOpen) lightArrayLastTaken = lightArrayFirstOpen; //todo redo return returnid; }
void Canvas::setup(int bots, int lights, QVector<QPointF> botLoc, QVector<QPointF> lightLoc, int **matrix) { this->addLine(0,0,400,400); if (bots == 0) { bots = 1; qDebug() << "ERROR: Invalid number of robots. Defaulting to 1."; } if (lights == 0) { lights = 1; qDebug() << "ERROR: Invalid number of lights. Defaulting to 1."; } if (botLoc.size() < bots) { botLoc.clear(); botLoc = defaultBotLoc(bots); qDebug() << "ERROR: Not enough robot locations. Using the default locations."; } if (lightLoc.size() < bots) { lightLoc.clear(); lightLoc = defaultLightLoc(lights); qDebug() << "ERROR: Not enough light locations. Using the default locations."; } m_robotManager->setKMatrix(matrix); Robot* robot; for(int i = 0; i < bots; i++) { robot = new Robot(); robot->setTransformOriginPoint(ROBOT_HEIGHT, ROBOT_HEIGHT); robot->setPos(botLoc[i]); createRobot(robot); } LightSource *light; for (int i = 0; i < lights; i++) { light = new LightSource(); light->setPos(lightLoc[i]); // TODO: take intensity from a file light->setIntensity(100); createLight(light); } }
//----------------------------------------------------------------------- void LightObject::updateRenderInstance(void) { if (mBaseSceneNode) { if (mStaticLight) { destroyLight(); } else { if (!mLight) { createLight(); } updateRenderInstanceImpl(); } } }
light_t * light_addRPOINT(const char * name){ lightcount++; for(; lightArrayFirstOpen < lightArraySize && lightlist[lightArrayFirstOpen].type; lightArrayFirstOpen++); if(lightArrayFirstOpen == lightArraySize){ //resize lightArraySize++; lightlist = realloc(lightlist, lightArraySize * sizeof(light_t)); } lightlist[lightArrayFirstOpen] = createLight(name); int returnid = (lightcount << 16) | lightArrayFirstOpen; lightlist[lightArrayFirstOpen].myid = returnid; addToHashTable(lightlist[lightArrayFirstOpen].name, returnid, lighthashtable); //todo maybe have light have a hash variable, so i dont have to calculate it again if i want to delete... maybe if(lightArrayLastTaken < lightArrayFirstOpen) lightArrayLastTaken = lightArrayFirstOpen; // printf("lightarraysize = %i\n", lightArraySize); // printf("lightcount = %i\n", lightcount); return &lightlist[lightArrayFirstOpen]; }
Scene SDFLoader::loadScene(std::string const& filePath) { //std::cout << "loadScene: " << filePath << std::endl; std::ifstream file; std::string text; Scene scene; file.open(filePath, std::ios::in); //std::cout << "loadScene (openFile): " << filePath << std::endl; while(!file.eof()) { std::getline(file, text); std::istringstream textStream{text}; std::string word; textStream >> word; ////std::cout << "Word:" << word << "\n"; //std::cout << "loadScene (start): " << filePath << "Word:" << word << std::endl; if(word == "camera") { ////std::cout << "Is Camera \n"; auto tmpCamera = createCamera(textStream); _cameras.insert(std::make_pair(tmpCamera.name(),tmpCamera)); } if(word == "render") { ////std::cout << "Is Render \n"; setRenderData(textStream,scene); } //std::cout << "loadScene (preDefine): " << filePath << "Word:" << word << std::endl; if(word == "define") { //std::cout << "loadScene (Define): " << filePath << std::endl; ////std::cout << "Is Define \n"; textStream >> word; //std::cout << "loadScene (preLight): " << filePath << std::endl; if(word == "light") { //std::cout << "loadScene (Light): " << filePath << std::endl; ////std::cout << "Is Light \n"; auto tmpLight = createLight(textStream); scene._lights.insert(std::make_pair(tmpLight.name(),tmpLight)); } //std::cout << "loadScene (preMaterial): " << filePath << std::endl; if(word == "material") { //std::cout << "loadScene (Material): " << filePath << std::endl; ////std::cout << "Is Material \n"; auto tmpMaterial = createMaterial(textStream); _materials.insert(std::make_pair(tmpMaterial.name(),tmpMaterial)); } //std::cout << "loadScene (preShape): " << filePath << std::endl; if (word == "shape") { //std::cout << "loadScene (Shape): " << filePath << std::endl; ////std::cout << "Is Shape \n"; textStream >> word; if(word == "sphere") { ////std::cout << "Is Sphere \n"; auto tmpSphere = createSphere(textStream); scene._shapes.insert(std::make_pair(tmpSphere->name(),tmpSphere)); } if(word == "box") { ////std::cout << "Is Box \n"; auto tmpBox = createBox(textStream); scene._shapes.insert(std::make_pair(tmpBox->name(),tmpBox)); } if(word == "composite") { ////std::cout << "Is Compsite \n"; auto tmpShapeComposite = createShapeComposite(textStream,scene._shapes); scene._shapes.insert(std::make_pair(tmpShapeComposite->name(),tmpShapeComposite)); } } }
void TerrainManager::terrainInit(Ogre::String file, OgreManager* o) { _OgreManager = o; initialiseResources(); createLight(); setGlobalOptions(); _TerrainGroup = OGRE_NEW Ogre::TerrainGroup(_OgreManager->getSceneManager(), Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); _TerrainGroup->setFilenameConvention(Ogre::String("GameTerrain"), Ogre::String("dat")); _TerrainGroup->setOrigin(Ogre::Vector3::ZERO); setDefaultImportSettings(); bool lTerrainsImported = false; for (long x = 0; x <= 0; ++x) { for (long y = 0; y <= 0; ++y) { //Define terrain function Ogre::String filename = _TerrainGroup->generateFilename(x, y); if (Ogre::ResourceGroupManager::getSingleton().resourceExists(_TerrainGroup->getResourceGroup(), filename)) { _TerrainGroup->defineTerrain(x, y); } else { Ogre::Image img; //Get terrain image Ogre::String tempFile = Ogre::StringConverter::toString(x * 10 + y); tempFile.append(".bmp"); img.load("terrain.bmp", Ogre::String("TerrainResources")); if (x % 2 != 0) img.flipAroundY(); if (y % 2 != 0) img.flipAroundX(); //Get terrain image end _TerrainGroup->defineTerrain(x, y, &img); lTerrainsImported = true; } //Define terrain function end } } _TerrainGroup->loadAllTerrains(true); if (lTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = _TerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; //Init blend maps function start Ogre::TerrainLayerBlendMap* blendMap0 = t->getLayerBlendMap(1); Ogre::TerrainLayerBlendMap* blendMap1 = t->getLayerBlendMap(2); Ogre::Real minHeight0 = -10; Ogre::Real fadeDist0 = 0;//40; Ogre::Real minHeight1 = -10; Ogre::Real fadeDist1 = 0;//15; float* pBlend0 = blendMap0->getBlendPointer(); float* pBlend1 = blendMap1->getBlendPointer(); for (Ogre::uint16 y = 0; y < t->getLayerBlendMapSize(); ++y) { for (Ogre::uint16 x = 0; x < t->getLayerBlendMapSize(); ++x) { Ogre::Real tx, ty; blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty); Ogre::Real height = t->getHeightAtTerrainPosition(tx, ty); Ogre::Real val = (height - minHeight0) / fadeDist0; val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1); *pBlend0++ = val; val = (height - minHeight1) / fadeDist1; val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1); *pBlend1++ = val; } } blendMap0->dirty(); blendMap1->dirty(); blendMap0->update(); blendMap1->update(); //Init blend maps end } } _TerrainGroup->freeTemporaryResources(); _OgreManager->getSceneManager()->setSkyBox(true, "Examples/EarlyMorningSkyBox", 5000, true, Ogre::Quaternion::IDENTITY, "GameResources"); }
Node* Universe::createUniverse() { // we need the scene's state set to enable the light for the entire scene Group *scene = new Group(); lightStateSet = scene->getOrCreateStateSet(); lightStateSet->ref(); // create a light LightSource *lightSource = new LightSource(); lightSource->setLight(createLight(Vec4(0.9, 0.9, 0.9, 1.0))); // enable the light for the entire scene lightSource->setLocalStateSetModes(StateAttribute::ON); lightSource->setStateSetModes(*lightStateSet, StateAttribute::ON); lightTransform = new PositionAttitudeTransform(); lightTransform->addChild(lightSource); lightTransform->setPosition(Vec3(3, 0, 0)); // create objects try { CrfGeometry* crfGeometry = new CrfGeometry(); // Stars Material *material = new Material(); material->setEmission(Material::FRONT, Vec4(1.0, 1.0, 1.0, 1.0)); material->setAmbient(Material::FRONT, Vec4(1.0, 1.0, 1.0, 1.0)); material->setShininess(Material::FRONT, 25.0); crfGeometry->prepareMaterial(material); if(_starfield_enabled) { for (int i = 0; i < 6; i++) { starField[i] = crfGeometry->createPlane(_diameter, "./textures/stars.jpg", true); scene->addChild(starField[i]); } this->positionStarField(); } if(_spacewarp_enabled) scene->addChild(this->createSpacewarp()); // sun crfGeometry->prepareMaterial(material); sun = crfGeometry->createSphere(300, "./textures/sunmap.jpg", false); // planets Material *material2 = new Material(); material2->setEmission(Material::FRONT, Vec4(0.1, 0.1, 0.1, 1.0)); crfGeometry->prepareMaterial(material2); mercury= crfGeometry->createSphere(3.8, "./textures/mercurymap.jpg", false); venus = crfGeometry->createSphere(9.5, "./textures/venusmap.jpg", false); earth = crfGeometry->createSphere(10, "./textures/earthmap1k.jpg", false); emoon = crfGeometry->createSphere(2, "./textures/moonmap1k.jpg", false); mars = crfGeometry->createSphere(5.3, "./textures/mars_1k_color.jpg", false); jupiter = crfGeometry->createSphere(109, "./textures/jupitermap.jpg", false); saturn = crfGeometry->createSphere(91, "./textures/saturnmap.jpg", false); } catch (char *e) { std::cerr << e; } lightTransform->addChild(sun); scene->addChild(lightTransform); scene->addChild(mercury); scene->addChild(venus); earth->addChild(emoon); scene->addChild(earth); scene->addChild(mars); scene->addChild(jupiter); scene->addChild(saturn); return scene; }