コード例 #1
0
ファイル: scene.cpp プロジェクト: dminor/raytrace
static int plane(lua_State *ls)
{
    if (!lua_istable(ls, -1)) {
        luaL_error(ls, "plane: expected table");
    }

    double pt_x, pt_y, pt_z;
    lua_getfield(ls, -1, "pt");
    get_xyz(ls, pt_x, pt_y, pt_z);
    lua_pop(ls, 1);

    double norm_x, norm_y, norm_z;
    lua_getfield(ls, -1, "norm");
    get_xyz(ls, norm_x, norm_y, norm_z);
    lua_pop(ls, 1);


    lua_getfield(ls, -1, "material");
    Material *mat = reinterpret_cast<Material *>(lua_touserdata(ls, -1));
    lua_pop(ls, 1);

    Plane *plane = new Plane;
    plane->p.x = pt_x; plane->p.y = pt_y; plane->p.z = pt_z;
    plane->normal.x = norm_x; plane->normal.y = norm_y; plane->normal.z = norm_z;
    plane->material.reset(mat);
    lua_pushlightuserdata(ls, plane);

    return 1;
}
コード例 #2
0
ファイル: scene.cpp プロジェクト: dminor/raytrace
static int transform(lua_State *ls)
{
    if (!lua_istable(ls, -1)) {
        luaL_error(ls, "transform: expected table");
    }

    double x, y, z;
    lua_getfield(ls, -1, "translation");
    get_xyz(ls, x, y, z);
    lua_pop(ls, 1);

    //rotations -- we loop over these and multiply them together
    Quat rotation;
    lua_getfield(ls, -1, "rotation");
    lua_pushnil(ls);
    while (lua_next(ls, -2)) {
        std::unique_ptr<Quat> q(reinterpret_cast<Quat *>(lua_touserdata(ls, -1)));
        lua_pop(ls, 1);
        rotation = rotation * *q;
    }
    lua_pop(ls, 1);

    lua_getfield(ls, -1, "child");
    Intersectable *child = reinterpret_cast<Intersectable *>(lua_touserdata(ls, -1));
    lua_pop(ls, 1);

    Transform *transform = new Transform;
    transform->translation.x = x; transform->translation.y = y; transform->translation.z = z;
    transform->rotation = rotation;
    transform->child = child;

    lua_pushlightuserdata(ls, transform);

    return 1;
}
コード例 #3
0
ファイル: scene.cpp プロジェクト: dminor/raytrace
static int sphere(lua_State *ls)
{
    if (!lua_istable(ls, -1)) {
        luaL_error(ls, "sphere: expected table");
    }

    double x, y, z;
    lua_getfield(ls, -1, "centre");
    get_xyz(ls, x, y, z);
    lua_pop(ls, 1);

    lua_getfield(ls, -1, "radius");
    double radius = luaL_checknumber(ls, -1);
    lua_pop(ls, 1);

    lua_getfield(ls, -1, "material");
    Material *mat = reinterpret_cast<Material *>(lua_touserdata(ls, -1));
    lua_pop(ls, 1);

    Sphere *sphere = new Sphere;
    sphere->centre.x = x; sphere->centre.y = y; sphere->centre.z = z;
    sphere->radius = radius;
    sphere->material.reset(mat);
    lua_pushlightuserdata(ls, sphere);

    return 1;
}
コード例 #4
0
ファイル: main.c プロジェクト: wangjun0710/bloodhound
unsigned char ADXL345_Work(RecordData *Xdata,RecordData *Ydata,RecordData *Zdata)
{
      devid=Single_Read_ADXL345(0X00);	//读出的数据为0XE5,表示正确
      if(devid!=0XE5)
      {		
         
          return FALSE;
      }
      else
      {			
             
                err = 0;
                Multiple_read_ADXL345();       	//连续读出数据,存储在BUF中  
                if (err == 1)
                {
                     
                    return FALSE;
                }
                else
                {
                    get_xyz(Xdata,Ydata,Zdata);                      //原5次采样取最大的数值
                    Dis_ADXL345_Data(Xdata);
                    return TRUE;
                }
            
      }  
  
}
コード例 #5
0
ファイル: compvacuum.C プロジェクト: Eigenstate/vmd-python
void AtomGrid::store(char* fname)
{
  FILE* outf = fopen(fname,"w");
  if (outf == NULL) {
    printf("Couldn't open file %s\n",fname);
    exit(-1);
  }
  
  int k;
  for(k=0;k < nc; k++) {
    int i;
    for(i=0; i < na; i++) {
      int j;
      for(j=0; j < nb; j++) {
        if (!get(i,j,k)) {
          Vector3D v = get_xyz(i,j,k);
          if (fprintf(outf,"%f %f %f\n",v.x,v.y,v.z) < 0) {
            printf("Store grid error %s\n",fname);
            exit(-2);
          }
        }
      }
    }
  }
    
  fclose(outf);
  return;
}
コード例 #6
0
ファイル: scene.cpp プロジェクト: dminor/raytrace
static int trimesh(lua_State *ls)
{
    if (!lua_istable(ls, -1)) {
        luaL_error(ls, "trimesh: expected table");
    }

    std::vector<Vec> vertices;
    lua_getfield(ls, -1, "vertices");
    lua_pushnil(ls);
    while (lua_next(ls, -2) != 0) {
        double x, y, z;
        get_xyz(ls, x, y, z);
        vertices.push_back(Vec{x, y, z});
        lua_pop(ls, 1);
    }
    lua_pop(ls, 1);

    std::vector<TriangleMesh::Face> faces;
    lua_getfield(ls, -1, "faces");
    lua_pushnil(ls);
    while (lua_next(ls, -2) != 0) {
        size_t i, j, k;
        lua_getfield(ls, -1, "i");
        i = static_cast<size_t>(luaL_checknumber(ls, -1));
        lua_pop(ls, 1);

        lua_getfield(ls, -1, "j");
        j = static_cast<size_t>(luaL_checknumber(ls, -1));
        lua_pop(ls, 1);

        lua_getfield(ls, -1, "k");
        k = static_cast<size_t>(luaL_checknumber(ls, -1));
        lua_pop(ls, 1);

        Vec ab = vertices[j] - vertices[i];
        Vec ac = vertices[k] - vertices[i];
        Vec norm = ab.cross(ac);
        norm.normalize();

        faces.push_back(TriangleMesh::Face{i, j, k, norm});
        lua_pop(ls, 1);
    }
    lua_pop(ls, 1);

    lua_getfield(ls, -1, "material");
    Material *mat = reinterpret_cast<Material *>(lua_touserdata(ls, -1));
    lua_pop(ls, 1);

    TriangleMesh *tm = new TriangleMesh;
    tm->faces = std::move(faces);
    tm->vertices = std::move(vertices);
    tm->material.reset(mat);

    lua_pushlightuserdata(ls, tm);

    return 1;
}
コード例 #7
0
ファイル: scene.cpp プロジェクト: dminor/raytrace
static int quat(lua_State *ls)
{
    if (!lua_istable(ls, -1)) {
        luaL_error(ls, "quat: expected table");
    }

    lua_getfield(ls, -1, "angle");
    double angle = luaL_checknumber(ls, -1);
    lua_pop(ls, 1);

    double x, y, z;
    get_xyz(ls, x, y, z);

    Quat *quat = new Quat(angle, x, y, z);
    lua_pushlightuserdata(ls, quat);

    return 1;
}
コード例 #8
0
 Vector3D wrap_xyz(const Vector3D xyz) const
 {
    Vector3D gridcoord = get_ijk(xyz);
    gridcoord.x = fmod(gridcoord.x,na);
    if (gridcoord.x < 0)
       gridcoord.x += na;
    gridcoord.y = fmod(gridcoord.y,nb);
    if (gridcoord.y < 0)
       gridcoord.y += nb;
    gridcoord.z = fmod(gridcoord.z,nc);
    if (gridcoord.z < 0)
       gridcoord.z += nc;
    
    const Vector3D ret = get_xyz(gridcoord);
    //    if (gc2.x != gridcoord.x || gc2.y != gridcoord.y || gc2.z != gridcoord.z) {
    //      printf("gc2 %f %f %f grid %f %f %f ret %f %f %f\n",
    //        gc2.x,gc2.y,gc2.z,gridcoord.x,
    //        gridcoord.y,gridcoord.z,ret.x,ret.y,ret.z);
    //    }
    return ret;
 }
