예제 #1
0
void click(float x,float y) {
    uint64_t start = high_precision_time();
    const float
    unit_x = (2.0f*(x/screen->w))-1.0f,
    unit_y = 1.0f-(y/screen->h);
#if 0
    const vec_t near(world()->unproject(vec_t(unit_x,unit_y,-1))),
          far(world()->unproject(vec_t(unit_x,unit_y,1)));
#else
    GLint vp[4];
    double p[16], mv[16], a,b,c,d,e,f;
    glGetIntegerv(GL_VIEWPORT,vp);
    glGetDoublev(GL_PROJECTION_MATRIX,p);
    glGetDoublev(GL_MODELVIEW_MATRIX,mv);
    gluUnProject(x,screen->h-y,0,mv,p,vp,&a,&b,&c);
    gluUnProject(x,screen->h-y,1,mv,p,vp,&d,&e,&f);
    const vec_t near(a,b,c), far(d,e,f);
#endif
    ray = ray_t(near,far-near);
    std::cout << std::endl << "(" << x << "," << y << ") (" << unit_x << ',' << unit_y << ") " << ray << std::endl;
    world_t::hits_t hits;
    world()->intersection(ray,~0,hits);
    uint64_t ns = high_precision_time()-start;
    std::cout << std::endl << "click(" << x << "," << y << ") (" << unit_x << ',' << unit_y << ") " << ray << " (" << ns << " ns) "<<hits.size()<< std::endl;
    selection = false;
    for(world_t::hits_t::iterator i=hits.begin(); i!=hits.end(); i++) {
        vec_t pt;
        start = high_precision_time();
        bool hit = i->obj->refine_intersection(ray,pt);
        ns = high_precision_time()-start;
        if(hit) {
            std::cout << "hit " << pt << " ";
            if(!selection ||
                    (pt.distance_sqrd(ray.o)<selected_point.distance_sqrd(ray.o))) {
                selection = true;
                selected_point = pt;
                std::cout << "BEST ";
            }
        } else
            std::cout << "miss ";
        std::cout << *i << " (" << ns << " ns)" << std::endl;
    }
    if(selection) std::cout << "SELECTION: " << selected_point << std::endl;
    // the slow way
    if(terrain()) {
        terrain_t::test_hits_t test;
        start = high_precision_time();
        terrain()->intersection(ray,test);
        ns = high_precision_time()-start;
        std::cout << "(slow check: " << ns << " ns)" << std::endl;
        for(terrain_t::test_hits_t::iterator i=test.begin(); i!=test.end(); i++)
            std::cout << "TEST " <<
                      (i->obj->sphere_t::intersects(ray)?"+":"-") <<
                      (i->obj->aabb_t::intersects(ray)?"+":"-") <<
                      *i->obj << i->hit << std::endl;
        vec_t surface;
        if(selection && terrain()->surface_at(selected_point,surface))
            std::cout << "(surface_at " << surface << " - " << selected_point << " = " << (selected_point-surface) << ")" << std::endl;
    }
}
예제 #2
0
third_person_cam::vec_t third_person_cam::calc_ideal_position(vec_t const& player_pos, orient_t const& player_orient) const
{
	vec_t player_dir = player_orient * vec_t(0, 0, 1);
	return vec_t(
		player_pos[0] - player_dir[0] * 0.4f,
		player_pos[1] - player_dir[1] * 0.4f,
		player_pos[2] - player_dir[2] * 0.4f
		);
}
예제 #3
0
    void read_vertex () {
        int number;
        is >> number;

        // vertex number is terminated by colon
        is >> std::ws;
        int colon;
        if ((colon = is.get ()) != ':')
            format_error ("expected colon, got %c", colon);

        // coords
        double x, y, z;
        is >> x >> y >> z;

        // rest of record (i.e. attributes) is ignored for now
        ignore_rest_of_line ();

        // z coordinate is ignored
        int vert_id = b->insert_vertex (vec_t (x, y));

        // saved for later reference
        if ((int)vertex_map.size () <= number) {
            vertex_map.resize (number + 1, Boundary::INVALID_VERTEX);
        }
        vertex_map[number] = vert_id;
    }
