Exemple #1
0
void gl_lights_build_from_model(model_draw *draw,view_glsl_light_list_type *light_list)
{
	int					n,cx,cy,cz,sz,idx;
	float				fx,fy,fz;
	d3pnt				pnt,min,max;
	matrix_type			mat;
	
		// need to move model if no rot on

	memmove(&pnt,&draw->pnt,sizeof(d3pnt));
		
	if (draw->no_rot.on) {
		matrix_rotate_y(&mat,draw->no_rot.ang.y);

		fx=(float)(pnt.x-draw->no_rot.center.x);
		fy=(float)(pnt.y-draw->no_rot.center.y);
		fz=(float)(pnt.z-draw->no_rot.center.z);
		
		matrix_vertex_multiply(&mat,&fx,&fy,&fz);
		
		pnt.x=((int)fx)+draw->no_rot.center.x;
		pnt.y=((int)fy)+draw->no_rot.center.y;
		pnt.z=((int)fz)+draw->no_rot.center.z;
	}

		// get model bounds

	sz=draw->size.x>>1;
	min.x=pnt.x-sz;
	max.x=pnt.x+sz;

	sz=draw->size.z>>1;
	min.z=pnt.z-sz;
	max.z=pnt.z+sz;

	min.y=pnt.y-draw->size.y;
	max.y=pnt.y;

		// any rotations

	cx=pnt.x+draw->center.x;
	cy=pnt.y+draw->center.y;
	cz=pnt.z+draw->center.z;

	rotate_point(&min.x,&min.y,&min.z,cx,cy,cz,draw->rot.x,draw->rot.y,draw->rot.z);
	rotate_point(&max.x,&max.y,&max.z,cx,cy,cz,draw->rot.x,draw->rot.y,draw->rot.z);

	gl_lights_build_from_box(&pnt,&min,&max,light_list);

		// do any tints

	for (n=0;n!=max_view_lights_per_poly;n++) {
		idx=n*3;

		light_list->col[idx]*=draw->tint.r;
		light_list->col[idx+1]*=draw->tint.g;
		light_list->col[idx+2]*=draw->tint.b;
	}

}
void mesh_3D::rotate(double angle, rotation_type type)
  {
    unsigned int i;

    for (i = 0; i < this->vertices.size(); i++)
      {
        rotate_point(this->vertices[i].position,angle,type);
        rotate_point(this->vertices[i].normal,angle,type);
      }

    this->update_bounding_sphere();
  }
	void init_enemy_segments() {
		// TODO: the ball might also bounce off the enemy in the right direction thus not being a problem after all
		static sptr<robot> last_enemy;
		if(!enemy || (last_enemy && enemy->x == last_enemy->x && enemy->y == last_enemy->y))
			return;
		last_enemy = sptr<robot>(new robot(*enemy));

		const int safety = scale(3) + ball_radius;
		Point points[] = {rotate_point(enemy->x, enemy->y, -robot_width / 2 - safety, -robot_height / 2 - safety, enemy->rotation),
			rotate_point(enemy->x, enemy->y, robot_width / 2 + safety, -robot_height / 2 - safety, enemy->rotation),
			rotate_point(enemy->x, enemy->y, robot_width / 2 + safety, robot_height / 2 + safety, enemy->rotation),
			rotate_point(enemy->x, enemy->y, -robot_width / 2 - safety, robot_height / 2 + safety, enemy->rotation)};
		for(int i = 0; i < 4; ++i)
			enemy_sides[i] = Segment(points[i], points[(i + 1) % 4]);
	}
Exemple #4
0
void Transform::apply_parent_transform(const Transform& parent)
{
    x *= parent.scale_x;
    y *= parent.scale_y;
    
    bool flipped = ((parent.scale_x < 0) != (parent.scale_y < 0));
    rotate_point(x, y, parent.angle, parent.x, parent.y, flipped);
    
    angle += parent.angle;
    scale_x *= parent.scale_x;
    scale_y *= parent.scale_y;
    
    rotationAngle += parent.rotationAngle;
    if(rotationAngle < 0) {
        spin = -1;
    } else if(rotationAngle == 0) {
        spin = 0;
    } else {
        spin = 1;
    }
    
    if(curve_type == "") {
        curve_type = parent.curve_type;
        c1 = parent.c1;
        c2 = parent.c2;
        c3 = parent.c3;
        c4 = parent.c4;
    }
}
Exemple #5
0
void draw_attitude_indic()
{
	/*
	* simple attitude indicator with the horizon represented by a straight line
	* and the drone by a line with a center point.
	*/
	int i=0;
	//nose inclination = y offset from the horizon
	int nose_incl = (int)(horiz_pitchScale * pitch);
	//"center" of the drone, unaffected by roll
	SDL_Point center = {horiz_posx + horiz_size/2, horiz_posy-nose_incl};
	//series of points representing the drone on the indicator, affected by pitch
	SDL_Point drone_points[] = {
		{horiz_posx, center.y},
		{center.x-5, center.y},
		{center.x, center.y-5},
		{center.x+5, center.y},
		{horiz_posx+horiz_size, center.y}
	};
	int nb_points = sizeof(drone_points)/sizeof(SDL_Point);
	//apply roll to the points
	for(i=0; i<nb_points; i++)
		rotate_point(&drone_points[i], &center, roll);
	//1. draw the horizon
	SDL_RenderDrawLine(renderer, horiz_posx, horiz_posy, horiz_posx+horiz_size, horiz_posy);
	//2. draw the drone's "flight line"
	SDL_RenderDrawLines(renderer, drone_points, nb_points);
}
Exemple #6
0
/*! \brief
 *  \par Function Description
 *  This function rotates the world coordinates of an arc of an angle
 *  specified by <B>angle</B>. The center of the rotation is given by
 *  (<B>world_centerx</B>,<B>world_centery</B>).
 *
 *  The arc is translated in order to put the center of the rotation
 *  on the origin. The center of the arc is then rotated of the angle
 *  specified by <B>angle</B>. The start angle of the arc is incremented by <B>angle</B>.
 *
 *  The arc is finally back translated to its previous location on the page.
 *
 *  <B>world_centerx</B> and <B>world_centery</B> are in world units, <B>angle</B> is in degrees.
 *
 *  \param [in] toplevel      The TOPLEVEL object.
 *  \param [in] world_centerx
 *  \param [in] world_centery
 *  \param [in] angle
 *  \param [in] object
 */
