inline bool sphere_aabb_intersection( const Sphere& s, const AABB& aabb, Point& p )
{
    using point_t = typename geometric_traits<Sphere>::point_type;
    using length_t = typename geometric_traits<point_t>::arithmetic_type;
    using vector_t = vector<length_t, dimension_of<point_t>::value>;

    assign(p, point_aabb_closest_point(get_center(s), aabb));

    //! Sphere and AABB intersect if the distance from sphere center to point p is less than the sphere radius.
    auto v = vector_t{ p - get_center(s) };
    return magnitude_sqrd(v) <= get_radius(s) * get_radius(s);
}
Esempio n. 2
0
void
layout_boxes(Layouter *layouter)
{
  log_s(L_Layouter, "init\n");
  u32 passes = 0;
  b32 moved_rect = true;
  while (moved_rect && passes < MAX_PASSES)
  {
    log_s(L_Layouter, ">\n");
    moved_rect = false;

    for (u32 subject_index = 0;
         subject_index < layouter->next_free;
         ++subject_index)
    {
      log_s(L_Layouter, "  ");
      Rectangle *current_subject = layouter->rects + subject_index;

      for (u32 test_index = 0;
           test_index < layouter->next_free;
           ++test_index)
      {
        Rectangle *test = layouter->rects + test_index;

        if (test != current_subject)
        {
          if (overlaps(*current_subject, *test))
          {
            log_s(L_Layouter, "  ");
            moved_rect = true;
            Rectangle overlap = get_overlap(*current_subject, *test);

            r32 h_dist = overlap.end.x - overlap.start.x;
            r32 v_dist = overlap.end.y - overlap.start.y;

            V2 direction = vector_direction_or_1(get_center(*test) - get_center(*current_subject));

            if (h_dist < v_dist)
            {
              *test += (V2){h_dist, 0} * direction.x;
            }
            else
            {
              *test += (V2){0, v_dist} * direction.y;
            }

          }
          else
          {
            log_s(L_Layouter, "# ");
          }
        }
Esempio n. 3
0
bool get_plane_rg(pointlist& INpL, plane& OUplane) {
   double  xx, xy, xz, yy, yz;
   point  center;
   pointlist  MpL;

   if (get_center(INpL, center) < 3)
        return false;

   MpL = trans_coord(INpL,center);
   xx = get_sumprod(MpL, X_, X_);
   xy = get_sumprod(MpL, X_, Y_);
   xz = get_sumprod(MpL, X_, Z_);
   yy = get_sumprod(MpL, Y_, Y_);
   yz = get_sumprod(MpL, Y_, Z_);
   free_pointlist(MpL);
   double div = ( xx * yy - xy * xy );

   if (div == 0)
   {
       OUplane.A = 0;
       OUplane.B = 0;
       return false;
   }
   else
   {
       OUplane.A = ( xz * yy - xy * yz ) / div;
       OUplane.B = ( xy * xz - xx * yz ) / -div;
   }

   OUplane.C = center.coord[Z_]
             - OUplane.A * center.coord[X_] - OUplane.B * center.coord[Y_];

   return true;
}
Esempio n. 4
0
PyObject *PyPSFExObject_center(struct PyPSFExObject *self, PyObject *args)
{
    PyObject *retval = NULL;
    double row=0, col=0;
    double rowcen, colcen;
    
    int ndims=1;
    npy_intp dims[1];
    double *data;

    
    if (!PyArg_ParseTuple(args, (char*)"dd", &row, &col)) {
	return NULL;
    }

    get_center(RECON_NROW(self->psfex), RECON_NCOL(self->psfex),
	       row, col,
	       self->psfex->pixstep,
	       &rowcen, &colcen);

    dims[0] = 2;
    retval = PyArray_SimpleNew(ndims, dims, NPY_FLOAT64);

    data = (double *) PyArray_DATA(retval);
    data[0] = rowcen;
    data[1] = colcen;

    return retval;
}
Esempio n. 5
0
File: cpml-arc.c Progetto: bert/adg
/**
 * cpml_arc_info:
 * @arc:    (in):               the #CpmlPrimitive arc data
 * @center: (out) (allow-none): where to store the center coordinates
 * @r:      (out) (allow-none): where to store the radius
 * @start:  (out) (allow-none): where to store the starting angle
 * @end:    (out) (allow-none): where to store the ending angle
 *
 * Given an @arc, this function calculates and returns its basic data.
 * Any pointer can be <constant>NULL</constant>, in which case the requested
 * info is not returned. This function can fail (when the three points lay on
 * a straight line, for example) in which case 0 is returned and no data can
 * be considered valid.
 *
 * The radius @r can be 0 when the three points are coincidents: a
 * circle with radius 0 is considered a valid path.
 *
 * When the start and end angle are returned, together with their
 * values these angles implicitely gives another important information:
 * the arc direction.
 *
 * If @start &lt; @end the arc must be rendered with increasing angle
 * value (clockwise direction using the ordinary cairo coordinate
 * system) while if @start > @end the arc must be rendered in reverse
 * order (that is counterclockwise in the cairo world). This is the
 * reason the angle values are returned in the range <constant>-M_PI
 * &lt; <varname>value</varname> &lt; 3 M_PI</constant> inclusive instead of
 * the usual <constant>-M_PI &lt; <varname>value</varname> &lt; M_PI</constant>.
 *
 * Returns: (type boolean): 1 if the function worked succesfully, 0 on errors.
 *
 * Since: 1.0
 **/
int
cpml_arc_info(const CpmlPrimitive *arc, CpmlPair *center,
              double *r, double *start, double *end)
{
    CpmlPair p[3], l_center;

    cpml_pair_from_cairo(&p[0], arc->org);
    cpml_pair_from_cairo(&p[1], &arc->data[1]);
    cpml_pair_from_cairo(&p[2], &arc->data[2]);

    if (! get_center(p, &l_center))
        return 0;

    if (center)
        *center = l_center;

    if (r != NULL)
        *r = cpml_pair_distance(&p[0], &l_center);

    if (start != NULL || end != NULL) {
        double l_start, l_end;

        get_angles(p, &l_center, &l_start, &l_end);

        if (start != NULL)
            *start = l_start;
        if (end != NULL)
            *end = l_end;
    }

    return 1;
}
Esempio n. 6
0
void wf_2D_view::render_box(uint32_t src_tex, wlr_box src_box,
    wlr_box scissor_box, const wf_framebuffer& fb)
{
    auto quad = center_geometry(fb.geometry, src_box, get_center(view->get_wm_geometry()));

    quad.geometry.x1 *= scale_x;
    quad.geometry.x2 *= scale_x;
    quad.geometry.y1 *= scale_y;
    quad.geometry.y2 *= scale_y;

    auto rotate = glm::rotate(glm::mat4(1.0), angle, {0, 0, 1});
    auto translate = glm::translate(glm::mat4(1.0),
                                    {quad.off_x + translation_x,
                                     quad.off_y - translation_y, 0});

    auto ortho = glm::ortho(-fb.geometry.width  / 2.0f, fb.geometry.width  / 2.0f,
                            -fb.geometry.height / 2.0f, fb.geometry.height / 2.0f);

    auto transform = fb.transform * ortho * translate * rotate;

    OpenGL::render_begin(fb);
    fb.scissor(scissor_box);
    OpenGL::render_transformed_texture(src_tex, quad.geometry, {},
                                       transform, {1.0f, 1.0f, 1.0f, alpha});
    OpenGL::render_end();
}
Esempio n. 7
0
		void move(const player &player, bullets_type &bullets) override
		{
			auto now = std::chrono::system_clock::now();

			auto v = player.get_center() - get_center();
			auto rad = std::atan2(v.y, v.x);
			
			set_vector(transform::rotation(rad) * vector(3.f, 0.f));
			character::move();

			if(std::chrono::duration_cast<std::chrono::milliseconds>(now - time).count() >= 500){
				time = now;
				bullets.push_back(new bullet(holder));
				auto &b = bullets.back();
				b->set_position(get_center());
				b->set_vector(transform::rotation(rad) * vector(static_cast<float>(rand() % 4 + 3), 0.f));
			}
		}
inline bool sphere_aabb_intersection( const Sphere& s, const AABB& aabb )
{
    using point_t = typename geometric_traits<Sphere>::point_type;
    using length_t = typename geometric_traits<point_t>::arithmetic_type;
    using vector_t = vector<length_t, dimension_of<point_t>::value>;

    auto d2 = point_aabb_distance_sqrd(get_center(s), aabb);
    return d2 <= get_radius(s) * get_radius(s);
}
Esempio n. 9
0
core::MonteCarloMoverResult TransformMover::do_propose() {
  IMP_OBJECT_LOG;

  
  xyzs_.resize(pixyzs_.size());
  rbts_.resize(pirbs_.size());  
  
  //xyzc=bb....;
  
  //get_rotation_about_point(const Vector3D &point,
  //                                               const Rotation3D &rotation)
  
  algebra::Vector3D xyzc=get_center(); //check the correct type from algebra::get_unit_sphere_d<3>()
  algebra::Transformation3D c_(xyzc);
  
  algebra::Vector3D translation = algebra::get_random_vector_in(
      algebra::Sphere3D(algebra::get_zero_vector_d<3>(), max_translation_));
  if (constr_==0){
  axis_=algebra::get_random_vector_on(algebra::get_unit_sphere_d<3>());}
  ::boost::uniform_real<> rand(-max_angle_, max_angle_);
  Float angle = rand(random_number_generator);
  algebra::Rotation3D r = algebra::get_rotation_about_axis(axis_, angle);
  algebra::Transformation3D t_(r, translation); 
  
  algebra::Transformation3D tt = c_*t_*c_.get_inverse();

  
  for (unsigned int i=0;i<pixyzs_.size();i++) {
       core::XYZ d(get_model(), pixyzs_[i]);
       xyzs_[i]=d.get_coordinates();
       core::transform(d,tt);
  }

  for (unsigned int i=0;i<pirbs_.size();i++){
      core::RigidBody d(get_model(), pirbs_[i]);
       rbts_[i]=d.get_reference_frame().get_transformation_to();
       core::transform(d,tt);
  }

  //for (unsigned int i=0;i<pirbs_.size();i++){
  //       RigidBody d(get_model(), pirbs_[i]);
  //       last_transformation_[i] = d.get_reference_frame().get_transformation_to();
  //    algebra::Rotation3D rc =
  //    r * d.get_reference_frame().get_transformation_to().get_rotation();
  //    algebra::Transformation3D t(rc, translation);  
         
  //IMP_LOG_VERBOSE("proposed move " << t_ << std::endl);
  //IMP_USAGE_CHECK(
  //    d.get_coordinates_are_optimized(),
  //    "Rigid body passed to TransformMover"
  //        << " must be set to be optimized. particle: " << d->get_name());
  //d.set_reference_frame(algebra::ReferenceFrame3D(t));

  return core::MonteCarloMoverResult(pis_, 1.0);
}
Esempio n. 10
0
line  get_line_regr_YZ(pointlist& INpL) {
   double  yy, yz;
   point  center;
   pointlist  MpL;
   line  OUline;

   get_center(INpL,center);
   MpL = trans_coord(INpL, center);
   yy = get_sumprod(MpL, Y_, Y_);
   yz = get_sumprod(MpL, Y_, Z_);
   free_pointlist(MpL);
   OUline.A = yz / yy;
   OUline.B = center.coord[Z_] - OUline.A * center.coord[Y_];
   return OUline;
}
Esempio n. 11
0
line  get_line_regr_XZ(pointlist& INpL) {
   double  xx, xz;
   point  center;
   pointlist  MpL;
   line  OUline;

   get_center(INpL,center);
   MpL = trans_coord(INpL, center);
   xx = get_sumprod(MpL, X_, X_);
   xz = get_sumprod(MpL, X_, Z_);
   free_pointlist(MpL);
   OUline.A = xz / xx;
   OUline.B = center.coord[Z_] - OUline.A * center.coord[X_];
   return OUline;
}
Esempio n. 12
0
line  get_line_regr_YX(pointlist& INpL) {
   double  xy, yy;
   point  center;
   pointlist  MpL;
   line  OUline;

   get_center(INpL,center);
   MpL = trans_coord(INpL, center);
   yy = get_sumprod(MpL, Y_, Y_);
   xy = get_sumprod(MpL, X_, Y_);
   free_pointlist(MpL);
   OUline.A = xy / yy;
   OUline.B = center.coord[X_] - OUline.A * center.coord[Y_];
   return OUline;
}
Esempio n. 13
0
void new_ship( char *t )
{
  Sint32 frames;
  Sint32 delay;
  Sint32 speed;
  Sint32 x, y;

  x = screen_width() / 2;
  y = screen_height() - 50;

  frames = get_num_frames( t );
  delay = get_frame_delay( t );
  speed = get_speed( t );
  ship.hp = get_hp( t ) * PLAYER_HP_FACTOR; 
  ship.hp_max = ship.hp;
  ship.type = strdup( t );

  ship.left = new_sprite_array( x, y, frames, get_left( t ), delay );
  if( ship.left == NULL ) { 
    fprintf( stderr, "Error creating new sprite: %s.\n", SDL_GetError() );
    exit( 1 );
  }
  set_speed( ship.left, speed );
  no_off_screen( ship.left );

  ship.right = new_sprite_array( x, y, frames, get_right( t ), delay );
  if( ship.right == NULL ) { 
    fprintf( stderr, "Error creating new sprite: %s.\n", SDL_GetError() );
    exit( 1 );
  }
  set_speed( ship.right, speed );
  no_off_screen( ship.right );

  ship.center = new_sprite_array( x, y, frames, get_center( t ), delay );
  if( ship.center == NULL ) { 
    fprintf( stderr, "Error creating new sprite: %s.\n", SDL_GetError() );
    exit( 1 );
  }
  set_speed( ship.center, speed );
  no_off_screen( ship.center );

  ship.current = ship.center;
  ship_center();
}
Esempio n. 14
0
void aabb2<T>::get_edges(vec2<T> edges[4]) const
{
	const vec2<T> middle = get_center();
	const vec2<T> diag = middle - maxPoint;

	/*
	Edges are stored in this way:
	Hey, am I an ascii artist, or what? :) niko.
          1---------2
          |         |
          |         |
          |         |
          0---------3
	*/

	edges[0] = vec2<T>(middle.x - diag.x, middle.y - diag.y);
	edges[1] = vec2<T>(middle.x - diag.x, middle.y + diag.y);
	edges[2] = vec2<T>(middle.x + diag.x, middle.y + diag.y);
	edges[3] = vec2<T>(middle.x + diag.x, middle.y - diag.y);
}
Esempio n. 15
0
bool aabb2<T>::intersect_with_line(const vec2<T>& linemiddle, const vec2<T>& linevect, T halflength) const
{
	const vec2<T> e = get_extent() * (T)0.5;
	const vec2<T> t = get_center() - linemiddle;

	if (
		(abs(t.x) > e.x + halflength * abs(linevect.x))  ||
		(abs(t.y) > e.y + halflength * abs(linevect.y)))
	{
		return false;
	}

	T r = e.x * (T)abs(linevect.y) + e.y * (T)abs(linevect.x);
	if (abs(t.x*linevect.y - t.y*linevect.x) > r)
	{
		return false;
	}

	return true;
}
Esempio n. 16
0
void wf_3D_view::render_box(uint32_t src_tex, wlr_box src_box,
    wlr_box scissor_box, const wf_framebuffer& fb)
{
    auto quad = center_geometry(fb.geometry, src_box, get_center(src_box));

    auto transform = calculate_total_transform();
    auto translate = glm::translate(glm::mat4(1.0), {quad.off_x, quad.off_y, 0});
    auto scale = glm::scale(glm::mat4(1.0), {
                                2.0 / fb.geometry.width,
                                2.0 / fb.geometry.height,
                                1.0
                            });

    transform = fb.transform * scale * translate * transform;

    OpenGL::render_begin(fb);
    fb.scissor(scissor_box);
    OpenGL::render_transformed_texture(src_tex, quad.geometry, {},
                                       transform, color);
    OpenGL::render_end();
}
Esempio n. 17
0
File: cpml-arc.c Progetto: bert/adg
static void
offset(CpmlPrimitive *arc, double offset)
{
    CpmlPair p[3], center;
    double r;

    cpml_pair_from_cairo(&p[0], arc->org);
    cpml_pair_from_cairo(&p[1], &arc->data[1]);
    cpml_pair_from_cairo(&p[2], &arc->data[2]);

    if (!get_center(p, &center))
        return;

    r = cpml_pair_distance(&p[0], &center) + offset;

    /* Offset the three points by calculating their vector from the center,
     * setting the new radius as length and readding the center */
    p[0].x -= center.x;
    p[0].y -= center.y;
    p[1].x -= center.x;
    p[1].y -= center.y;
    p[2].x -= center.x;
    p[2].y -= center.y;

    cpml_vector_set_length(&p[0], r);
    cpml_vector_set_length(&p[1], r);
    cpml_vector_set_length(&p[2], r);

    p[0].x += center.x;
    p[0].y += center.y;
    p[1].x += center.x;
    p[1].y += center.y;
    p[2].x += center.x;
    p[2].y += center.y;

    cpml_pair_to_cairo(&p[0], arc->org);
    cpml_pair_to_cairo(&p[1], &arc->data[1]);
    cpml_pair_to_cairo(&p[2], &arc->data[2]);
}
Esempio n. 18
0
int main(int argc, char* argv[]) {
  // Check arguments
  if (argc < 5) {
    std::cerr << "Usage: final_project NODES_FILE TRIS_FILE ball.nodes ball.tris \n";
    exit(1);
  }

  MeshType mesh;
  std::vector<typename MeshType::node_type> mesh_node;

  // Read all water Points and add them to the Mesh
  std::ifstream nodes_file(argv[1]);
  Point p;
  uint water_nodes = 0;
  while (CS207::getline_parsed(nodes_file, p)) {
    mesh_node.push_back(mesh.add_node(p));
    water_nodes++;
  }

  // Read all water mesh triangles and add them to the Mesh
  std::ifstream tris_file(argv[2]);
  std::array<int,3> t;
  int water_tris = 0;
  while (CS207::getline_parsed(tris_file, t)) {
    mesh.add_triangle(mesh_node[t[0]], mesh_node[t[1]], mesh_node[t[2]]);
    water_tris++;
  }
  uint water_edges = mesh.num_edges();

  std::ifstream nodes_file2(argv[3]);
  double radius = 1 * scale;
  while (CS207::getline_parsed(nodes_file2, p)) {
    p *= scale;
    p.z += + start_height;
    mesh_node.push_back(mesh.add_node(p));
  }

  // Read all ball mesh triangles and add them to the mesh
  std::ifstream tris_file2(argv[4]);
  while (CS207::getline_parsed(tris_file2, t)) {
    mesh.add_triangle(mesh_node[t[0]+water_nodes], mesh_node[t[1]+water_nodes], mesh_node[t[2]+water_nodes]);
  }

  // Print out the stats
  std::cout << mesh.num_nodes() << " "
            << mesh.num_edges() << " "
            << mesh.num_triangles() << std::endl;

  /* Set the initial conditions */ 
  // Set the initial values of the nodes and get the maximum height double
  double max_h = 0;
  double dx = 0;
  double dy = 0;
  auto init_cond = Still();
  auto b_init_cond = Cone(); 

  // Find the maximum height and apply initial conditions to nodes
  for (auto it = mesh.node_begin(); it != mesh.node_end(); ++it) { 
    auto n = *it;
    if (n.index() < water_nodes){
	    n.value().q = init_cond(n.position());
	    n.value().b = b_init_cond(n.position());
	    max_h = std::max(max_h, n.value().q.h);
  	}
  	else {
  		n.value().q = QVar(n.position().z, 0, 0);
      n.value().mass = total_mass/(mesh.num_nodes() - water_nodes);
      n.value().velocity = Point(0.0,0.0,0.0);
  	}
  } 

  // Set the initial values of the triangles to the average of their nodes and finds S
  // Set the triangle direction values so that we can determine which 
  // way to point normal vectors. This part assumes a convex shape
  Point center = get_center(mesh); 
  for (auto it = mesh.triangle_begin(); it != mesh.triangle_end(); ++it) {
    auto t = *it; 
    if (t.index() < water_tris){
	    t.value().q_bar = (t.node1().value().q + 
	                       t.node2().value().q + 
	                       t.node3().value().q) / 3.0;
	    t.value().q_bar2 = t.value().q_bar;

	    double b_avg = (t.node1().value().b + 
	                    t.node2().value().b + 
	                    t.node3().value().b) / 3.0;
	    // finds the max dx and dy to calculate Source
	    dx = std::max(dx, fabs(t.node1().position().x - t.node2().position().x));
	    dx = std::max(dx, fabs(t.node2().position().x - t.node3().position().x));
	    dx = std::max(dx, fabs(t.node3().position().x - t.node1().position().x));
	    dy = std::max(dy, fabs(t.node1().position().y - t.node2().position().y));
	    dy = std::max(dy, fabs(t.node2().position().y - t.node3().position().y));
	    dy = std::max(dy, fabs(t.node3().position().y - t.node1().position().y));
	    t.value().S = QVar(0, -grav * t.value().q_bar.h * b_avg / dx, -grav * t.value().q_bar.h * b_avg / dy);
	  } 
    else
      set_normal_direction((*it),center);
  }

  // Calculate the minimum edge length and set edge inital condititons
  double min_edge_length = std::numeric_limits<double>::max();
  uint count = 0;
  for (auto it = mesh.edge_begin(); it != mesh.edge_end(); ++it, count++){
    if (count < water_edges)
      min_edge_length = std::min(min_edge_length, (*it).length());
    else {
      (*it).value().spring_constant = spring_const;
      (*it).value().initial_length = (*it).length();
    }
  }
	
  // Launch the SDLViewer
  CS207::SDLViewer viewer;
  viewer.launch();

  auto node_map = viewer.empty_node_map(mesh);
  viewer.add_nodes(mesh.node_begin(), mesh.node_end(),
                   Color(water_nodes), NodePosition(), node_map);
  viewer.add_edges(mesh.edge_begin(), mesh.edge_end(), node_map);
  // adds solid color-slows down program significantly
  //viewer.add_triangles(mesh.triangle_begin(), mesh.triangle_end(), node_map);
  viewer.center_view();


  // CFL stability condition requires dt <= dx / max|velocity|
  // For the shallow water equations with u = v = 0 initial conditions
  //   we can compute the minimum edge length and maximum original water height
  //   to set the time-step
  // Compute the minimum edge length and maximum water height for computing dt
  double dt = 0.25 * min_edge_length / (sqrt(grav * max_h));
  double t_start = 0;
  double t_end = 10;
  Point ball_loc = Point(0,0,0);
  double dh = 0;
  // double pressure = gas_const/(4/3*M_PI*radius*radius*radius);

  // add listener
  my_listener* l = new my_listener(viewer,mesh,dt); 
  viewer.add_listener(l);

  // Preconstruct a Flux functor
  EdgeFluxCalculator f;
  // defines the constraint
  PlaneConstraint c = PlaneConstraint(plane_const);

  // Begin the time stepping
  for (double t = t_start; t < t_end; t += dt) {
    // define forces on ball
    GravityForce g_force;
    BuoyantForce b_force = BuoyantForce(dh, ball_loc.z);
    WindForce w_force;
    MassSpringForce ms_force;
    // PressureForce p_force = PressureForce(pressure);
    // DampingForce d_force = DampingForce(mesh.num_nodes());
    auto combined_forces = make_combined_force(g_force, b_force, w_force, ms_force);
    
    // Step forward in time with forward Euler
    hyperbolic_step(mesh, f, t, dt, ball_loc, water_tris);

    // Update node values with triangle-averaged values
    ball_loc = post_process(mesh, combined_forces, c, t, dt, water_nodes);

    // Update the viewer with new node positions
    viewer.add_nodes(mesh.node_begin(), mesh.node_end(), 
                     Color(water_nodes), NodePosition(), node_map);
    // viewer.add_triangles(mesh.triangle_begin(), mesh.triangle_end(), node_map);
    viewer.set_label(t);

    // find radius of cross sectional radius of ball submerged
    dh = ball_loc.z;
    if (dh > 2*radius)
      dh = 2 * radius;
    ball_loc.z = cross_radius(radius, dh);

    // These lines slow down the animation for small meshes.
    if (mesh.num_nodes() < 100)
      CS207::sleep(0.05);
  }
  return 0;
}
Esempio n. 19
0
void iir_coeff::set_bandpass_gain() {
  double w = 2.0*M_PI*get_center();
  float_type gain = freqz_mag(w);
  apply_gain(1.0 / gain);
}
Esempio n. 20
0
void new_enemy( Sint32 x, Sint32 y, const char *t )
{
  /* Paths to directions. */
  Sint32 frames;
  Sint32 delay;
  Uint32 speed;
  
  ENEMY *e;
   
  /* Create new ENEMY and add it to the list. */
  e = (ENEMY*) malloc( sizeof(ENEMY) );

  e->flags = 0;
  e->next = head;
  head = e;

  /* Set defaults. */
  e->hp = 1;
  e->type = "no_type";
  e->move_funct = NULL;
  speed = 1;
  delay = 100;
  frames = 1;
  memset( e->move_vars, -1, NUM_MOVE_VARS );

  frames = get_num_frames( t );
  delay = get_frame_delay( t );
  speed = get_speed( t );
  e->hp = get_hp( t );
  e->type = strdup( t );
  e->move_funct = get_move_funct( t );

  /* Make the left facing sprite */
  e->left = new_sprite_array( x, y, frames, get_left( t ), delay );
  if( e->left == NULL ) {
    fprintf( stderr, "Error creating new sprite: %s.\n",
              SDL_GetError() );
    exit(1);
  }
  set_speed( e->left, speed ); 

  /* Make the left facing sprite */
  e->right = new_sprite_array( x, y, frames, get_right( t ), delay );
  if( e->right == NULL ) {
    fprintf( stderr, "Error creating new sprite: %s.\n",
              SDL_GetError() );
    exit(1);
  }
  set_speed( e->right, speed ); 

  /* Make the left facing sprite */
  e->center = new_sprite_array( x, y, frames, get_center( t ), delay );
  if( e->center == NULL ) {
    fprintf( stderr, "Error creating new sprite: %s.\n",
              SDL_GetError() );
    exit(1);
  }
  set_speed( e->center, speed ); 
  
  e->current = e->center;
  enemy_center( e );

  num_enemies++;
}
Esempio n. 21
0
float *get_ellipse_feature(const IplImage *src) {
    IplImage *img = get_gray(src);

    CvPoint center = get_center(img);
    
}
vector<double>  read_xtc2dist(char * filename,vector<int> serial_1,vector<int> serial_2,vector<double> mass_1,vector<double> mass_2)

{
        int natoms,step;
        float time_temp;
        float p;
		vector<double> coor_x;
		vector<double> coor_y;
		vector<double> coor_z;
		vector<double> result;
        matrix box;
        rvec *x;
        XDRFILE *xtc;
        xtc=xdrfile_open(filename,"r");
        int read_return=read_xtc_natoms(filename,&natoms);


        x=(rvec * )calloc(natoms,sizeof(x[0]));
        while(1)
        {
                read_return=read_xtc(xtc,natoms,&step,&time_temp,box,x,&p);
		if(step%100000==0)
		{
			
			cout<<"Reading frame"<<"\t"<<step<<" time "<<time_temp<<endl;
		}
                if(read_return!=0)
                {
                        break;
                }

				coor_x.clear();
				coor_y.clear();
				coor_z.clear();

				for(int i=0;i<serial_1.size();i++)
                {
       //                 cout<<step<<"\t"<<time_temp<<"\t"<<natom<<"\t"<<x[natom][0]<<"\t"<<x[natom][1]<<"\t"<<x[natom][2]<<endl;
					
					int natom=serial_1.at(i);
					coor_x.push_back(x[natom][0]);
					coor_y.push_back(x[natom][1]);
					coor_z.push_back(x[natom][2]);
				}
				vector<double> cent_1 =get_center(coor_x,coor_y,coor_z,mass_1);

				coor_x.clear();
				coor_y.clear();
				coor_z.clear();
				for(int i=0;i<serial_2.size();i++)
				{
					int natom=serial_2.at(i);
					coor_x.push_back(x[natom][0]);
					coor_y.push_back(x[natom][1]);
					coor_z.push_back(x[natom][2]);
				}
				vector<double> cent_2 =get_center(coor_x,coor_y,coor_z,mass_2);

				double dist_temp=get_dist(cent_1,cent_2);

				result.push_back(time_temp);
				result.push_back(dist_temp);

        }
        xdrfile_close(xtc);
		return result;

}
Esempio n. 23
0
int main(int argc, char* argv[]) {
  // Check arguments
  if (argc < 2) {
    std::cerr << "Usage: " << argv[0] << " NODES_FILE TETS_FILE\n";
    exit(1);
  }

  MeshType mesh;
  std::vector<typename MeshType::node_type> nodes;

  // Create a nodes_file from the first input argument
  std::ifstream nodes_file(argv[1]);
  
  // Interpret each line of the nodes_file as a 3D Point and add to the Mesh
  Point p;
  while (CS207::getline_parsed(nodes_file, p))
    nodes.push_back(mesh.add_node(p));

  // Create a trianges_file from the second input argument
  std::ifstream triangles_file(argv[2]);

  // Interpret each line of the tets_file as three ints which refer to nodes
  std::array<int,3> t;


  // add in the triangles
  while (CS207::getline_parsed(triangles_file, t))
    for (unsigned i = 1; i < t.size(); ++i)
      for (unsigned j = 0; j < i; ++j)
        for (unsigned k = 0; k < j; ++k)
        {
          mesh.add_triangle(nodes[t[i]], nodes[t[j]], nodes[t[k]]);
      }   

  // Set masses of nodes equal to 1/N where N is the number of nodes
  // and the initial velocities to 0. Also, get the indexes of
  // the nodes at positions (1,0,0) and (0,0,0)
  for(auto it=mesh.node_begin(); it != mesh.node_end(); ++ it)
  {
      (*it).value().mass = total_mass/mesh.num_nodes();
      (*it).value().velocity = Point(0.0,0.0,0.0);
  }

  // Set spring constants for each node equal to spring_const variable
  // and set initial length values equal to lengths of edges prior to
  // running the symplectic Euler steps
  for(auto it=mesh.edge_begin(); it != mesh.edge_end(); ++ it)
  {
      (*it).value().spring_constant = spring_const;
      (*it).value().initial_length = (*it).length();
  }


  // Set the triangle direction values so that we can determine which 
  // way to point normal vectors. This part assumes a convex shape
  Point center = get_center(mesh);
  for(auto it=mesh.triangle_begin(); it != mesh.triangle_end(); ++ it)
  {  
  	//std::cout << (*it).index() << std::endl;
  	set_normal_direction((*it),center);
  }

  // Print out the stats
  std::cout << mesh.num_nodes() << " " << mesh.num_edges() << std::endl;

  std::cout << "Center: " << get_center(mesh) << std::endl;
  // Launch the SDLViewer
  CS207::SDLViewer viewer;
  auto node_map = viewer.empty_node_map(mesh);
  viewer.launch();

  viewer.add_nodes(mesh.node_begin(), mesh.node_end(), node_map);
  viewer.add_edges(mesh.edge_begin(), mesh.edge_end(), node_map);

  viewer.center_view();

  // Begin the mass-spring simulation
  double dt = 0.0001;
  double t_start = 0;
  double t_end = 20.0;
  

  // Initialize constraints
  PlaneConstraint c1;
  //SelfCollisionConstraint c2;
  //auto combined_constraints = make_combined_constraints(c1,c2);
  


  for (double t = t_start; t < t_end; t += dt) {
    MassSpringForce ms_force;
    PressureForce p_force = PressureForce(0.0);
    DampingForce d_force = DampingForce(mesh.num_nodes());
    GravityForce g_force;
    WindForce w_force;

    (void) d_force; // prevents compiler from throwing error for unused variable
      
    
    if (t >= t_addgas - dt) {
      p_force.set_pressure(gas_const/get_volume(mesh));
      if (t < t_addgas)
        std::cout << "Adding gas to the ball now..." << std::endl;
    }

    auto combined_forces = make_combined_force(ms_force, p_force, w_force, g_force);

    symp_euler_step(mesh, t, dt, combined_forces, c1);

    // Update viewer with nodes' new positions
    viewer.add_nodes(mesh.node_begin(), mesh.node_end(), node_map);

    // update the viewer's label with the ball center's position on the z axis 
    viewer.set_label(get_center(mesh).z);

  }
  return 0;
}
Esempio n. 24
0
 paint::circle get_circle() const
 {
     return paint::circle(get_center(), radius);
 }
/*Function executes only if there is button press event*/
static gboolean button_press_event( GtkWidget      *widget,
                                    GdkEventButton *event )
{	
	int i;
	if (( event->button == 1) && SPLINE==0 && FILL==0 && line==0 && complete==0 && CENTER!=1 && RADIUS!=1&&CIRCLE==0)
	{
	    draw_brush (widget, event->x, event->y); 
	    return TRUE;
  	}
  
	if(SPLINE==1)
  	{
    	get_points_spline(widget, event);
    	return TRUE;
  	}
  
    if(CENTER==1)
    {
  		get_center(widget,event);
  		return TRUE;
    }
  
    if(RADIUS==1)
    {
  		get_radius(widget,event);
  		return TRUE;
    }
  
  	if(FILL==1)
  	{
    	floodfill_select(widget,event);
    	return TRUE;
  	}
  
  	if( complete == 1 )
  	{
    	if (event->button == 1 ) 
    	{
        	glob.coordx[glob.count] = event->x;         //stores the coordinates of present point
        	glob.coordy[glob.count] = event->y;
        	draw_brush (widget, event->x, event->y);
        	if(glob.count>0)
        	{
          		cr = gdk_cairo_create(widget->window);
	      		cairo_set_source_rgb(cr,red,green,blue);
          		cairo_set_line_width(cr, rec1);  
          			//moves to present point  
          			for( i = 0; i<=glob.count-1; i++ )                     
          			{ 
					   cairo_move_to(cr, glob.coordx[glob.count], glob.coordy[glob.count]);
         			   //line is made to previous point.
          			   cairo_line_to(cr, glob.coordx[i], glob.coordy[i]);
					   int end_x = glob.coordx[glob.count];
					   //present point coordinates stored in end_x.
					   int end_y = glob.coordy[glob.count];
					   int start_x = glob.coordx[i];
					   //coordinates of previously selected points.
					   int start_y = glob.coordy[i]; 
					   pixels[start_x][start_y]=1;
					   R[start_x][start_y]=red;
					   G[start_x][start_y]=green;
					   B[start_x][start_y]=blue;
					   int distance = sqrt(pow((end_x - start_x),2) + pow((end_y - start_y),2)); 
					   double slope = ((double)(end_y-start_y)/(double)(end_x-start_x));
					   int i,j;
					   for(i=start_x;i<=end_x;i++)
					   {
					  		j=(slope*i)-(slope*start_x)+(start_y);
					  		pixels[i][j]=1;
						  	pixels[i+1][j]=1;
						  	pixels[i-1][j]=1;
						  	pixels[i][j+1]=1;
						  	pixels[i][j-1]=1;
						  	pixels[i+2][j]=1;
						  	pixels[i-2][j]=1;
						  	pixels[i][j+2]=1;
						  	pixels[i][j-2]=1;
						  	R[i][j]=red;
						  	G[i][j]=green;
						  	B[i][j]=blue;
					  }
					  cairo_stroke(cr); 
          			}
          		} glob.count++;
          }
     }

  if( line == 1 )
  {
    if (event->button == 1 ) 
    {
        glob.coordx[glob.count] = event->x;
        glob.coordy[glob.count] = event->y;
        int end_x = event->x;
        // coordinates of present points
        int end_y = event->y;
        pixels[end_x][end_y]=1;
        R[end_x][end_y]=1;
		G[end_x][end_y]=1;
		B[end_x][end_y]=1;
        // this function shows the presently selected point.
        draw_brush (widget, event->x, event->y);
        if(glob.count>0)
        {
          cr = gdk_cairo_create(widget->window);
	      cairo_set_source_rgb(cr,red,green,blue);
	      //line colour is set
          cairo_set_line_width(cr, rec1);
          // line width is set rec1 is global variable
          // moved to present point
          cairo_move_to(cr, glob.coordx[glob.count], glob.coordy[glob.count]);
          // line is made to previous point
          cairo_line_to(cr, glob.coordx[glob.count-1], glob.coordy[glob.count-1]);
          line=0;
          gtk_label_set_text (GTK_LABEL(butlabel),"Pencil");
          int start_x = glob.coordx[glob.count-1];
          int start_y = glob.coordy[glob.count-1]; 
		  pixels[start_x][start_y]=1;
          R[start_x][start_y]=red;
		  G[start_x][start_y]=green;
		  B[start_x][start_y]=blue;
		  int distance = sqrt(pow((end_x - start_x),2) + pow((end_y - start_y),2)); 
		  double slope = ((double)(end_y-start_y)/(double)(end_x-start_x));
		  int i,j;
		  for(i=start_x;i<=end_x;i++)
		  {
		  	j=(slope*i)-(slope*start_x)+(start_y);
		  	pixels[i][j]=1;
		  	pixels[i+1][j]=1;
		  	pixels[i-1][j]=1;
		  	pixels[i][j+1]=1;
		  	pixels[i][j-1]=1;
		  	pixels[i+2][j]=1;
		  	pixels[i-2][j]=1;
		  	pixels[i][j+2]=1;
		  	pixels[i][j-2]=1;
		  	R[i][j]=red;
		  	G[i][j]=green;
		  	B[i][j]=blue;
		  }
		  cairo_stroke_preserve(cr);
          cairo_stroke(cr);
        }
        glob.count++;   
     }
     
    }
    
    if(CIRCLE==1)
    {
		cr=gdk_cairo_create(widget->window);
		cairo_set_source_rgb(cr, red, green, blue);
		cairo_set_line_width(cr,1);
		cairo_rectangle(cr, event->x,event->y, rec1, rec2);
		int X=event->x;
		int Y=event->y;
		R[X][Y]=red;
		B[X][Y]=blue;
		G[X][Y]=green;
		cairo_stroke_preserve(cr);
		cairo_fill(cr);
		return TRUE;
    }
    
}
Esempio n. 26
0
 /**
  * @brief Get maximum.
  *
  * Gets the maximum of the box.
  * @return The maximum of the box.
  */
 inline glm::vec3 get_max() const
 {
     return get_center() + get_half_size();
 }
Esempio n. 27
0
 /**
  * @brief Get minimum.
 *
  * Gets the minimun of the box.
  * @return The minimum of the box.
  */
 inline glm::vec3 get_min() const
 {
     return get_center() - get_half_size();
 }
		TITANIUM_PROPERTY_GETTER(Animation, center)
		{
			return Point_to_js(get_context(), get_center());
		}