void KisColorSelector::mousePressEvent(QMouseEvent* event) { m_clickPos = mapCoord(event->posF(), m_renderArea); m_mouseMoved = false; m_pressedButtons = event->buttons(); m_clickedRing = getSaturationIndex(m_clickPos); qint8 clickedLightPiece = getLightIndex(event->posF()); if (clickedLightPiece >= 0) { setLight(getLight(event->posF()), m_relativeLight); m_selectedLightPiece = clickedLightPiece; setSelectedColor(m_selectedColor, !(m_pressedButtons & Qt::RightButton), true); m_mouseMoved = true; } else if (m_clickedRing >= 0) { if (getNumPieces() > 1) { for(int i=0; i<getNumRings(); ++i) m_colorRings[i].setTemporaries(m_selectedColor); } else { Radian angle = std::atan2(m_clickPos.x(), m_clickPos.y()) - RAD_90; m_selectedColor.setH(angle.scaled(0.0f, 1.0f)); m_selectedColor.setS(getSaturation(m_clickedRing)); m_selectedColor.setX(getLight(m_light, m_selectedColor.getH(), m_relativeLight)); setSelectedColor(m_selectedColor, !(m_pressedButtons & Qt::RightButton), true); m_selectedRing = m_clickedRing; m_mouseMoved = true; update(); } } }
void TerrainWrapper::Enable() { Controller * ctrl = static_cast<Controller*>(GetManager()->Get("Controller")); DataManager * dm = static_cast<DataManager*>(GetManager()->Get("DataManager")); Techniques * tech = static_cast<Techniques*>(dm->Get("Techniques")); ResourceLoader * res = static_cast<ResourceLoader*>(dm->Get("Resources")); Environment * env = static_cast<Environment*>(res->Get("Environment")); Camera * camera = static_cast<Camera*>(ctrl->Get("Camera")); View * view = camera->GetView(); ViewInfo * info = camera->GetInfo(); Shader::Enable(); Shader::Set("myTextureSampler", 0); Shader::Set("myTextureSampler2", 1); Shader::Set("myTextureSampler3", 2); Shader::Set("shadow_map", 3); TerrainShader::SendTextureAttributes(terra->GetTextureAttributes(), 4); /** Raising to power for gamma correction */ getLight()->SetFog(glm::pow(env->fog_color, glm::vec3(2.2)), env->fog_density); getLight()->SetDirectionalLight(env->terrain_bright* glm::pow(env->sun_color, glm::vec3(2.2)), env->sun_dir, env->terrain_ambient, env->terrain_diffuse); Set("LightMatrix", Math::GetBiasMatrix()* tech->GetShadow()->GetDirectionalShadow(env, info, view)); tech->GetShadow()->GetShadowMap()->BindTexture(0, GL_TEXTURE3); tech->GetShadow()->GetShadowMap()->ResetTextureState(); ManagePlayerCollision(ctrl, false); }
void KisColorSelector::drawRing(QPainter& painter, KisColorSelector::ColorRing& ring, const QRect& rect) { painter.setRenderHint(QPainter::Antialiasing, false); painter.resetTransform(); painter.translate(rect.width()/2, rect.height()/2); if (ring.pieced.size() > 1) { painter.rotate(-ring.getShift().degrees()); painter.scale(rect.width()/2, rect.height()/2); painter.setPen(Qt::NoPen); QBrush brush(Qt::SolidPattern); for(int i=0; i<ring.pieced.size(); ++i) { float hue = float(i) / float(ring.pieced.size()) + ring.getShift().scaled(0.0f, 1.0f); hue = (hue >= 1.0f) ? (hue - 1.0f) : hue; hue = (hue < 0.0f) ? (hue + 1.0f) : hue; KisColor color(hue, 1.0f, m_colorSpace); color.setS(ring.saturation); color.setX(getLight(m_light, hue, m_relativeLight)); brush.setColor(color.getQColor()); painter.fillPath(ring.pieced[i], brush); } } else { KisColor colors[7] = { KisColor(Qt::red , m_colorSpace), KisColor(Qt::yellow , m_colorSpace), KisColor(Qt::green , m_colorSpace), KisColor(Qt::cyan , m_colorSpace), KisColor(Qt::blue , m_colorSpace), KisColor(Qt::magenta, m_colorSpace), KisColor(Qt::red , m_colorSpace) }; QConicalGradient gradient(0, 0, 0); for(int i=0; i<=6; ++i) { qreal hue = float(i) / 6.0f; colors[i].setS(ring.saturation); colors[i].setX(getLight(m_light, hue, m_relativeLight)); gradient.setColorAt(hue, colors[i].getQColor()); } painter.scale(rect.width()/2, rect.height()/2); painter.fillPath(ring.pieced[0], QBrush(gradient)); } painter.resetTransform(); }
void KisColorSelector::mouseMoveEvent(QMouseEvent* event) { QPointF dragPos = mapCoord(event->posF(), m_renderArea); qint8 clickedLightPiece = getLightIndex(event->posF()); if (clickedLightPiece >= 0) { setLight(getLight(event->posF()), m_relativeLight); m_selectedLightPiece = clickedLightPiece; setSelectedColor(m_selectedColor, m_selectedColorIsFgColor, true); } if (m_clickedRing < 0) return; if (getNumPieces() > 1) { float angle = std::atan2(dragPos.x(), dragPos.y()) - std::atan2(m_clickPos.x(), m_clickPos.y()); float dist = std::sqrt(dragPos.x()*dragPos.x() + dragPos.y()*dragPos.y()) * 0.80f; float threshold = 5.0f * (1.0f-(dist*dist)); if (qAbs(angle * TO_DEG) >= threshold || m_mouseMoved) { bool selectedRingMoved = true; if (m_pressedButtons & Qt::RightButton) { selectedRingMoved = m_clickedRing == m_selectedRing; m_colorRings[m_clickedRing].angle = m_colorRings[m_clickedRing].tmpAngle + angle; } else for(int i=0; i<getNumRings(); ++i) m_colorRings[i].angle = m_colorRings[i].tmpAngle + angle; if (selectedRingMoved) { KisColor color = m_colorRings[m_clickedRing].tmpColor; Radian angle = m_colorRings[m_clickedRing].getMovedAngel() + (color.getH()*PI2); color.setH(angle.scaled(0.0f, 1.0f)); color.setX(getLight(m_light, color.getH(), m_relativeLight)); m_selectedPiece = getHueIndex(angle, m_colorRings[m_clickedRing].getShift()); setSelectedColor(color, m_selectedColorIsFgColor, true); } m_mouseMoved = true; } } else { Radian angle = std::atan2(dragPos.x(), dragPos.y()) - RAD_90; m_selectedColor.setH(angle.scaled(0.0f, 1.0f)); m_selectedColor.setX(getLight(m_light, m_selectedColor.getH(), m_relativeLight)); setSelectedColor(m_selectedColor, m_selectedColorIsFgColor, true); } update(); }
void ossimPlanetViewer::addEphemeris(ossim_uint32 memberBitMask) { if(!theEphemerisLayer.valid()) { if(getLight()) { theSavedLight = (osg::Light*)getLight()->clone(osg::CopyOp::DEEP_COPY_ALL); } ossimPlanet* tempPlanet = new ossimPlanet; tempPlanet->setComputeIntersectionFlag(false); theEphemerisRoot = tempPlanet; theEphemerisLayer = new ossimPlanetEphemeris(); theEphemerisLayer->setRoot(theRootNode.get()); theEphemerisLayer->setMembers(memberBitMask); // planet()->addChild(theEphemerisLayer.get()); tempPlanet->addChild(theEphemerisLayer.get()); theRootNode->addChild(tempPlanet); theEphemerisCamera = new osg::Camera; theEphemerisCamera->setProjectionResizePolicy(getCamera()->getProjectionResizePolicy()); theEphemerisCamera->setClearColor(getCamera()->getClearColor()); theEphemerisCamera->setRenderOrder(osg::Camera::PRE_RENDER); theEphemerisCamera->setRenderTargetImplementation( getCamera()->getRenderTargetImplementation() ); // theEphemerisCamera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // getCamera()->setClearMask(getCamera()->getClearMask() & ~GL_COLOR_BUFFER_BIT & ~GL_DEPTH_BUFFER_BIT); theEphemerisCamera->setClearMask(GL_COLOR_BUFFER_BIT); getCamera()->setClearMask(getCamera()->getClearMask() & ~GL_COLOR_BUFFER_BIT); if(getCamera()->getViewport()) { theEphemerisCamera->setViewport(new osg::Viewport(*getCamera()->getViewport())); } else { theEphemerisCamera->setViewport(new osg::Viewport()); } addSlave(theEphemerisCamera.get(), false); theEphemerisLayer->setCamera(theEphemerisCamera.get()); theEphemerisCamera->setEventCallback(new ossimPlanetTraverseCallback()); theEphemerisCamera->setUpdateCallback(new ossimPlanetTraverseCallback()); theEphemerisCamera->setCullCallback(new ossimPlanetTraverseCallback()); //theEphemerisCamera->addChild(theRootNode.get()); //getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); //theEphemerisCamera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); //double fov, aspectRatio, near, far; //osg::Matrixd& m = getCamera()->getProjectionMatrix(); //m.getPerspective(fov, aspectRatio, near, far); //theEphemerisCamera->setProjectionMatrixAsPerspective(fov, aspectRatio, .2, 5.0); //getCamera()->setProjectionMatrixAsPerspective(fov, aspectRatio, .0000001, .2); } }
static inline loopSensorMode() { while(1) { if(twiDataInReceiveBuffer()) { uint8_t usiRx = twiReceiveByte(); if(TWI_GET_CAPACITANCE == usiRx) { twiTransmitByte(currCapacitance >> 8); twiTransmitByte(currCapacitance &0x00FF); currCapacitance = getCapacitance(); } else if(TWI_SET_ADDRESS == usiRx) { uint8_t newAddress = twiReceiveByte(); if(twiIsValidAddress(newAddress)) { eeprom_write_byte((uint8_t*)0x01, newAddress); } } else if(TWI_GET_ADDRESS == usiRx) { uint8_t newAddress = eeprom_read_byte((uint8_t*) 0x01); twiTransmitByte(newAddress); } else if(TWI_MEASURE_LIGHT == usiRx) { if(!lightMeasurementInProgress()) { getLight(); } } else if(TWI_GET_LIGHT == usiRx) { GIMSK &= ~_BV(PCIE0);//disable pin change interrupts TCCR1B = 0; //stop timer twiTransmitByte(lightCounter >> 8); twiTransmitByte(lightCounter & 0x00FF); GIMSK |= _BV(PCIE0); TCCR1B = _BV(CS10) | _BV(CS11); //start timer1 with prescaler clk/64 } else if(TWI_GET_TEMPERATURE == usiRx) {
void getSensors() { int counter1 = 0; int counter2 = 0; while(true) { // Formatted Data acc.getAxis(acc_data); mag.getAxis(mag_data); printf("ACC: X=%1.4f Y=%1.4f Z=%1.4f\r\n", acc_data.x, acc_data.y, acc_data.z); printf("MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z); printf("Light: %f\r\n\n\n", getLight()); wait(.5); if (mag_data.x < 10.0f) counter1++; printf("Counter = %d\r\n", counter1); changeLED(counter2); counter2++; /* //raw acc.getAxis(acc_raw); mag.getAxis(mag_raw); printf("ACC_raw: X=%d Y=%d Z=%d\r\n", acc_raw.x, acc_raw.y, acc_raw.z); printf("MAG_raw: X=%d Y=%d Z=%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z); wait(5); */ } }
Patch::Patch(const Vertex& a_, const Vertex& b_, const Vertex& c_, const Colour& col, const Plane& p_, float emit_) : Triangle(a_, b_, c_, col, p_, emit_), mid(oneThird * (a_ + b_ + c_)), area(0.5f * abs(getTrianglePlane().getNormal())), sphere(a_,b_,c_) { lastLight = getLight(); }
void Scenario::setNew(){ reset(); // ensure the seed is populated before anything else is set seed.populate(history); // set the environment to new seed values environment = new Environment(*getSurface(), *getMedium()); // TODO: move mesh into setSurface method for Sprites spriteSeed = SpriteSeed(seed, environment->getSurfaceMesh()); // set light to new seed values light = getLight(); // set surface first, then set the player to new seed values player.setSurface(environment->getSurfaceMesh()); setPlayer(seed); sprites.clear(); setSprites(); // sound.loadMusic(); // sound.playMusic(); }
void gamehsp::selectLight( int lightid ) { if ( lightid >= 0 ) { Light *light; light = getLight( lightid ); if ( light == NULL ) return; } _curlight = lightid; }
//----------------------------------------------------------------------------- Vector4 AutoParamDataSource::getLightAttenuation(size_t index) const { // range, const, linear, quad const Light& l = getLight(index); return Vector4(l.getAttenuationRange(), l.getAttenuationConstant(), l.getAttenuationLinear(), l.getAttenuationQuadric()); }
void KisColorSelector::setLight(float light, bool relative) { m_light = qBound(0.0f, light, 1.0f); m_selectedColor.setX(getLight(m_light, m_selectedColor.getH(), relative)); m_relativeLight = relative; m_selectedLightPiece = getLightIndex(m_selectedColor.getX()); update(); }
LightStage::Index LightStage::addShadow(Index lightIndex) { auto light = getLight(lightIndex); Index shadowId = INVALID_INDEX; if (light) { shadowId = _shadows.newElement(std::make_shared<Shadow>(light)); _descs[lightIndex].shadowId = shadowId; } return shadowId; }
//----------------------------------------------------------------------------- const Matrix4& AutoParamDataSource::getSpotlightViewProjMatrix(size_t index) const { if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS) { const Light& l = getLight(index); if (&l != &mBlankLight && l.getType() == Light::LT_SPOTLIGHT && mSpotlightViewProjMatrixDirty[index]) { Frustum frust; SceneNode dummyNode(0); dummyNode.attachObject(&frust); frust.setProjectionType(PT_PERSPECTIVE); frust.setFOVy(l.getSpotlightOuterAngle()); frust.setAspectRatio(1.0f); // set near clip the same as main camera, since they are likely // to both reflect the nature of the scene frust.setNearClipDistance(mCurrentCamera->getNearClipDistance()); // Calculate position, which same as spotlight position, in camera-relative coords if required dummyNode.setPosition(l.getDerivedPosition(true)); // Calculate direction, which same as spotlight direction Vector3 dir = - l.getDerivedDirection(); // backwards since point down -z dir.normalise(); Vector3 up = Vector3::UNIT_Y; // Check it's not coincident with dir if (Math::Abs(up.dotProduct(dir)) >= 1.0f) { // Use camera up up = Vector3::UNIT_Z; } // cross twice to rederive, only direction is unaltered Vector3 left = dir.crossProduct(up); left.normalise(); up = dir.crossProduct(left); up.normalise(); // Derive quaternion from axes Quaternion q; q.FromAxes(left, up, dir); dummyNode.setOrientation(q); // The view matrix here already includes camera-relative changes if necessary // since they are built into the frustum position mSpotlightViewProjMatrix[index] = PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE * frust.getProjectionMatrixWithRSDepth() * frust.getViewMatrix(); mSpotlightViewProjMatrixDirty[index] = false; } return mSpotlightViewProjMatrix[index]; } else return Matrix4::IDENTITY; }
//----------------------------------------------------------------------------- const ColourValue AutoParamDataSource::getLightSpecularColourWithPower(size_t index) const { const Light& l = getLight(index); ColourValue scaled(l.getSpecularColour()); Real power = l.getPowerScale(); // scale, but not alpha scaled.r *= power; scaled.g *= power; scaled.b *= power; return scaled; }
//--------------------------------------------------------------------------- void CLight::add() { // cout << "Adding light" << endl << endl; tLight *new_light = new tLight; initLight (new_light); getLight (new_light); linkLight (new_light); // adds light to linked-list of lights numLights++; }
void lightArray::tick(float dt) { dt = dt+1; lightSource* l1 = getLight(0); if(l1!=NULL && (rand() % 10 == 0)) { l1->sourceDiffuse[0] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[1] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[2] = ((rand() % 40)/100.0)+0.2; } l1 = getLight(1); if(l1!=NULL && (rand() % 10 == 0)) { l1->sourceDiffuse[0] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[1] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[2] = ((rand() % 40)/100.0)+0.2; } l1 = getLight(2); if(l1!=NULL && (rand() % 10 == 0)) { l1->sourceDiffuse[0] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[1] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[2] = ((rand() % 40)/100.0)+0.2; } l1 = getLight(3); if(l1!=NULL && (rand() % 10 == 0)) { l1->sourceDiffuse[0] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[1] = ((rand() % 40)/100.0)+0.2; l1->sourceDiffuse[2] = ((rand() % 40)/100.0)+0.2; } }
void Scene::drawLightWall(Shader shader){ for (int i = 0; i < getLightNumber(); ++i) { string pointLight = "pointLights[" + to_string(i) + "]"; Light light = getLight(i); glUniform3f(glGetUniformLocation(shader.Program, (pointLight + ".position").c_str()), light.getPosition().x, light.getPosition().y, light.getPosition().z); glUniform3f(glGetUniformLocation(shader.Program, (pointLight + ".ambient").c_str()), 0.5f, 0.5f, 0.5f); glUniform3f(glGetUniformLocation(shader.Program, (pointLight + ".diffuse").c_str()), 0.5f, 0.5f, 0.5f); glUniform3f(glGetUniformLocation(shader.Program, (pointLight + ".specular").c_str()), 1.0f, 1.0f, 1.0f); glUniform1f(glGetUniformLocation(shader.Program, (pointLight + ".constant").c_str()), 1.0f); glUniform1f(glGetUniformLocation(shader.Program, (pointLight + ".linear").c_str()), 0.09); glUniform1f(glGetUniformLocation(shader.Program, (pointLight + ".quadratic").c_str()), 0.032); } }
bool WindowsManager::setLightingMode (const char* nodeNameCorba, const char* lightingModeCorba) { const std::string nodeName (nodeNameCorba); const std::string lightingMode (lightingModeCorba); LightingMode light = getLight (lightingMode); if (nodes_.find (nodeName) == nodes_.end ()) { std::cout << "Node \"" << nodeName << "\" doesn't exist." << std::endl; return false; } mtx_.lock(); nodes_[nodeName]->setLightingMode (light); mtx_.unlock(); return true; }
//----------------------------------------------------------------------------- Real AutoParamDataSource::getShadowExtrusionDistance(void) const { const Light& l = getLight(0); // only ever applies to one light at once if (l.getType() == Light::LT_DIRECTIONAL) { // use constant return mDirLightExtrusionDistance; } else { // Calculate based on object space light distance // compared to light attenuation range Vector3 objPos = getInverseWorldMatrix().transformAffine(l.getDerivedPosition(true)); return l.getAttenuationRange() - objPos.length(); } }
void ThingType::draw(const Point& dest, float scaleFactor, int layer, int xPattern, int yPattern, int zPattern, int animationPhase, LightView *lightView) { if(m_null) return; if(animationPhase >= m_animationPhases) return; const TexturePtr& texture = getTexture(animationPhase); // texture might not exists, neither its rects. if(!texture) return; uint frameIndex = getTextureIndex(layer, xPattern, yPattern, zPattern); if(frameIndex >= m_texturesFramesRects[animationPhase].size()) return; Point textureOffset; Rect textureRect; if(scaleFactor != 1.0f) { textureRect = m_texturesFramesOriginRects[animationPhase][frameIndex]; } else { textureOffset = m_texturesFramesOffsets[animationPhase][frameIndex]; textureRect = m_texturesFramesRects[animationPhase][frameIndex]; } Rect screenRect(dest + (textureOffset - m_displacement - (m_size.toPoint() - Point(1, 1)) * 32) * scaleFactor, textureRect.size() * scaleFactor); bool useOpacity = m_opacity < 1.0f; if(useOpacity) g_painter->setColor(Color(1.0f,1.0f,1.0f,m_opacity)); g_painter->drawTexturedRect(screenRect, texture, textureRect); if(useOpacity) g_painter->setColor(Color::white); if(lightView && hasLight()) { Light light = getLight(); if(light.intensity > 0) lightView->addLightSource(screenRect.center(), scaleFactor, light); } }
void SceneNodeWidget::updateSceneNode() { auto target=m_node.lock(); if(!target){ return; } // position auto &position=target->position(); ui->q_x->setValue(position[0]); ui->q_y->setValue(position[1]); ui->q_z->setValue(position[2]); // rotation auto &quternion=target->quaternion(); // mesh auto mesh=target->getMesh(); if(mesh){ ui->meshWidget->show(); } else{ ui->meshWidget->hide(); } // camera auto camera=target->getCamera(); if(camera){ ui->cameraWidget->show(); } else{ ui->cameraWidget->hide(); } // light auto light=target->getLight(); if(light){ ui->lightWidget->show(); } else{ ui->lightWidget->hide(); } }
//----------------------------------------------------------------------------- const Matrix4& AutoParamDataSource::getSpotlightWorldViewProjMatrix(size_t index) const { if (index < OGRE_MAX_SIMULTANEOUS_LIGHTS) { const Light& l = getLight(index); if (&l != &mBlankLight && l.getType() == Light::LT_SPOTLIGHT && mSpotlightWorldViewProjMatrixDirty[index]) { mSpotlightWorldViewProjMatrix[index] = getSpotlightViewProjMatrix(index) * getWorldMatrix(); mSpotlightWorldViewProjMatrixDirty[index] = false; } return mSpotlightWorldViewProjMatrix[index]; } else return Matrix4::IDENTITY; }
//----------------------------------------------------------------------------- Vector4 AutoParamDataSource::getSpotlightParams(size_t index) const { // inner, outer, fallof, isSpot const Light& l = getLight(index); if (l.getType() == Light::LT_SPOTLIGHT) { return Vector4(Math::Cos(l.getSpotlightInnerAngle().valueRadians() * 0.5f), Math::Cos(l.getSpotlightOuterAngle().valueRadians() * 0.5f), l.getSpotlightFalloff(), 1.0); } else { // Use safe values which result in no change to point & dir light calcs // The spot factor applied to the usual lighting calc is // pow((dot(spotDir, lightDir) - y) / (x - y), z) // Therefore if we set z to 0.0f then the factor will always be 1 // since pow(anything, 0) == 1 // However we also need to ensure we don't overflow because of the division // therefore set x = 1 and y = 0 so divisor doesn't change scale return Vector4(1.0, 0.0, 0.0, 0.0); // since the main op is pow(.., vec4.z), this will result in 1.0 } }
void KisColorSelector::mouseReleaseEvent(QMouseEvent* /*event*/) { if (!m_mouseMoved && m_clickedRing >= 0) { Radian angle = std::atan2(m_clickPos.x(), m_clickPos.y()) - RAD_90; m_selectedRing = m_clickedRing; m_selectedPiece = getHueIndex(angle, m_colorRings[m_clickedRing].getShift()); if (getNumPieces() > 1) m_selectedColor.setH(getHue(m_selectedPiece, m_colorRings[m_clickedRing].getShift())); else m_selectedColor.setH(angle.scaled(0.0f, 1.0f)); m_selectedColor.setS(getSaturation(m_selectedRing)); m_selectedColor.setX(getLight(m_light, m_selectedColor.getH(), m_relativeLight)); setSelectedColor(m_selectedColor, !(m_pressedButtons & Qt::RightButton)); } else if (m_mouseMoved) setSelectedColor(m_selectedColor, m_selectedColorIsFgColor); m_clickedRing = -1; update(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments( &argc, argv ); std::string dbPath; arguments.read("--db_path", dbPath); std::srand ( unsigned ( std::time(0) ) ); auto board = Board(boardDefinition, boardSizeX, boardSizeY, dbPath); auto ghostFactory = GhostFactory(); auto main_obj = make_ref<osg::Group>(); main_obj->addChild(board.draw().get()); auto ghostModel = osgDB::readNodeFile(dbPath + "/cow.osg"); auto ghostCount = 16; while(ghostCount--) { main_obj->addChild(ghostFactory.drawGhost(board, ghostModel).get()); } // init rotate auto init_rotate = make_ref<osg::MatrixTransform>(); init_rotate->setMatrix( osg::Matrix::rotate(osg::PI * 2, osg::Vec3(1.0f, 0.0f, 0.0f)) ); // chain rotates init_rotate->addChild(main_obj); // Root group auto root = make_ref<osg::Group>(); root->addChild(init_rotate); // Setup fog if(FogEnabled) { osg::ref_ptr<osg::Fog> fog = new osg::Fog; fog->setMode( osg::Fog::EXP2 ); fog->setStart( 0.0f ); fog->setEnd(board.getFieldSizeX() * 20); fog->setDensity(0.0135); fog->setColor( osg::Vec4(0., 0., 0., 1.0) ); root->getOrCreateStateSet()->setAttributeAndModes(fog.get()); } // Start viewer osgViewer::Viewer viewer; // Set up flashlight auto lightSource = make_ref<osg::LightSource>(); lightSource->setReferenceFrame(osg::LightSource::ABSOLUTE_RF); auto light = lightSource->getLight(); const osg::Vec3 lightPosition{1.5, -1, -1}; // right, down, front light->setPosition(osg::Vec4{lightPosition, 1}); light->setDirection(osg::Vec3{0, 0, -1} * 30 - lightPosition); light->setSpotExponent(60); light->setSpotCutoff(90); light->setDiffuse(osg::Vec4(1, 1, 1, 1)); light->setAmbient(osg::Vec4(0.6, 0.6, 0.6, 1)); light->setSpecular(osg::Vec4(1, 1, 1, 1)); light->setLinearAttenuation(0.001); light->setConstantAttenuation(0.5); root->addChild(lightSource); double height = std::min(board.getFieldSizeX(), board.getFieldSizeY()) / 1.5; auto fpsManipulator = make_ref<FPSManipulator>(board, viewer, *light); fpsManipulator->setHomePosition( osg::Vec3d(board.getFieldCenterX(1), board.getFieldCenterY(10), height), osg::Vec3d(0.0f, 0.0f, height), osg::Vec3d(0.0f, 0.0f, 1.0f) ); auto keySwitch = make_ref<osgGA::KeySwitchMatrixManipulator>(); keySwitch->addNumberedMatrixManipulator(make_ref<osgGA::OrbitManipulator>()); keySwitch->addNumberedMatrixManipulator(fpsManipulator); viewer.setCameraManipulator(keySwitch); viewer.home(); viewer.setSceneData( root ); osgViewer::Viewer::Windows windows; viewer.getWindows(windows); viewer.getCamera()->setClearColor(osg::Vec4{0, 0, 0, 0}); viewer.getCamera()->getView()->setLightingMode(osg::View::HEADLIGHT); auto defaultLight = viewer.getCamera()->getView()->getLight(); defaultLight->setDiffuse(osg::Vec4(0, 0, 0, 1)); defaultLight->setAmbient(osg::Vec4(0, 0, 0, 1)); defaultLight->setSpecular(osg::Vec4(0, 0, 0, 1)); // Shaders auto program = make_ref<osg::Program>(); auto fragmentObject = make_ref<osg::Shader>(osg::Shader::FRAGMENT); loadShaderSource(fragmentObject, dbPath + "/shader.frag"); auto vertexObject = make_ref<osg::Shader>(osg::Shader::VERTEX); loadShaderSource(vertexObject, dbPath + "/shader.vert"); program->addShader(vertexObject); program->addShader(fragmentObject); root->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON); root->getOrCreateStateSet()->addUniform(new osg::Uniform("samplerName", TEXTURE_UNIT)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("Shininess", BoardObjectsShininess)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("FogEnabled", FogEnabled)); // Optimize osgUtil::Optimizer optimzer; optimzer.optimize(root); viewer.setUpViewOnSingleScreen(0); return viewer.run(); }
bool Level::isWithinVision(Vec2 from, Vec2 to, VisionId v) const { return Vision::get(v)->isNightVision() || from.distD(to) <= darkViewRadius || getLight(to) > 0.3; }
//----------------------------------------------------------------------------- Real AutoParamDataSource::getLightPowerScale(size_t index) const { return getLight(index).getPowerScale(); }
//--------------------------------------------------------------------- float AutoParamDataSource::getLightCastsShadows(size_t index) const { return getLight(index).getCastShadows() ? 1.0f : 0.0f; }
void DirectionalLight::updateUniforms(Shader* shader) { InstanceDirectionalShader* s = (InstanceDirectionalShader*)shader; s->setLightColor(getLight()); s->setLightDirection(m_direction); }