コード例 #1
0
ファイル: apitrigeom.cpp プロジェクト: GDXN/fitsliberator
void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) {
  vector x, y, z, tmp;
  double u, v, u2, v2;
  int j;
  vector p1, p2, p3, p4;
  vector n1, n2;

  z = axis;
  MyVNorm(&z);
  tmp.x = z.y - 2.1111111;
  tmp.y = -z.z + 3.14159267;
  tmp.z = z.x - 3.915292342341;
  MyVNorm(&z);
  MyVNorm(&tmp);
  MyVCross(&z, &tmp, &x);
  MyVNorm(&x);
  MyVCross(&x, &z, &y);
  MyVNorm(&y);

  for (j=0; j<CYLFACETS; j++) {
     u = rad * sin((6.28 * j) / (CYLFACETS - 1.0));
     v = rad * cos((6.28 * j) / (CYLFACETS - 1.0));
    u2 = rad * sin((6.28 * (j + 1.0)) / (CYLFACETS - 1.0));
    v2 = rad * cos((6.28 * (j + 1.0)) / (CYLFACETS - 1.0));

    p1.x = p1.y = p1.z = 0.0;
    p4 = p3 = p2 = p1;

    MyVAddS(u, &x, &p1, &p1);
    MyVAddS(v, &y, &p1, &p1);
    n1 = p1;
    MyVNorm(&n1);
    MyVAddS(1.0, &ctr, &p1, &p1);
  

    MyVAddS(u2, &x, &p2, &p2);
    MyVAddS(v2, &y, &p2, &p2);
    n2 = p2;
    MyVNorm(&n2);
    MyVAddS(1.0, &ctr, &p2, &p2);

    MyVAddS(1.0, &axis, &p1, &p3);
    MyVAddS(1.0, &axis, &p2, &p4);

    rt_stri(tex, p1, p2, p3, n1, n2, n1);
    rt_stri(tex, p3, p2, p4, n1, n2, n2);
  }
}
コード例 #2
0
static errcode GetSTri(parsehandle * ph, SceneHandle scene) {
  apivector v0,v1,v2,n0,n1,n2;
  void * tex;
  errcode rc;

  rc = GetString(ph, "V0");
  rc |= GetVector(ph, &v0);

  rc |= GetString(ph, "V1");
  rc |= GetVector(ph, &v1);

  rc |= GetString(ph, "V2");
  rc |= GetVector(ph, &v2);
  
  rc |= GetString(ph, "N0");
  rc |= GetVector(ph, &n0);

  rc |= GetString(ph, "N1");
  rc |= GetVector(ph, &n1);

  rc |= GetString(ph, "N2");
  rc |= GetVector(ph, &n2);

  rc |= GetTexture(ph, scene, &tex);
  
  rt_stri(scene, tex, v0, v1, v2, n0, n1, n2);

  return rc;
}
コード例 #3
0
static errcode GetSTri(FILE * dfile) {
  vector v0,v1,v2,n0,n1,n2;
  void * tex;
  errcode rc;

  rc = GetString(dfile, "V0");
  rc |= GetVector(dfile, &v0);

  rc |= GetString(dfile, "V1");
  rc |= GetVector(dfile, &v1);

  rc |= GetString(dfile, "V2");
  rc |= GetVector(dfile, &v2);
  
  rc |= GetString(dfile, "N0");
  rc |= GetVector(dfile, &n0);

  rc |= GetString(dfile, "N1");
  rc |= GetVector(dfile, &n1);

  rc |= GetString(dfile, "N2");
  rc |= GetVector(dfile, &n2);

  rc |= GetTexture(dfile, &tex);
  
  rt_stri(tex, v0, v1, v2, n0, n1, n2);

  return rc;
}
コード例 #4
0
ファイル: apitrigeom.cpp プロジェクト: GDXN/fitsliberator
void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) {
  vector x, y, z, tmp;
  double u, v, u2, v2;
  int j;
  vector p1, p2, p3, p4;
  vector n1, n2;

  z = norm;
  MyVNorm(&z);
  tmp.x = z.y - 2.1111111;
  tmp.y = -z.z + 3.14159267;
  tmp.z = z.x - 3.915292342341;
  MyVNorm(&z);
  MyVNorm(&tmp);
  MyVCross(&z, &tmp, &x);
  MyVNorm(&x);
  MyVCross(&x, &z, &y);
  MyVNorm(&y);

  for (j=0; j<RINGFACETS; j++) {
     u = sin((6.28 * j) / (RINGFACETS - 1.0));
     v = cos((6.28 * j) / (RINGFACETS - 1.0));
    u2 = sin((6.28 * (j + 1.0)) / (RINGFACETS - 1.0));
    v2 = cos((6.28 * (j + 1.0)) / (RINGFACETS - 1.0));

    p1.x = p1.y = p1.z = 0.0;
    p4 = p3 = p2 = p1;

    MyVAddS(u, &x, &p1, &p1);
    MyVAddS(v, &y, &p1, &p1);
    n1 = p1;
    MyVNorm(&n1);
    MyVAddS(a, &n1, &ctr, &p1);
    MyVAddS(b, &n1, &ctr, &p3);

    MyVAddS(u2, &x, &p2, &p2);
    MyVAddS(v2, &y, &p2, &p2);
    n2 = p2;
    MyVNorm(&n2);
    MyVAddS(a, &n2, &ctr, &p2);
    MyVAddS(b, &n2, &ctr, &p4);

    rt_stri(tex, p1, p2, p3, norm, norm, norm);
    rt_stri(tex, p3, p2, p4, norm, norm, norm);

  }
} 
コード例 #5
0
static void gen_triangles(SceneHandle scene, tri_list * tlist, 
                          apivector * vertex, apivector * normal) {
  tri_list * cur;

  cur = tlist;
  while (cur != NULL) {
    if (cur->smooth) {
      rt_stri(scene, textable[cur->texnum].tex, 
        vertex[cur->v0], vertex[cur->v1], vertex[cur->v2],
        normal[cur->v0], normal[cur->v1], normal[cur->v2]);
     
    }
    else {
      rt_tri(scene, textable[cur->texnum].tex, 
        vertex[cur->v0], vertex[cur->v1], vertex[cur->v2]);
    }

    cur = cur->next;
  }
}
コード例 #6
0
int NFFGetPatch(FILE *dfile, SceneHandle scene) {
  int numverts, i;
  apivector v0, n0;
  apivector vold, nold;
  apivector vnew, nnew;

  fscanf(dfile, "%d", &numverts); 
  NFFGetVector(dfile, &v0);
  NFFGetVector(dfile, &n0);
  NFFGetVector(dfile, &vold);
  NFFGetVector(dfile, &nold);

  for (i=2; i<numverts; i++) {
    NFFGetVector(dfile, &vnew);
    NFFGetVector(dfile, &nnew);
    rt_stri(scene, curtexture, v0, vold, vnew, n0, nold, nnew) ;
    vold = vnew;
    nold = nnew;
  } 

  return NFFNOERR;
}
コード例 #7
0
static void rt_sheightfield(void * tex, vector ctr, int m, int n, 
                    apiflt * field, apiflt wx, apiflt wy) {
  vector * vertices;
  vector * normals;
  vector offset;
  apiflt xinc, yinc;
  int x, y, addr; 
   
  vertices = (vector *) malloc(m*n*sizeof(vector));
  normals = (vector *) malloc(m*n*sizeof(vector));

  offset.x = ctr.x - (wx / 2.0);
  offset.y = ctr.z - (wy / 2.0);
  offset.z = ctr.y;

  xinc = wx / ((apiflt) m);
  yinc = wy / ((apiflt) n);

  /* build vertex list */
  for (y=0; y<n; y++) { 
    for (x=0; x<m; x++) {
      addr = y*m + x;
      vertices[addr] = rt_vector(
        x * xinc + offset.x,
        field[addr] + offset.z,
        y * yinc + offset.y);
    }
  }

  /* build normals from vertex list */
  for (x=1; x<m; x++) {
    normals[x] = normals[(n - 1)*m + x] = rt_vector(0.0, 1.0, 0.0);
  }
  for (y=1; y<n; y++) {
    normals[y*m] = normals[y*m + (m-1)] = rt_vector(0.0, 1.0, 0.0);
  }
  for (y=1; y<(n-1); y++) {
    for (x=1; x<(m-1); x++) {
      addr = y*m + x;

      normals[addr] = rt_vector(
        -(field[addr + 1] - field[addr - 1]) / (2.0 * xinc), 
        1.0, 
        -(field[addr + m] - field[addr - m]) / (2.0 * yinc));

      MyVNorm(&normals[addr]);
    }
  }    

  /* generate actual triangles */
  for (y=0; y<(n-1); y++) {
    for (x=0; x<(m-1); x++) {
      addr = y*m + x;

      rt_stri(tex, vertices[addr], vertices[addr + 1 + m], vertices[addr + 1],
                   normals[addr], normals[addr + 1 + m], normals[addr + 1]);
      rt_stri(tex, vertices[addr], vertices[addr + m], vertices[addr + 1 + m],
                   normals[addr], normals[addr + m], normals[addr + 1 + m]);
    }
  }

  free(normals);
  free(vertices);
} /* end of smoothed heightfield */