本文整理汇总了C++中ray::get_direction方法的典型用法代码示例。如果您正苦于以下问题:C++ ray::get_direction方法的具体用法?C++ ray::get_direction怎么用?C++ ray::get_direction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ray
的用法示例。
在下文中一共展示了ray::get_direction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
bool triangle::intersect(ray const& Ray, intersection& Intersection) const
{
glm::vec3 w = Ray.get_position() - A;
glm::vec3 u = -(B - A);
glm::vec3 v = -(C - A);
float D = glm::dot(glm::cross(u, v), Ray.get_direction());
float a = -glm::dot(glm::cross(w, v), Ray.get_direction()) / D;
float b = -glm::dot(glm::cross(u, w), Ray.get_direction()) / D;
float t = glm::dot(glm::cross(u, v), w) / D;
if(a > 0.0f && b > 0.0f && a + b < 1.0)
return true;
return false;
}
示例2: intersect
bool plane::intersect(ray const& Ray, intersection& Intersection) const
{
bool hit = false;
if(glm::abs(Ray.get_direction().z) > 0.0f)
{
float t = -Ray.get_position().z / Ray.get_direction().z;
if(t > glm::epsilon<float>() * 100.f)
{
Intersection.set_local_position(Ray.get_position() + Ray.get_direction() * t);
hit = true;
}
}
return hit;
}
示例3: intersects
bool bounding_box::intersects(const ray & ray, intersection_data & out) const
{
float distance_max = std::numeric_limits<float>::max();
const box & aabb = bounding_box::get_box();
const point & min = aabb.get_min();
const point & max = aabb.get_max();
const float epsilon = 0.01f;
for (int i = 0; i < 3; i++)
{
if (std::abs(ray.get_direction()[i]) < epsilon)
{
if (ray.get_origin()[i] < min[i] || ray.get_origin()[i] > max[i])
return false;
}
else
{
float ood = 1.0f / ray.get_direction()[i];
float t1 = (min[i] - ray.get_origin()[i]) * ood;
float t2 = (max[i] - ray.get_origin()[i]) * ood;
if (t1 > t2) std::swap(t1, t2);
if (t1 > out.distance) out.distance = t1;
if (t2 > distance_max) distance_max = t2;
if (out.distance > distance_max)
return false;
}
}
out.coordinates = ray.get_origin() + float3(ray.get_direction());
out.coordinates = out.coordinates * out.distance;
return true;
}