本文整理汇总了C++中Hit::setTexCoord方法的典型用法代码示例。如果您正苦于以下问题:C++ Hit::setTexCoord方法的具体用法?C++ Hit::setTexCoord怎么用?C++ Hit::setTexCoord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hit
的用法示例。
在下文中一共展示了Hit::setTexCoord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
bool Triangle::intersect( const Ray& r , Hit& h , float tmin){
Vector3f R_o = r.getOrigin();
Vector3f R_d = r.getDirection();
Matrix3f A( this->a.x()-this->b.x() , this->a.x()-this->c.x() , R_d.x() ,
this->a.y()-this->b.y() , this->a.y()-this->c.y() , R_d.y() ,
this->a.z()-this->b.z() , this->a.z()-this->c.z() , R_d.z() );
Matrix3f BetaM( this->a.x()-R_o.x() , this->a.x()-this->c.x() , R_d.x() ,
this->a.y()-R_o.y() , this->a.y()-this->c.y() , R_d.y() ,
this->a.z()-R_o.z() , this->a.z()-this->c.z() , R_d.z() );
float beta = BetaM.determinant() / A.determinant();
Matrix3f GammaM( this->a.x()-this->b.x() , this->a.x()-R_o.x() , R_d.x() ,
this->a.y()-this->b.y() , this->a.y()-R_o.y() , R_d.y() ,
this->a.z()-this->b.z() , this->a.z()-R_o.z() , R_d.z() );
float gamma = GammaM.determinant() / A.determinant();
float alpha = 1.0f - beta - gamma;
Matrix3f tM( this->a.x()-this->b.x() , this->a.x()-this->c.x() , this->a.x()-R_o.x() ,
this->a.y()-this->b.y() , this->a.y()-this->c.y() , this->a.y()-R_o.y() ,
this->a.z()-this->b.z() , this->a.z()-this->c.z() , this->a.z()-R_o.z() );
float t = tM.determinant() / A.determinant();
if (beta + gamma > 1){
return false;
}
if (beta < 0){
return false;
}
if (gamma < 0){
return false;
}
if (t > tmin && t < h.getT()){
Vector3f newNormal = (alpha*this->normals[0] + beta*this->normals[1] + gamma*this->normals[2]).normalized();
h.set(t, this->material, newNormal);
Vector2f newTexCoord = (alpha*this->texCoords[0] + beta*this->texCoords[1] + gamma*this->texCoords[2]);
h.setTexCoord(newTexCoord);
return true;
}
else{
return false;
}
}
示例2: intersect
bool Triangle::intersect(const Ray& ray, Hit& hit, float tmin)
{
Vector3f direction = ray.getDirection();
Vector3f origin = ray.getOrigin();
float list[9] = { (a.x()) - (b.x()),(a.y()) - (b.y()),(a.z()) - (b.z()), (a.x()) - (c.x()),(a.y()) - (c.y()),(a.z()) - (c.z()), (a[0]) - (origin[0]),(a[1]) - (origin[1]),(a[2]) - (origin[2]), };
Matrix3f A = Matrix3f(list[0], list[3], direction[0], list[1], list[4], direction[1], list[2], list[5], direction[2]);
float determinant = A.determinant();
if (determinant == 0) { return false; }
float t = Matrix3f::determinant3x3(list[0], list[3], list[6], list[1], list[4], list[7], list[2], list[5], list[8]) / determinant;
if (t <= tmin || t >= hit.getT()) { return false; }
float beta = Matrix3f::determinant3x3(list[6], list[3], direction[0], list[7], list[4], direction[1], list[8], list[5], direction[2]) / determinant;
float gamma = Matrix3f::determinant3x3(list[0], list[6], direction[0], list[1], list[7], direction[1], list[2], list[8], direction[2]) / determinant;
if ((beta >= 0 && gamma >= 0 && beta + gamma <= 1) )
{
if(hasTex)
{
hit.hasTex = true; hit.setTexCoord((1 - beta - gamma)*texCoords[0] + beta*texCoords[1] + gamma*texCoords[2]);
}
hit.set(t, this->material, ((1-beta-gamma)*normals[0]+beta*normals[1]+gamma*normals[2]).normalized());
return true;
}
return false;
}