void o_arc_rotate_world(TOPLEVEL *toplevel,
			int world_centerx, int world_centery, int angle,
			OBJECT *object)
{
  int x, y, newx, newy;

  /* translate object to origin */
  object->arc->x -= world_centerx;
  object->arc->y -= world_centery;

  /* get center, and rotate center */
  x = object->arc->x;
  y = object->arc->y;
  if(angle % 90 == 0) {
	  rotate_point_90(x, y, angle % 360, &newx, &newy);
  } else {
	  rotate_point(x, y, angle % 360, &newx, &newy);
  }
  object->arc->x = newx;
  object->arc->y = newy;

  /* apply rotation to angles */
  object->arc->start_angle = (object->arc->start_angle + angle) % 360;
  /* end_angle is unchanged as it is the sweep of the arc */
  /* object->arc->end_angle = (object->arc->end_angle); */

  /* translate object to its previous place */
  object->arc->x += world_centerx;
  object->arc->y += world_centery;

  /* update the screen coords and the bounding box */
  o_arc_recalc(toplevel, object);
  
}                                   
Regular_hexagon::Regular_hexagon(Point cc, int dd)
:c{cc}, d{dd}
{
	add(Point{cc.x+dd,cc.y});
	for (int a = 60; a < 360; a += 60) {
		Point p = rotate_point(c,point(0),a);
		add(p);
	}
}
Exemple #8
0
/*
 * Aperture macro primitive 4 (outline)
 * - Start point is not included in number of points.
 * - Outline is 1 pixel.
 */
static void
gerbv_gdk_draw_prim4(GdkPixmap *pixmap, GdkGC *gc, double *p, 
		     double scale, gint x, gint y)
{
    const int exposure_idx = 0;
    const int nuf_points_idx = 1;
    const int first_x_idx = 2;
    const int first_y_idx = 3;
    const int rotext_idx = 4;
    GdkGC *local_gc = gdk_gc_new(pixmap);
    int nuf_points, point;
    double rotation;
    GdkPoint *points;
    GdkColor color;

    /* Include start point */
    nuf_points = (int)p[nuf_points_idx] + 1;
    points = (GdkPoint *)g_malloc(sizeof(GdkPoint) * nuf_points);
    if (!points) {
	g_free(points);
	return;
    }

    rotation = p[(nuf_points - 1) * 2 + rotext_idx];
    for (point = 0; point < nuf_points; point++) {
	points[point].x = (int)round(scale * p[point * 2 + first_x_idx]);
	points[point].y = -(int)round(scale * p[point * 2 + first_y_idx]);
	if (rotation != 0.0)
	    points[point] = rotate_point(points[point], rotation);
	points[point].x += x;
	points[point].y += y;
    }

    gdk_gc_copy(local_gc, gc);

    /* Exposure */
    if (p[exposure_idx] == 0.0) {
	color.pixel = 0;
	gdk_gc_set_foreground(local_gc, &color);
    }

    gdk_gc_set_line_attributes(local_gc, 
			       1, /* outline always 1 pixels */
			       GDK_LINE_SOLID, 
			       GDK_CAP_BUTT, 
			       GDK_JOIN_MITER);
    gdk_draw_polygon(pixmap, local_gc, 1, points, nuf_points);

    g_free(points);

    gdk_gc_unref(local_gc);

    return;
} /* gerbv_gdk_draw_prim4 */
int main() {
	Simple_window win1 {x,800,600,"Exercise 12"};
	Graph_lib::Circle c {Point{200,200},30};
	Graph_lib::Mark m {Point{0,0},'x'};
	win1.attach(c);
	win1.attach(m);
	for(int i = 0; i < 360; i+=10) {
		m.set_point(0,rotate_point(c.center(),Point{c.center().x,c.center().y-c.radius()},i));
		win1.wait_for_button();
	}
}
Exemple #10
0
void Transform::apply_parent_transform(const Transform& parent)
{
    x *= parent.scale_x;
    y *= parent.scale_y;
    
    bool flipped = ((parent.scale_x < 0) != (parent.scale_y < 0));
    rotate_point(x, y, parent.angle, parent.x, parent.y, flipped);
    
    angle += parent.angle;
    scale_x *= parent.scale_x;
    scale_y *= parent.scale_y;
}
Exemple #11
0
EXPORT	void rotate_and_zoom_rect_grid(
	RECT_GRID *gr,
	double	  *L,
	double	  *U,
	double	  **Q)
{
	double	     **Qi = NULL;
	int	     i, j, dim = gr->dim;
	static double **pc = NULL;

	if (pc == NULL)
	    bi_array(&pc,MAXNCORNERS,MAXD,FLOAT);
	if (Q != NULL)
	{	
	    static double** M = NULL;
		
	    if (M == NULL)
	    	bi_array(&M,MAXD,MAXD,FLOAT);

	    Qi = M;
	    for (i = 0; i < dim; i++)
	    	for (j = 0; j < dim; j++)
	    	    Qi[i][j] = Q[j][i];
	}
	calculate_box(L,U,pc,Q,Qi,dim);
	for (i = 0; i < dim; i++)
	{
	    gr->gmax[i] = irint(_scaled_separation(pc[1<<i],pc[0],gr->h,dim));
	    if (gr->gmax[i] < 1)
		gr->gmax[i] = 1;
	}
	if (Qi != NULL)
	{
	    rotate_point(L,U,Qi,gr->U,dim);
	    rotate_point(L,gr->GU,Qi,gr->GU,dim);
	    rotate_point(L,gr->GL,Qi,gr->GL,dim);
	}
	set_rect_grid(L,gr->U,gr->GL,gr->GU,gr->lbuf,gr->ubuf,gr->gmax,
		      dim,&gr->Remap,gr);
}		/*end rotate_and_zoom_rect_grid*/
Exemple #12
0
static void
gerbv_gdk_draw_prim21(GdkPixmap *pixmap, GdkGC *gc, double *p, 
		  double scale, gint x, gint y)
{
    const int exposure_idx = 0;
    const int width_idx = 1;
    const int height_idx = 2;
    const int exp_x_idx = 3;
    const int exp_y_idx = 4;
    const int rotation_idx = 5;
    const int nuf_points = 4;
    GdkPoint points[nuf_points];
    GdkColor color;
    GdkGC *local_gc = gdk_gc_new(pixmap);
    int half_width, half_height;
    int i;

    half_width = (int)round(p[width_idx] * scale / 2.0);
    half_height =(int)round(p[height_idx] * scale / 2.0);

    points[0].x = half_width;
    points[0].y = half_height;

    points[1].x = half_width;
    points[1].y = -half_height;

    points[2].x = -half_width;
    points[2].y = -half_height;

    points[3].x = -half_width;
    points[3].y = half_height;

    for (i = 0; i < nuf_points; i++) {
	points[i] = rotate_point(points[i], p[rotation_idx]);
	points[i].x += (x + (int)(p[exp_x_idx] * scale));
	points[i].y += (y - (int)(p[exp_y_idx] * scale));
    }

    gdk_gc_copy(local_gc, gc);

    /* Exposure */
    if (p[exposure_idx] == 0.0) {
	color.pixel = 0;
	gdk_gc_set_foreground(local_gc, &color);
    }

    gdk_draw_polygon(pixmap, local_gc, 1, points, nuf_points);

    gdk_gc_unref(local_gc);

    return;
} /* gerbv_gdk_draw_prim21 */
Exemple #13
0
/*
 * Doesn't handle explicit x,y yet
 */
