SPoint2 GEdge::reparamOnFace(const GFace *face, double epar,int dir) const { // reparametrize the point onto the given face. const GPoint p3 = point(epar); SPoint3 sp3(p3.x(), p3.y(), p3.z()); return face->parFromPoint(sp3); }
int main(int, const char * []) { IloEnv env; try { IloIntVarArray x(env); for (IloInt i = 0; i < 10; i++) { char name[6]; sprintf(name, "X%ld", i); x.add(IloIntVar(env, 0, 100 - 2*(i / 2), name)); } IloModel mdl(env); mdl.add(IloAllDiff(env, x)); mdl.add(x); IloIntVarChooser varChooser = ChooseSmallestCentroid(env); IloIntValueChooser valChooser = ChooseSmallestDistanceFromCentroid(env); IloSearchPhase sp1(env, x, varChooser, valChooser); IloIntVarEval varEval = Centroid(env); IloIntValueEval valEval = DistanceFromCentroid(env); IloSearchPhase sp2(env, x, IloSelectSmallest(varEval), IloSelectSmallest(valEval)); // sp2 can have ties as two variable or values could evaluate // to the same values. sp3 shows how to break these ties // choosing, for equivalent centroid and distance-to-centroid // evaluations, the lowest indexed variable in x and the // lowest value. IloVarSelectorArray selVar(env); selVar.add(IloSelectSmallest(varEval)); selVar.add(IloSelectSmallest(IloVarIndex(env, x))); // break ties on index IloValueSelectorArray selValue(env); selValue.add(IloSelectSmallest(valEval)); selValue.add(IloSelectSmallest(IloValue(env))); // break ties on smallest IloSearchPhase sp3(env, x, selVar, selValue); IloCP cp(mdl); cp.setParameter(IloCP::Workers, 1); cp.setParameter(IloCP::SearchType, IloCP::DepthFirst); cp.setParameter(IloCP::LogPeriod, 1); cp.out() << "Choosers" << std::endl; cp.solve(sp1); cp.out() << cp.domain(x) << std::endl; cp.out() << "Evaluators" << std::endl; cp.solve(sp2); cp.out() << cp.domain(x) << std::endl; cp.out() << "Evaluators (with tie-break)" << std::endl; cp.solve(sp3); cp.out() << cp.domain(x) << std::endl; cp.end(); } catch (IloException & ex) { env.out() << "Caught: " << ex << std::endl; } env.end(); return 0; }
void test3(){ SharePtr<int> sp(new int(1)); SharePtr<int> sp1(sp); SharePtr<int> sp5(sp); SharePtr<int> sp6(sp); SharePtr<int> sp7(sp); SharePtr<int> sp3(new int(2)); SharePtr<int> sp4(sp3); SharePtr<int> sp8(sp3); SharePtr<int> sp9(sp3); SharePtr<int> sp10(sp3); //sp3 = sp1; //*sp3 = 20; }
int main() { iset data; spi sp0(new int(0)); spi sp1(new int(1)); spi sp2(new int(2)); spi sp3(sp1); spi sp4(new int(1)); data.insert(sp0); data.insert(sp1); data.insert(sp2); lookup(data, sp1); lookup(data, sp3); lookup(data, sp4); return 0; }
void SharedPtr() { struct Object { Object() { std::cout << "(Object ctor) " << std::flush; } ~Object() { std::cout << "(Object dtor) " << std::flush; } }; outHeader("shared_ptr"); outIdent(); std::cout << "(Creating Object) " << std::flush; std::shared_ptr<Object> sp(new Object); { std::cout << "(1st Sharing Object ownership) " << std::flush; std::shared_ptr<Object> sp2(sp); { std::cout << "(2nd Sharing Object ownership) " << std::flush; std::shared_ptr<Object> sp3(sp); } } std::cout << std::endl; }
//Create a triangle that contains all other vertices Triangle createSuperTriangle(const std::vector<Vector2>& vertices) { float M = vertices[0].mX; //Get max X and Y for (std::vector<Vector2>::const_iterator it = vertices.begin(); it != vertices.end(); ++it) { float xAbs = fabs(it->mX); float yAbs = fabs(it->mY); if (xAbs > M) M = xAbs; if (yAbs > M) M = yAbs; } //Create super triangle Vector2 sp1(10 * M, 0); Vector2 sp2(0, 10 * M); Vector2 sp3(-10 * M, -10 * M); return Triangle(sp1, sp2, sp3); }
int main(int argc, char **argv) { // Traits typedefs // {{{ // typedef ::World< ::CyclicWorldTraits<Real> > world_type; // typedef EGFRDSimulator< ::EGFRDSimulatorTraitsBase<world_type> > // simulator_type; typedef ecell4::egfrd::EGFRDWorld world_type; typedef ecell4::egfrd::EGFRDSimulator simulator_type; typedef simulator_type::multi_type multi_type; // }}} // Constants // {{{ const ecell4::Real L(1e-6); const ecell4::Real3 edge_lengths(L, L, L); const ecell4::Integer3 matrix_sizes(3, 3, 3); const ecell4::Real volume(L * L * L); const ecell4::Integer N(60); const ecell4::Real kd(0.1), U(0.5); const ecell4::Real ka(kd * volume * (1 - U) / (U * U * N)); const ecell4::Real k2(ka), k1(kd); const ecell4::Integer dissociation_retry_moves(3); // }}} boost::shared_ptr<ecell4::NetworkModel> model(new ecell4::NetworkModel()); // add ::SpeciesType to ::ParticleModel // {{{ ecell4::Species sp1( std::string("A"), std::string("2.5e-09"), std::string("1e-12")); model->add_species_attribute(sp1); ecell4::Species sp2( std::string("B"), std::string("2.5e-09"), std::string("1e-12")); model->add_species_attribute(sp2); ecell4::Species sp3( std::string("C"), std::string("2.5e-09"), std::string("1e-12")); model->add_species_attribute(sp3); // }}} // ReactionRules // {{{ // A -> B + C k1 // {{{ ecell4::ReactionRule rr1( ecell4::create_unbinding_reaction_rule(sp1, sp2, sp3, k1)); model->add_reaction_rule(rr1); // }}} // B + C -> A k2 // {{{ ecell4::ReactionRule rr2( ecell4::create_binding_reaction_rule(sp2, sp3, sp1, k2)); model->add_reaction_rule(rr2); // }}} // }}} // Random Number Generator (Instanciate and Initialize) // {{{ // boost::shared_ptr<ecell4::GSLRandomNumberGenerator> boost::shared_ptr<ecell4::RandomNumberGenerator> rng(new ecell4::GSLRandomNumberGenerator()); rng->seed((unsigned long int)0); // rng->seed(time(NULL)); // }}} // World Definition // {{{ boost::shared_ptr<world_type> world(new world_type(edge_lengths, matrix_sizes, rng)); world->bind_to(model); // }}} // add ecell4::Species( ::SpeciesInfo) to ::World // {{{ // world->add_species(ecell4::Species("A")); // world->add_species(ecell4::Species("B")); // world->add_species(ecell4::Species("C")); // }}} // Thorow particles into world at random // {{{ world->add_molecules(ecell4::Species("A"), N); typedef std::vector<std::pair<ecell4::ParticleID, ecell4::Particle> > particle_id_pair_list; const particle_id_pair_list particles(world->list_particles()); for (particle_id_pair_list::const_iterator i(particles.begin()); i != particles.end(); ++i) { const ecell4::Real3 pos((*i).second.position()); std::cout << "(" << pos[0] << pos[1] << pos[2] << ")" << std::endl; } // }}} // Logger Settings // {{{ boost::shared_ptr< ::LoggerManager> logger_mng( new ::LoggerManager("dummy", ::Logger::L_WARNING)); ::LoggerManager::register_logger_manager( "ecell.EGFRDSimulator", logger_mng); // }}} // EGFRDSimulator instance generated // {{{ boost::shared_ptr<simulator_type> sim( new simulator_type(world, model, dissociation_retry_moves)); // sim->paranoiac() = true; sim->initialize(); // }}} // Simulation Executed // {{{ ecell4::Real next_time(0.0), dt(0.02); std::cout << sim->t() << "\t" << world->num_molecules_exact(sp1) << "\t" << world->num_molecules_exact(sp2) << "\t" << world->num_molecules_exact(sp3) << "\t" << std::endl; // for (int i(0); i < 10; i++) // for (int i(0); i < 100; i++) for (int i(0); i < 100; i++) { next_time += dt; while (sim->step(next_time)) { // if (sim->last_reactions().size() > 0) // { // std::cout << sim->t() << "\t" // << world->num_molecules_exact(sp1) << "\t" // << world->num_molecules_exact(sp2) << "\t" // << world->num_molecules_exact(sp3) << "\t" << std::endl; // } } std::cout << sim->t() << "\t" << world->num_molecules_exact(sp1) << "\t" << world->num_molecules_exact(sp2) << "\t" << world->num_molecules_exact(sp3) << "\t" << std::endl; } // }}} // world->save("test.h5"); // Statistics // {{{ int num_single_steps_per_type[simulator_type::NUM_SINGLE_EVENT_KINDS]; num_single_steps_per_type[simulator_type::SINGLE_EVENT_REACTION] = sim->num_single_steps_per_type(simulator_type::SINGLE_EVENT_REACTION); num_single_steps_per_type[simulator_type::SINGLE_EVENT_ESCAPE] = sim->num_single_steps_per_type(simulator_type::SINGLE_EVENT_ESCAPE); std::cout << (boost::format("%1%: %2% \n") % "SINGLE_EVENT_REACTION" % num_single_steps_per_type[simulator_type::SINGLE_EVENT_REACTION]); std::cout << (boost::format("%1%: %2% \n") % "SINGLE_EVENT_ESCAPE" % num_single_steps_per_type[simulator_type::SINGLE_EVENT_ESCAPE]); std::cout << (boost::format("%1%: %2% \n") % "PAIR_EVENT_SINGLE_REACTION_0" % sim->num_pair_steps_per_type( simulator_type::PAIR_EVENT_SINGLE_REACTION_0)); std::cout << (boost::format("%1%: %2% \n") % "PAIR_EVENT_SINGLE_REACTION_1" % sim->num_pair_steps_per_type( simulator_type::PAIR_EVENT_SINGLE_REACTION_1)); std::cout << (boost::format("%1%: %2% \n") % "PAIR_EVENT_COM_ESCAPE" % sim->num_pair_steps_per_type(simulator_type::PAIR_EVENT_COM_ESCAPE)); std::cout << (boost::format("%1%: %2% \n") % "PAIR_EVENT_IV_UNDETERMINED" % sim->num_pair_steps_per_type( simulator_type::PAIR_EVENT_IV_UNDETERMINED)); std::cout << (boost::format("%1%: %2% \n") % "PAIR_EVENT_IV_ESCAPE" % sim->num_pair_steps_per_type(simulator_type::PAIR_EVENT_IV_ESCAPE)); std::cout << (boost::format("%1%: %2% \n") % "PAIR_EVENT_IV_REACTION" % sim->num_pair_steps_per_type(simulator_type::PAIR_EVENT_IV_REACTION)); std::cout << (boost::format("%1%: %2% \n") % "NONE" % sim->num_multi_steps_per_type(multi_type::NONE)); std::cout << (boost::format("%1%: %2% \n") % "ESCAPE" % sim->num_multi_steps_per_type(multi_type::ESCAPE)); std::cout << (boost::format("%1%: %2% \n") % "REACTION" % sim->num_multi_steps_per_type(multi_type::REACTION)); // }}} // { // boost::scoped_ptr<world_type> // world2(new world_type(ecell4::Real3(1, 2, 3), ecell4::Integer3(3, 6, 9))); // std::cout << "edge_lengths:" << world2->edge_lengths()[0] << " " << world2->edge_lengths()[1] << " " << world2->edge_lengths()[2] << std::endl; // std::cout << "matrix_sizes:" << world2->matrix_sizes()[0] << " " << world2->matrix_sizes()[1] << " " << world2->matrix_sizes()[2] << std::endl; // std::cout << "num_particles: " << world2->num_particles() << std::endl; // world2->load("test.h5"); // std::cout << "edge_lengths:" << world2->edge_lengths()[0] << " " << world2->edge_lengths()[1] << " " << world2->edge_lengths()[2] << std::endl; // std::cout << "matrix_sizes:" << world2->matrix_sizes()[0] << " " << world2->matrix_sizes()[1] << " " << world2->matrix_sizes()[2] << std::endl; // std::cout << "num_particles: " << world2->num_particles() << std::endl; // } return 0; }
void run() { const Real world_size(1e-6); const Position3 edge_lengths(world_size, world_size, world_size); const Real volume(world_size * world_size * world_size); const Integer N(60); const std::string D("1e-12"), radius("2.5e-9"); // const Real kD( // 4 * M_PI * (2 * std::atof(D.c_str())) * (2 * std::atof(radius.c_str()))); const Real kd(0.1), U(0.5); const Real ka(kd * volume * (1 - U) / (U * U * N)); #if (STYPE == EGFRD_MODE) || (STYPE == BD_MODE) const Real k2(ka), k1(kd); #else const Real k2(ka * kD / (ka + kD)); const Real k1(k2 * kd / ka); #endif Species sp1("A", radius, D), sp2("B", radius, D), sp3("C", radius, D); ReactionRule rr1(create_unbinding_reaction_rule(sp1, sp2, sp3, k1)), rr2(create_binding_reaction_rule(sp2, sp3, sp1, k2)); boost::shared_ptr<NetworkModel> model(new NetworkModel()); model->add_species_attribute(sp1); model->add_species_attribute(sp2); model->add_species_attribute(sp3); model->add_reaction_rule(rr1); model->add_reaction_rule(rr2); boost::shared_ptr<GSLRandomNumberGenerator> rng(new GSLRandomNumberGenerator()); rng->seed(time(NULL)); #if STYPE == EGFRD_MODE const Integer matrix_size(3); boost::shared_ptr<world_type> world( new world_type(world_size, matrix_size, rng)); #elif STYPE == BD_MODE boost::shared_ptr<world_type> world(new world_type(edge_lengths, rng)); #elif STYPE == ODE_MODE boost::shared_ptr<world_type> world(new world_type(volume)); #else // STYPE == GILLESPIE_MODE boost::shared_ptr<world_type> world(new world_type(volume, rng)); #endif world->add_molecules(sp1, N); simulator_type sim(model, world); #if STYPE == BD_MODE sim.set_dt(1e-3); #endif Real next_time(0.0), dt(0.02); // sim.save_hdf5_init(std::string("mapk.hdf5")); std::cout << sim.t() << "\t" << world->num_molecules(sp1) << "\t" << world->num_molecules(sp2) << "\t" << world->num_molecules(sp3) << std::endl; for (unsigned int i(0); i < 100; ++i) { next_time += dt; while (sim.step(next_time)) {} std::cout << sim.t() << "\t" << world->num_molecules(sp1) << "\t" << world->num_molecules(sp2) << "\t" << world->num_molecules(sp3) << std::endl; // sim.save_hdf5(); } }
bool ossimViewshedUtil::initialize(ossimArgumentParser& ap) { // Base class first: if (!ossimUtility::initialize(ap)) return false; std::string ts1; ossimArgumentParser::ossimParameter sp1(ts1); std::string ts2; ossimArgumentParser::ossimParameter sp2(ts2); std::string ts3; ossimArgumentParser::ossimParameter sp3(ts3); if (ap.read("--dem", sp1) || ap.read("--dem-file", sp1)) m_demFile = ts1; if ( ap.read("--fov", sp1, sp2) ) { m_startFov = ossimString(ts1).toDouble(); m_stopFov = ossimString(ts2).toDouble(); if (m_startFov < 0) m_startFov += 360.0; } if ( ap.read("--gsd", sp1) ) m_gsd = ossimString(ts1).toDouble(); if ( ap.read("--hgt-of-eye", sp1) || ap.read("--height-of-eye", sp1) ) m_obsHgtAbvTer = ossimString(ts1).toDouble(); if ( ap.read("--horizon", sp1) || ap.read("--horizon-file", sp1)) m_horizonFile = ossimString(ts1); if ( ap.read("--lut", sp1) || ap.read("--lut-file", sp1)) m_lutFile = ts1; if ( ap.read("--observer", sp1, sp2) ) { m_observerGpt.lat = ossimString(ts1).toDouble(); m_observerGpt.lon = ossimString(ts2).toDouble(); m_observerGpt.hgt = 0.0; } if ( ap.read("--radius", sp1) ) m_visRadius = ossimString(ts1).toDouble(); if ( ap.read("--reticle", sp1) ) m_reticleSize = ossimString(ts1).toInt32(); if ( ap.read("--tbs") ) m_threadBySector = true; if ( ap.read("--simulation") ) m_simulation = true; if ( ap.read("--summary") ) m_outputSummary = true; if ( ap.read("--size", sp1) ) m_halfWindow = ossimString(ts1).toUInt32() / 2; if ( ap.read("--threads", sp1) ) m_numThreads = ossimString(ts1).toUInt32(); if ( ap.read("--values", sp1, sp2, sp3) ) { m_visibleValue = ossimString(ts1).toUInt8(); m_hiddenValue = ossimString(ts2).toUInt8(); m_observerValue = ossimString(ts3).toUInt8(); } // There should only be the required command line args left: if ( (m_observerGpt.hasNans() && (ap.argc() != 4)) || (!m_observerGpt.hasNans() && (ap.argc() != 2)) ) { setUsage(ap); return false; } // Verify minimum required args were specified: if (m_demFile.empty() && (m_visRadius == 0) && (m_halfWindow == 0)) { ossimNotify(ossimNotifyLevel_WARN) << "ossimViewshedUtil::initialize ERR: Command line is underspecified." << std::endl; setUsage(ap); return false; } // Parse the required command line params: int ap_idx = 1; if (m_observerGpt.hasNans()) { m_observerGpt.lat = ossimString(ap[1]).toDouble(); m_observerGpt.lon = ossimString(ap[2]).toDouble(); m_observerGpt.hgt = 0; ap_idx = 3; } m_filename = ap[ap_idx]; return initializeChain(); }
void test_transformations_spherical() { T const input_long = 15.0; T const input_lat = 5.0; T const expected_long = 0.26179938779914943653855361527329; T const expected_lat = 0.08726646259971647884618453842443; // Can be checked using http://www.calc3d.com/ejavascriptcoordcalc.html // (for phi use long, in radians, for theta use lat, in radians, they are listed there as "theta, phi") T const expected_polar_x = 0.084186; T const expected_polar_y = 0.0225576; T const expected_polar_z = 0.996195; // Can be checked with same URL using 90-theta for lat. // So for theta use 85 degrees, in radians: 0.08726646259971647884618453842443 T const expected_equatorial_x = 0.962250; T const expected_equatorial_y = 0.257834; T const expected_equatorial_z = 0.0871557; // 1: Spherical-polar (lat=5, so it is near the pole - on a unit sphere) bg::model::point<T, 2, bg::cs::spherical<bg::degree> > sp(input_long, input_lat); // 1a: to radian bg::model::point<T, 2, bg::cs::spherical<bg::radian> > spr; bg::transform(sp, spr); BOOST_CHECK_CLOSE(bg::get<0>(spr), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(spr), expected_lat, 0.001); // 1b: to cartesian-3d bg::model::point<T, 3, bg::cs::cartesian> pc3; bg::transform(sp, pc3); BOOST_CHECK_CLOSE(bg::get<0>(pc3), expected_polar_x, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(pc3), expected_polar_y, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(pc3), expected_polar_z, 0.001); BOOST_CHECK_CLOSE(check_distance<T>(pc3), 1.0, 0.001); // 1c: back bg::transform(pc3, spr); BOOST_CHECK_CLOSE(bg::get<0>(spr), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(spr), expected_lat, 0.001); // 2: Spherical-equatorial (lat=5, so it is near the equator) bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::degree> > se(input_long, input_lat); // 2a: to radian bg::model::point<T, 2, bg::cs::spherical_equatorial<bg::radian> > ser; bg::transform(se, ser); BOOST_CHECK_CLOSE(bg::get<0>(ser), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(ser), expected_lat, 0.001); bg::transform(se, pc3); BOOST_CHECK_CLOSE(bg::get<0>(pc3), expected_equatorial_x, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(pc3), expected_equatorial_y, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(pc3), expected_equatorial_z, 0.001); BOOST_CHECK_CLOSE(check_distance<T>(pc3), 1.0, 0.001); // 2c: back bg::transform(pc3, ser); BOOST_CHECK_CLOSE(bg::get<0>(spr), expected_long, 0.001); // expected_long BOOST_CHECK_CLOSE(bg::get<1>(spr), expected_lat, 0.001); // expected_lat // 3: Spherical-polar including radius bg::model::point<T, 3, bg::cs::spherical<bg::degree> > sp3(input_long, input_lat, 0.5); // 3a: to radian bg::model::point<T, 3, bg::cs::spherical<bg::radian> > spr3; bg::transform(sp3, spr3); BOOST_CHECK_CLOSE(bg::get<0>(spr3), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(spr3), expected_lat, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(spr3), 0.5, 0.001); // 3b: to cartesian-3d bg::transform(sp3, pc3); BOOST_CHECK_CLOSE(bg::get<0>(pc3), expected_polar_x / 2.0, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(pc3), expected_polar_y / 2.0, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(pc3), expected_polar_z / 2.0, 0.001); BOOST_CHECK_CLOSE(check_distance<T>(pc3), 0.5, 0.001); // 3c: back bg::transform(pc3, spr3); BOOST_CHECK_CLOSE(bg::get<0>(spr3), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(spr3), expected_lat, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(spr3), 0.5, 0.001); // 4: Spherical-equatorial including radius bg::model::point<T, 3, bg::cs::spherical_equatorial<bg::degree> > se3(input_long, input_lat, 0.5); // 4a: to radian bg::model::point<T, 3, bg::cs::spherical_equatorial<bg::radian> > ser3; bg::transform(se3, ser3); BOOST_CHECK_CLOSE(bg::get<0>(ser3), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(ser3), expected_lat, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(ser3), 0.5, 0.001); // 4b: to cartesian-3d bg::transform(se3, pc3); BOOST_CHECK_CLOSE(bg::get<0>(pc3), expected_equatorial_x / 2.0, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(pc3), expected_equatorial_y / 2.0, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(pc3), expected_equatorial_z / 2.0, 0.001); BOOST_CHECK_CLOSE(check_distance<T>(pc3), 0.5, 0.001); // 4c: back bg::transform(pc3, ser3); BOOST_CHECK_CLOSE(bg::get<0>(ser3), expected_long, 0.001); BOOST_CHECK_CLOSE(bg::get<1>(ser3), expected_lat, 0.001); BOOST_CHECK_CLOSE(bg::get<2>(ser3), 0.5, 0.001); }
int Game::Run(RenderWindow &win, VideoMode &vMode) { Music m; SoundBuffer playerShootBuffer; SoundBuffer meteorBuffer; meteorBuffer.LoadFromFile("..\\Resources\\meteorexplosion.ogg"); playerShootBuffer.LoadFromFile("..\\Resources\\playerShoot.ogg"); Sound playerSound; Sound meteorSound; meteorSound.SetBuffer(meteorBuffer); playerSound.SetBuffer(playerShootBuffer); playerSound.SetLoop(false); meteorSound.SetLoop(false); m.OpenFromFile("..\\Resources\\asteroid.ogg"); m.SetLoop(true); m.SetVolume(100); PlayerShip ship(player_ship, 2, vMode); EnemyShip enemy(enemy_ship, vMode); Collision col; Event events; Image bg1; Image bg2; Image bg3; bg1.LoadFromFile("..\\Resources\\bg.jpg"); Image stars; string abc = "..\\Resources\\star.png"; stars.LoadFromFile(abc); Sprite sp(bg1); Sprite sp2(bg1); Sprite sp3(bg1); Sprite spStar[10]; Clock clock; srand((unsigned)time(0)); for(int i = 0; i<10; i++) { spStar[i].SetImage(stars); //spStar[i].SetPosition } spStar[0].SetPosition(0,100); spStar[1].SetPosition(70,200); spStar[2].SetPosition(200,300); spStar[3].SetPosition(320,400); spStar[4].SetPosition(460,500); spStar[5].SetPosition(260,300); spStar[6].SetPosition(160,400); spStar[7].SetPosition(400,200); spStar[8].SetPosition(760,100); spStar[9].SetPosition(800,600); int lowestx, highestx, lowesty, highesty, rangex, rangey, random_integerx, random_integery; float time1 = 0; float time2 = 0; bool start = false; //Sprite spStar1(stars); //spStar1.SetPosition(spStar.GetPosition().x, spStar.GetPosition().y - spStar.GetSize().y); sp.Resize((float)vMode.Width, (float)vMode.Height); sp2.Resize((float)vMode.Width, (float)vMode.Height); sp2.SetPosition(sp.GetPosition().x, sp.GetPosition().y - sp.GetSize().y); sp3.SetPosition(sp2.GetPosition().x, sp2.GetPosition().y - sp2.GetSize().y); //spStar.Resize((float)vMode.Width, (float)vMode.Height); bool key = false; bool down = false; Bullet *bul; Meteor* met[METEORCOUNT]; for(int i = 0; i<METEORCOUNT; i++) { met[i] = new Meteor(meteor, vMode); } met[0]->SetPosition(200,-400); met[1]->SetPosition(420,-200); met[2]->SetPosition(720,-400); met[3]->SetPosition(520,-600); met[4]->SetPosition(320,-400); /*met[5]->SetPosition(620,-400); met[6]->SetPosition(100,-400); */ int bulletCount = 0; vector<Bullet*> bulletVector; vector<Meteor*> meteorVector; for(int i = 0; i<METEORCOUNT; i++) { meteorVector.push_back(met[i]); } bool fired = false; bool pressed = false; int count; bool change = false; //win.UseVerticalSync(true); //win.SetFramerateLimit(60); int type = pistol; Image sunImg; sunImg.LoadFromFile("..\\Resources\\Sun.png"); Sprite sunSp(sunImg); sunSp.SetPosition(500,2000); //void* user; //int score = 0; // enemys e(vMode); //Thread thread(Thread::FuncType Move,void* enemy, void* &win, void* ship); m.Play(); while(win.IsOpened()) { while(win.GetEvent(events)) { if(events.Type == Event::Closed) { win.Close(); return -1; } if((events.Type == Event::KeyPressed) && (events.Key.Code == Key::Escape)) { return 0; } if(ship.IsDestroyed() && ((events.Type == Event::KeyPressed) && (events.Key.Code == Key::Return))) { return 0; } } if(win.GetInput().IsKeyDown(Key::Up) && !ship.IsDestroyed()) { ship.Throttled(); } if(!win.GetInput().IsKeyDown(Key::Up)&& !ship.IsDestroyed()) { ship.NoThrottle(); key = false; } if(!win.GetInput().IsKeyDown(Key::Right) && !win.GetInput().IsKeyDown(Key::Up) && !ship.IsDestroyed()) { ship.NoThrottle(); } if(!win.GetInput().IsKeyDown(Key::Left)&& !win.GetInput().IsKeyDown(Key::Up) && !ship.IsDestroyed()) { ship.NoThrottle(); } if(win.GetInput().IsKeyDown(Key::Right) && !ship.IsDestroyed()) { ship.Right(); if(ship.GetPositionX()<=vMode.Width) { //ship.SetSpeed(100); ship.AddVelocity(300,0); ship.MoveSide(win.GetFrameTime()); } } if(win.GetInput().IsKeyDown(Key::Left) && !ship.IsDestroyed()) { ship.Left(); if(ship.GetPositionX()>=0) { ship.AddVelocity(-300,0); //ship.SetSpeed(-100); ship.MoveSide(win.GetFrameTime()); } } if(win.GetInput().IsKeyDown(Key::LShift)) { ship.TellDestroyed(); //ship.Destroyed(); //win.Close(); } if(win.GetInput().IsKeyDown(Key::B)) { } if(win.GetInput().IsKeyDown(Key::Space) && !ship.IsDestroyed()&&!pressed) { playerSound.Play(); bul = new Bullet(bullets, vMode, &ship, type); //bul->ChangeType(type); //bul->ChangeType(pistol); bulletVector.push_back(bul); count = bulletVector.size(); //cout<<count; pressed = true; } if(!win.GetInput().IsKeyDown(Key::Space)) { pressed = false; } if(win.GetInput().IsKeyDown(Key::N)) { type = laser; for(int i = 0; i< METEORCOUNT; i++) { met[i]->SetDestroyed(); } } win.Clear(); ship.MoveUp(win.GetFrameTime()); if(enemy.GetPositionY()>ship.GetPositionY()-500) { enemy.MoveUp(&win, ship); //enemy.NavigatorUp(&win, ship); } //ship.Simulate(win.GetFrameTime(), key, down); for(int i = 0; i<10; i++) { if(spStar[i].GetPosition().y>ship.GetPositionY() + 50) { lowesty=(int)ship.GetPositionY(), highesty=(int)ship.GetPositionY()-600; rangey=(highesty-lowesty)+1; random_integery; random_integery = lowesty+int(rangey*rand()/(RAND_MAX + 1.0)); //cout << random_integery << endl; lowestx=0, highestx=800; rangex=(highestx-lowestx)+1; random_integerx; random_integerx = lowestx+int(rangex*rand()/(RAND_MAX + 1.0)); //cout << random_integerx << endl; spStar[i].SetPosition((float)random_integerx, (float)random_integery); } } for(int i = 0; i<METEORCOUNT; i++) { if(ship.GetPositionY()<=-2000)//Score compare { met[i]->ChangeSpeed(); } met[i]->Update(win.GetFrameTime()); if(met[i]->GetPositionY()>ship.GetPositionY() + 50) { lowesty=(int)ship.GetPositionY() - 600, highesty=(int)ship.GetPositionY()-1200; rangey=(highesty-lowesty)+1; random_integery; random_integery = lowesty+int(rangey*rand()/(RAND_MAX + 1.0)); //cout << random_integery << endl; lowestx=0, highestx=720; rangex=(highestx-lowestx)+1; random_integerx; random_integerx = lowestx+int(rangex*rand()/(RAND_MAX + 1.0)); // cout << random_integerx << endl; if(met[i]->IsDestroyed()) { met[i]->SetAlive(); } met[i]->SetPosition(random_integerx, random_integery); if(!ship.IsDestroyed()) { ship.IncreaseScore(); ship.UpdateScore(); } } met[i]->UpdateAI(); } if(enemy.IsFired()) { if(col.PixelPerfectTest(enemy.GetBullet(), ship.GetSprite())) { //ship.TellDestroyed(); ship.DecreaseHealth(); if(ship.GetHealth()<=0) { ship.TellDestroyed(); } enemy.BulletReset(); enemy.NotAttacking(); } } if(!meteorVector.empty()) { for(int i = 0; i<METEORCOUNT; i++) { if(col.CircleTest(enemy.GetBullet(), meteorVector[i]->GetSprite())) { //win.Close(); //ship.TellDestroyed(); met[i]->SetDestroyed(); meteorSound.Play(); enemy.BulletReset(); } if(col.CircleTest(ship.GetSprite(), meteorVector[i]->GetSprite())) { //win.Close(); ship.TellDestroyed(); met[i]->SetDestroyed(); } if(col.CircleTest(ship.GetSprite(), sunSp)) { //win.Close(); ship.TellDestroyed(); //met[i]->SetDestroyed(); } if(col.PixelPerfectTest(enemy.GetSprite(), meteorVector[i]->GetSprite())) { //win.Close(); enemy.DecreaseHealth(10); met[i]->SetDestroyed(); meteorSound.Play(); } if(col.PixelPerfectTest(enemy.GetSprite(), sunSp)) { //win.Close(); enemy.DecreaseHealth(20); //met[i]->SetDestroyed(); } // if(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator2())||(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator3())||(col.PixelPerfectTest(sunSp, enemy.GetNavigator3()) ))) { //win.Close(); enemy.MoveLeft(1, &win, ship); } else if(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator1())||(col.PixelPerfectTest(meteorVector[i]->GetSprite(), enemy.GetNavigator4())||(col.PixelPerfectTest(sunSp, enemy.GetNavigator4()) ))) { //win.Close(); enemy.MoveRight(&win, ship); } else { enemy.Attacking(); enemy.UpdatePlayerPosition(ship.GetSprite().GetPosition(), &win); } if(!bulletVector.empty()) { for(int j = 0; j< (int)bulletVector.size(); j++) { //if((bulletVector[j]->GetSprite().GetPosition().x >= meteorVector[i]->GetSprite().GetPosition().x && bulletVector[j]->GetSprite().GetPosition().x < meteorVector[i]->GetSprite().GetPosition().x +meteorVector[i]->GetSprite().GetSize().x ) && (bulletVector[j]->GetSprite().GetPosition().y >= meteorVector[i]->GetSprite().GetPosition().y && bulletVector[j]->GetSprite().GetPosition().y < meteorVector[i]->GetSprite().GetPosition().y + meteorVector[i]->GetSprite().GetSize().x)) //{ // //win.Close(); // bulletVector[j]->Hit(); // meteorVector[i]->SetDestroyed(); // delete bulletVector[j]; // bulletVector.erase(bulletVector.begin() + j); //} if(col.PixelPerfectTest(enemy.GetBullet(), ship.GetSprite())) { //ship.TellDestroyed(); /*ship.DecreaseHealth(); if(ship.GetHealth()<=0) { ship.TellDestroyed(); }*/ } if(col.PixelPerfectTest(bulletVector[j]->GetSprite(), enemy.GetSprite())) { enemy.DecreaseHealth(); meteorSound.Play(); bulletVector[j]->Hit(); delete bulletVector[j]; bulletVector.erase(bulletVector.begin() + j); } else if(col.PixelPerfectTest(bulletVector[j]->GetSprite(), meteorVector[i]->GetSprite())) { bulletVector[j]->Hit(); meteorVector[i]->SetDestroyed(); meteorSound.Play(); delete bulletVector[j]; bulletVector.erase(bulletVector.begin() + j); } //if(col.BoundingBoxTest(bulletVector[j]->GetBulletSprite(), meteorVector[i]->GetSprite()))//collision condition should be checked here bullet and other ships //{ // cout<<i<<"T"; // cout<<j<<"T"; // win.Close(); // bulletVector[j]->Hit(); //} } } } } ship.UpdateAI(); if(enemy.GetPositionY()>ship.GetPositionY()-700) enemy.UpdateAI(); if(enemy.IsDestroyed()) { lowestx=200, highestx=620; rangex=(highestx-lowestx)+1; random_integerx; random_integerx = lowestx+int(rangex*rand()/(RAND_MAX + 1.0)); enemy.EnemyReset(random_integerx, ship); if(!ship.IsDestroyed()) { ship.IncreaseScore(10); ship.UpdateScore(); } } //win.Draw(sp); //win.Draw(sp2); //win.Draw(sp3); ship.UpdateHealth(); Drawing drawing; drawing.win = &win; drawing.ship = &ship; drawing.enemy = &enemy; drawing.Bulletvectors = bulletVector; drawing.MeteorCounts = METEORCOUNT; for(int i = 0; i<5; i++) drawing.met[i] = met[i]; win.Draw(sunSp); for(int i = 0; i< 10; i++) win.Draw(spStar[i]); //win.Draw(spStar1); //ship.UpdateScore(); // DrawingTHread(drawing); ship.Draw(&win); //score.SetPosition(100,100); //win.Draw(score); if(enemy.GetPositionY()>ship.GetPositionY()-700) enemy.Draw(&win, ship); for(int i = 0; i<METEORCOUNT; i++) { met[i]->Draw(&win); } if(!bulletVector.empty()) { for(int i = 0; i<(int)bulletVector.size();i++) { //d.Bulletvectors[i]->ChangeType(type); bulletVector[i]->Fired(); bulletVector[i]->Draw(&win, &ship); bulletVector[i]->UpdateBullet(win.GetFrameTime()); bulletVector[i]->UpdateAI(); //if(d.Bulletvectors[i]->GetPositiony()<=ship.GetPositionY()-500) win.Close(); if(bulletVector[i]->GetPositiony()<ship.GetPositionY()-600) { delete bulletVector[i]; bulletVector.erase(bulletVector.begin()+i); //count = d.Bulletvectors.size(); //cout<<count<<"\n"; } } } win.SetView(ship.GetView()); win.Display(); } return 1; }
void Bond::Render(Render2D * r) { double myangle, x1, y1, x2, y2, rise, run, lx, ly, cf = 0.02; QColor c1; if ( highlighted ) c1 = Render2D::highlightColor; else c1 = color; // for single bonds if ( order == 1 ) { if ( dashed > 0 ) r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1, 1 ); else r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1 ); return; } // for stereo_up bonds if ( order == 5 ) { r->drawUpLine( start->toQPoint(), end->toQPoint(), c1 ); return; } // for wavy bonds (order = 6) if ( order == 6 ) { r->drawWavyLine( start->toQPoint(), end->toQPoint(), c1 ); return; } // for stereo_down bonds if ( order == 7 ) { r->drawDownLine( start->toQPoint(), end->toQPoint(), c1 ); return; } // for double and triple bonds myangle = getAngle( start, end ); myangle += 90.0; myangle = myangle * ( M_PI / 180.0 ); //double offs = start->distanceTo(end) / 25.0; /* offs = preferences.getDoubleBondOffset(); if (order == 3) { if (thick > 2) offs += 0.5; if (thick > 3) offs += 0.4; if (thick > 4) offs += 0.3; } else { if (thick > 2) offs += 0.3; if (thick > 4) offs += 0.3; } x2 = cos(myangle) * 3.0 * offs; y2 = sin(myangle) * 3.0 * offs; // x1, y1, 3 and 4 are for use with special case 1 below x1 = cos(myangle) * 2.5 * offs; y1 = sin(myangle) * 2.5 * offs; */ /* original (does not use preferences!) double abl = 1.0; abl = (double)thick / 2.0 + 1.0; */ double abl = 1.0; abl = ( double ) thick / 2.0 + preferences.getDoubleBondOffset(); // check for order 2 special case (center double bond) bool special_case_1 = false; if ( order == 2 ) { //qDebug() << "start->element: " << start->element ; //qDebug() << "start->subst: " << start->substituents ; //qDebug() << "end->element: " << end->element ; //qDebug() << "end->subst: " << end->substituents ; if ( ( start->element == "O" ) && ( start->substituents == 2 ) ) special_case_1 = true; if ( ( end->element == "O" ) && ( end->substituents == 2 ) ) special_case_1 = true; if ( ( start->element == "C" ) && ( start->substituents == 2 ) ) special_case_1 = true; if ( ( end->element == "C" ) && ( end->substituents == 2 ) ) special_case_1 = true; if ( ( start->element == "CH2" ) && ( start->substituents == 2 ) ) special_case_1 = true; if ( ( end->element == "CH2" ) && ( end->substituents == 2 ) ) special_case_1 = true; if ( ( start->element == "N" ) && ( end->element == "N" ) ) special_case_1 = true; if ( wside == 2 ) // force centered double bond special_case_1 = true; } if ( special_case_1 ) abl = ( double ) thick / 2.0 + preferences.getDoubleBondOffset() / 4.0; else abl = ( double ) thick / 2.0 + preferences.getDoubleBondOffset() / 2.0; //qDebug() << "abl = " << abl; x2 = cos( myangle ) * abl; y2 = sin( myangle ) * abl; // x1, y1, 3 and 4 are for use with special case 1 below x1 = cos( myangle ) * abl; y1 = sin( myangle ) * abl; QPoint sp3( qRound( start->x + x1 ), qRound( start->y + y1 ) ); QPoint ep3( qRound( end->x + x1 ), qRound( end->y + y1 ) ); QPoint sp4( qRound( start->x - x1 ), qRound( start->y - y1 ) ); QPoint ep4( qRound( end->x - x1 ), qRound( end->y - y1 ) ); // shorten lines by removing from each end double bl = start->distanceTo( end ); if ( bl < 100.0 ) cf = 0.03; if ( bl < 51.0 ) cf = 0.05; if ( bl < 27.0 ) cf = 0.07; // find sp1 and ep1 rise = ( end->y + y2 ) - ( start->y + y2 ); run = ( end->x + x2 ) - ( start->x + x2 ); lx = start->x + x2 + run * cf; ly = start->y + y2 + rise * cf; QPoint sp1( ( int ) lx, ( int ) ly ); lx = start->x + x2 + run * ( 1.0 - cf ); ly = start->y + y2 + rise * ( 1.0 - cf ); QPoint ep1( ( int ) lx, ( int ) ly ); // find sp2 and ep2 rise = ( end->y - y2 ) - ( start->y - y2 ); run = ( end->x - x2 ) - ( start->x - x2 ); lx = start->x - x2 + run * cf; ly = start->y - y2 + rise * cf; QPoint sp2( ( int ) lx, ( int ) ly ); lx = start->x - x2 + run * ( 1.0 - cf ); ly = start->y - y2 + rise * ( 1.0 - cf ); QPoint ep2( ( int ) lx, ( int ) ly ); if ( special_case_1 == true ) { if ( dashed > 1 ) r->drawLine( sp3, ep3, thick, c1, 1 ); else r->drawLine( sp3, ep3, thick, c1 ); if ( dashed > 0 ) r->drawLine( sp4, ep4, thick, c1, 1 ); else r->drawLine( sp4, ep4, thick, c1 ); return; } QPoint sp, ep; if ( order == 2 ) { if ( wside == 1 ) { sp = sp1; ep = ep1; } else { sp = sp2; ep = ep2; } //qDebug() << "wside:" << wside; if ( dashed > 1 ) r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1, 1 ); else r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1 ); if ( dashed > 0 ) r->drawLine( sp, ep, thick, c1, 1 ); else r->drawLine( sp, ep, thick, c1 ); return; } if ( order == 3 ) { if ( dashed > 2 ) r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1, 1 ); else r->drawLine( start->toQPoint(), end->toQPoint(), thick, c1 ); if ( dashed > 1 ) r->drawLine( sp1, ep1, thick, c1, 1 ); else r->drawLine( sp1, ep1, thick, c1 ); if ( dashed > 0 ) r->drawLine( sp2, ep2, thick, c1, 1 ); else r->drawLine( sp2, ep2, thick, c1 ); return; } }