예제 #4
0
파일: table_man.cpp 프로젝트: llersch/zapps
w_rc_t table_man_t<T>::add_tuple(ss_m* db,
                                 table_row_t* ptuple,
                                 const lock_mode_t /* lock_mode */,
                                 const lpid_t& /* primary_root */)
{
    assert (_ptable);
    assert (ptuple);
    assert (ptuple->_rep);
    assert (ptuple->_rep_key);
    // uint32_t system_mode = _ptable->get_pd();

    // figure out what mode will be used
    // bool bIgnoreLocks = false;
    // if (lock_mode==NL) bIgnoreLocks = true;

    index_desc_t* pindex = _ptable->primary_idx();

    // build tuple data without index fields
    size_t tsz = ptuple->_rep->_bufsz;
    ptuple->store_value(ptuple->_rep->_dest, tsz, pindex);
    assert (ptuple->_rep->_dest); // if NULL invalid

    // build key data
    w_keystr_t kstr;
    size_t ksz = ptuple->_rep_key->_bufsz;
    ptuple->store_key(ptuple->_rep_key->_dest, ksz, pindex);
    kstr.construct_regularkey(ptuple->_rep_key->_dest, ksz);

    W_DO(db->create_assoc(pindex->stid(), kstr, vec_t(ptuple->_rep->_dest, tsz)));

    // update the indexes
    const std::vector<index_desc_t*>& indexes = _ptable->get_indexes();
    for (size_t i = 0; i < indexes.size(); i++) {
        size_t sec_ksz = ptuple->_rep->_bufsz;
        ptuple->store_key(ptuple->_rep->_dest, sec_ksz, indexes[i]);
        w_keystr_t sec_kstr;
        sec_kstr.construct_regularkey(ptuple->_rep->_dest, sec_ksz);

        // primary key value (i.e., pointer) is stored in _rep_key
        W_DO(db->create_assoc(indexes[i]->stid(),
                              sec_kstr,
                              vec_t(ptuple->_rep_key->_dest, ksz)
                             ));
    }
    return (RCOK);
}
예제 #5
0
 test_t(): object_t(UNIT), age(MIN_AGE+(rand()%(MAX_AGE-MIN_AGE))),
     r(128+(rand()%128)), g(128+(rand()%128)), b(128+(rand()%128)),
     rx(randf()), ry(randf()), rz(randf()),
     dir(randf(),randf(),randf()),
     drawn(false)
 {
     bounds_include(vec_t(0,0,0));
     bounds_include(vec_t(SZ*2,SZ*2,SZ*2));
     bounds_fix();
     bounds_include(bounding_box().a);
     bounds_include(bounding_box().b);
     bounds_fix();
     set_pos(vec_t(randf()-MARGIN,randf()-MARGIN,randf()-MARGIN));
     world()->add(this);
     dir.normalise();
     dir *= SPEED;
 }