static void
gerbv_gdk_draw_prim22(GdkPixmap *pixmap, GdkGC *gc, double *p, 
		  double scale, gint x, gint y)
{
    const int exposure_idx = 0;
    const int width_idx = 1;
    const int height_idx = 2;
    const int x_lower_left_idx = 3;
    const int y_lower_left_idx = 4;
    const int rotation_idx = 5;
    const int nuf_points = 4;
    GdkPoint points[nuf_points];
    GdkGC *local_gc = gdk_gc_new(pixmap);
    GdkColor color;
    int i;

    points[0].x = (int)round(p[x_lower_left_idx] * scale);
    points[0].y = (int)round(p[y_lower_left_idx] * scale);

    points[1].x = (int)round((p[x_lower_left_idx] + p[width_idx])
			     * scale);
    points[1].y = (int)round(p[y_lower_left_idx] * scale);

    points[2].x = (int)round((p[x_lower_left_idx]  + p[width_idx])
			     * scale);
    points[2].y = (int)round((p[y_lower_left_idx]  + p[height_idx])
			     * scale);

    points[3].x = (int)round(p[x_lower_left_idx] * scale);
    points[3].y = (int)round((p[y_lower_left_idx] + p[height_idx])
			     * scale);

    for (i = 0; i < nuf_points; i++) {
	points[i] = rotate_point(points[i], p[rotation_idx]);
	points[i].x = x + points[i].x;
	points[i].y = y - points[i].y;
    }

    gdk_gc_copy(local_gc, gc);

    /* Exposure */
    if (p[exposure_idx] == 0.0) {
	color.pixel = 0;
	gdk_gc_set_foreground(local_gc, &color);
    }

    gdk_draw_polygon(pixmap, local_gc, 1, points, nuf_points);

    gdk_gc_unref(local_gc);

    return;
} /* gerbv_gdk_draw_prim22 */
Exemple #14
0
LOCAL void calculate_box(
	double		*L,
	double		*U,
	double		**rot_box,
	double		**Q,
	double		**Qi,
	int		dim)
{
	double		corner[2][MAXD];
	double		new_U[MAXD];
	int		i, j, imax = (1<<dim);

	/*  rotate upper corner backwards  */
	if (Qi != NULL)
		rotate_point(L, U, Qi, new_U, dim);
	else
		for (j = 0; j < dim; j++) new_U[j] = U[j];

	for (j = 0; j < dim; j++)
	{
		corner[0][j] = rot_box[0][j] = L[j];
		corner[1][j] = new_U[j];
		rot_box[imax-1][j] = U[j];
	}

	/*  find corners to be rotated  */
	for (i = 1; i < imax-1; i++)
		for (j = 0; j < dim; j++)
			rot_box[i][j] = corner[(i>>j)%2][j];

	/*  rotate corners   */
	if (Q != NULL)
	{
		for (i = 1; i < imax-1; i++)
			rotate_point(L, rot_box[i],
				     Q, rot_box[i], dim);
	}
}		/*end calculate_box*/
Exemple #15
0
/*
 * Doesn't handle and explicit x,y yet
 */
