Пример #1
0
static void project_object(PROJECT *Project, OBJECT *Object, int Axis, VECTOR Origin, int proj_thru, PROJECT *proj_proj)
{
  int visible, Number;
  VECTOR Points[8];

  /* Do not project infinite objects (always visible!) */

  if (Test_Flag(Object, INFINITE_FLAG))
  {
    Project->x1 = Project->y1 = MIN_BUFFER_ENTRY;
    Project->x2 = Project->y2 = MAX_BUFFER_ENTRY;

    return;
  }

  /* Get points to project */

  calc_points(Axis, Object, &Number, Points, Origin);

  visible = false;

  Project->x1 = Project->y1 = MAX_BUFFER_ENTRY;
  Project->x2 = Project->y2 = MIN_BUFFER_ENTRY;

  if (Number == 3)
  {
    project_triangle(Project, Points[0], Points[1], Points[2], &visible);
  }
  else
  {
    project_bbox(Project, Points, &visible);
  }

  if ( visible && proj_thru ) {
    visible = intersect_projects( Project, proj_proj );
    if ( visible ) {
      if (Project->x1 < proj_proj->x1 ) Project->x1 = proj_proj->x1;
      if (Project->x2 > proj_proj->x2 ) Project->x2 = proj_proj->x2;
      if (Project->y1 < proj_proj->y1 ) Project->y1 = proj_proj->y1;
      if (Project->y2 > proj_proj->y2 ) Project->y2 = proj_proj->y2;
    }
  }

  if (!visible)
  {
    /* Object is invisible */

    Project->x1 = Project->y1 = MAX_BUFFER_ENTRY;
    Project->x2 = Project->y2 = MIN_BUFFER_ENTRY;
  }
  else
  {
    /* We don't want to miss something */

    Project->x1 -= 2;
    Project->x2 += 2;
    Project->y1 -= 2;
    Project->y2 += 2;
  }
}
// LSCM equation, geometric form :
// (Z1 - Z0)(U2 - U0) = (Z2 - Z0)(U1 - U0)
// Where Uk = uk + i.vk is the complex number 
//                       corresponding to (u,v) coords
//       Zk = xk + i.yk is the complex number 
//                       corresponding to local (x,y) coords
void MeshPara::setup_conformal_map_relations(Mesh::FHandle fh)
{
	int id[3];
	Vec3f p[3];
	auto fv = mesh_.fv_begin(fh);
	for (int i = 0; i < 3; i++, fv++)
	{
		p[i] = mesh_.point(*fv);
		id[i] = (*fv).idx();
	}

	Vec2f z[3];
	project_triangle(p[0], p[1], p[2], z[0], z[1], z[2]);
	Vec2f z01 = z[1] - z[0];
	Vec2f z02 = z[2] - z[0];
	double a = z01[0];
	double b = z01[1];
	double c = z02[0];
	double d = z02[1];
	assert(b == 0.0);

	// Note  : 2*id + 0 --> u
	//         2*id + 1 --> v
	int u0_id = 2 * id[0];
	int v0_id = 2 * id[0] + 1;
	int u1_id = 2 * id[1];
	int v1_id = 2 * id[1] + 1;
	int u2_id = 2 * id[2];
	int v2_id = 2 * id[2] + 1;

	// Note : b = 0

	// Real part
	nlBegin(NL_ROW);
	nlCoefficient(u0_id, -a + c);
	nlCoefficient(v0_id, b - d);
	nlCoefficient(u1_id, -c);
	nlCoefficient(v1_id, d);
	nlCoefficient(u2_id, a);
	nlEnd(NL_ROW);

	// Imaginary part
	nlBegin(NL_ROW);
	nlCoefficient(u0_id, -b + d);
	nlCoefficient(v0_id, -a + c);
	nlCoefficient(u1_id, -d);
	nlCoefficient(v1_id, -c);
	nlCoefficient(v2_id, a);
	nlEnd(NL_ROW);
}