本文整理汇总了C++中Ray::getInvDirection方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::getInvDirection方法的具体用法?C++ Ray::getInvDirection怎么用?C++ Ray::getInvDirection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ray
的用法示例。
在下文中一共展示了Ray::getInvDirection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/** Test for an intersection between a ray and this box
* @param
* ray The ray to test against intersection
* @return
* bool True if intersection is found, false otherwise
*/
bool Box3::intersect(const Ray& ray) const
{
float tMin, tMax, tyMin, tyMax, tzMin, tzMax;
tMin = (_bounds[ray.getSign()[0]].getX() - ray.getOrigin().getX()) * ray.getInvDirection().getX();
tMax = (_bounds[1 - ray.getSign()[0]].getX() - ray.getOrigin().getX()) * ray.getInvDirection().getX();
tyMin = (_bounds[ray.getSign()[1]].getY() - ray.getOrigin().getY()) * ray.getInvDirection().getY();
tyMax = (_bounds[1 - ray.getSign()[1]].getY() - ray.getOrigin().getY()) * ray.getInvDirection().getY();
// Check x and y bounds
if((tMin > tyMax) || (tyMin > tMax))
{
return false;
}
// Calculate tMin and tMax
if(tyMin > tMin)
{
tMin = tyMin;
}
if(tyMax < tMax)
{
tMax = tyMax;
}
// Calculate tzmin and max
tzMin = (_bounds[ray.getSign()[2]].getZ() - ray.getOrigin().getZ()) * ray.getInvDirection().getZ();
tzMax = (_bounds[1 - ray.getSign()[2]].getZ() - ray.getOrigin().getZ()) * ray.getInvDirection().getZ();
if((tMin > tzMax) || (tzMin > tMax))
{
return false;
}
// Calculate new tMin and tMax
if(tzMin > tMin)
{
tMin = tzMin;
}
if(tzMax < tMax)
{
tMax = tzMax;
}
// Check tMin and tMax against the ray's distances
if(tMin > ray.getTMin())
{
ray.setTMin(tMin);
}
if(tMax < ray.getTMax())
{
ray.setTMax(tMax);
}
return true;
}
示例2: IntersectP
bool BoundingBox::IntersectP(const Ray & ray)
{
//shadow ray and reflected ray returns false mistakenly
//probably because they are in the box
Vector3f pos(ray.getStartPosition());
Vector3f inv_dir(ray.getInvDirection());
float tx1 = (min_pos.x() - pos.x())*inv_dir.x();
float tx2 = (max_pos.x() - pos.x())*inv_dir.x();
float tmin = min(tx1, tx2);
float tmax = max(tx1, tx2);
float ty1 = (min_pos.y() - pos.y())*inv_dir.y();
float ty2 = (max_pos.y() - pos.y())*inv_dir.y();
tmin = max(tmin, min(ty1, ty2));
tmax = min(tmax, max(ty1, ty2));
//TODO, t should >0
if (tmax >= tmin)
{
float tz1 = (min_pos.z() - pos.z())*inv_dir.z();
float tz2 = (max_pos.z() - pos.z())*inv_dir.z();
tmin = max(tmin, min(tz1, tz2));
tmax = min(tmax, max(tz1, tz2));
//To confirm?? tmax>0
if(tmax >= tmin && tmax > 0)
{
//the line of ray will intersect
//but maybe the t < 0
return true;
}
}
return false;
//Vector3f dir(ray.getDirection());
//Vector3f inv_dir(ray.getInvDirection());
//float tx1 = (min_pos.x() - dir.x())*inv_dir.x();
//float tx2 = (max_pos.x() - dir.x())*inv_dir.x();
//float tmin = min(tx1, tx2);
//float tmax = max(tx1, tx2);
//float ty1 = (min_pos.y() - dir.y())*inv_dir.y();
//float ty2 = (max_pos.y() - dir.y())*inv_dir.y();
//tmin = max(tmin, min(ty1, ty2));
//tmax = min(tmax, max(ty1, ty2));
////TODO, t should >0
//if (tmax >= tmin)
//{
// float tz1 = (min_pos.z() - dir.z())*inv_dir.z();
// float tz2 = (max_pos.z() - dir.z())*inv_dir.z();
// tmin = max(tmin, min(tz1, tz2));
// tmax = min(tmax, max(tz1, tz2));
// if(tmax >= tmin)
// {
// //the line of ray will intersect
// //but maybe the t < 0
// //TODO
// return true;
// }
//}
//return false;
//.........这里部分代码省略.........