static void
gerbv_gdk_draw_prim20(GdkPixmap *pixmap, GdkGC *gc, double *p, 
		  double scale, gint x, gint y)
{
    const int exposure_idx = 0;
    const int linewidth_idx = 1;
    const int start_x_idx = 2;
    const int start_y_idx = 3;
    const int end_x_idx = 4;
    const int end_y_idx = 5;
    const int rotation_idx = 6;
    const int nuf_points = 2;
    GdkGC *local_gc = gdk_gc_new(pixmap);
    GdkPoint points[nuf_points];
    GdkColor color;
    int i;

    gdk_gc_copy(local_gc, gc);

    /* Exposure */
    if (p[exposure_idx] == 0.0) {
	color.pixel = 0;
	gdk_gc_set_foreground(local_gc, &color);
    }

    gdk_gc_set_line_attributes(local_gc, 
			       (int)round(scale * p[linewidth_idx]),
			       GDK_LINE_SOLID, 
			       GDK_CAP_BUTT, 
			       GDK_JOIN_MITER);

    points[0].x = (p[start_x_idx] * scale);
    points[0].y = (p[start_y_idx] * scale);
    points[1].x = (p[end_x_idx] * scale);
    points[1].y = (p[end_y_idx] * scale);

    for (i = 0; i < nuf_points; i++) {
	points[i] = rotate_point(points[i], -p[rotation_idx]);
	points[i].x = x + points[i].x;
	points[i].y = y - points[i].y;
    }

    gdk_draw_line(pixmap, local_gc, 
		  points[0].x, points[0].y, 
		  points[1].x, points[1].y);
    
    gdk_gc_unref(local_gc);

    return;
} /* gerbv_gdk_draw_prim20 */
Exemple #16
0
LOCAL void rotate_interface(
	INTERFACE	*intfc,
	double		*origin,
	double		**Q)
{
	BOND		*b;
	CURVE	 	**c;
	NODE  		**n;
	POINT		*p;
	int		dim = intfc->dim;
	
	if (is_identity_matrix(Q,dim) == YES)
	    return;

	for (n = intfc->nodes; *n; n++)
	{
		p = (*n)->posn;
		rotate_point(origin,Coords(p),Q,Coords(p),dim);
	}

	for (c = intfc->curves; *c; c++)
	{
		for (b = (*c)->first; b != (*c)->last; b = b->next)
		{
			p = b->end;
			rotate_point(origin,Coords(p),Q,Coords(p),dim);
		}
	}

	if (dim == 3)
	{
		/* TODO */
		screen("ERROR in rotate_interface(), 3D code needed\n");
		clean_up(ERROR);
	}
}		/*end rotate_interface*/
Exemple #17
0
void TerrainRotateFunction::AddPoint(float relative_normalized_x, float relative_normalized_y, float scale,
	float absolute_xy_distance, vec3& point) const {
	// TODO: optimize by using matrices for rotation.
	const float new_relative_normalized_x = ::cos(-angle_)*relative_normalized_x - ::sin(-angle_)*relative_normalized_y;
	const float new_relative_normalized_y = ::sin(-angle_)*relative_normalized_x + ::cos(-angle_)*relative_normalized_y;
	vec3 rotate_point(new_relative_normalized_x, new_relative_normalized_y, point.z/outer_radius_);
	rotate_point *= outer_radius_;
	rotate_point.x += position_.x;
	rotate_point.y += position_.y;
	function_->AddPoint(new_relative_normalized_x, new_relative_normalized_y, scale, absolute_xy_distance, rotate_point);
	rotate_point.x -= position_.x;
	rotate_point.y -= position_.y;
	point.x = ::cos(angle_)*rotate_point.x - ::sin(angle_)*rotate_point.y + position_.x;
	point.y = ::sin(angle_)*rotate_point.x + ::cos(angle_)*rotate_point.y + position_.y;
	point.z = rotate_point.z;
}
Exemple #18
0
int main(int argc, char *argv[]) {
  int x, y;
  //PronWindowAttributes newAttr;

  if (argc > 2) {
    x = atoi(argv[1]);
    y = atoi(argv[2]);
    printf("Position: %d %d\n", x, y);
  } else {
    x = 20;
    y = 10;
  }

  Display *d = pronConnect();
  if (d == NULL) {
    fprintf(stderr, "Unable to connect to pron.\n");
    exit(1);
  }

  Window w = pronCreateWindow(d, d->rootWindow, x, y, 320, 240);
  /*
  newAttr.x = 400;
  pronSetWindowAttributes(d, w, newAttr, WIN_ATTR_X);
  */

  while (1) {
    /*
    newAttr.x = (newAttr.x + 1) % 500;
    pronSetWindowAttributes(d, w, newAttr, WIN_ATTR_X);
    */
    pronClearWindow(d, w);  
    int i = 0;
    for (i = 0; i < 8; i++) {
      rotate_point(cube[i]);
    }
    draw_cube(d, w);
    usleep(20000);
  }

  pronDisconnect(d);

  return 0;
}
Exemple #19
0
int main() {
	int vga_fd = open("/dev/vga", O_RDONLY);
	ioctl(vga_fd, SETVGAMODE, (void*)vga_mode_320x200x256); 
	init();

	while (1) {	
		clear_buffer(buffer);
		int i = 0;
		for (i = 0; i < 8; i++) {
			rotate_point(cube[i]);
		}
		draw_cube(buffer);
		ioctl(vga_fd, FLUSHVGA, buffer);
		usleep(10000);
	}

	close(vga_fd);

	return 0;
}
void Triangle::init_edges()
{
	Point *bounds[3];

	for(int i = 0, next = 1, angle = 0; i < 3; i++, angle += 120, next++) //must be 120 degree to get right triangle
	{
		Point *v = new Point();
		rotate_point(v, center, angle);
		bounds[i] = v;
	}

	for(int cur = 0, next = 1; cur < 3; cur++, next++)
	{
		if(next > 2) next = 0;
		edges[cur] = new Line(	new Point(center->x + bounds[cur]->x, center->y  + bounds[cur]->y),
								new Point(center->x + bounds[next]->x, center->y + bounds[next]->y));
	}

	draw();
	draw_doodle();
}
Exemple #21
0
static void update_window(handle_t hwnd, hsi_window_t *wnd)
  {
  rect_t wnd_rect;
  get_window_rect(hwnd, &wnd_rect);

  extent_t ex;
  rect_extents(&wnd_rect, &ex);

  point_t pt;
  rect_t rect;
  // fill without a border
  rectangle(hwnd, &wnd_rect, 0, wnd->background_color, &wnd_rect);

  if (wnd->draw_border)
    round_rect(hwnd, &wnd_rect, &gray_pen, color_hollow, &wnd_rect, 12);

  /////////////////////////////////////////////////////////////////////////////
  //
  // Draw the HSI Indicator

  const gdi_dim_t mark_start = 12;
  const gdi_dim_t center_x = ex.dx >> 1;
  const gdi_dim_t center_y = ex.dy >> 1;
  const gdi_dim_t window_x = ex.dx;
  const gdi_dim_t window_y = ex.dy;
  const gdi_dim_t border = 10;
  const gdi_dim_t pixels_per_nm_cdi = 6;
  const point_t median = { center_x, center_y };
  const gdi_dim_t major_mark = mark_start + 16;
  const gdi_dim_t minor_mark = mark_start + 8;
  const gdi_dim_t font_x_y = 19;
  const gdi_dim_t font_center = (font_x_y >> 1) + 1;
  const gdi_dim_t font_ordinal = major_mark + font_center;

  // start at 0
  gdi_dim_t i = 0;
  gdi_dim_t index;
  for (index = -wnd->direction; i < 12; index += 30, i++)
    {
    while (index > 359)
      index -= 360;

    while (index < 0)
      index += 360;

    // draw the marker
    point_t pts[2];

    pts[0].x = center_x; pts[0].y = mark_start;
    pts[1].x = center_x; pts[1].y = major_mark;
    rotate_point(&median, &pts[0], index);
    rotate_point(&median, &pts[1], index);

    polyline(hwnd, &wnd_rect, &white_pen, 2, pts);

    bool do_minor_mark = false;
    int16_t minor_index;
    for (minor_index = 0; minor_index < 30; minor_index += 5)
      {
      pts[0].x = center_x; pts[0].y = mark_start;
      pts[1].x = center_x; pts[1].y = do_minor_mark ? minor_mark : major_mark;

      rotate_point(&median, &pts[0], index + minor_index);
      rotate_point(&median, &pts[1], index + minor_index);

      polyline(hwnd, &wnd_rect, &white_pen, 2, pts);

      do_minor_mark = !do_minor_mark;
      }

    // we now draw the text onto the canvas.  The text has a 23x23 pixel
    // block so the center is 12, 12.
    pts[0].x = center_x; pts[0].y = font_ordinal;
    int16_t rotn = (index < 0) ? index + 360 : index;
    rotate_point(&median, &pts[0], rotn);

    draw_text(hwnd, &wnd_rect, wnd->font, color_white, color_black,
      (char *)&i, 1,
      make_point(pts[0].x - font_center, pts[0].y - font_center, &pt),
      0, 0, 0);
    }

  ///////////////////////////////////////////////////////////////////////////
  // Draw the Track

  int rotation = wnd->track - wnd->direction;

  // the marker is a dashed line
  point_t track_marker[4] = {
    { center_x, center_y - 88 },
    { center_x - 7, center_y - 95 },
    { center_x + 7, center_y - 95 },
    { center_x, center_y - 88 }
    };

  for (i = 0; i < 4; i++)
    rotate_point(&median, &track_marker[i], rotation);

  polygon(hwnd, &wnd_rect, &gray_pen, color_hollow, 4, track_marker);

  point_t track_line[2] = {
    { center_x, center_y - 88 },
    { median.x, median.y }
    };

  rotate_point(&median, &track_line[0], rotation);

  polyline(hwnd, &wnd_rect, &track_pen, 2, track_line);

  ///////////////////////////////////////////////////////////////////////////
  // Draw the CDI

  rotation = wnd->course - wnd->direction;

  gdi_dim_t dist;
  for (dist = -10; dist < 11; dist += 2)
    {
    if (dist == 0)
      continue;

    point_t pts[2] = {
      { center_x + (pixels_per_nm_cdi * dist), center_y - 5 },
      { center_x + (pixels_per_nm_cdi * dist), center_y + 5 }
      };

    rotate_point(&median, &pts[0], rotation);
    rotate_point(&median, &pts[1], rotation);

    polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);
    }

  // draw the CDI Marker head next
  point_t cdi_pts[4] = {
    { center_x, center_y - 97 },
    { center_x - 6, center_y - 88 },
    { center_x + 6, center_y - 88 },
    { center_x, center_y - 97 }
    };

  for (i = 0; i < 4; i++)
    rotate_point(&median, &cdi_pts[i], rotation);

  polygon(hwnd, &wnd_rect, 0, color_green, 4, cdi_pts);

  // we now convert the deviation to pixels.
  // 1 degree = 24 pixels
  double cdi_var = pixels_per_nm_cdi *((double)wnd->deviation / 10);

  gdi_dim_t cdi = (gdi_dim_t) max(-66, min(66, roundf(cdi_var)));

  point_t pts[4];
  pts[0].x = center_x; pts[0].y = center_y - 98;
  pts[1].x = center_x; pts[1].y = center_y - 50;

  rotate_point(&median, &pts[0], rotation);
  rotate_point(&median, &pts[1], rotation);

  polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);

  pts[0].x = center_x; pts[0].y = center_y + 50;
  pts[1].x = center_x; pts[1].y = center_y + 98;

  rotate_point(&median, &pts[0], rotation);
  rotate_point(&median, &pts[1], rotation);

  polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);

  pts[0].x = center_x + cdi; pts[0].y = center_y - 48;
  pts[1].x = pts[0].x; pts[1].y = center_y + 48;

  rotate_point(&median, &pts[0], rotation);
  rotate_point(&median, &pts[1], rotation);

  polyline(hwnd, &wnd_rect, &green_pen_3, 2, pts);

  /////////////////////////////////////////////////////////////////////////////
  //	Draw the heading bug.

  int hdg = wnd->heading - wnd->direction;

  point_t heading_points[8] = {
    { center_x - 15, 3 },
    { center_x - 5, 3 },
    { center_x, 10 },
    { center_x + 5, 3 },
    { center_x + 15, 3 },
    { center_x + 15, 12 },
    { center_x - 15, 12 },
    { center_x - 15, 3 }
    };

  for (i = 0; i < 8; i++)
    rotate_point(&median, &heading_points[i], hdg);

  polyline(hwnd, &wnd_rect, &magenta_pen, 8, heading_points);

  heading_points[0].x = center_x - 5; heading_points[0].y = 0;
  heading_points[1].x = center_x + 5; heading_points[1].y = 0;
  heading_points[2].x = center_x; heading_points[2].y = 10;
  heading_points[3].x = center_x - 5; heading_points[3].y = 0;

  polygon(hwnd, &wnd_rect, &white_pen, color_white, 4, heading_points);

  /////////////////////////////////////////////////////////////////////////////
  // Draw the wind direction indicator.
  // it is in the top left of the HSI and has an arrow that is
  // relative to the magnetic heading of the aircraft and the
  // speed/magnetic heading in the form deg/speed so
  // so for a wind of 15 knots at 50 degrees magnetic we would
  // show 050/15.  If the aircraft heading is 240 degrees magnetic we
  // would see a wind vector on the tail of 40 degrees toward the aircraft
  // the wind direction is shown as a yellow triangle around the HSI indicator
  // the text allows for 3 characters with an maximum width of 23 pixels each
  // so the allowance is 69 by 64 pixels

  int16_t relative_wind = wnd->direction + wnd->magnetic_variation - wnd->direction;
  while (relative_wind < 0)
    relative_wind += 360;

  // draw the wind first
  point_t wind_bug[4] =
    {
    { center_x - 15, 2 },
    { center_x + 15, 2 },
    { center_x, 12 },
    { center_x - 15, 2 }
    };

  for (i = 0; i < 4; i++)
    rotate_point(&median, &wind_bug[i], relative_wind);

  polyline(hwnd, &wnd_rect, &yellow_pen, 4, wind_bug);

  // now the text in upper left

  char msg[32];
  sprintf(msg, "%03.3d", wnd->direction + wnd->magnetic_variation);
  size_t length = strlen(msg);

  extent_t pixels;
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(25 - (pixels.dx >> 1), 2, &pt), 0, 0, 0);

  sprintf(msg, "%d", wnd->wind_speed);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(25 - (pixels.dx >> 1), 13, &pt), 0, 0, 0);

  /////////////////////////////////////////////////////////////////////////////
  // Draw the estimated time to waypoint.
  // drawn in top right as distance/time
  sprintf(msg, "%d", wnd->distance_to_waypoint);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(window_x - 25 - (pixels.dx >> 1), 2, &pt), 0, 0, 0);

  sprintf(msg, "%02.2d:%02.2d", wnd->time_to_waypoint / 60, wnd->time_to_waypoint % 60);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(window_x - 25 - (pixels.dx >> 1), 13, &pt), 0, 0, 0);

  sprintf(msg, "%s", wnd->waypoint_name);
  length = strlen(msg);
  text_extent(wnd, wnd->font, msg, length, &pixels);
  draw_text(hwnd, &wnd_rect, wnd->font, color_yellow, color_hollow,
    msg, length, make_point(window_x - 25 - (pixels.dx >> 1), 24, &pt), 0, 0, 0);
  }
	bool ball_in_kicker_area(float rotation) {
		Point points[] = {rotate_point(us->x, us->y, -robot_width / 2, -robot_height / 2, rotation), rotate_point(us->x, us->y, robot_width / 2, -robot_height / 2, rotation),
			rotate_point(us->x, us->y, robot_width / 2, robot_height / 2 + kicker_reach, rotation), rotate_point(us->x, us->y, -robot_width / 2, robot_height / 2 + kicker_reach, rotation)};
		return CGAL::bounded_side_2(points, points + 4, Point(ball->x, ball->y), Kernel()) != CGAL::ON_UNBOUNDED_SIDE;
	}
