Exemplo n.º 1
0
float rayIntersectDisk(ShadeRec* sr, Disk* disk, const Ray ray)
{
    vec3 displacement;
    vec3_sub(displacement, disk->center, ray.origin);
    float t = vec3_dot(displacement, disk->normal) / vec3_dot(ray.direction, disk->normal);
    if(t > K_EPSILON)
    {
        vec3 hit_point;
        getPointOnRay(hit_point, ray, t);
        vec3_sub(displacement, hit_point, disk->center);
        if(vec3_length(displacement) <= disk->radius)
        {
            vec3_negate(sr->wo, ray.direction);
            if(vec3_dot(sr->wo, disk->normal) < 0)
            {
                vec3_negate(sr->wo, disk->normal);
            }else
            {
                vec3_copy(sr->normal, disk->normal);
            }
            vec3_copy(sr->hit_point, hit_point);
            sr->mat = *(disk->mat);
            return t;
        }
    }
    return TMAX;
}
Exemplo n.º 2
0
Vector Ray::nearestPointOnZAxis(Vector Origin) const
{
	Origin[3] = 0;
	float t = nearestTOnZAxis(Origin);
	Vector result = getPointOnRay(t);
	// project to axis
	result[0] = Origin[0];
	result[1] = Origin[1];
	return result;
}
Exemplo n.º 3
0
float shadowRayIntersectDisk(const Disk* disk, const Ray ray)
{
    vec3 displacement;
    vec3_sub(displacement, disk->center, ray.origin);
    float t = vec3_dot(displacement, disk->normal) / vec3_dot(ray.direction, disk->normal);
    if(t > K_EPSILON)
    {
        vec3 hit_point;
        getPointOnRay(hit_point, ray, t);        
        vec3_sub(displacement, hit_point, disk->center);
        if(vec3_length(displacement) <= disk->radius)
        {
            return t;
        }
    }
    return TMAX;
}