コード例 #9
0
ファイル: compvacuum.C プロジェクト: Eigenstate/vmd-python
void AtomGrid::build(const MolData* mdata)
{
  Vector3D corner[8];

  // Fill the grid
  // Find the bounding box for the atom radius
  Vector3D bb = findAtomBox(mdata->getRadius());
  
  const int imax = (int)ceil(bb.x);
  const int jmax = (int)ceil(bb.y);
  const int kmax = (int)ceil(bb.z);

  printf("Box=%d, %d, %d\n",imax,jmax,kmax);
  const double rsq = mdata->getRadius() * mdata->getRadius();
  int atomi;
  for(atomi=0; atomi<mdata->count; atomi++) {
    Vector3D atom = mdata->coords[atomi].coord;
//    std::cout << "Checking atom " << atomi << "(" << atom.x << "," << atom.y << "," << atom.z <<std::endl;
    Vector3D atomijk = get_ijk(atom);
    const int ai = (int)atomijk.x;
    const int aj = (int)atomijk.y;
    const int ak = (int)atomijk.z;
    int i;
    for(i=ai-imax; i <= ai+imax; i++) {
      int ii = i;
      if (i < 0)
        ii += na;
      else if (i >= na)
        ii -= na;
      int j;
      for(j=aj-jmax; j <= aj+jmax; j++) {
        int jj = j;
        if (j < 0)
          jj += nb;
        else if (j >= nb)
          jj -= nb;
        // Do the positive half of the loop. Stop once we get to
        // the first cell that is outside the boundary
        int k;
        for(k=0; k <= kmax; k++) {
          int k_no_wrap = ak+k;
          int kk = k_no_wrap;
          if (k_no_wrap < 0)
            kk += nc;
          else if (k_no_wrap >= nc)
            kk -= nc;

          // If cell is already filled, just continue
          if (get(ii,jj,kk))
            continue;

          const Vector3D v = get_xyz(i,j,k_no_wrap);
          const Vector3D dv = v - atom;
          if (dv.length2() <= rsq) {
            set(ii,jj,kk);
          } else {
            break;
          }
        }
        for(k=1; k <= kmax; k++) {
          int k_no_wrap = ak-k;
          int kk = k_no_wrap;
          if (k_no_wrap < 0)
            kk += nc;
          else if (k_no_wrap >= nc)
            kk -= nc;

          // If cell is already filled, just continue
          if (get(ii,jj,kk))
            continue;

          const Vector3D v = get_xyz(i,j,k_no_wrap);
          const Vector3D dv = v - atom;
          if (dv.length2() <= rsq) {
            set(ii,jj,kk);
          } else {
            break;
          }
        }
      }
    }
  }
  return;
}