bool circle::contains(const shape &point) { const auto d = pow((point.get_x() - get_x()), 2.0) + pow((point.get_y() - get_y()), 2.0); // TODO: cache rsquared //return d <= this.rSquared; return d <= pow( /*TODO FIX THIS BY TAKING A CIRCLE AS PARAM */ (get_radius()*2 + get_radiussize()*2), 2.0); }
void rotateshape(shape & s, double rotation) { for (shapeIterator shapeIter = s.begin(); shapeIter != s.end(); ++shapeIter) { (*shapeIter).argument ((*shapeIter).argument() + rotation); } }
void write_shape(shape const & s, std::ostream &streamToWriteTo) { streamToWriteTo << s.size() << "\n"; for (constShapeIterator shapeIter = s.begin(); shapeIter != s.end(); ++shapeIter) { send_to (*shapeIter, streamToWriteTo); streamToWriteTo << "\n"; } }
void sheershape(shape & s, double sheer) { for (shapeIterator shapeIter = s.begin(); shapeIter != s.end(); ++shapeIter) { double newArgument = (*shapeIter).argument() + sheer; //we just need to change the x so that it's angle is changed, while maintaining the y as it is. double newModulus = (*shapeIter).modulus() * sin (radians((*shapeIter).argument())) / sin (radians(newArgument)); (*shapeIter).argument (newArgument); (*shapeIter).modulus (newModulus); } }
void trigger(double x, double y, double, shape const& shape, double vx, double vy, uint64_t origin_id, noise_queue& nqueue, comm::msg_queue& queue) { std::uniform_int_distribution<int> bmp_dist(0, _images.size() - 1); for(uint32_t i = 0; i < _num_debris; ++i) { uint32_t index = _randomize ? bmp_dist(rnd::engine) : (i % _images.size()); res::res_id bmp = _images[index]; double deb_x, deb_y; std::tie(deb_x, deb_y) = shape.get_random_point(); queue.push(comm::create_spawn_debris( deb_x + x, deb_y + y, vx, vy, _vmin, _vmax, _theta_min, _theta_max, bmp, _explode, origin_id)); } }
void move_shots(linkedlist <shottype> &shot, shape &ground, shape &shotimage, shape &drakmsimage, drakmstype &drakms){ shot.reset(); while (shot.next()){ // move shot().x += shot().xs; shot().y += shot().ys; shot().time--; // ground collisions / off screen / timed out / drakms collision if ((ground.collide(0, 0, shotimage, (int)shot().x, (int)shot().y)) || (shot().x < -16.0) || (shot().x > GAME_WIDTH) || (shot().y < -16.0) || (shot().y > GAME_HEIGHT) || (shot().time == 0) || ((drakms.exist == 1) && (drakmsimage.collide((int)drakms.x,(int)drakms.y, shotimage,(int)shot().x,(int)shot().y)))){ shot.kill(); } } }
bool shape::intersects(shape const& shape) const { vector direction(shape.centroid() - centroid()); std::vector<vector> simplex; simplex.push_back(vertices_[support(direction)] - shape.vertices()[shape.support(-direction)]); direction = -direction; for(;;) { vector const a(vertices_[support(direction)] - shape.vertices()[shape.support(-direction)]); if(a.dot(direction) <= 0.0f) return false; simplex.push_back(a); vector const ao(-a); if(simplex.size() == 3) { vector const b(simplex[1]); vector const c(simplex[0]); vector const ab(b - a); vector const ac(c - a); vector const ab_triple(vector::triple_product_left(ac, ab, ab)); if(ab_triple.dot(ao) >= 0.0f) { simplex.erase(simplex.begin()); direction = ab_triple; } else { vector const ac_triple(vector::triple_product_left(ab, ac, ac)); if(ac_triple.dot(ao) >= 0.0f) { simplex.erase(simplex.begin() + 1); direction = ac_triple; } else return true; } } else { vector const b(simplex[0]); vector const ab(b - a); direction = vector::triple_product_left(ab, ao, ab); if(!direction) direction = ab.left(); } } }
bool geom::circle::intersects(const shape & that) const { switch (that.kind()) { case shape::circle: return intersects(static_cast<const circle &>(that)); case shape::circular_sector: return static_cast<const geom::circular_sector &>(that).intersects(*this); case shape::rect: return static_cast<const geom::rect &>(that).intersects(*this); case shape::binary_op: return static_cast<const geom::binary_op &>(that).intersects(*this); default: throw std::domain_error("intersection not defined"); } }
shape shape::operator=( shape & s ) { shapetype = s.shapetype; topLeft = s.topLeft; bottomRight = s.bottomRight; allPoints.clear(); for( int i = 0; i < s.size(); i++ ) allPoints.push_back( s[i] ); for( int j = 0; j < s.shapeRecord.size(); j++ ) shapeRecord.push_back( s.shapeRecord[j] ); return *this; }
void trigger(double x, double y, double phi, shape const& shape, double, double, uint64_t origin_id, noise_queue& nqueue, comm::msg_queue& queue) { double delay = 0.0; std::uniform_real_distribution<double> delay_dist(_min_delay, _max_delay); for(uint32_t i = 0; i < _num_explosions; ++i) { double expl_x, expl_y; std::tie(expl_x, expl_y) = shape.get_random_point(); queue.push(comm::create_spawn_explosion(expl_x + x, expl_y + y), delay); nqueue.push(res::res_id::EXPLOSION_SND, delay); delay += delay_dist(rnd::engine); } }
std::tuple<bool, vector, float, vector, vector> shape::distance(shape const& shape) const { vector direction(shape.centroid() - centroid()); vector a1(vertices_[support(direction)]); vector a2(shape.vertices()[shape.support(-direction)]); vector a(a1 - a2); vector b1(vertices_[support(-direction)]); vector b2(shape.vertices()[shape.support(direction)]); vector b(b1 - b2); vector c1, c2, c; direction = segment(b, a).closest(vector()); for(int unsigned iterations(0); iterations < 10; ++iterations) { direction = -direction.normalize(); if(!direction) return std::make_tuple(false, vector(), 0.0f, vector(), vector()); c1 = vertices_[support(direction)]; c2 = shape.vertices()[shape.support(-direction)]; c = c1 - c2; if(a.cross(b) * b.cross(c) > 0.0f && a.cross(b) * c.cross(a) > 0.0f) return std::make_tuple(false, vector(), 0.0f, vector(), vector()); float const projection(c.dot(direction)); if(projection - a.dot(direction) < std::sqrt(std::numeric_limits<float>::epsilon())) { std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, b1, b2, b)); return std::make_tuple(true, direction, -projection, std::get<0>(closest_points), std::get<1>(closest_points)); } vector const point1(segment(a, c).closest(vector())); vector const point2(segment(c, b).closest(vector())); float const point1_length(point1.length()); float const point2_length(point2.length()); if(point1_length <= std::numeric_limits<float>::epsilon()) { std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, c1, c2, c)); return std::make_tuple(true, direction, point1_length, std::get<0>(closest_points), std::get<1>(closest_points)); } else if(point2_length <= std::numeric_limits<float>::epsilon()) { std::tuple<vector, vector> const closest_points(get_closest_points(c1, c2, c, b1, b2, b)); return std::make_tuple(true, direction, point2_length, std::get<0>(closest_points), std::get<1>(closest_points)); } if(point1_length < point2_length) { b1 = c1; b2 = c2; b = c; direction = point1; } else { a1 = c1; a2 = c2; a = c; direction = point2; } } std::tuple<vector, vector> const closest_points(get_closest_points(a1, a2, a, b1, b2, b)); return std::make_tuple(true, direction, -c.dot(direction), std::get<0>(closest_points), std::get<1>(closest_points)); }
bool operator==(shape const& lhs, shape const& rhs) { return lhs.getName() == rhs.getName(); }