예제 #6
0
static void caret(const vec_t& pos,float scale,float rx,float ry,float rz,bool mark=false) {
    glPushMatrix();
    glTranslatef(pos.x,pos.y,pos.z);
    glScalef(scale,scale,scale);
    if(rx) glRotatef(360.0/rx,1,0,0);
    if(ry) glRotatef(360.0/ry,0,1,0);
    if(rz) glRotatef(360.0/rz,0,0,1);
    bounds_t box(vec_t(-1,-1,-1),vec_t(1,1,1));
    if(!mark && model.get()) {
        model->draw(0);
        box = model->get_bounds();
    }
    if(!mark)
        glColor4ub(0xff,0xff,0xff,0x15);
    draw_cube(box);
    glPopMatrix();
    return;
}
예제 #7
0
파일: table_man.cpp 프로젝트: llersch/zapps
w_rc_t table_man_t<T>::add_index_entry(ss_m* db,
                                       const char* idx_name,
                                       table_row_t* ptuple,
                                       const lock_mode_t /* lock_mode */,
                                       const lpid_t& /* primary_root */)
{
    assert (_ptable);
    assert (ptuple);
    assert (ptuple->_rep);

    // get the index
    index_desc_t* pindex = _ptable->find_index(idx_name);
    assert (pindex);

    // if (!ptuple->is_rid_valid()) return RC(se_NO_CURRENT_TUPLE);

    // uint32_t system_mode = _ptable->get_pd();

    // figure out what mode will be used
    // bool bIgnoreLocks = false;
    // if (lock_mode==NL) bIgnoreLocks = true;

    // build primary key value (i.e., pointer)
    size_t ksz = ptuple->_rep_key->_bufsz;
    ptuple->store_key(ptuple->_rep_key->_dest, ksz,
                      ptuple->_ptable->primary_idx());

    // update the index
    size_t sec_ksz = ptuple->_rep->_bufsz;
    ptuple->store_key(ptuple->_rep->_dest, ksz, pindex);
    w_keystr_t sec_kstr;
    sec_kstr.construct_regularkey(ptuple->_rep->_dest, sec_ksz);
    W_DO(db->create_assoc(pindex->stid(),
                          sec_kstr,
                          vec_t(ptuple->_rep_key->_dest, ksz)
                         ));

    return (RCOK);
}
예제 #8
0
w_rc_t table_desc_t::create_physical_index(ss_m* db, index_desc_t* index)
{
    // Create all the indexes of the table
    stid_t stid = stid_t::null;

    W_DO(db->create_index(_vid, stid));
    w_assert0(index);
    index->set_stid(stid);

    // Add entry on catalog
    w_keystr_t kstr;
    kstr.construct_regularkey(index->name().c_str(), index->name().length());
    W_DO(db->create_assoc(get_catalog_stid(), kstr,
                vec_t(&stid, sizeof(stid_t))));

    // Print info
    TRACE( TRACE_STATISTICS, "%s %d (%s) (%s) (%s)\n",
           index->name().c_str(), stid.store,
           (index->is_latchless() ? "no latch" : "latch"),
           (index->is_relaxed() ? "relaxed" : "no relaxed"),
           (index->is_unique() ? "unique" : "no unique"));

    return (RCOK);
}
예제 #9
0
const vec_t operator / (const vec_t & _u, long double _c) {
  return vec_t(_u) /= _c;
}
예제 #10
0
int main(int argc, char *argv[])
{
	model_t		model;		// model (the world)
	std::ifstream	model_ifs;	// input file stream
	atd::timer_t	timer;

  if(argc != 2) {
    std::cerr << "Usage " << argv[0] << " <model_file>" << std::endl;
    return 1;
  }

  // open file, read in model
  model_ifs.open(argv[1],std::ifstream::in);
  model_ifs >> model;
  model_ifs.close();

  // debugging
  std::cerr << model;

	int		tid,ncores=1;
	int		w=model.getpixel_w(), h=model.getpixel_h();
	int		chunk;
	double		wx,wy,wz=0.0;
	double		ww=model.getworld_w(), wh=model.getworld_h();
	vec_t		pos=model.getviewpoint();
	vec_t		pix,dir;
	ray_t		*ray=NULL;
	rgb_t<double>	color;
	rgb_t<uchar>	*imgloc,*img=NULL;

  img = new rgb_t<uchar>[w*h];
  memset(img,0,3*w*h);

  // figure out how many threads we have available, then calculate chunk,
  // splitting up the work as evenly as possible
  #pragma omp parallel private(tid)
  {
    if((tid = omp_get_thread_num())==0)
      ncores = omp_get_num_threads();
  }
  chunk = h/ncores;

  timer.start();

// two statements...
//#pragma omp parallel \
//          shared(model,w,h,ww,wh,wz,pos,img) \
//          private(tid,wx,wy,pix,dir,ray,color,imgloc)
//#pragma omp for schedule(static,chunk)

// ...or all-in-one
  #pragma omp parallel for \
            shared(model,w,h,ww,wh,wz,pos,img) \
            private(tid,wx,wy,pix,dir,ray,color,imgloc) \
            schedule(static,chunk)
  for(int y=h-1;y>=0;y--) {
    for(int x=0;x<w;x++) {
      wx = (double)x/(double)(w-1) * ww;
      wy = (double)y/(double)(h-1) * wh;

      // set pixel position vector (in world coordinates)
      pix = vec_t(wx,wy,wz);

      // compute the vector difference  v3 = v2 - v1
      dir = pix - pos;

      // our ray is now {pos, dir} (in world coordinates), normalize dir
      dir = dir.norm();

      // zero out color
      color.zero();

      // spawn new ray
      ray = new ray_t(pos,dir);

      // trace ray
      ray->trace(model, color, 0);

      // nuke this ray, we don't need it anymore, prevent memory leak
      delete ray;

      // where are we in the image (using old i*c + j)
      imgloc = img + y*w + x;

      // scale pixel by maxval, store at dereferenced image location
      for(int i=0;i<3;i++) (*imgloc)[i] = static_cast<uchar>(255.0 * color[i]);
    }
  }
  timer.end();

  std::cerr << "cores: " << ncores << ", ";
  std::cerr << "time: " << timer.elapsed_ms() << " ms" << std::endl;

  // output image
  std::cout << "P6 " << w << " " << h << " " << 255 << std::endl;
  for(int y=h-1;y>=0;y--) {
    for(int x=0;x<w;x++) {
      imgloc = img + y*w + x;
      std::cout.write((char *)imgloc,3);
    }
  }

  return 0;
}
예제 #11
0
파일: util.cpp 프로젝트: mapleyustat/papaya
Boundary::vec_t Boundary::edge_normal (Boundary::edge_iterator it) const {
    vec_t tmp = vertex(it->vert1);
    tmp -= vertex(it->vert0);
    tmp /= tmp.norm ();
    return vec_t (tmp[1], -tmp[0]);
}
예제 #12
0
const vec_t operator + (const vec_t & _u, const vec_t & _v) {
  return vec_t(_u) += _v;
}
예제 #13
0
const vec_t operator - (const vec_t & _u) {
  return vec_t(-_u.x, -_u.y);
}
예제 #14
0
    }
    void draw(float) {
        drawn = true;
    }
    bool refine_intersection(const ray_t&, vec_t& I) {
        I = centre;
        return true;
    }
    int age;
    const uint8_t r,g,b;
    const float rx, ry, rz;
    vec_t dir;
    bool drawn;
};
const float test_t::SZ = 0.05, test_t::MARGIN = test_t::SZ*2, test_t::SPEED = 0.01;
bounds_t test_t::legal(vec_t(-1.0+MARGIN,-1.0+MARGIN,-1.0+MARGIN),
                       vec_t(1.0-MARGIN,1.0-MARGIN,1.0-MARGIN));
typedef std::vector<test_t*> tests_t;
tests_t objs;

void ui() {
    glColor3f(1,1,1);
    if(selection) {
        glDisable(GL_DEPTH_TEST);
        glColor3f(1,0,0);
        caret(selected_point,0.03,0,0,0,true);
        glEnable(GL_DEPTH_TEST);
    }
    // draw logo
    if(logo.get()) {
        glPushMatrix();
예제 #15
0
const lrot(const vec_t & _u) {
  return vec_t(-_u.y, _u.x);
}
예제 #16
0
third_person_cam::orient_t third_person_cam::calc_ideal_orientation(vec_t const& player_pos, orient_t const& player_orient) const
{
	vec_t ideal_pos = calc_ideal_position(player_pos, player_orient);

	return lookat_orientation((player_pos - ideal_pos).normalized(), player_orient * vec_t(0, 1, 0));
}
예제 #17
0
const vec_t operator * (long double _c, const vec_t & _v) {
  return vec_t(_v) *= _c;
}
예제 #18
0
const vec_t operator - (const vec_t & _u, const vec_t & _v) {
  return vec_t(_u) -= _v;
}