本文整理汇总了C++中vec_t::distance_sqrd方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_t::distance_sqrd方法的具体用法?C++ vec_t::distance_sqrd怎么用?C++ vec_t::distance_sqrd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_t
的用法示例。
在下文中一共展示了vec_t::distance_sqrd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: click
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;
}
}