示例#1
0
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;
}
示例#2
0
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;
}