Пример #1
0
bool IntersectFromTo(HitInfo_s &hi, float f[3], float t[3], map_s *map, unsigned int mask )
{
	float d[3], nd[3];
	vec3Sub( d, t, f );
	vec3Norm( nd, d );
	return IntersectRay( hi, f, nd, sqrtf(vec3Dot(d,d)), map, mask );
}
Пример #2
0
bool PlaneData::SetCorners(double *R, double *t, double f, int w, int h, int ymin, int ymax, int xmin, int xmax)
{
	if(xmax==-1)  xmax=w;
	if(ymax==-1)  ymax=h;
	if(xmax>w || ymax>h ||xmax<-1 || ymax<-1) printf("Error in bounding box data w=%d h=%d xmin=%d xmax=%d ymin=%d ymax=%d\n",w,h,xmin,xmax,ymin,ymax);
	//printf("xmin=%d xmax=%d ymin=%d ymax=%d\n",xmin,xmax,ymin,ymax);
    double Rt[9];
    matrix_transpose(3, 3, R, Rt);

    double center[3];
    matrix_product(3, 3, 3, 1, Rt, t, center);
    matrix_scale(3, 1, center, -1.0, center);

    /* Create rays for the four corners */
	//uncomment the follwing code to use the 4 image corners
    //double ray1[3] = { -0.5 * w, -0.5 * h, -f };
    //double ray2[3] = {  0.5 * w, -0.5 * h, -f };
    //double ray3[3] = {  0.5 * w,  0.5 * h, -f };
    //double ray4[3] = { -0.5 * w,  0.5 * h, -f };

	double ray1[3] = { xmin-0.5 * w, ymin-0.5 * h, -f };
	double ray2[3] = {  xmax-0.5 * w, ymin-0.5 * h, -f };
	double ray3[3] = {  xmax -0.5 * w,  ymax-0.5 * h, -f };
	double ray4[3] = {xmin -0.5 * w,  ymax - 0.5 * h, -f };

    double ray_world[18];
    matrix_product(3, 3, 3, 1, Rt, ray1, ray_world + 0);
    matrix_product(3, 3, 3, 1, Rt, ray2, ray_world + 3);
    matrix_product(3, 3, 3, 1, Rt, ray3, ray_world + 6);
    matrix_product(3, 3, 3, 1, Rt, ray4, ray_world + 9);

    double t0 = IntersectRay(center, ray_world + 0, m_corners + 0);
    double t1 = IntersectRay(center, ray_world + 3, m_corners + 3);
    double t2 = IntersectRay(center, ray_world + 6, m_corners + 6);
    double t3 = IntersectRay(center, ray_world + 9, m_corners + 9);

    if (t0 > 0.0 && t1 > 0.0 && t2 > 0.0 && t3 > 0.0)
        return true;
    else
        return false;
}
Пример #3
0
 bool GroupModel::IsInsideObject(const Vector3& pos, const Vector3& down, float& z_dist) const
 {
     if (!triangles.size() || !iBound.contains(pos))
         return false;
     GModelRayCallback callback(triangles, vertices);
     Vector3 rPos = pos - 0.1f * down;
     float dist = G3D::inf();
     G3D::Ray ray(rPos, down);
     bool hit = IntersectRay(ray, dist, false);
     if (hit)
         z_dist = dist - 0.1f;
     return hit;
 }
Пример #4
0
    bool GroupModel::IsInsideObject(const Vector3& pos, const Vector3& down, float& z_dist) const
    {
        if (triangles.empty() || !iBound.contains(pos))
            { return false; }

        Vector3 rPos = pos - 0.1f * down;
        float dist = G3D::inf();
        G3D::Ray ray(rPos, down);
        bool hit = IntersectRay(ray, dist, false);
        if (hit)
            { z_dist = dist - 0.1f; }
        return hit;
    }
Пример #5
0
void CPU_Worker::Intersect(RayBuffer *rayBuffer) {

    // Trace rays
    const Ray *rb = rayBuffer->GetRayBuffer();
    RayHit *hb = rayBuffer->GetHitBuffer();

    double start = WallClockTime();

#ifndef __DEBUG
    omp_set_num_threads(config->max_threads);
    #pragma omp parallel for schedule(guided)
#endif
    for (unsigned int i = 0; i < rayBuffer->GetRayCount(); ++i) {
        hb[i].SetMiss();
        IntersectRay(&rb[i], &hb[i]);
    }

    profiler->addRayTracingTime(WallClockTime() - start);
    profiler->addRaysTraced(rayBuffer->GetSize());

}