void ParticleField::updateParticles() { for (std::list<Particle>::iterator it = m_Particles.begin(); it != m_Particles.end(); it++) { ci::Vec4f curParticle = it->history.back(); if (curParticle[3] < HEAT_KILL_THRESHOLD) { it->history.pop_front(); continue; } if (inView(curParticle)) { curParticle[3] = std::min(static_cast<float>(curParticle[3] + HEAT_CHANGE_RATE), 1.0f); } else { curParticle[3] = std::max(static_cast<float>(curParticle[3] - HEAT_CHANGE_RATE), 0.0f); } ci::Vec3f vel; ci::Vec3f updatedLoc(curParticle[0], curParticle[1], curParticle[2]); getPerlin(updatedLoc, vel); updatedLoc += it->mult * vel * (m_CurTimeSeconds - m_LastTimeSeconds); applyForces(updatedLoc); curParticle[0] = updatedLoc[0]; curParticle[1] = updatedLoc[1]; curParticle[2] = updatedLoc[2]; it->history.push_back(curParticle); if (it->history.size() > MAX_HISTORY_LENGTH) { it->history.pop_front(); } } }
bool StageLayer::handleEventMouse(EventMouse *e) { auto btn = e->getMouseButton(); auto idx = (int)btn; switch(e->getMouseCode()) { // FIX: no need to start with press ok case MouseCode::SCROLL: case MouseCode::PRESS: { auto const &pos = e->getCursorPos(); if(!inView(pos.x, pos.y)) return false; auto worldPos = screenToWorld(pos); e->setCursorWorld(worldPos.x, worldPos.y); return dispatchEvent(e); } case MouseCode::RELEASE: { auto l = static_cast<EventMouseListener*>(mouseSlots_[idx].get()); auto ok = l && l->isRunning(); if(ok && l->onRelease) { auto worldPos = screenToWorld(e->getCursorPos()); e->setCursorWorld(worldPos); l->onRelease(e); } mouseSlots_[idx] = nullptr; return ok; } case MouseCode::MOVE: { auto l = static_cast<EventMouseListener*>(mouseSlots_[idx].get()); auto ok = l && l->isRunning(); if(ok && l->onMove) { auto worldPos = screenToWorld(e->getCursorPos()); e->setCursorWorld(worldPos); l->onMove(e); } return ok; } } return false; }
/* Weeping Apples are quantum locked as long as they are observed Un-observed apples might move around, disappear, or even attack the snake if given the chance. */ void quantumLock(Game *g, Apple *self) { Bounds b; if(!inView(self->c, g->snake.head->c, g->snake.dir)) { if(inRadius(g->snake.head->c, self->c, WeepingAttackRange) && ODDS(WeepingAttackChance)) { trimSnake(g, WeepingAttackDamage, 0); self->dead = true; } else if(ODDS(WeepingWarpChance)) { if(ODDS(WeepingChaseChance)) { b.x.min = MIN(self->c.x, g->snake.head->c.x); b.x.max = MAX(self->c.x, g->snake.head->c.x); b.y.min = MIN(self->c.y, g->snake.head->c.y); b.y.max = MAX(self->c.y, g->snake.head->c.y); placeInBounds(g, b, &self->c); } else placeRandomly(g, &self->c); } } }
bool ProteinLoader::importPDBFile( const std::string &filename, const Vector3f& position, const int material, Scene& scene) { Vector3f inViewPos(0,0,0); float inViewRadius = 1.0; int index(0); std::ifstream file(filename.c_str()); if(!file.is_open()) { BRAYNS_ERROR << "Could not open " << filename << std::endl; return false; } else { while( file.good() ) { std::string line; std::string value; std::getline( file, line ); if( line.find("ATOM") == 0 ) { // Atom Atom atom; atom.chainId = 0; atom.residue = 0; atom.index = index; index++; std::string atomName; std::string atomCode; size_t i=0; while( i<line.length() ) { switch(i) { case 6: //ID case 12: case 76: // Atom name case 22: // ChainID case 30: // x case 38: // y case 46: // z value = ""; break; case 21: atom.chainId = (int)line.at(i)-64; break; case 11: atom.id = static_cast<int>(atoi(value.c_str())); break; case 17: atomCode = value; break; case 79: atomName = value; break; case 26: atom.residue = static_cast<int>(atoi(value.c_str())); break; case 37: atom.position[0] = static_cast<float>(atof(value.c_str())); break; case 45: atom.position[1] = static_cast<float>(atof(value.c_str())); break; case 53: atom.position[2] = static_cast<float>(atof(value.c_str())); break; default: if( line.at(i) != ' ' ) value += line.at(i); break; } i++; } // Material atom.materialId = 0; i=0; bool found(false); const ColorScheme colorScheme = _geometryParameters.getColorScheme( ); if( colorScheme == CS_PROTEIN_BACKBONE ) atom.materialId = material; else { while(!found && i<colorMapSize) { if( atomName == colorMap[i].symbol ) { found = true; switch( colorScheme ) { case CS_PROTEIN_CHAINS: atom.materialId = abs(atom.chainId) % scene.getMaterials().size(); break; case CS_PROTEIN_RESIDUES: atom.materialId = abs(atom.residue) % scene.getMaterials().size(); break; case CS_PROTEIN_BACKBONE: atom.materialId = 0; break; default: atom.materialId = static_cast<int>(i); break; } } ++i; } } // Radius atom.radius = 25.f; i=0; found = false; while( !found && i<colorMapSize ) { if( atomName == atomic_radii[i].Symbol ) { atom.radius = atomic_radii[i].radius; found = true; } ++i; } SpherePtr sphere(new Sphere( 0, Vector3f( position[0] + 0.01f*atom.position[0], position[1] + 0.01f*atom.position[1], position[2] + 0.01f*atom.position[2]), 0.0001f * atom.radius * _geometryParameters.getRadiusMultiplier(), 0.f, 0.f)); if( colorScheme == CS_PROTEIN_BACKBONE ) { Vector3f inView( sphere->getCenter() - inViewPos ); float dist = inView.length(); if( dist > inViewRadius ) { atom.materialId = ( dist < (inViewRadius+0.1) ) ? 1 : 0; scene.getPrimitives()[atom.materialId].push_back(sphere); } } else scene.getPrimitives()[atom.materialId].push_back(sphere); scene.getWorldBounds().merge(sphere->getCenter()); } } file.close(); } return true; }