Exemple #23
0
BaseSprite spriter_append(BaseSprite list, Animation* anim, Vector pos,
                          float sx, float sy, unsigned short anim_time_ms) {
  // clamp or restrict the animation time
  if(anim->looping) {
    anim_time_ms = anim_time_ms % anim->length_ms;
  } else {
    anim_time_ms = MAX(0, MIN(anim->length_ms, anim_time_ms));
  }

  // find the master keys that sandwich this time
  int idx_before = -1;
  int idx_after = -1;

  for(int ii = 0; ii < anim->nframes; ++ii) {
    MasterKey* frame = &anim->frames[ii];
    if(frame->time_ms > anim_time_ms) {
      // found the stopping point
      if(ii == 0) {
        // at or before zero, are we looping?
        if(anim->looping) {
          idx_before = anim->nframes - 1;
          idx_after = ii;
        } else {
          idx_before = ii;
          idx_after = ii;
        }
      } else {
        idx_before = ii - 1;
        idx_after = ii;
      }
      break;
    }
  }

  if(idx_before == -1) {
    // we must be off the end of the animation
    if(anim->looping) {
      idx_before = anim->nframes - 1;
      idx_after = 0;
    } else {
      idx_before = anim->nframes - 1;
      idx_after = anim->nframes - 1;
    }
  }

  unsigned short before_t = anim->frames[idx_before].time_ms;
  unsigned short after_t = anim->frames[idx_after].time_ms;
  if(after_t < before_t) {
    // in the looping section
    after_t = anim->length_ms;
  }
  unsigned short dt = after_t - before_t;

  // compute the scale factor
  float s;
  if(dt == 0) {
    s = 0;
  } else {
    s = ((double)(anim_time_ms - before_t)) / ((double)dt);
  }

  MasterKey* master = &anim->frames[idx_before];

  // build a transform stack that is as big as the bone heirarchy
  // could possibly be deep
  int timeline_stack_size = master->nrefs + 1;
  int* timeline_stack = (int*)GIGGLE->renderer->alloc(sizeof(int) * timeline_stack_size);

  // now, using the list in the before key, we start tweening and
  // drawing
  for(int ii = master->nrefs - 1; ii >= 0; --ii) {
    MasterElementRef* ref = &master->refs[ii];

    // create the sprite
    Sprite sprite = GIGGLE->make_sprite();
    KeyFrameElement* end_before = &anim->timelines[ref->timeline_idx].elements[ref->keyframe_idx];
    sprite_fillfromentry(sprite, end_before->entry);
    sprite->originX = 0;
    sprite->originY = 0;

    // fill out the list of timelines we need to step through to
    // follow the bone heirarchy
    int last_stack_idx = timeline_stack_size - 1;
    timeline_stack[last_stack_idx] = ref->timeline_idx;

    while(ref->parent_idx >= 0) {
      ref = &master->bones[ref->parent_idx];
      SAFETY(if(last_stack_idx == 0) { fail_exit("bone stack exhausted"); });
      timeline_stack[--last_stack_idx] = ref->timeline_idx;
    }

    // now walk from root to end following the bone heirarchy and
    // composing the transforms
    float pscale_x = sx;
    float pscale_y = sy;
    float pangle = 0.0f;
    float px = pos->x;
    float py = pos->y;

    for(int ii = last_stack_idx; ii < timeline_stack_size; ++ii) {
      int tl_idx = timeline_stack[ii];
      Timeline* tl = &anim->timelines[tl_idx];
      KeyFrameElement* before = &tl->elements[idx_before];
      KeyFrameElement* after = &tl->elements[idx_after];
      float scale_x = lerp(before->scale_x, after->scale_x, s);
      float scale_y = lerp(before->scale_y, after->scale_y, s);
      float angle = clerp(before->angle, after->angle, before->spin, s);
      float x = lerp(before->x, after->x, s) * pscale_x;
      float y = lerp(before->y, after->y, s) * pscale_y;

      bool flipped = (pscale_x < 0) != (pscale_y < 0);
      rotate_point(x, y, pangle, px, py, flipped);
      px = x;
      py = y;

      pscale_x *= scale_x;
      pscale_y *= scale_y;
      pangle += angle;

      // now we're at the leaf node
      if(ii == (timeline_stack_size - 1)) {
        sprite->originX = lerp(before->pivot_x, after->pivot_x, s);
        sprite->originY = lerp(before->pivot_y, after->pivot_y, s);
        sprite->w *= pscale_x;
        sprite->h *= pscale_y;
        if(flipped) {
          sprite->angle = -pangle;
        } else {
          sprite->angle = pangle;
        }
        sprite->displayX = px;
        sprite->displayY = py;
      }
    }

    sprite_append(list, sprite);
  }
/* ----------------------------------------------------------------------------
 * Draws a Pikmin, including its leaf/bud/flower, idle glow, etc.
 */
void pikmin::draw_mob(bitmap_effect_manager* effect_manager) {

    sprite* s_ptr = anim.get_cur_sprite();
    
    if(!s_ptr) return;
    
    point draw_pos = get_sprite_center(s_ptr);
    point draw_size = get_sprite_dimensions(s_ptr);
    
    bool is_idle =
        fsm.cur_state->id == PIKMIN_STATE_IDLING ||
        fsm.cur_state->id == PIKMIN_STATE_IDLING_H ||
        fsm.cur_state->id == PIKMIN_STATE_SPROUT;
        
    bitmap_effect_manager effects;
    add_sector_brightness_bitmap_effect(&effects);
    add_status_bitmap_effects(&effects);
    
    if(is_idle) {
        bitmap_effect idle_effect;
        bitmap_effect_props idle_effect_props;
        idle_effect_props.glow_color = al_map_rgb(255, 255, 255);
        idle_effect.add_keyframe(0, idle_effect_props);
        effects.add_effect(idle_effect);
    }
    
    draw_bitmap_with_effects(
        s_ptr->bitmap,
        draw_pos, draw_size,
        angle + s_ptr->angle, &effects
    );
    
    if(s_ptr->top_visible) {
        point top_pos;
        top_pos = rotate_point(s_ptr->top_pos, angle);
        draw_bitmap_with_effects(
            pik_type->bmp_top[maturity],
            pos + top_pos,
            s_ptr->top_size,
            angle + s_ptr->top_angle,
            &effects
        );
    }
    
    if(is_idle) {
        draw_bitmap(
            bmp_idle_glow,
            pos,
            point(standard_pikmin_radius * 8, standard_pikmin_radius * 8),
            area_time_passed * IDLE_GLOW_SPIN_SPEED,
            type->main_color
        );
    }
    
    float status_bmp_scale;
    ALLEGRO_BITMAP* status_bmp = get_status_bitmap(&status_bmp_scale);
    if(status_bmp) {
        draw_bitmap(
            status_bmp, pos,
            point(type->radius * 2 * status_bmp_scale, -1)
        );
    }
    
}
Point rotate_point_copy(const Point & point, const FlatMatrix9 & mat)
{
    Point ret(point);
    rotate_point(ret, mat);
    return ret;    
}
void Right_triangle::rotate(Point c, int angle) {
	set_point(0,rotate_point(c,point(0),angle));
	set_point(2,rotate_point(c,point(2),angle));
	r = point(0);
}
void rotate_point_container(PointContainer & cont, const FlatMatrix9 & mat)
{
    for(auto & it : cont)
        rotate_point(it, mat);
}
 PieSliceSensorSpecial(double angle1, double angle2) : PieSliceSensor(angle1, angle2) 
 {
   offset = rotate_point(Vector(radius_special, 0), angle1);
   offset2 = rotate_point(Vector(radius_special, 0), angle2);
 }
Exemple #29
0
/* pass player struct and set ship to null if the player is firing, otherwise, keep player at null and pass ship */
void fire(struct _ship *ship, short int which_mount) {
	int i;
	
	assert(ship != NULL);
	
	if (which_mount == -1)
		return;
	
	if (ship->weapon_mount[which_mount] == NULL) {
		fprintf(stdout, "WARNING: fire() which_mount = (%d) but that weapon mount is invalid\n", which_mount);
		fprintf(stdout, "WARNING: model is \"%s\"\n", ship->model->name);
		return;
	}
	
	if ((ship->weapon_mount[which_mount]->ammo <= 0) && (ship->weapon_mount[which_mount]->weapon->uses_ammo))
		return;
	
	if (ship->weapon_mount[which_mount]->time > current_time)
		return;

	if (ship->hull_strength <= 0)
		return; /* dead ships can't fire */
	
	i = get_free_weapon_slot();
	if (i == -1) {
		return; /* no free weapon slots */
	} else {
		/* fire the weapon */
		int angle, fire_x, fire_y;
		
		angle = (ship->angle + ship->weapon_mount[which_mount]->angle) % 360;
		
		assert(ship);
		assert(ship->weapon_mount[which_mount]);
		assert(ship->weapon_mount[which_mount]->weapon);
		fires[i].surface = rotate(ship->weapon_mount[which_mount]->weapon->ammo_image, angle); /* cannot be void if creaated, set this to an image */
		fires[i].weapon = ship->weapon_mount[which_mount]->weapon;
		fires[i].velocity = fires[i].weapon->velocity;
		fires[i].owner = ship;
		/* assign the world x & y values */
		fire_x = (int)fires[i].world_x;
		fire_y = (int)fires[i].world_y;
		rotate_point(ship->weapon_mount[which_mount]->x, ship->weapon_mount[which_mount]->y, angle, &fire_x, &fire_y);
		fires[i].world_x = (float)fire_x;
		fires[i].world_y = (float)fire_y;
		fires[i].world_x += ship->world_x;
		fires[i].world_y = ship->world_y - fires[i].world_y;
		fires[i].screen_x = -1500;
		fires[i].screen_y = -1500;
		fires[i].angle = ship->angle + ship->weapon_mount[which_mount]->angle;
		if (ship->weapon_mount[which_mount]->range != 0) {
			/* the weapon has a range, meaning it can turn, let's apply this by aiming toward the target if there is one */
			if (ship->target) {
				float angle_to = get_angle_to(ship->world_x, ship->world_y, ship->target->offender->world_x, ship->target->offender->world_y);
				int range = ship->weapon_mount[which_mount]->range / 2; /* divided by 2 because the range is counting both left and right */
				int angle = fires[i].angle;

				/* if the angle is within our range, aim straight at the target */
				if (((angle + range) > angle_to) && ((angle - range) < angle_to))
					fires[i].angle = angle_to;
				else {
					/* it's not within range, so aim closest to it */
					if (angle_to > (angle + range))
						fires[i].angle = angle + range;
					else
						fires[i].angle = angle - range;
				}
			}
		}
		fires[i].angle %= 360;
		
		/* if it has auto-aim, fire towards the target if possible, if not, it fires at the closest angle */
		if (ship->weapon_mount[which_mount]->range) {
			/* somewhat diff. variables for player */
			if (ship == player.ship) {
				if (player.target.type != TARGET_NONE) {
					float new_angle;
					float world_x, world_y;
					int aim_angle = (int)player.ship->weapon_mount[which_mount]->angle;
					int range = (int)player.ship->weapon_mount[which_mount]->range;
					
					if (player.target.type == TARGET_GATE) {
						struct _gate *gate = (struct _gate *)player.target.target;
						world_x = gate->world_x;
						world_y = gate->world_y;
					} else if (player.target.type == TARGET_SHIP) {
						struct _ship *ship = (struct _ship *)player.target.target;
						world_x = ship->world_x;
						world_y = ship->world_y;
					}
					
					new_angle = (float)atan2((float)((-1 * world_y) - (-1 * fires[i].world_y)), (float)(world_x - fires[i].world_x));
					
					/* convert aim_angle and range to radians :-) */
					aim_angle = (int)(((float)aim_angle * M_PI) / 180.0f);
					range = (int)(((float)range * M_PI) / 180.0f);
					
					/* see if the angle is in the range, if not, get it as close as possible */
					if ((new_angle < (angle + range)) && (new_angle > (angle - range))) {
						angle = (int)((new_angle * 180.0f) / M_PI);
					} else {
						/* the angle is not in the range, but get it as close as possible */
						if (new_angle > (angle + range))
							angle = (int)(((float)(aim_angle + range) * 180.0f) / M_PI);
						else
							angle = (int)(((float)(aim_angle - range) * 180.0f) / M_PI);
					}
				}
			} else {
				if ((ship->target != NULL) && (ship->target->offender != NULL)) {
					float new_angle;
					int aim_angle = (int)ship->weapon_mount[which_mount]->angle;
					int range = (int)ship->weapon_mount[which_mount]->range;
					new_angle = (float)atan2((float)((-1 * ship->target->offender->world_y) - (-1 * fires[i].world_y)), (float)(ship->target->offender->world_x - fires[i].world_x));
					
					/* convert aim_angle and range to radians :-) */
					aim_angle = (int)(((float)aim_angle * M_PI) / 180.0f);
					range = (int)(((float)range * M_PI) / 180.0f);
					
					/* see if the angle is in the range, if not, get it as close as possible */
					if ((new_angle < (angle + range)) && (new_angle > (angle - range))) {
						angle = (int)((new_angle * 180.0f) / M_PI);
					} else {
						/* the angle is not in the range, but get it as close as possible */
						if (new_angle > (angle + range))
							angle = (int)(((float)(aim_angle + range) * 180.0f) / M_PI);
						else
							angle = (int)(((float)(aim_angle - range) * 180.0f) / M_PI);
					}
				}
			}
		}
		
		fires[i].expire_time = current_time + (Uint32)ship->weapon_mount[which_mount]->weapon->lifetime;
		
		/* subtract the fire from the ship's amount to fire and set their next firing time */
		ship->weapon_mount[which_mount]->ammo--;
		
		ship->weapon_mount[which_mount]->time = current_time + (Uint32)ship->weapon_mount[which_mount]->weapon->recharge;
		
		num_fires++;
	}
}
Exemple #30
0
void object_position_rotate_points(OBJECT_POSITION *obj, float rads) {
  unsigned i;
  for (i = 0; i < obj->points_size; i++)
    obj->points[i] = rotate_point(obj->points[i], obj->center, rads);
}