bool IsotopeDistribution::operator<(const IsotopeDistribution & rhs) const { if (distribution_.size() != rhs.distribution_.size()) { return distribution_.size() < rhs.distribution_.size(); } // both vectors have same size auto it = distribution_.begin(); auto rhs_it = rhs.distribution_.begin(); for (; it != distribution_.end(); ++it, ++rhs_it) { if (*it != *rhs_it) { const double mz = it->getMZ(); const double in = it->getIntensity(); const double rhs_mz = rhs_it->getMZ(); const double rhs_in = rhs_it->getIntensity(); return tie(mz, in) < tie(rhs_mz, rhs_in); } } return false; }
void SegmentImage::getSegmentedImage(QVector<QImage> &segmentedQImages, QImage& contourQImage) { //Returns segmented and contour images using references int rows = getImgRows(); int cols = getImgCols(); int nSeeds = getSeedNumber(); Mat segmentationMatrix = getSegmentationMatrix(); QVector<Mat > segmentedImages;// This will contain two segmented images: background and foreground //initialize both segmented images by setting background to be white for(int i = 0; i < nSeeds; i++) { segmentedImages.append(Mat( getImgSize(), getImgType())); segmentedImages[i].setTo(cv::Scalar(255, 255, 255)); } //If wrong number of seeds provided, return blank images if(nSeeds != 2) { segmentedQImages.resize(2); segmentedQImages[0] = QImage(rows, cols, QImage::Format_RGB16); segmentedQImages[0].fill(Qt::white); segmentedQImages[1] = QImage(rows, cols, QImage::Format_RGB16); segmentedQImages[1].fill(Qt::white); contourQImage = QImage(rows, cols, QImage::Format_RGB16); contourQImage.fill(Qt::white); return; } for(int i = 0; i < rows; i++) for (int j = 0; j < cols; j++ ) { // seed value #1 is 1 and #2 is 2 // So using 1.5 as threshold we separate foreground from background if (segmentationMatrix.at<double>(i, j) >= 1.5) segmentedImages[0].at<Vec3b>(i, j) = getIntensity(i,j); else segmentedImages[1].at<Vec3b>(i,j) = getIntensity(i,j); } //Find contours and return the image with drawn contours Mat contourIm; //Compute the contour image getImageWithContour(getOrigImage(), contourIm);//contour image returned via reference //Save two SegmentationData images(one for background, one for foreground) into a QVector segmentedQImages segmentedQImages.clear(); for(int i = 0; i < nSeeds; i++) segmentedQImages.push_back(cvMatToQImage(segmentedImages[i]));//convert to QImage and save in a vector //Convert the contour image into a QImage contourQImage = cvMatToQImage(contourIm); // All three images are returned through a reference }
void RenderableLightEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableLightEntityItem::render"); assert(getType() == EntityTypes::Light); glm::vec3 position = getPosition(); glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z); glm::vec3 color = toGlm(getXColor()); float intensity = getIntensity(); float exponent = getExponent(); float cutoff = glm::radians(getCutoff()); if (_isSpotlight) { DependencyManager::get<DeferredLightingEffect>()->addSpotLight(position, largestDiameter / 2.0f, color, intensity, rotation, exponent, cutoff); } else { DependencyManager::get<DeferredLightingEffect>()->addPointLight(position, largestDiameter / 2.0f, color, intensity); } #ifdef WANT_DEBUG Q_ASSERT(args->_batch); gpu::Batch& batch = *args->_batch; batch.setModelTransform(getTransformToCenter()); DependencyManager::get<GeometryCache>()->renderWireSphere(batch, 0.5f, 15, 15, glm::vec4(color, 1.0f)); #endif };
void CX3DDirectionalLightNode::print(int indent) { FILE *fp = CX3DParser::getDebugLogFp(); char *nodeName = getNodeName(); if (nodeName) { float r, g, b; float x, y, z; CX3DParser::printIndent(indent); fprintf(fp, "%s (%s)\n", nodeName, CX3DNode::getNodeTypeString(getNodeType())); CX3DParser::printIndent(indent+1); fprintf(fp, "ambientIntensity : (%f)\n", getAmbientIntensity()->getValue()); getColor()->getValue(r, g, b); CX3DParser::printIndent(indent+1); fprintf(fp, "color : (%f %f %f)\n", r, g, b); getDirection()->getValue(x, y, z); CX3DParser::printIndent(indent+1); fprintf(fp, "direction : (%f %f %f)\n", x, y, z); CX3DParser::printIndent(indent+1); fprintf(fp, "intensity : (%f)\n", getIntensity()->getValue()); CX3DParser::printIndent(indent+1); fprintf(fp, "on : %s\n", getOn()->getValue() ? "TRUE" : "FALSE"); CX3DParser::printIndent(indent+1); fprintf(fp, "global : %s\n", getGlobal()->getValue() ? "TRUE" : "FALSE"); } }
void LightCategory::bind( castor::PxBufferBase & p_texture, uint32_t index )const { uint32_t offset = 0u; doCopyComponent( getColour(), index, offset, p_texture ); doCopyComponent( getIntensity(), getFarPlane(), index, offset, p_texture ); doBind( p_texture, index, offset ); }
void Scene::render() { for(int i = -CWIDTH / 2; i < CWIDTH / 2; i ++) { qDebug() << i; for(int j = -CHEIGHT / 2; j < CHEIGHT / 2; j ++) { QVector<Ray*> rSeq = camera->pixelLight(i, j); int s = rSeq.size(); Intensity rgb(0, 0, 0); while(!rSeq.empty()) { Ray* tmp = rSeq.front(); rgb = rgb + (1.0 / s) * getIntensity(tmp); rSeq.pop_front(); if(tmp != NULL) { delete tmp; tmp = NULL; } } pixels[i + CWIDTH / 2][j + CHEIGHT / 2] = rgb.toRGB(); } } }
//! [5] void VibrationSurface::paintEvent(QPaintEvent *) { QPainter painter(this); QRect rect = geometry(); int dx = 0, dy = 0; if (height() > width()) { dy = height() / NumberOfLevels; rect.setHeight(dy); } else { dx = width() / NumberOfLevels; rect.setWidth(dx); } //! [5] //! [6] for (int i = 0; i < NumberOfLevels; i++) { int x = i * dx; int y = i * dy; int intensity = getIntensity(x, y); QColor color = QColor(40, 80, 10).lighter(100 + intensity); rect.moveTo(x, y); painter.fillRect(rect, color); painter.setPen(color.darker()); painter.drawText(rect, Qt::AlignCenter, QString::number(intensity)); } }
void PointLightNode::getDiffuseColor(float value[]) { getColor(value); float intensity = getIntensity(); value[0] *= intensity; value[1] *= intensity; value[2] *= intensity; }
void KeyLightPropertyGroup::debugDump() const { qDebug() << " KeyLightPropertyGroup: ---------------------------------------------"; qDebug() << " color:" << getColor(); // << "," << getColor()[1] << "," << getColor()[2]; qDebug() << " intensity:" << getIntensity(); qDebug() << " direction:" << getDirection(); qDebug() << " ambientIntensity:" << getAmbientIntensity(); qDebug() << " ambientURL:" << getAmbientURL(); }
void LifeCycleParticleLayer::setFadingOut(ParticleStorage::Particle *p) { // making sure that the intensity won't pop to 1.0 when deleting a fading in particle float i = getIntensity(p); if (!isFadingOut(p)) { getLifeCycle(p)->birthDate = time - (fadeInDelay + activeDelay + (1.0f - i) * fadeOutDelay); } }
void PointLightNode::getAmbientColor(float value[]) { getColor(value); float intensity = getIntensity(); float ambientIntensity = getAmbientIntensity(); value[0] *= intensity * ambientIntensity; value[1] *= intensity * ambientIntensity; value[2] *= intensity * ambientIntensity; }
//! [3] void VibrationSurface::applyIntensity(int x, int y) { int intensity = getIntensity(x, y); if (intensity != lastIntensity) { vibra->setIntensity(intensity); lastIntensity = intensity; } }
float PointLight::getRange(void) { float a = m_attenuation->getExponent(); float b = m_attenuation->getLinear(); float c = m_attenuation->getConstant() - BITS_PER_CHANNEL * getIntensity() * glm::max(m_color.x, glm::max(m_color.y, m_color.z)); m_range = (-b + glm::sqrt(b * b - 4 * a * c)) / (2 * a); return m_range; }
// main() int main() { printf("beginning of program in C\n"); //struct lightBulb bulb; struct timeEmulate bulbTime; int i, level[10]; bool isHealth = true; pthread_t threadPush, threadTime; pthread_mutex_init(&lock, NULL); printf("Do we get here?\n"); // Obtain socket FD using PORT_WEATHER to communicate with weather.py int servSockWeather = createServerSocket(PORT_WEATHER); pthread_mutex_lock(&lock); bulb.health = 0; pthread_mutex_unlock(&lock); bulbTime.hour = 0; bulbTime.min = 0; for (i = 0; i < 10; i++){ level[i] = i+1; } printf("do we get to this in main?\n"); /* Two threads that run in background to update the time of the bulb and also push/pull notifications periodically to * Parse Cloud */ pthread_create(&threadPush, NULL, threadPushNotifications, NULL); pthread_create(&threadTime, NULL, updateBulbTime, (void *)(&bulbTime)); //MOVED THIS FROM ITS ORIGINAL SPOT updateIntensity(0, NULL); printf("what about here?\n"); while(1) { char str[4]; updateBasedOnTime(&bulbTime, level, servSockWeather); // doesn't get to here...printf("after UBOT?"); sprintf(str, "%d", getIntensity(&bulb)); clientSendSocket(PORT_INTENSITY, str); printf("Main loop thing\n"); while (bulb.health == 2) { if (isHealth) { updateOnParse("Intensity", 0); updateOnParse("Health", 2); //updateOnParse("Intensity", 0, "Health", 2); isHealth = false; printf("Bulb Health is screwed up\n"); } } // Avoid crazy looping during bulb DAMAGED condition. Optimization to avoid excess CPU cycle usage. isHealth = true; } return 0; }
void IsotopeDistribution::trimLeft(double cutoff) { for (auto iter = distribution_.begin(); iter != distribution_.end(); ++iter) { if (iter->getIntensity() >= cutoff) { distribution_.erase(distribution_.begin(), iter); break; } } }
void PointLight::SetLight(X3DDrawContext* pDC) { // m_radius->m_value; D3DXMATRIX modelView = pDC->m_renderContext->modelViewMatrix(); D3DXVECTOR3 location(m_location->getValue()); D3DXVECTOR4 v; D3DXVec3Transform(&v, &location, &modelView); float ambientIntensity = getAmbientIntensity(); float intensity = getIntensity(); Vec3f color = getColor(); Vec3f attenuation = getAttenuation(); Graphics::Light light; light.m_type = 2; light.m_ambient = Vec4f(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f); light.m_diffuse = Vec4f(color[0]*intensity, color[1]*intensity, color[2]*intensity, 1.0f); light.m_position = Vec4f(v.x, v.y, v.z, 1/*positional*/); light.m_constant_attenuation = attenuation[0]; light.m_linear_attenuation = attenuation[1]; light.m_quadratic_attenuation = attenuation[2]; pDC->m_renderContext->m_lights.push_back(light); ++pDC->m_renderContext->m_nLight; #if 0 pDC->m_pGraphics3D->PushMatrix(); // glTranslated(0, 0, 100); float light_position[4]; m_location->getValue(light_position); light_position[3] = 1; // positional float ambient[4] = {m_ambientIntensity->m_value, m_ambientIntensity->m_value, m_ambientIntensity->m_value, 1.0}; float diffuse_specular[4] = {m_color->m_value[0], m_color->m_value[1], m_color->m_value[2], m_intensity->m_value}; pDC->m_pGraphics3D->Enable(GL_LIGHT0+pDC->m_nLight); pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_POSITION, light_position); pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_AMBIENT, ambient); pDC->m_pGraphics3D->Lightfv(GL_LIGHT0+pDC->m_nLight, GL_DIFFUSE, diffuse_specular); // pDC->m_pGraphics3D->glLightfv(GL_LIGHT0+pDC->m_nLight, GL_SPECULAR , diffuse_specular); pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_CONSTANT_ATTENUATION, m_attenuation->m_value[0]); pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_LINEAR_ATTENUATION, m_attenuation->m_value[1]); pDC->m_pGraphics3D->Lightf(GL_LIGHT0+pDC->m_nLight, GL_QUADRATIC_ATTENUATION, m_attenuation->m_value[2]); pDC->m_pGraphics3D->PopMatrix(); #endif }
void IsotopeDistribution::trimRight(double cutoff) { auto riter = distribution_.rbegin(); // loop from right to left until an entry is larger than the cutoff for (; riter != distribution_.rend(); ++riter) { if (riter->getIntensity() >= cutoff) break; } // trim the container distribution_.resize(riter.base() - distribution_.begin()); }
void Sound::OnFieldChanged(X3DField* field) { if (field == m_intensity) { if (m_sourceVoice) { float volume = getIntensity(); // TODO ?? m_sourceVoice->SetVolume(volume); } } baseClass::OnFieldChanged(field); }
double PeakIntegrator::simpson_(PeakContainerConstIteratorT it_begin, PeakContainerConstIteratorT it_end) const { double integral = 0.0; for (auto it = it_begin + 1; it < it_end - 1; it = it + 2) { const double h = it->getPos() - (it - 1)->getPos(); const double k = (it + 1)->getPos() - it->getPos(); const double y_h = (it - 1)->getIntensity(); const double y_0 = it->getIntensity(); const double y_k = (it + 1)->getIntensity(); integral += (1.0 / 6.0) * (h + k) * ((2.0 - k / h) * y_h + (pow(h + k, 2) / (h * k)) * y_0 + (2.0 - h / k) * y_k); } return integral; }
void LightEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, EntityPropertyFlags& requestedProperties, EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, int& propertyCount, OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, getIsSpotlight()); APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_INTENSITY, getIntensity()); APPEND_ENTITY_PROPERTY(PROP_EXPONENT, getExponent()); APPEND_ENTITY_PROPERTY(PROP_CUTOFF, getCutoff()); }
void PointLightNode::outputContext(ostream &printStream, const char *indentString) { SFColor *color = getColorField(); SFVec3f *attenuation = getAttenuationField(); SFVec3f *location = getLocationField(); SFBool *bon = getOnField(); printStream << indentString << "\t" << "on " << bon << endl; printStream << indentString << "\t" << "intensity " << getIntensity() << endl; printStream << indentString << "\t" << "ambientIntensity " << getAmbientIntensity() << endl; printStream << indentString << "\t" << "color " << color << endl; printStream << indentString << "\t" << "location " << location << endl; printStream << indentString << "\t" << "radius " << getRadius() << endl; printStream << indentString << "\t" << "attenuation " << attenuation << endl; }
void KeyLightPropertyGroup::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData, EntityPropertyFlags& requestedProperties, EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, int& propertyCount, OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, getIntensity()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, getAmbientIntensity()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, getDirection()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_URL, getAmbientURL()); }
void IsotopeDistribution::renormalize() { if (distribution_.size() != 0) { double sum(0); // loop backwards as most distributions contains a lot of small values at the end for (auto it = distribution_.rbegin(); it != distribution_.rend(); ++it) { sum += it->getIntensity(); } for (Iterator it = distribution_.begin(); it != distribution_.end(); ++it) { it->setIntensity(it->getIntensity() / sum); } } }
bool KeyLightPropertyGroup::appendToEditPacket(OctreePacketData* packetData, EntityPropertyFlags& requestedProperties, EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, int& propertyCount, OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_INTENSITY, getIntensity()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, getAmbientIntensity()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_DIRECTION, getDirection()); APPEND_ENTITY_PROPERTY(PROP_KEYLIGHT_AMBIENT_URL, getAmbientURL()); return true; }
cv::Vec3f AreaLight::getIntensity(const HitRecord & hit, QVector3D &direction, const Intersectable &scene, const Sample &sample) const { QVector3D at = hit.getIntersectingPoint().toVector3DAffine(); QPointF p = sample.getSample(); QVector3D lightLocation = getLocation(p); direction = at - lightLocation; HitRecord shadowHit = scene.intersect(Ray(at, -direction.normalized(), EPSILON, direction.length() - EPSILON)); if(shadowHit.intersects() && &shadowHit.getMaterial() != this) { return cv::Vec3f(); } else { return getIntensity(direction); } }
//----------------------------------------------------------------------------- void Volume::compareVolume(Volume *i_obj) { std::cout << "start comparing volume " << m_type << " " << i_obj->m_type << "\n" ; unsigned int wrong(0); std::cout << i_obj->m_noOfVoxelsX << " " << i_obj->m_noOfVoxelsY << " " << i_obj->getNoVoxelsZ() << "\n"; std::cout << m_noOfVoxelsX << " " << m_noOfVoxelsY << " " << m_noOfVoxelsZ << "\n"; unsigned int zeros(0); unsigned int nonzerosButnotEqual(0); for(unsigned int x=0; x<m_noOfVoxelsX; x++) { for(unsigned int y=0; y<m_noOfVoxelsY; y++) { for(unsigned int z=0; z<m_noOfVoxelsZ; z++) { double int1 = getIntensity(x,y,z); double int2 = i_obj->getIntensity(x,y,z); // std::cout << wrong << " " << int1 << " " << int2 << "\n"; if(int1>int2+0.0001 || int1<int2-0.0001) { wrong++; std::cout << x << " " << y << " " << z << " : " << int1 << " " << int2 << "\n"; // std::cout << wrong << " " << int1 << " " << int2 << "\n"; } else { if(int1<0.01) { zeros++; } else { nonzerosButnotEqual++; } } } } } std::cout<< "Compare Volumes Results:\nDifferent Voxels are " << wrong << " of " << m_noOfVoxelsX*m_noOfVoxelsY*m_noOfVoxelsZ << "\n" <<"Percentage = "<<double(wrong/double(m_noOfVoxelsX*m_noOfVoxelsY*m_noOfVoxelsZ)) << "\nzeros = " << zeros << " + " << nonzerosButnotEqual << "\n" << "\n"; }
PeakIntegrator::PeakShapeMetrics PeakIntegrator::calculatePeakShapeMetrics_( const PeakContainerT& pc, double left, double right, const double peak_height, const double peak_apex_pos ) const { PeakContainerT emg_pc; const PeakContainerT& p = EMGPreProcess_(pc, emg_pc, left, right); PeakShapeMetrics psm; psm.points_across_baseline = 0; psm.points_across_half_height = 0; for (auto it = p.PosBegin(left); it != p.PosEnd(right); ++it) { // points across the peak ++(psm.points_across_baseline); if (it->getIntensity() >= 0.5 * peak_height) { ++(psm.points_across_half_height); } } // positions at peak heights typename PeakContainerT::ConstIterator it_PosBegin_l = p.PosBegin(left); typename PeakContainerT::ConstIterator it_PosEnd_apex = p.PosEnd(peak_apex_pos); typename PeakContainerT::ConstIterator it_PosEnd_r = p.PosEnd(right); psm.start_position_at_5 = findPosAtPeakHeightPercent_(it_PosBegin_l, it_PosEnd_apex - 1, peak_height, 0.05, true); psm.start_position_at_10 = findPosAtPeakHeightPercent_(it_PosBegin_l, it_PosEnd_apex - 1, peak_height, 0.1, true); psm.start_position_at_50 = findPosAtPeakHeightPercent_(it_PosBegin_l, it_PosEnd_apex - 1, peak_height, 0.5, true); psm.end_position_at_5 = findPosAtPeakHeightPercent_(it_PosEnd_apex, it_PosEnd_r, peak_height, 0.05, false); psm.end_position_at_10 = findPosAtPeakHeightPercent_(it_PosEnd_apex, it_PosEnd_r, peak_height, 0.1, false); psm.end_position_at_50 = findPosAtPeakHeightPercent_(it_PosEnd_apex, it_PosEnd_r, peak_height, 0.5, false); // peak widths psm.width_at_5 = psm.end_position_at_5 - psm.start_position_at_5; psm.width_at_10 = psm.end_position_at_10 - psm.start_position_at_10; psm.width_at_50 = psm.end_position_at_50 - psm.start_position_at_50; psm.total_width = (p.PosEnd(right) - 1)->getPos() - p.PosBegin(left)->getPos(); psm.slope_of_baseline = (p.PosEnd(right) - 1)->getIntensity() - p.PosBegin(left)->getIntensity(); psm.baseline_delta_2_height = psm.slope_of_baseline / peak_height; // Source of tailing_factor and asymmetry_factor formulas: // USP 40 - NF 35 The United States Pharmacopeia and National Formulary - Supplementary psm.tailing_factor = psm.width_at_5 / (2*(peak_apex_pos - psm.start_position_at_5)); psm.asymmetry_factor = (psm.end_position_at_10 - peak_apex_pos) / (peak_apex_pos - psm.start_position_at_10); return psm; }
void RenderableLightEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderableLightEntityItem::render"); assert(getType() == EntityTypes::Light); glm::vec3 position = getPosition(); glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z); const float MAX_COLOR = 255.0f; float colorR = getColor()[RED_INDEX] / MAX_COLOR; float colorG = getColor()[GREEN_INDEX] / MAX_COLOR; float colorB = getColor()[BLUE_INDEX] / MAX_COLOR; glm::vec3 color = glm::vec3(colorR, colorG, colorB); float intensity = getIntensity(); float exponent = getExponent(); float cutoff = glm::radians(getCutoff()); if (_isSpotlight) { DependencyManager::get<DeferredLightingEffect>()->addSpotLight(position, largestDiameter / 2.0f, color, intensity, rotation, exponent, cutoff); } else { DependencyManager::get<DeferredLightingEffect>()->addPointLight(position, largestDiameter / 2.0f, color, intensity); } #ifdef WANT_DEBUG glm::vec4 color(diffuseR, diffuseG, diffuseB, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glPushMatrix(); glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); DependencyManager::get<DeferredLightingEffect>()->renderWireSphere(0.5f, 15, 15, color); glPopMatrix(); glPopMatrix(); #endif };
bool PlatformDemoState::update(float dt) { playerController->applyInput(playerInput); m_scene.update(dt); m_meshRenderer.update(); //update lighting auto& shader = m_shaderResource.get(PlatformShaderId::SpecularSmooth2D); //shader.setUniform("u_ambientColour", sf::Glsl::Vec4(m_scene.getAmbientColour())); auto lights = m_scene.getVisibleLights(m_scene.getVisibleArea()); auto i = 0u; for (; i < lights.size() && i < xy::Shader::NormalMapped::MaxPointLights; ++i) { auto light = lights[i]; if (light) { const std::string idx = std::to_string(i); auto pos = light->getWorldPosition(); shader.setUniform("u_pointLightPositions[" + std::to_string(i) + "]", pos); shader.setUniform("u_pointLights[" + idx + "].intensity", light->getIntensity()); shader.setUniform("u_pointLights[" + idx + "].diffuseColour", sf::Glsl::Vec4(light->getDiffuseColour())); shader.setUniform("u_pointLights[" + idx + "].specularColour", sf::Glsl::Vec4(light->getSpecularColour())); shader.setUniform("u_pointLights[" + idx + "].inverseRange", light->getInverseRange()); } } //switch off inactive lights for (; i < xy::Shader::NormalMapped::MaxPointLights; ++i) { shader.setUniform("u_pointLights[" + std::to_string(i) + "].intensity", 0.f); } //update skylight const auto& skyLight = m_scene.getSkyLight(); shader.setUniform("u_directionalLight.diffuseColour", sf::Glsl::Vec4(skyLight.getDiffuseColour())); shader.setUniform("u_directionalLight.specularColour", sf::Glsl::Vec4(skyLight.getSpecularColour())); shader.setUniform("u_directionalLight.intensity", skyLight.getIntensity()); shader.setUniform("u_directionaLightDirection", skyLight.getDirection()); return true; }
void RenderableLightEntityItem::updateRenderItemFromEntity(LightPayload& lightPayload) { auto entity = this; lightPayload.setVisible(entity->getVisible()); auto light = lightPayload.editLight(); light->setPosition(entity->getPosition()); light->setOrientation(entity->getRotation()); bool success; lightPayload.editBound() = entity->getAABox(success); if (!success) { lightPayload.editBound() = render::Item::Bound(); } glm::vec3 dimensions = entity->getDimensions(); float largestDiameter = glm::compMax(dimensions); light->setMaximumRadius(largestDiameter / 2.0f); light->setColor(toGlm(entity->getXColor())); float intensity = entity->getIntensity();//* entity->getFadingRatio(); light->setIntensity(intensity); light->setFalloffRadius(entity->getFalloffRadius()); float exponent = entity->getExponent(); float cutoff = glm::radians(entity->getCutoff()); if (!entity->getIsSpotlight()) { light->setType(model::Light::POINT); } else { light->setType(model::Light::SPOT); light->setSpotAngle(cutoff); light->setSpotExponent(exponent); } }