本文整理汇总了C++中QVector4D::normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector4D::normalize方法的具体用法?C++ QVector4D::normalize怎么用?C++ QVector4D::normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector4D
的用法示例。
在下文中一共展示了QVector4D::normalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trace
QVector3D WhittedRenderer::trace(const Ray& primaryRay, int depth, const QList<Shape*>& shapes, const QList<Light*>& lights)
{
double minDist = std::numeric_limits<double>::max();
Shape* closestShape = nullptr;
QVector3D shaded;
if (m_grid->intersect(primaryRay, closestShape, minDist)) {
auto material = closestShape->material();
shaded = material->ambientReflectivity() * m_ambientLightColor * material->colorVector();
QColor color = material ? material->color() : QColor(40, 40, 40);
QVector3D diffuseColor(color.redF(), color.greenF(), color.blueF());
QVector4D hitPoint = primaryRay.along(minDist);
QVector4D normalVector = closestShape->surfaceNormal(hitPoint, primaryRay);
QVector4D viewVector = -primaryRay.direction();
foreach(Light* light, lights) {
QVector3D emittance;
QVector4D lightVector;
light->sample(lightVector, emittance);
lightVector = lightVector - hitPoint;
float lightVectorLengthSquared = lightVector.lengthSquared();
float lightVectorLength = sqrt(lightVectorLengthSquared);
lightVector.normalize();
Ray shadowRay(hitPoint, lightVector);
double t;
Shape* blockingShape;
bool shadowRayHit = m_grid->intersect(shadowRay, blockingShape, t);
if (!shadowRayHit || (shadowRayHit && (lightVectorLengthSquared < t * t))) {
// Diffuse
float dot = fmax(0.0f, QVector4D::dotProduct(lightVector, normalVector)) * material->diffuseReflectivity();
emittance *= 1 / (1 + 0.2 * lightVectorLength + 0.08 * lightVectorLengthSquared);
shaded += dot * QVector3D(emittance.x() * diffuseColor.x(),
emittance.y() * diffuseColor.y(),
emittance.z() * diffuseColor.z());
// Specular
if (material->specularReflectivity() > 0.0) {
QVector4D reflectedLightVector = MathUtils::reflect(-lightVector, normalVector); // lightVector and normalVector are already normalized
float dot = QVector4D::dotProduct(reflectedLightVector, viewVector);
if (dot > 0.0)
shaded += material->specularReflectivity() * pow(dot, material->shininess()) * emittance;
}
}
}