void GraphicsView::initializeEvent() { glShadeModel(GL_FLAT); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); ///---------------- glClearColor(backgroundColor_[0], backgroundColor_[1], backgroundColor_[2], backgroundColor_[3]); // ウインドウの背景色の指定 glShadeModel(GL_SMOOTH); glEnable(GL_LINE_SMOOTH); // アンチエイリアス glEnable(GL_POINT_SMOOTH); // glEnable(GL_POLYGON_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); addLight(LightPtr(new Light(0))); addLight(LightPtr(new Light(1))); light(0)->setPosition({100,100,200}); light(1)->setPosition({100,-100,200}); camera_->initializeConfiguration(); initialized_ = true; }
void SpiralScene::setupLights() { Color white(1, 1, 1); LightPointer l1(new Light(Vector3d(-3, 12, -15), 0)); l1->setAmbient(white * .2); l1->setDiffuse(white); l1->setSpecular(white); addLight(l1); LightPointer l2(new Light(Vector3d(-10, 10, -15), 0)); Color l2Color(.3, .8, .3); l2->setDiffuse(l2Color * .8); l2->setSpecular(l2Color); addLight(l2); LightPointer l3(new Light(Vector3d(10, 10, -50), 0)); Color l3Color(.3, .3, .8); l3->setDiffuse(l3Color * .9); l3->setSpecular(l3Color); addLight(l3); LightPointer l4(new Light(Vector3d(0, 0, -100), 0)); Color l4Color(.8, .3, .3); l4->setDiffuse(l4Color * .9); l4->setSpecular(l4Color); addLight(l4); }
/** * Recalculate lighting for the units. */ void TerrainModifier::calculateUnitLighting() { const int layer = 2; // Dynamic lighting layer. const int personalLightPower = 15; // amount of light a unit generates // during daytime don't calculate lighting if (_save->getGlobalShade() < 1) return; // reset all light to 0 first for (int i = 0; i < _save->getWidth() * _save->getLength() * _save->getHeight(); i++) { _save->getTiles()[i]->resetLight(layer); } // add lighting of soldiers for (std::vector<BattleUnit*>::iterator i = _save->getUnits()->begin(); i != _save->getUnits()->end(); i++) { if ((*i)->getFaction() == FACTION_PLAYER) { addLight((*i)->getPosition(), personalLightPower, layer); } } // set changed light tiles to uncached for (int i = 0; i < _save->getWidth() * _save->getLength() * _save->getHeight(); i++) { _save->getTiles()[i]->checkForChangedLight(layer); } }
/** * Recalculate lighting for the terrain: objects,items,fire. */ void TerrainModifier::calculateTerrainLighting() { const int layer = 1; // Static lighting layer. const int fireLightPower = 15; // amount of light a fire generates // during daytime don't calculate lighting if (_save->getGlobalShade() < 1) return; // reset all light to 0 first for (int i = 0; i < _save->getWidth() * _save->getLength() * _save->getHeight(); i++) { _save->getTiles()[i]->resetLight(layer); } // add lighting of terrain for (int i = 0; i < _save->getWidth() * _save->getLength() * _save->getHeight(); i++) { // only floors and objects can light up if (_save->getTiles()[i]->getMapData(O_FLOOR) && _save->getTiles()[i]->getMapData(O_FLOOR)->getLightSource()) { addLight(_save->getTiles()[i]->getPosition(), _save->getTiles()[i]->getMapData(O_FLOOR)->getLightSource(), layer); } if (_save->getTiles()[i]->getMapData(O_OBJECT) && _save->getTiles()[i]->getMapData(O_OBJECT)->getLightSource()) { addLight(_save->getTiles()[i]->getPosition(), _save->getTiles()[i]->getMapData(O_OBJECT)->getLightSource(), layer); } // fires if (_save->getTiles()[i]->getFire()) { addLight(_save->getTiles()[i]->getPosition(), fireLightPower, layer); } } // todo: add lighting of items (flares) // set changed light tiles to uncached for (int i = 0; i < _save->getWidth() * _save->getLength() * _save->getHeight(); i++) { _save->getTiles()[i]->checkForChangedLight(layer); } }
//------------------------------ bool LightImporter::import() { addLight( *mLight ); LightObject* maxLight = createLight(mLight); handleObjectReferences(mLight, maxLight); return true; }
void OBJScene::setupLights() { Color white(1, 1, 1); LightPointer l1(new Light(Vector3d(-3, 12, -15), 0)); l1->setAmbient(white * .2); l1->setDiffuse(white); l1->setSpecular(white); addLight(l1); }
void World::addAmbientLight(D3DXCOLOR color) { // Create and add an ambient light. Light* light = new Light(); light->setMaterial(Material(color, D3DXCOLOR(0, 0, 0, 0), D3DXCOLOR(0, 0, 0, 0))); light->setPosition(D3DXVECTOR3(0, 0, 0)); light->setDirection(D3DXVECTOR3(0, 0, 0)); light->setSpotPower(0.0f); light->setLength(10000.0f); addLight(light); }
uint32_t LightManager::addLight(const Light& data, osg::Node* remove_with) { uint32_t light_uid = addLight(data); if(!remove_with->getUserData()) remove_with->setUserData(new DelLights); dynamic_cast<DelLights*>(remove_with->getUserData())->d_lights.push_back(new DelLight(this, light_uid)); return light_uid; }
//--------------------------------------------------------------- void LightExporter::exportEnvironmentAmbientLight() { // Add the ambient lighting from the environment settings Point3 ambientColor = mDocumentExporter->getMaxInterface()->GetAmbient(0, FOREVER); COLLADASW::Color ambientLightColor = EffectExporter::maxColor2Color( ambientColor ); COLLADASW::AmbientLight ambientLight(COLLADASW::LibraryLights::mSW, ENVIRONMENT_AMBIENT_LIGHT_ID, ENVIRONMENT_AMBIENT_LIGHT_NAME); ambientLight.setColor( ambientLightColor ); addLight( ambientLight ); }
void NativeRenderLogic::initLights(ozone::WorldModel::WorldAccess *worldAccess) { assert(worldAccess); const size_t objectsCount = worldAccess->objectsCount(); for(size_t i = 0; i < objectsCount; ++i) { GameObject *object = (*worldAccess)[i]; assert(object); object::Light* light = dynamic_cast<object::Light*>(object); if(light) addLight(light); } }
Four_Spheres_Reflexions::Four_Spheres_Reflexions() : camera(rt::Point(0, 0, 0), rt::Point(0, 500, 0), rt::vector(0, 0, 1)), light(0., 0., 0., rt::color::WHITE, this), s1(rt::Point(3, 20, 0), 3, rt::Texture(rt::color::WHITE, rt::color(255, 255, 0), 1000, 0, 1)), s2(rt::Point(-3, 20, 3), 3, rt::Texture(rt::color::WHITE, rt::color(255, 0, 255), 1000, 0, 1)), s3(rt::Point(-3, 20, -3), 3, rt::Texture(rt::color::WHITE, rt::color(0, 255, 255), 1000, 0, 1)), s4(rt::Point(3, 20, 6), 3, rt::Texture(rt::color::WHITE, rt::color::RED, 1000, 0, 1)) { setCamera(&camera); addLight(&light); addSolid(&s1); addSolid(&s2); addSolid(&s3); addSolid(&s4); }
Many_Spheres::Many_Spheres(int nbSpheres) : camera(rt::Point(0, 0, 0), rt::Point(0, 500, 0), rt::vector(0, 0, 1)), light(-20, -25, 0, rt::color::WHITE, this), spheres(nbSpheres), plan(rt::Texture(rt::color::WHITE, rt::color::WHITE, 1, 0, 1), rt::Point(0, 0, 10), rt::vector(0, 0, -1)) { setCamera(&camera); addLight(&light); for(int k = 0 ; k < nbSpheres ; k++) { rt::Sphere* sphere = new rt::Sphere(rt::Point(0 * cos(k), 20 + 35* cos(k), 25 * cos(k) ), 3, rt::Texture(rt::color::BLUE, rt::color::RED, 1, 0, 1)); spheres[k] = sphere; addSolid(sphere); } addSolid(&plan); }
void MissionLighting::processLights( ITRBasicLighting::LightList & lightList, SimContainer & interior ) { // reset the ambient intensity ITRBasicLighting::m_ambientIntensity.set( 0.f, 0.f, 0.f ); // walk the lights for( int i = 0; i < m_lights.size(); i++ ) { SimLightQuery query; // grab the light info if( ( m_lights[i]->processQuery( &query ) ) ) { // go through the lights associated with this object for( int j = 0; j < query.count; j++ ) addLight( lightList, interior, *query.light[j], query.ambientIntensity ); } } }
void Scene::componentListener(std::shared_ptr<Component> component, ComponentUpdateStatus status){ componentEvents.notifyListeners({component, status}); auto camera = std::dynamic_pointer_cast<Camera>(component); auto light = std::dynamic_pointer_cast<Light>(component); if (status == ComponentUpdateStatus::Created){ if (camera){ mCameras.push_back(camera); } else if (light){ mLights[light] = light->lightTypeChanged.createListener([&](std::shared_ptr<Light> l){ rebuildSceneLights(); }, 0); addLight(light); } auto updateable = std::dynamic_pointer_cast<Updatable>(component); if (updateable){ mUpdatable.push_back(updateable); } } if (status == ComponentUpdateStatus::Destroyed){ if (camera){ auto pos = find(mCameras.begin(), mCameras.end(), camera); if (pos != mCameras.end()){ mCameras.erase(pos); } } else if (light){ // rebuild lights auto lightPos = mLights.find(light); if (lightPos != mLights.end()){ mLights.erase(lightPos); rebuildSceneLights(); } } auto updateable = std::dynamic_pointer_cast<Updatable>(component); if (updateable){ auto pos = find(mUpdatable.begin(), mUpdatable.end(), updateable); if (pos != mUpdatable.end()){ mUpdatable.erase(pos); } } } }
Real_Transparence::Real_Transparence() : bmap(new rt::ProceduralBumpmap(0.9, 0.9, 10)), camera(rt::Point(0, 0, 0), rt::Point(0, 500, 0), rt::vector(0, 0, 1)), light(0., 0., 0., rt::color::WHITE, this), s1(rt::Point(3, 20, 0), 3, rt::Texture(rt::color::WHITE, rt::color(255, 255, 0), 100, 0, 1, bmap)), s2(rt::Point(-3, 20, 3), 3, rt::Texture(rt::color::WHITE, rt::color(255, 0, 255), 100, 0, 1, bmap)), s3(rt::Point(-3, 20, -3), 3, rt::Texture(rt::color::WHITE, rt::color(0, 255, 255), 100, 0, 1, bmap)), s4(rt::Point(0, 15, 0), 3, rt::Texture(rt::color::WHITE, rt::color::WHITE, 1, 0, 1, bmap)), s5(rt::Point(3, 20, 6), 3, rt::Texture(rt::color::WHITE, rt::color::RED, 100, 0, 1, bmap)) { setCamera(&camera); addLight(&light); addSolid(&s1); addSolid(&s2); addSolid(&s3); addSolid(&s4); addSolid(&s5); }
QOgrePointLightWidget::QOgrePointLightWidget(Ogre::SceneManager* s, QWidget *p, std::string lightName,const char * name):QOgreLightWidget(s,p,lightName,name) { //Position globalLayout->addWidget(new QLabel(QString("Position"), global),3,0); position[0] = new WDoubleLineEdit(global,"positionX"); globalLayout->addWidget(position[0],3,1); position[0]->setMinValue( (double)-INFINITY); position[0]->setMaxValue( (double) INFINITY); connect( position[0], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); position[1] = new WDoubleLineEdit(global,"positionY"); globalLayout->addWidget(position[1],3,2); position[1]->setMinValue( (double)-INFINITY); position[1]->setMaxValue( (double) INFINITY); connect( position[1], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); position[2] = new WDoubleLineEdit(global,"positionZ"); globalLayout->addWidget(position[2],3,3); position[2]->setMinValue( (double)-INFINITY); position[2]->setMaxValue( (double) INFINITY); connect( position[2], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); position[0]->setValue(0); position[1]->setValue(50); position[2]->setValue(0); addLight(); }
QOgreSpotLightWidget::QOgreSpotLightWidget(Ogre::SceneManager* s, QWidget *p, std::string lightName, const char * name):QOgreLightWidget(s,p,lightName,name) { //Position globalLayout->addWidget(new QLabel(QString("Position"), global),3,0); position[0] = new WDoubleLineEdit(global,"positionX"); globalLayout->addWidget(position[0],3,1); position[0]->setMinValue( (double)-INFINITY); position[0]->setMaxValue( (double) INFINITY); connect( position[0], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); position[1] = new WDoubleLineEdit(global,"positionY"); globalLayout->addWidget(position[1],3,2); position[1]->setMinValue( (double)-INFINITY); position[1]->setMaxValue( (double) INFINITY); connect( position[1], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); position[2] = new WDoubleLineEdit(global,"positionZ"); globalLayout->addWidget(position[2],3,3); position[2]->setMinValue( (double)-INFINITY); position[2]->setMaxValue( (double) INFINITY); connect( position[2], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); //Direction globalLayout->addWidget(new QLabel(QString("Direction"), global),4,0); direction[0] = new WDoubleLineEdit(global,"directionX"); globalLayout->addWidget(direction[0],4,1); direction[0]->setMinValue( (double)-INFINITY); direction[0]->setMaxValue( (double) INFINITY); connect( direction[0], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); direction[1] = new WDoubleLineEdit(global,"directionY"); globalLayout->addWidget(direction[1],4,2); direction[1]->setMinValue( (double)-INFINITY); direction[1]->setMaxValue( (double) INFINITY); connect( direction[1], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); direction[2] = new WDoubleLineEdit(global,"directionZ"); globalLayout->addWidget(direction[2],4,3); direction[2]->setMinValue( (double)-INFINITY); direction[2]->setMaxValue( (double) INFINITY); connect( direction[2], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); //Range globalLayout->addWidget(new QLabel(QString("Range In"), global),5,0); range[0] = new WDoubleLineEdit(global,"rangeIN"); range[0]->setMaximumWidth(SIZE_ENTRY); globalLayout->addWidget(range[0],5,1); range[0]->setMinValue( 0.0f); range[0]->setMaxValue( 360.0f); connect( range[0], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); globalLayout->addWidget(new QLabel(QString("Out"), global),5,2); range[1] = new WDoubleLineEdit(global,"rangeOUT"); range[1]->setMaximumWidth(SIZE_ENTRY); globalLayout->addWidget(range[1],5,3); range[1]->setMinValue( 0.0f); range[1]->setMaxValue( 360.0f); connect( range[1], SIGNAL( returnPressed() ), this, SLOT( setDirty() ) ); position[0]->setValue(0); position[1]->setValue(50); position[2]->setValue(0); direction[0]->setValue(0); direction[1]->setValue(-1); direction[2]->setValue(0); range[0]->setValue(30.0f); range[1]->setValue(50.0f); addLight(); }
//--------------------------------------------------------------- void LightExporter::exportLight( ExportNode* exportNode ) { if ( !exportNode->getIsInVisualScene() ) return; String lightId = getLightId(*exportNode); INode * iNode = exportNode->getINode(); LightObject* lightObject = (LightObject*) (iNode->GetObjectRef()); if ( !lightObject ) return; if ( mDocumentExporter->isExportedObject(ObjectIdentifier(lightObject)) ) return; mDocumentExporter->insertExportedObject(ObjectIdentifier(lightObject), exportNode); // Retrieve the target node, if we are not baking matrices. // Baked matrices must always sample the transform! ULONG ClassId = lightObject->ClassID().PartA(); bool isTargeted = !mDocumentExporter->getOptions().getBakeMatrices() && (ClassId == SPOT_LIGHT_CLASS_ID || ClassId == TDIR_LIGHT_CLASS_ID); INode* targetNode = isTargeted ? iNode->GetTarget() : 0; // some lights are not supported at all switch (ClassId) { case FSPOT_LIGHT_CLASS_ID: case SPOT_LIGHT_CLASS_ID: case DIR_LIGHT_CLASS_ID: case TDIR_LIGHT_CLASS_ID: case SKY_LIGHT_CLASS_ID_PART_A: case OMNI_LIGHT_CLASS_ID: break; default: return; } // Determine the light's type bool isSpot = false; bool isDirectional = false; bool isPoint = false; bool isSky = false; COLLADASW::Light::LightType lightType; switch (ClassId) { case FSPOT_LIGHT_CLASS_ID: case SPOT_LIGHT_CLASS_ID: lightType = COLLADASW::Light::SPOT; isSpot = true; break; case DIR_LIGHT_CLASS_ID: case TDIR_LIGHT_CLASS_ID: lightType = COLLADASW::Light::DIRECTIONAL; isDirectional = true; break; case SKY_LIGHT_CLASS_ID_PART_A: lightType = COLLADASW::Light::POINT; isSky = true; break; case OMNI_LIGHT_CLASS_ID: lightType = COLLADASW::Light::POINT; isPoint = true; break; } COLLADASW::Light * colladaLight = 0; switch ( lightType ) { case COLLADASW::Light::DIRECTIONAL: colladaLight = new COLLADASW::DirectionalLight(COLLADASW::LibraryLights::mSW, lightId, COLLADASW::Utils::checkNCName(NativeString(exportNode->getINode()->GetName()))); break; case COLLADASW::Light::POINT: colladaLight = new COLLADASW::PointLight(COLLADASW::LibraryLights::mSW, lightId, COLLADASW::Utils::checkNCName(NativeString(exportNode->getINode()->GetName()))); break; case COLLADASW::Light::SPOT: colladaLight = new COLLADASW::SpotLight(COLLADASW::LibraryLights::mSW, lightId, COLLADASW::Utils::checkNCName(NativeString(exportNode->getINode()->GetName()))); break; } // Retrieve the parameter block IParamBlock* parameters = 0; IParamBlock2* parametersSky = 0; if (isSky) parametersSky = (IParamBlock2*) lightObject->GetReference(MaxLight::PBLOCK_REF_SKY); else parameters = (IParamBlock*) lightObject->GetReference(MaxLight::PBLOCK_REF); if (!parameters && !parametersSky) { delete colladaLight; return; } if (parameters) { bool hasAnimatedColor = mAnimationExporter->addAnimatedParameter(parameters, MaxLight::PB_COLOR, lightId, colladaLight->getColorDefaultSid(), 0 ); colladaLight->setColor(EffectExporter::maxColor2Color(parameters->GetColor(MaxLight::PB_COLOR)), hasAnimatedColor); } else if (parametersSky ) { bool hasAnimatedColor = mAnimationExporter->addAnimatedParameter(parametersSky, MaxLight::PB_SKY_COLOR, lightId, colladaLight->getColorDefaultSid(), 0 ); colladaLight->setColor(EffectExporter::maxColor2Color(parametersSky->GetColor(MaxLight::PB_SKY_COLOR)), hasAnimatedColor); } if (isSpot || isPoint) { int decayFunction = parameters->GetInt(isPoint ? MaxLight::PB_DECAY : MaxLight::PB_OMNIDECAY, mDocumentExporter->getOptions().getAnimationStart()); switch (decayFunction) { case 1: colladaLight->setConstantAttenuation(0.0f); colladaLight->setLinearAttenuation(1.0f); break; case 2: colladaLight->setConstantAttenuation(0.0f); colladaLight->setQuadraticAttenuation(1.0f); break; case 0: default: colladaLight->setConstantAttenuation(1.0f); break; } } else if (isSky) { colladaLight->setConstantAttenuation(1.0f); } setExtraTechnique(colladaLight); if ( parameters ) addParamBlockAnimatedExtraParameters(LIGHT_ELEMENT, LIGHT_PARAMETERS, LIGHT_PARAMETER_COUNT, parameters, lightId); else addParamBlockAnimatedExtraParameters(SKYLIGHT_ELEMENT, SKYLIGHT_PARAMETERS, SKYLIGHT_PARAMETER_COUNT, parametersSky, lightId); // add all the information to extra tag, that are not contained in IParamBlock if (isSpot || isDirectional || isPoint) { GenLight* light = (GenLight*)(lightObject); if (!light) { delete colladaLight; return; } // Export the overshoot flag for directional lights if (isDirectional || isSpot) { addExtraChildParameter(LIGHT_ELEMENT, OVERSHOOT_PARAMETER, light->GetOvershoot() != false); } addExtraChildParameter(LIGHT_ELEMENT, DECAY_TYPE_PARAMETER, (int)light->GetDecayType()); addExtraChildParameter(LIGHT_ELEMENT, USE_NEAR_ATTENUATION_PARAMETER, (light->GetUseAttenNear() != false)); addExtraChildParameter(LIGHT_ELEMENT, USE_FAR_ATTENUATION_PARAMETER, (light->GetUseAtten() != false)); exportShadowParameters(light); if (light->GetProjector()) { Texmap* projectorMap = light->GetProjMap(); if (projectorMap) { String imageId = exportTexMap(projectorMap); if ( !imageId.empty() ) { addExtraChildParameter(LIGHT_ELEMENT, LIGHT_MAP_ELEMENT, "#" + imageId); } } } } else // isSky { Texmap *colorMap = parametersSky->GetTexmap(MaxLight::PB_SKY_COLOR_MAP, mDocumentExporter->getOptions().getAnimationStart()); String imageId = exportTexMap(colorMap); if ( !imageId.empty()) { addExtraChildParameter(SKYLIGHT_ELEMENT, SKYLIGHT_COLORMAP_ELEMENT, "#" + imageId); } } addLight(*colladaLight); delete colladaLight; }
void TunnelLevel::setup(){ INFO("Generating Test Level..."); readFile(); initalizeGrid(); createRenders(); createLevel(); INFO("Removal String so less of make"); waterSurfaceManager = WaterSurfaceManagerPtr(new WaterSurfaceManager()); addGameObject(waterSurfaceManager); CameraPtr cam3(new Camera(glm::vec3(30, 45, 0), glm::vec3(30, 15, 6), glm::vec3(0, 1, 0))); cam3->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("CinematicCamera", cam3); setMainCamera("CinematicCamera"); setCullingCamera("CinematicCamera"); INFO("Setting up the cameras for the Test Level..."); CameraPtr cam1(new Camera(glm::vec3(32.0f, 12.0f, -24.0f), glm::vec3(4, 4, -10), glm::vec3(0, 1, 0))); cam1->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("Camera1", cam1); setMainCamera("Camera1"); setCullingCamera("Camera1"); CameraPtr cam2(new Camera(glm::vec3(0, 1, 0), glm::vec3(-6, -3, 6), glm::vec3(0, 1, 0))); cam2->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); l1 = LightPtr(new Light(glm::vec3(1), 30.0f, glm::vec3(32, 30, -20))); l1->setPosition(l1->getDirection()); Uniform3DGridPtr<int> typeGrid = getTypeGrid(); gridCenter = glm::vec3((typeGrid->getMaxX() - typeGrid->getMinX())/2.0f, (typeGrid->getMaxY() - typeGrid->getMinY())/2.0f, (typeGrid->getMinZ() - typeGrid->getMaxZ())/2.0f); l1->setViewMatrix(glm::lookAt( l1->getPosition(), gridCenter, glm::vec3(0, 1, 0))); l1->setProjectionMatrix(glm::ortho<float>(-30,30,-30,30,-70,70)); addLight("Sun", l1); cinematicPlayer = CinematicPlayerPtr(new CinematicPlayer(cam3)); cinematicPlayer->setup(); addGameObject("cinematicPlayer", cinematicPlayer); INFO("Setting up the player for the Test Level..."); player = PlayerPtr(new Player(cam1, 2)); player->setup(); addGameObject("player" , player); CollisionManager::addCollisionObjectToList(player); debugPlayer = DebugPlayerPtr(new DebugPlayer(cam2)); debugPlayer->setup(); addGameObject("debugPlayer" , debugPlayer); addCamera("DebugCamera", cam2); INFO("Creating Switch for the Test Level..."); SwitchPtr s1(new Switch(glm::vec3(0.9f, 0.1f, 0.1f), glm::vec3(33.7f, 11.0f, -27.0f), glm::vec3(0,0,1), -20.0f, 1)); s1->setup(); addGameObject("s1", s1); CollisionManager::addCollisionObjectToGrid(s1); std::list<SolidCubePtr> solidCubes; // INFO("Creating Active Terrain for the Test Level..."); for(int i = 11; i < 36; i+=2) { for(int j = -27; j < -20; j+=2) { SolidCubePtr at1(new SolidCube(glm::vec3(29, i, j))); at1->setup(); RenderEngine::getRenderGrid()->removeObject(at1->getObject()); solidCubes.push_back(at1); } } ActiveTerrainPtr a1(new ActiveTerrain(s1, glm::vec3(), glm::vec3(), 50.0f)); a1->setup(); a1->setCubes(solidCubes); addGameObject("a1", a1); sky = ObjectPtr(new Object( LoadManager::getMesh("sphere.obj"), MaterialManager::getMaterial("None"))); sky->applyTexture(LoadManager::getTexture("Sky")); sky->enableTexture(); sky->scale(glm::vec3(-50.0f,-50.0f,-50.0f)); sky->translate(Director::getScene()->getCamera()->getEye()); RenderEngine::getRenderElement("textured")->addObject(sky); ExclamationPtr exclamation = ExclamationPtr(new Exclamation(glm::vec3(60, 5, -23))); exclamation->setup(); addGameObject("exclamation", exclamation); PTR_CAST(SolidCube, (*grid)(7, 20, 11))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(7, 20, 12))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(7, 20, 11))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(7, 20, 12))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(8, 10, 21, 21, 11, 12, 1, 0, 0.0f); shearRegion(11, 13, 20, 20, 11, 12, 1, 0, 0.5f); PTR_CAST(SolidCube, (*grid)(16, 12, 0))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 0))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(16, 12, 0))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 0))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(16, 17, 13, 13, 1, 4, 0, 1, 0.0f); shearRegion(16, 17, 12, 12, 5, 8, 0, 1, 0.5f); PTR_CAST(SolidCube, (*grid)(16, 12, 23))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 23))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(16, 12, 23))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(17, 12, 23))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); shearRegion(16, 17, 13, 13, 19, 22, 0, -1, 0.0f); shearRegion(16, 17, 12, 12, 15, 18, 0, -1, 0.5f); PTR_CAST(SolidCube, (*grid)(26, 12, 15))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(26, 12, 8))->getObject()->applyTextureIndex(LoadManager::getTexture("DrainTexture"), 0); PTR_CAST(SolidCube, (*grid)(26, 12, 15))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); PTR_CAST(SolidCube, (*grid)(26, 12, 8))->getObject()->applyNormalMapIndex(LoadManager::getTexture("RegularNormalMap"), 0); }
// ------------------------------------ bool LightExporter::exportLight ( const MDagPath& dagPath ) { if ( !ExportOptions::exportLights() ) return false; MObject lightNode = dagPath.node(); // Retrieve the Maya light object MStatus status; MFnLight lightFn(lightNode, &status); CHECK_STAT(status); if (status != MStatus::kSuccess) return false; // Get the maya light id. String mayaLightId = mDocumentExporter->dagPathToColladaId ( dagPath ); // Generate a COLLADA id for the new object String colladaLightId; // Check if there is an extra attribute "colladaId" and use this as export id. MString attributeValue; DagHelper::getPlugValue ( lightNode, COLLADA_ID_ATTRIBUTE_NAME, attributeValue ); if ( attributeValue != EMPTY_CSTRING ) { // Generate a valid collada name, if necessary. colladaLightId = mDocumentExporter->mayaNameToColladaName ( attributeValue, false ); } else { // Generate a COLLADA id for the new object colladaLightId = mDocumentExporter->dagPathToColladaId ( dagPath ); } // Make the id unique and store it in a map. colladaLightId = mLightIdList.addId ( colladaLightId ); mMayaIdColladaIdMap [ mayaLightId ] = colladaLightId; // Get a pointer to the stream writer. COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); // The light name String lightName = mDocumentExporter->dagPathToColladaName ( dagPath ); // Figure out the type of light and create it COLLADASW::Light* light = NULL; MFn::Type type = lightNode.apiType(); switch (type) { case MFn::kAmbientLight: light = new COLLADASW::AmbientLight( streamWriter, colladaLightId, lightName ); break; case MFn::kDirectionalLight: light = new COLLADASW::DirectionalLight( streamWriter, colladaLightId, lightName ); break; case MFn::kSpotLight: light = new COLLADASW::SpotLight( streamWriter, colladaLightId, lightName ); break; case MFn::kPointLight: // Intentional pass-through default: light = new COLLADASW::PointLight( streamWriter, colladaLightId, lightName ); break; } // Export the original maya name. light->addExtraTechniqueParameter ( PROFILE_MAYA, PARAMETER_MAYA_ID, mayaLightId ); // Get a pointer to the animation exporter. AnimationExporter* anim = mDocumentExporter->getAnimationExporter(); bool animated = false; // Color/Intensity are the common attributes of all lights MColor mayaColor = lightFn.color ( &status ); CHECK_STAT(status); COLLADASW::Color lightColor ( mayaColor.r, mayaColor.g, mayaColor.b, mayaColor.a ); animated = anim->addNodeAnimation ( lightNode, ATTR_COLOR, kColour, RGBA_PARAMETERS ); light->setColor( lightColor, animated ); float intensity = lightFn.intensity ( &status ); CHECK_STAT(status); animated = anim->addNodeAnimation ( lightNode, ATTR_INTENSITY, kSingle ); light->setIntensity( intensity, animated ); // Export light intensity light->addExtraTechniqueParameter(PROFILE_MAYA, ATTR_INTENSITY, intensity); // Add the type specific attributes if (lightNode.hasFn(MFn::kNonAmbientLight)) { // Needed Point and Spot light types parameters: Attenuation and Attenuation_Scale // Attenuation in COLLADA is equal to Decay in Maya. MFnNonAmbientLight naLightFn(lightNode); int decayRate = naLightFn.decayRate(&status); CHECK_STAT(status); decayRate = std::min ( decayRate, 2 ); decayRate = std::max ( decayRate, 0 ); light->setConstantAttenuation ( ( decayRate == 0 ) ? 1.0f : 0.0f); light->setLinearAttenuation ( ( decayRate == 1 ) ? 1.0f : 0.0f); light->setQuadraticAttenuation ( ( decayRate == 2 ) ? 1.0f : 0.0f); } else if (lightNode.hasFn(MFn::kAmbientLight)) { MFnAmbientLight ambientLightFn ( lightNode ); float ambientShade = ambientLightFn.ambientShade(); String paramSid = EMPTY_STRING; animated = anim->addNodeAnimation ( lightNode, ATTR_AMBIENT_SHADE, kSingle ); if ( animated ) paramSid = ATTR_AMBIENT_SHADE; light->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_AMBIENTSHADE_LIGHT_PARAMETER, ambientShade, paramSid ); } if (lightNode.hasFn(MFn::kSpotLight)) { // Put in the needed spot light type attributes : Falloff, Falloff_Scale and Angle MFnSpotLight spotFn(lightNode); float fallOffAngle = COLLADABU::Math::Utils::radToDegF ( (float)spotFn.coneAngle( &status ) ); CHECK_STAT(status); animated = anim->addNodeAnimation ( lightNode, ATTR_CONE_ANGLE, ( SampleType ) ( kSingle | kAngle ) ); light->setFallOffAngle ( fallOffAngle, animated ); light->setFallOffExponent ( 1.0f ); float penumbraValue = COLLADABU::Math::Utils::radToDegF ( (float)spotFn.penumbraAngle( &status ) ); CHECK_STAT(status); animated = anim->addNodeAnimation ( lightNode, ATTR_PENUMBRA_ANGLE, ( SampleType ) ( kSingle | kAngle ) ); // Export spot setting float dropOff = (float)spotFn.dropOff(&status); CHECK_STAT(status); light->addExtraTechniqueParameter(PROFILE_MAYA, MAYA_PENUMBRA_LIGHT_PARAMETER, penumbraValue); light->addExtraTechniqueParameter(PROFILE_MAYA, MAYA_DROPOFF_LIGHT_PARAMETER, dropOff); // TODO // FCDLightTools::LoadPenumbra(light, penumbraValue, colladaLight->GetOuterAngle().GetAnimated()); // TODO // animated = anim->addNodeAnimation ( lightNode, ATTR_DROP_OFF, kSingle ); // light->setDropOff ( (float) spotFn.dropOff ( &status ), animated ); CHECK_MSTATUS(status); } SceneElement* sceneElement = NULL; SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph(); sceneElement = sceneGraph->findElement(dagPath); exportExtraAttributes(sceneElement, light); addLight ( *light ); delete light; return true; }
//parse a scene description file and generate a Scene Scene* SceneParser::parse(const char* filename){ std::cout << "SceneParser::parse parses scene... " << filename <<" \n"; struct basicxmlnode * rootNode = NULL; //open file FILE * fp = fopen(filename, "rt"); if (!fp) { std::cerr << "SceneParser - Error: Failed opening file " << filename << "\n"; return NULL; } std::string filenameString = std::string(filename); size_t index = filenameString.find_last_of("/"); if (index == std::string::npos) { index = filenameString.find_last_of("\\"); } if (index == std::string::npos) { directory = ""; } else { directory = filenameString.substr(0,index+1); } //read xml tree rootNode = readbasicxmlnode(fp); fclose(fp); if (!rootNode) { std::cerr << "SceneParser - Error: Failed reading file " << filename << ". Maybe an XML syntax error?\n"; return NULL; } //construct scene Scene* scene = new Scene(); //read scene properties if (!addSceneProperties(rootNode, scene)) { std::cerr << "SceneParser - Error: Failed to read Scene Properties in " << filename << "\n"; deletebasicxmlnode(rootNode); delete(scene); return NULL; } //read camera struct basicxmlnode * cameraNode = getchildnodebyname(rootNode, "Camera"); if (!addCamera(cameraNode, scene)) { std::cerr << "SceneParser - Error: Failed reading camera description in " << filename << "\n"; deletebasicxmlnode(rootNode); delete(scene); return NULL; } //read lights struct basicxmlnode * lightsNode = getchildnodebyname(rootNode, "Lights"); if (!lightsNode) { std::cout << "SceneParser - Warning: No Lights specified in " << filename << "\n"; } else if (!lightsNode->children[0]) { std::cout << "SceneParser - Warning: No Lights specified in " << filename << "\n"; } else { for(int lightsIndex = 0; lightsNode->children[lightsIndex]; lightsIndex++) { if(!addLight(lightsNode->children[lightsIndex], scene)) { std::cerr << "SceneParser - Error: Failed reading light description in " << filename << "\n"; deletebasicxmlnode(rootNode); delete(scene); return NULL; } } } //read materials struct basicxmlnode * materialsNode = getchildnodebyname(rootNode, "Materials"); if (!materialsNode) { std::cout << "SceneParser - No global Materials specified in " << filename << "\n"; } else if (!materialsNode->children[0]) { std::cout << "SceneParser - Empty Materials node in " << filename << "\n"; } else { for(int materialsIndex = 0; materialsNode->children[materialsIndex]; materialsIndex++) { if(!addGlobalMaterial(materialsNode->children[materialsIndex], scene)) { std::cerr << "SceneParser - Error: Failed reading global material description in " << filename << "\n"; deletebasicxmlnode(rootNode); delete(scene); return NULL; } } } //read textures struct basicxmlnode* texturesNode = getchildnodebyname(rootNode, "Textures"); if (!texturesNode) { std::cout << "SceneParser - No global Textures specified in " << filename << "\n"; } else if (!texturesNode->children[0]) { std::cout << "SceneParser - Empty Textures node in " << filename << "\n"; } else { for(int texturesIndex = 0; texturesNode->children[texturesIndex]; texturesIndex++) { if(!addGlobalTexture(texturesNode->children[texturesIndex], scene)) { std::cerr << "SceneParser - Error: Failed reading global texture description in " << filename << "\n"; deletebasicxmlnode(rootNode); delete(scene); return NULL; } } } //read elements struct basicxmlnode * elementsNode = getchildnodebyname(rootNode, "Elements"); if (!elementsNode) { std::cout << "SceneParser - Warning: No Elements specified in " << filename << "\n"; } else if (!elementsNode->children[0]) { std::cout << "SceneParser - Warning: No Elements specified in " << filename << "\n"; } for(int elementsIndex = 0; elementsNode->children[elementsIndex]; elementsIndex++) { if(!addElement(elementsNode->children[elementsIndex], scene)) { std::cerr << "SceneParser - Error: Failed reading element description in " << filename << "\n"; deletebasicxmlnode(rootNode); delete(scene); return NULL; } } //free xml memory deletebasicxmlnode(rootNode); std::cout << "[done]\n\n"; return scene; }
void AmplResult::addLight(int x, int y, int p) { addLight(AmplLight(x,y,p)); }
void LightsExporter::operator()(Object *ob) { Lamp *la = (Lamp*)ob->data; std::string la_id(get_light_id(ob)); std::string la_name(id_name(la)); COLLADASW::Color col(la->r * la->energy, la->g * la->energy, la->b * la->energy); float d, constatt, linatt, quadatt; d = la->dist; constatt = 1.0f; if(la->falloff_type==LA_FALLOFF_INVLINEAR) { linatt = 1.0f / d; quadatt = 0.0f; } else { linatt = 0.0f; quadatt = 1.0f / (d * d); } // sun if (la->type == LA_SUN) { COLLADASW::DirectionalLight cla(mSW, la_id, la_name); cla.setColor(col,false,"color"); cla.setConstantAttenuation(constatt); exportBlenderProfile(cla, la); addLight(cla); } // hemi else if (la->type == LA_HEMI) { COLLADASW::AmbientLight cla(mSW, la_id, la_name); cla.setColor(col,false,"color"); cla.setConstantAttenuation(constatt); exportBlenderProfile(cla, la); addLight(cla); } // spot else if (la->type == LA_SPOT) { COLLADASW::SpotLight cla(mSW, la_id, la_name); cla.setColor(col,false,"color"); cla.setFallOffAngle(la->spotsize,false,"fall_off_angle"); cla.setFallOffExponent(la->spotblend,false,"fall_off_exponent"); cla.setConstantAttenuation(constatt); cla.setLinearAttenuation(linatt); cla.setQuadraticAttenuation(quadatt); exportBlenderProfile(cla, la); addLight(cla); } // lamp else if (la->type == LA_LOCAL) { COLLADASW::PointLight cla(mSW, la_id, la_name); cla.setColor(col,false,"color"); cla.setConstantAttenuation(constatt); cla.setLinearAttenuation(linatt); cla.setQuadraticAttenuation(quadatt); exportBlenderProfile(cla, la); addLight(cla); } // area lamp is not supported // it will be exported as a local lamp else { COLLADASW::PointLight cla(mSW, la_id, la_name); cla.setColor(col,false,"color"); cla.setConstantAttenuation(constatt); cla.setLinearAttenuation(linatt); cla.setQuadraticAttenuation(quadatt); exportBlenderProfile(cla, la); addLight(cla); } }
bool ZoneMap::load(std::string p_zoneName) { std::cout << "Loading map map\\zones\\" << p_zoneName << "... "; std::ifstream _file; _file.open(std::string("map\\zones\\" + p_zoneName + "\\Info.cfg").c_str(), std::ios::binary); { if(!_file.good()) { std::cout << "No Info.cfg file found." << std::endl; return false; } } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\Ground.tmf").c_str(), std::ios::binary); { if(!_file.good()) { std::cout << "No Ground.tmf file found." << std::endl; return false; } } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\World.tmf").c_str(), std::ios::binary); { if(!_file.good()) { std::cout << "No World.tmf file found." << std::endl; return false; } } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\Entity.tmf").c_str(), std::ios::binary); { if(!_file.good()) { std::cout << "No Entity.tmf file found." << std::endl; return false; } } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\Sky.tmf").c_str(), std::ios::binary); { if(!_file.good()) { std::cout << "No Sky.tmf file found." << std::endl; return false; } } _file.close(); clear(); m_mapName = p_zoneName; Uint32 _length, _index; char* _data; _file.open(std::string("map\\zones\\" + p_zoneName + "\\Info.cfg").c_str(), std::ios::binary); { _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); m_mapSize.x = FileExt::readShort(_data, _index); m_mapSize.y = FileExt::readShort(_data, _index); init(); delete[] _data; } _file.close(); Uint16 _tileCount; Uint16 _tileId, _mapIndex; _file.open(std::string("map\\zones\\" + p_zoneName + "\\Ground.tmf").c_str(), std::ios::binary); { _mapIndex = 0; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); while(_mapIndex < m_mapSize.x * m_mapSize.y && _index < _length) { _tileCount = FileExt::readShort(_data, _index); _tileId = FileExt::readShort(_data, _index); for(Uint16 i = 0; i < _tileCount; i++) { m_tileData[0][_mapIndex % m_mapSize.x][int(floor(GLfloat(_mapIndex) / m_mapSize.x))] = _tileId; _mapIndex++; } } delete[] _data; } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\World.tmf").c_str(), std::ios::binary); { _mapIndex = 0; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); Uint16 _objCount = FileExt::readShort(_data, _index); Uint16 _objNameLen = 0; std::string _objName; Uint16 _interactionType, _tileTex; m_worldObjects.clear(); for(Uint16 i = 0; i < _objCount; i++) { _objName = ""; _objNameLen = FileExt::readChar(_data, _index); for(Uint16 j = 0; j < Uint16(_objNameLen); j++) _objName = _objName + char(FileExt::readChar(_data, _index)); _interactionType = FileExt::readShort(_data, _index); _tileTex = FileExt::readShort(_data, _index); m_worldObjects.push_back(WorldObject(_objName, _interactionType, _tileTex)); switch(m_worldObjects[i].m_interactionType) { case 0: // NONE break; case 1: // SOLID break; case 2: // SWITCH m_worldObjects[i].m_frequency = FileExt::readChar(_data, _index); break; case 3: // SOLID SWITCH m_worldObjects[i].m_frequency = FileExt::readChar(_data, _index); break; case 4: // PORTAL m_worldObjects[i].m_frequency = FileExt::readChar(_data, _index); _objName = ""; _objNameLen = FileExt::readChar(_data, _index); for(Uint16 j = 0; j < Uint16(_objNameLen); j++) _objName = _objName + char(FileExt::readChar(_data, _index)); m_worldObjects[i].m_portalDest = _objName; m_worldObjects[i].m_destX = FileExt::readShort(_data, _index); m_worldObjects[i].m_destY = FileExt::readShort(_data, _index); break; case 5: // DIRECTION m_worldObjects[i].m_direction = FileExt::readChar(_data, _index); break; case 6: // LIGHT m_worldObjects[i].m_lightValue = FileExt::readChar(_data, _index); break; } } while(_mapIndex < m_mapSize.x * m_mapSize.y && _index < _length) { _tileCount = FileExt::readShort(_data, _index); _tileId = FileExt::readShort(_data, _index); for(Uint16 i = 0; i < _tileCount; i++) { m_tileData[1][_mapIndex % m_mapSize.x][int(floor(GLfloat(_mapIndex) / m_mapSize.x))] = _tileId; if(m_worldObjects[_tileId].m_interactionType == 6) addLight(LightNode(_mapIndex % m_mapSize.x, floor(GLfloat(_mapIndex) / m_mapSize.x), m_worldObjects[_tileId].m_lightValue)); _mapIndex++; } } delete[] _data; } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\Sky.tmf").c_str(), std::ios::binary); { _mapIndex = 0; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); while(_mapIndex < m_mapSize.x * m_mapSize.y && _index < _length) { _tileCount = FileExt::readShort(_data, _index); _tileId = FileExt::readShort(_data, _index); for(Uint16 i = 0; i < _tileCount; i++) { m_tileData[2][_mapIndex % m_mapSize.x][int(floor(GLfloat(_mapIndex) / m_mapSize.x))] = _tileId; _mapIndex++; } } delete[] _data; } _file.close(); _file.open(std::string("map\\zones\\" + p_zoneName + "\\Entity.tmf").c_str(), std::ios::binary); { _mapIndex = 0; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); Uint16 _objCount = FileExt::readShort(_data, _index); Uint16 _objNameLen = 0; std::string _objName; Uint16 _texNameLen = 0; std::string _texName; m_entities.clear(); for(Uint16 i = 0; i < _objCount; i++) { _objName = ""; _objNameLen = FileExt::readShort(_data, _index); for(Uint16 j = 0; j < Uint16(_objNameLen); j++) _objName = _objName + char(FileExt::readChar(_data, _index)); m_entities.push_back(Entity(_objName)); m_entities[i].m_pos.x = FileExt::readShort(_data, _index); m_entities[i].m_pos.y = FileExt::readShort(_data, _index); } delete[] _data; } _file.close(); Uint16 _texNameLen = 0; std::string _texName = ""; for(Uint16 i = 0; i < m_entities.size(); i++) { _file.open(std::string("map\\zones\\" + p_zoneName + "\\entities\\" + m_entities[i].m_name + "\\Info.cfg").c_str(), std::ios::binary); { if(!_file.good()) continue; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); m_entities[i].m_entityType = FileExt::readChar(_data, _index); _texNameLen = FileExt::readShort(_data, _index); _texName = ""; for(Uint16 i = 0; i < _texNameLen; i++) _texName += FileExt::readChar(_data, _index); m_entities[i].m_entityTex = LTexture::getInstance().getImage(_texName); m_entities[i].m_entityTex.setName(_texName); m_entities[i].m_entityTexId = FileExt::readShort(_data, _index); delete[] _data; } _file.close(); } for(Uint16 i = 1; i < m_entities.size(); i++) { _file.open(std::string("map\\zones\\" + p_zoneName + "\\entities\\" + m_entities[i].m_name + "\\Interact").c_str(), std::ios::binary); { if(!_file.good()) continue; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); for(Uint16 j = 0; j < _length; j++) m_entities[i].m_interact += FileExt::readChar(_data, _index); delete[] _data; } _file.close(); } for(Uint16 i = 1; i < m_entities.size(); i++) { _file.open(std::string("map\\zones\\" + p_zoneName + "\\entities\\" + m_entities[i].m_name + "\\Idle").c_str(), std::ios::binary); { if(!_file.good()) continue; _index = 0; _file.seekg(0, _file.end); _length = Uint32(_file.tellg()); _file.seekg(0, _file.beg); _data = new char[_length]; _file.read(_data, _length); for(Uint16 j = 0; j < _length; j++) m_entities[i].m_idle += FileExt::readChar(_data, _index); delete[] _data; } _file.close(); } std::cout << "Complete." << std::endl; return true; }
// This method is templated on the implementation of hctMayaSceneExporter::createHkxNodes() void FbxToHkxConverter::addNodesRecursive(hkxScene *scene, FbxNode* fbxNode, hkxNode* node, int animStackIndex) { for (int childIndex = 0; childIndex < fbxNode->GetChildCount(); childIndex++) { FbxNode* fbxChildNode = fbxNode->GetChild(childIndex); FbxNodeAttribute* fbxNodeAtttrib = fbxChildNode->GetNodeAttribute(); bool selected = fbxChildNode->GetSelected(); // Ignore nodes(and their descendants) if they're invisible and we ignore invisible objects if ( !(!m_options.m_visibleOnly || fbxNode->GetVisibility()) ) continue; // Ignore nodes(and their descendants) if they're not selected and we ignore deselected objects if ( !(!m_options.m_selectedOnly || selected) ) continue; hkxNode* newChildNode = new hkxNode(); { newChildNode->m_name = fbxChildNode->GetName(); node->m_children.pushBack(newChildNode); } newChildNode->m_selected = selected; // Extract the following types of data from this node (taken from hkxScene.h): if (fbxNodeAtttrib != NULL) { switch (fbxNodeAtttrib->GetAttributeType()) { case FbxNodeAttribute::eMesh: { // Generate hkxMesh and all its dependent data (ie: hkxSkinBinding, hkxMeshSection, hkxMaterial) if (m_options.m_exportMeshes) { addMesh(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eNurbsCurve: { if (m_options.m_exportSplines) { addSpline(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eCamera: { // Generate hkxCamera if (m_options.m_exportCameras) { addCamera(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eLight: { // Generate hkxLight if (m_options.m_exportLights) { addLight(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eSkeleton: { // Flag this node as a bone if it's associated with a skeleton attribute newChildNode->m_bone = true; break; } default: break; } } // Extract this node's animation data and bind transform extractKeyFramesAndAnnotations(scene, fbxChildNode, newChildNode, animStackIndex); if (m_options.m_exportAttributes) { addSampledNodeAttributeGroups(scene, animStackIndex, fbxChildNode, newChildNode); } GetCustomVisionData(fbxChildNode, newChildNode->m_userProperties); addNodesRecursive(scene, fbxChildNode, newChildNode, animStackIndex); newChildNode->removeReference(); } }
void CB_StateCameraTest2::draw() { float iPolRot = (-cos(interpolation * PI) / 2 + 0.5); glPushMatrix(); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); if(!CB_StateManager::isDeactivating()) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } float autoFL = 1 / ((sin(theta * 1.5) * 0.5 + 1.0)); float usedScale = 0; if(!manualMode) { CB_Screen::setOrthoZoom(autoFL); usedScale = autoFL; } else { CB_Screen::setOrthoZoom(fLScale); usedScale = fLScale; } CB_Screen::setProjection(interpolation); //CB_Screen::setOrthoZoom(1.0); if(!manualMode) { camera->setFocalLength(CB_Screen::getZ() * autoFL); camera->setPosition(160 + 64 * sin(theta), 120 + 64 * cos(theta), 0); camera->setRotation(sin(theta * 2) * 10 * iPolRot, cos(theta * 2) * 10 * iPolRot, 0); } else { camera->setFocalLength(CB_Screen::getZ() * fLScale); camera->setPosition(x, y, z); camera->setRotation(xRot * iPolRot, yRot * iPolRot, 0); } double zPosThing = CB_Screen::getZ(); double fovThing = CB_Screen::getFOV(); camera->doCamera(); CB_Vector3D tVec(0, 0, camera->getFocalLength() - zPosThing); tVec = camera->getRotation() * tVec * tVec.length(); tVec = tVec + camera->getPosition(); CB_Vector3D dVec = camera->getActualPosition() - tVec; CB_Vector3D aVec = tVec - (dVec * (tVec.z / dVec.z)); box->addBox(aVec.x, aVec.y, aVec.z, -1, -1, -1, 2, 2, 2, 0xFFFF0000, false); tVec = CB_Vector3D(64, 0, camera->getFocalLength() - zPosThing); tVec = camera->getRotation() * tVec * tVec.length(); tVec = tVec + camera->getPosition(); dVec = camera->getActualPosition() - tVec; aVec = tVec - (dVec * (tVec.z / dVec.z)); box->addBox(aVec.x, aVec.y, aVec.z, -1, -1, -1, 2, 2, 2, 0xFFFF0000, false); tVec = CB_Vector3D(0, 64, camera->getFocalLength() - zPosThing); tVec = camera->getRotation() * tVec * tVec.length(); tVec = tVec + camera->getPosition(); dVec = camera->getActualPosition() - tVec; aVec = tVec - (dVec * (tVec.z / dVec.z)); box->addBox(aVec.x, aVec.y, aVec.z, -1, -1, -1, 2, 2, 2, 0xFFFF0000, false); //glPushMatrix(); //glTranslated(160 + 64 * sin(theta), 120 + 64 * cos(theta), 0); //drawBox(-4, -4, -4, 8, 8, 8); box->addBox(160 + 64 * sin(theta), 120 + 64 * cos(theta), 0, -4, -4, -4, 8, 8, 8, 0xFF5588FF, false); CB_Renderer::process(); //glPopMatrix(); //drawBox(80, 0, -1280, 320, 240, 80); //drawBox(128, 64, -24, 32, 16, 48); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); addLight(0.25, 0.5, 1, 0, 0xFF808080, 0xFFFFFFFF, GL_LIGHT0); box->addBox(80, 0, -1280, 0, 0, 0, 320, 240, 80, 0xFF8855FF, false); box->addBox(128, 64, -24, 0, 0, 0, 32, 16, 48, 0xFFFF5588, false); //drawBox(160, 0, -520, 320, 64, 400, 0xFF5599FF); box->addBox(160, 0, -520, 0, 0, 0, 160, 64, 200, 0xFF5599FF, false); box->addBox(320, 0, -520, 0, 0, 0, 160, 64, 200, 0xFF5599FF, true); box->addBox(160, 0, -320, 0, 0, 0, 160, 64, 200, 0xFF5599FF, true); box->addBox(320, 0, -320, 0, 0, 0, 160, 64, 200, 0xFF5599FF, false); CB_Renderer::process(); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); drawBox(448, 64, -520, 32, 32, 32); drawBox(0, 0, -120, 320, 32, 80); drawBox(0, 0, -400, 128, 144, 32); drawBox(0, 0, -40, 128, 128, 32); drawBox(0, 0, -8, 32, 16, 16); drawBox(32, 16, -8, 32, 16, 16); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); addLight(0, 0.25, 1, 0, 0xFF202020, 0xFFFFFFFF, 0xFFFFFFFF, GL_LIGHT0); glPushMatrix(); glTranslated(64, 40, 0); glRotated(theta * 45, 1.0, 0.0, 0.0); string sA1[] = {"h_right", "split_cross", "regular", "h_left", "h_right", "h_left"}; string sA2[] = {"h_center", "split_cross", "split_cross", "h_center", "h_center", "h_center"}; string sA3[] = {"h_left", "regular", "split_cross", "h_right", "h_left", "h_right"}; string sA4[] = {"regular", "regular", "regular", "regular", "regular", "regular"}; drawBox(0, -8, -8, 16, 16, 16, sheet, sA1); drawBox(16, -8, -8, 16, 16, 16, sheet, sA2); //drawBox(32, -8, -8, 16, 16, 16, sheet, sA2); //drawBox(48, -8, -8, 16, 16, 16, sheet, sA3); box->addBox(40, 0, 0, -8, -8, -8, 16, 16, 16, sheet, sA2, true); box->addBox(56, 0, 0, -8, -8, -8, 16, 16, 16, sheet, sA3, true); box->addBox(72, 0, 0, -8, -8, -8, 16, 16, 16, sheet, sA4, true); box->addBox(88, 0, 0, -8, -8, -8, 16, 16, 16, 0xFFFFFFFF, true); CB_SpriteRenderer * sprite = (CB_SpriteRenderer*)CB_Renderer::getRenderer("sprite"); sprite->addSprite(96, 8, 0, 0, 0, 0, sheet, "circle"); CB_Renderer::process(64, 40, 0); glPopMatrix(); CB_LineRenderer * lineRenderer = (CB_LineRenderer*)CB_Renderer::getRenderer("line"); CB_SphereRenderer * sphereRenderer = (CB_SphereRenderer*)CB_Renderer::getRenderer("sphere"); lineRenderer->addLine(120, 80, 0, -8, 0, 0, 8, 0, 0, 2); lineRenderer->addLine(120, 80, 0, 0, 0, 0, 0, 16, 0, 2); lineRenderer->addLine(136, 96, -8, -3, 0, 1, -1, 3, 1, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, -1, 3, 1, 0, 6, 0, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, 3, 0, -2, 3, 3.5, -2, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, 3, 3.5, -2, 0, 6, 0, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, 0, 6, 0, 0, 12, 0, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, 0, 12, 0, -2, 11, 3, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, -2, 11, 3, 1, 9, 4, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, 0, 12, 0, 3, 10, -2, 2, 0xFF0000FF); lineRenderer->addLine(136, 96, -8, 3, 10, -2, 6, 9, -2, 2, 0xFF0000FF); sphereRenderer->addSphere(136, 110, -8, 2, 32, 15, 0xFF0000FF, true); glDisable(GL_LIGHTING); CB_Renderer::process(); glEnable(GL_LIGHTING); glDepthFunc(GL_LEQUAL); drawBox(0, 80, -8, 16, 16, 8, sheet, sA4); glDisable(GL_TEXTURE_2D); sphereRenderer->addSphere(136, 128, -8, 2, 64, 31, 0xFF0000FF, true); //drawBox(96, 80, -8, 16, 16, 8, 0xFFFFFFFF); box->addBox(104, 88, -8, -8, -8, -8, 16, 16, 16, 0xFFFFFFFF, false); box->addBox(136, 88, -8, -8, -8, -8, 16, 16, 16, 0xFFFFFFFF, true); CB_Renderer::process(); glEnable(GL_TEXTURE_2D); glPushMatrix(); glEnable(GL_STENCIL_TEST); glClear(GL_STENCIL_BUFFER_BIT); glColorMask(0, 0, 0, 0); //glDisable(GL_DEPTH_TEST); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); //drawBox(96, 80, -8, 16, 16, 8, 0xFFFFFFFF); box->addBox(104, 88, -8, -8, -8, -8, 16, 16, 16, 0xFFFFFFFF, false); box->addBox(136, 88, -8, -8, -8, -8, 16, 16, 16, 0xFFFFFFFF, true); CB_Renderer::process(); glColorMask(1, 1, 1, 1); //glEnable(GL_DEPTH_TEST); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glMatrixMode(GL_PROJECTION); float fTest[16]; glGetFloatv(GL_PROJECTION_MATRIX, fTest); glLoadIdentity(); CB_Screen::setOrthoZoom((manualMode ? fLScale : autoFL)); CB_Screen::setOrtho(); CB_Screen::setOrthoZoom(1.0); glMatrixMode(GL_MODELVIEW); float fTest2[16]; glGetFloatv(GL_MODELVIEW_MATRIX, fTest2); glLoadIdentity(); glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glDepthMask(false); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef((manualMode ? yRot : cos(theta * 2) * 10) * iPolRot * PI / 180, (manualMode ? xRot : sin(theta * 2) * 10) * iPolRot * PI / 180, 0); glMatrixMode(GL_MODELVIEW); glBlendFunc(GL_DST_COLOR, GL_ZERO); glEnable(GL_BLEND); CB_Texture::getTexture("plaid")->bind(); glBegin(GL_QUADS); glTexCoord2d(0, 30); glVertex2d(-160, -120); glTexCoord2d(40, 30); glVertex2d(160, -120); glTexCoord2d(40, 0); glVertex2d(160, 120); glTexCoord2d(0, 0); glVertex2d(-160, 120); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glDepthMask(true); glEnable(GL_COLOR_MATERIAL); glEnable(GL_LIGHTING); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glLoadMatrixf(fTest); glMatrixMode(GL_MODELVIEW); glDisable(GL_STENCIL_TEST); glLoadIdentity(); glLoadMatrixf(fTest2); glPopMatrix(); glPushMatrix(); glTranslated(0, 144, -384); drawBox(0, 0, -4, 128, 4, 8, 0xFF808080); drawBox(0, 4, -4, 4, 16, 8, 0xFF808080); drawBox(124, 4, -4, 4, 16, 8, 0xFF808080); drawBox(0, 20, -4, 128, 4, 8, 0xFF808080); drawBox(4, 4, -4, 120, 16, 2, 0xFF808080); drawBox(4, 4, -2, 120, 16, 1.9, 0xFF000000); glEnable(GL_STENCIL_TEST); glClear(GL_STENCIL_BUFFER_BIT); glColorMask(0, 0, 0, 0); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glBegin(GL_QUADS); glVertex2d(4, 4); glVertex2d(124, 4); glVertex2d(124, 20); glVertex2d(4, 20); glEnd(); glColorMask(1, 1, 1, 1); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); double rTheta = theta * 100; uint32_t iTheta = (uint32_t)rTheta; rTheta = rTheta - iTheta; iTheta = iTheta % (tickerWidth + 248); rTheta+= iTheta; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0, 1.0, 1.0); //font->drawString(ticker, 124 - rTheta, 8); glTranslated(-rTheta, 0.0, 0.0); glCallList(tickerList); glDisable(GL_BLEND); glDisable(GL_STENCIL_TEST); glPopMatrix(); glDisable(GL_TEXTURE_2D); glColor3d(1.0, 1.0, 1.0); /*glLineWidth(10 * (manualMode?1/fLScale:1/autoFL)); glPointSize(10 * (manualMode?1/fLScale:1/autoFL)); glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glBegin(GL_POINTS); glVertex3d(-32, 128, -512); glEnd(); glBegin(GL_LINES); glVertex3d(-32, 128, -512); glVertex3d(-32, 128, 0); glEnd(); glBegin(GL_POINTS); glVertex3d(-32, 128, 0); glEnd(); glBegin(GL_LINES); glVertex3d(-32, 128, 0); glVertex3d(32, 128, 0); glEnd(); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glBegin(GL_POINTS); glVertex3d(32, 128, 0); glEnd(); glBegin(GL_LINES); glVertex3d(32, 128, 0); glVertex3d(32, 96, 0); glEnd(); glBegin(GL_POINTS); glVertex3d(32, 96, 0); glEnd(); glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH);*/ glLineWidth(1); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); camera->resetCamera(); glPopMatrix(); glPushMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); CB_Screen::setOrthoZoom(2.0); CB_Screen::setOrtho(); CB_Screen::setOrthoZoom(1.0); glMatrixMode(GL_MODELVIEW); glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4d(1.0, 1.0, 1.0, 1.0); if(displayHelp) { glCallList(instructionList); } //font->drawString((char*)glGetString(GL_EXTENSIONS), 0, 220); //font->drawString("ABCDEFGHIJKLM\nNOPQRSTUVWXYZ\nabcdefghijklm\nnopqrstuvwxyz", 0, 200); if(displayDebug) { for(int i = 0; i < 16; i++) { float cF = fTest[i]; stringstream cvt; cvt << cF; double cFX = -300 + (i / 4) * 100; double cFY = 50 - (i % 4) * 10; font->drawString(cvt.str(), cFX, cFY); } for(int i = 0; i < 16; i++) { float cF = fTest2[i]; stringstream cvt; cvt << cF; double cFX = -300 + (i / 4) * 100; double cFY = 0 - (i % 4) * 10; font->drawString(cvt.str(), cFX, cFY); } { stringstream cvt; cvt << zPosThing << " - " << fovThing; font->drawString(cvt.str(), -300, -50); } } glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glBegin(GL_LINES); glColor3d(1, 1, 1); glVertex2d(0, 0); glVertex2d(sin(interpolation * PI) * 100, cos(interpolation * PI) * 100); glEnd(); glPopMatrix(); }
void TutorialLevel::setup(){ INFO("Generating Tutorial Level..."); readFile(); initalizeGrid(); createRenders(); createLevel(); waterSurfaceManager = WaterSurfaceManagerPtr(new WaterSurfaceManager()); addGameObject(waterSurfaceManager); INFO("Removal String so less of make"); INFO("Setting up the cameras for the Test Level..."); CameraPtr cam3(new Camera(glm::vec3(25, 30, 0), glm::vec3(10, 20, 6), glm::vec3(0, 1, 0))); cam3->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("CinematicCamera", cam3); setMainCamera("CinematicCamera"); setCullingCamera("CinematicCamera"); CameraPtr cam1(new Camera(glm::vec3(4, 10, -5), glm::vec3(4, 4, -10), glm::vec3(0, 1, 0))); cam1->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); addCamera("Camera1", cam1); CameraPtr cam2(new Camera(glm::vec3(0, 1, 0), glm::vec3(-6, -3, 6), glm::vec3(0, 1, 0))); cam2->setProjectionMatrix( glm::perspective(glm::radians(90.0f), (float) Global::ScreenWidth/Global::ScreenHeight, 0.1f, 100.f)); l1 = LightPtr(new Light(glm::vec3(1), 30.0f, glm::vec3(0, 30, 0))); l1->setPosition(l1->getDirection()); Uniform3DGridPtr<int> typeGrid = getTypeGrid(); gridCenter = glm::vec3((typeGrid->getMaxX() - typeGrid->getMinX())/2.0f, (typeGrid->getMaxY() - typeGrid->getMinY())/2.0f, (typeGrid->getMinZ() - typeGrid->getMaxZ())/2.0f); l1->setViewMatrix(glm::lookAt( l1->getPosition(), gridCenter, glm::vec3(0, 1, 0))); l1->setProjectionMatrix(glm::ortho<float>(-30,30,-30,30,-70,70)); addLight("Sun", l1); INFO("Setting up the player for the Test Level..."); cinematicPlayer = CinematicPlayerPtr(new CinematicPlayer(cam3)); cinematicPlayer->setup(); addGameObject("cinematicPlayer", cinematicPlayer); player = PlayerPtr(new Player(cam1, 2)); player->setup(); addGameObject("player" , player); CollisionManager::addCollisionObjectToList(player); debugPlayer = DebugPlayerPtr(new DebugPlayer(cam2)); debugPlayer->setup(); addGameObject("debugPlayer" , debugPlayer); //Text addCamera("DebugCamera", cam2); sky = ObjectPtr(new Object( LoadManager::getMesh("sphere.obj"), MaterialManager::getMaterial("None"))); sky->applyTexture(LoadManager::getTexture("Sky")); sky->enableTexture(); sky->scale(glm::vec3(-90.0f,-90.0f,-90.0f)); sky->translate(Director::getScene()->getCamera()->getEye()); RenderEngine::getRenderElement("textured")->addObject(sky); ExclamationPtr exclamation = ExclamationPtr(new Exclamation(glm::vec3(30, 26, -48))); exclamation->setup(); addGameObject("exclamation", exclamation); }
void Renderer::handleFileLoading( const std::string& filename ) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile( filename, aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_GenSmoothNormals | aiProcess_SortByPType | aiProcess_FixInfacingNormals | aiProcess_CalcTangentSpace | aiProcess_GenUVCoords ); if ( !scene ) { return; } if ( !scene->HasLights() ) { return; } // Load lights for ( uint lightId = 0; lightId < scene->mNumLights; ++lightId ) { aiLight* ailight = scene->mLights[lightId]; aiString name = ailight->mName; aiNode* node = scene->mRootNode->FindNode( name ); Core::Matrix4 transform( Core::Matrix4::Identity() ); if ( node != nullptr ) { Core::Matrix4 t0; Core::Matrix4 t1; for ( uint i = 0; i < 4; ++i ) { for ( uint j = 0; j < 4; ++j ) { t0( i, j ) = scene->mRootNode->mTransformation[i][j]; t1( i, j ) = node->mTransformation[i][j]; } } transform = t0 * t1; } Core::Color color( ailight->mColorDiffuse.r, ailight->mColorDiffuse.g, ailight->mColorDiffuse.b, 1.0 ); switch ( ailight->mType ) { case aiLightSource_DIRECTIONAL: { Core::Vector4 dir( ailight->mDirection[0], ailight->mDirection[1], ailight->mDirection[2], 0.0 ); dir = transform.transpose().inverse() * dir; Core::Vector3 finalDir( dir.x(), dir.y(), dir.z() ); finalDir = -finalDir; DirectionalLight* light = new DirectionalLight; light->setColor( color ); light->setDirection( finalDir ); addLight( light ); } break; case aiLightSource_POINT: { Core::Vector4 pos( ailight->mPosition[0], ailight->mPosition[1], ailight->mPosition[2], 1.0 ); pos = transform * pos; pos /= pos.w(); PointLight* light = new PointLight; light->setColor( color ); light->setPosition( Core::Vector3( pos.x(), pos.y(), pos.z() ) ); light->setAttenuation( ailight->mAttenuationConstant, ailight->mAttenuationLinear, ailight->mAttenuationQuadratic ); addLight( light ); } break; case aiLightSource_SPOT: { Core::Vector4 pos( ailight->mPosition[0], ailight->mPosition[1], ailight->mPosition[2], 1.0 ); pos = transform * pos; pos /= pos.w(); Core::Vector4 dir( ailight->mDirection[0], ailight->mDirection[1], ailight->mDirection[2], 0.0 ); dir = transform.transpose().inverse() * dir; Core::Vector3 finalDir( dir.x(), dir.y(), dir.z() ); finalDir = -finalDir; SpotLight* light = new SpotLight; light->setColor( color ); light->setPosition( Core::Vector3( pos.x(), pos.y(), pos.z() ) ); light->setDirection( finalDir ); light->setAttenuation( ailight->mAttenuationConstant, ailight->mAttenuationLinear, ailight->mAttenuationQuadratic ); light->setInnerAngleInRadians( ailight->mAngleInnerCone ); light->setOuterAngleInRadians( ailight->mAngleOuterCone ); addLight( light ); } break; case aiLightSource_UNDEFINED: default: { // LOG(ERROR) << "Light " << name.C_Str() << " has undefined type."; } break; } } }
void View::initStatue(){ //whee different shader progs //ResourceLoader::initializeGlew(); m_statueShaderProgramID = ResourceLoader::createShaderProgram(":/shaders/statue.vert", ":/shaders/statue.frag"); m_uniformLocs["p"]= glGetUniformLocation(m_statueShaderProgramID, "p"); m_uniformLocs["m"]= glGetUniformLocation(m_statueShaderProgramID, "m"); m_uniformLocs["v"]= glGetUniformLocation(m_statueShaderProgramID, "v"); m_uniformLocs["allBlack"]= glGetUniformLocation(m_statueShaderProgramID, "allBlack"); m_uniformLocs["ambient_color"] = glGetUniformLocation(m_statueShaderProgramID, "ambient_color"); m_uniformLocs["diffuse_color"] = glGetUniformLocation(m_statueShaderProgramID, "diffuse_color"); m_uniformLocs["specular_color"] = glGetUniformLocation(m_statueShaderProgramID, "specular_color"); m_uniformLocs["shininess"] = glGetUniformLocation(m_statueShaderProgramID, "shininess"); m_uniformLocs["useTexture"] = glGetUniformLocation(m_statueShaderProgramID, "useTexture"); m_uniformLocs["tex"] = glGetUniformLocation(m_statueShaderProgramID, "tex"); m_uniformLocs["blend"] = glGetUniformLocation(m_statueShaderProgramID, "blend"); CS123SceneLightData light; light.color = CS123SceneColor{.6, .6, .6, 1}; light.function = glm::vec3(1, 0, 0); light.id = 0; light.pos = glm::vec4(0, 20, 0, 1); light.type = LIGHT_POINT; addLight(light); light.pos = glm::vec4(10, -10, 0, 1); addLight(light); m_global.ka = .5; m_global.kd = .5; m_global.ks = .25; int detail = 10; for (int i = 0; i < 5; i++){ primitives[i]->init(); primitives[i]->setT1(detail); primitives[i]->setT2(detail); primitives[i]->setT3(detail); primitives[i]->bufferVerts(m_statueShaderProgramID); } int num_statues = rand() % 6 + 1; for (int i = 0; i < num_statues; i++){ float x = Statue::floatRange(-14, 14); float quote_y_unquote = Statue::floatRange(-14, 14); if (i == 0){ x = 0.01; quote_y_unquote = 0.01; } { glm::vec3 xyz = glm::vec3(x, m_terrain.getHeight(quote_y_unquote, x), quote_y_unquote); glm::mat4 transform = glm::translate(xyz) * glm::scale(glm::vec3(.2, .2, .2)) * Statue::rotateTo(glm::vec4(0, 1, 0, 0), glm::vec4(m_terrain.getNormalVec(quote_y_unquote, x), 0)) * glm::rotate(static_cast<float>(Statue::floatRange(0, 2) * M_PI), glm::vec3(0, 1, 0)); Statue *s = new Statue(transform); m_statues.push_back(s); } x += Statue::intRange(0, 1) * 4 - 2; quote_y_unquote += Statue::intRange(0, 1) * 4 - 2; { glm::vec3 xyz = glm::vec3(x, m_terrain.getHeight(quote_y_unquote, x), quote_y_unquote); glm::mat4 transform = glm::translate(xyz) * glm::scale(glm::vec3(.2, .2, .2)) * Statue::rotateTo(glm::vec4(0, 1, 0, 0), glm::vec4(m_terrain.getNormalVec(quote_y_unquote, x), 0)) * glm::rotate(static_cast<float>(Statue::floatRange(0, 2) * M_PI), glm::vec3(0, 1, 0)); Statue *s = new Statue(transform); m_statues.push_back(s); } } for (std::vector<Statue*>::const_iterator iter = m_statues.begin(); iter != m_statues.end(); iter++){ Statue* stat = *iter; int particleNum = Statue::intRange(0, 5); for (std::vector<Statue::DoubleVec>::const_iterator iter = stat->getParticles()->begin(); iter != stat->getParticles()->end(); iter++){ Statue::DoubleVec db = *iter; std::string particlePath; switch (particleNum){ case 0: particlePath = ":/images/particle1.bmp"; break; case 1: particlePath = ":/images/particle2.bmp"; break; case 2: particlePath = ":/images/acid-front.jpg"; break; case 3: particlePath = ":/images/fireball-front.jpg"; break; case 4: particlePath = ":/images/starfield-300x300.jpg"; break; default: case 5: particlePath = ":/images/particle3.jpg"; break; } createParticleManager(glm::vec3(db.point),300,0.05f,particlePath,glm::vec3(1.0f,0.5f,0.2f),glm::vec3(0.0f,0.0001f,0.0f),(80.0f/100000.f),25.0f,glm::vec3(db.dir)); } } }
void GameEnvironment::draw() { if (blinkCounter++ < blinkDelay) ; else { blinkDelay = (30 * rand()) / (RAND_MAX + 1.0); lightOn = rand() % 2 == 1; blinkCounter = 0; if (blinkDelay > 15 && !lightOn) lightOn = true; } if (!gameOver && !gameWon) { if (lightOn || pause) { // add ambient and directed light addLight(); //add fog addFog(); // flashlight glPushMatrix(); //move with camera glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ()); //rotate with camera glRotatef(-cameraYaw * 180 / PI, 0, 1, 0); glRotatef(-cameraPitch * 180 / PI, 0, 0, 1); glScalef(0.25, 0.25, 0.25); glTranslatef(1.0, -0.4, +0.7); glRotated(60, 0.7, -3.0, 0.5); flashlight->draw(); glPopMatrix(); // level glPushMatrix(); level->draw(); glPopMatrix(); //table glPushMatrix(); table->draw(); glPopMatrix(); if (!accesscardIsFound) { //accesscard glPushMatrix(); glTranslatef(-38.0, -1.3, -58.0); accesscard->draw(); glPopMatrix(); } // terminal glPushMatrix(); glScalef(1.0, 0.9, 1.0); glTranslatef(-34.5, -1.3, -59); terminal->draw(); glPopMatrix(); // monster glPushMatrix(); monsterLastPositionZ = (monsterLastPositionZ + monsterSpeed); enemyMonster->jbTranslate(monsterLastPositionX, monsterLastPositionY, monsterLastPositionZ); glRotated(180, 0, -1.0, 0); enemyMonster->setFrameNumber(frame); enemyMonster->drawWithAni(monsterAnimationId); ++frame; if (monsterIsRunning) { monsterSpeed += 0.02; } else { monsterSpeed = 0.0; } if (frame == (enemyMonster->frame_count[monsterAnimationId] - 1)) { frame = 0; } glPopMatrix(); glDisable(GL_TEXTURE_2D); } setCameraBoundingBox(); //countDistanceToMonster(); jbCountDistanceToMonster(); detectCollision(enemyMonster); detectCollision(table); //collision with walls checkLevelCollisionX(); checkLevelCollisionZ(); playRadarSound(); playPlayerFootstepSound(); playEnemyMonsterRandomSound(); isEnemyMonsterSeePlayer(); isEnemyMonsterCatchPlayer(); isEnemyMonsterRunAway(); checkEndGame(); glFlush(); } else if (gameWon) { // Add ambient light GLfloat ambientColor[] = { 0.85f, 0.85f, 0.85f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); glPushMatrix(); //move with camera glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ()); //rotate with camera glRotatef(-cameraYaw * 180 / PI, 0, 1, 0); glRotatef(-cameraPitch * 180 / PI, 0, 0, 1); glScalef(0.5, 0.5, 0.5); glTranslatef(12.0, -5.0, 0.0); glRotated(90, 0.0, 1.0, 0.0); gameOverSuccess->draw(); glPopMatrix(); } else if (gameOver) { // Add ambient light GLfloat ambientColor[] = { 0.85f, 0.85f, 0.85f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); glPushMatrix(); //move with camera glTranslated(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ()); //rotate with camera glRotatef(-cameraYaw * 180 / PI, 0, 1, 0); glRotatef(-cameraPitch * 180 / PI, 0, 0, 1); glScalef(0.5, 0.5, 0.5); glTranslatef(12.0, -5.0, 0.0); glRotated(90, 0.0, 1.0, 0.0); gameOverFail->draw(); glPopMatrix(); } }