Point *findIntersectionPoint(Ray ray, Sphere sphere) { Vector sphereToRay = fromToVector(sphere.center, ray.point); double a = dotVector(ray.direction, ray.direction); double b = dotVector(scaleVector(sphereToRay, 2.0), ray.direction); double c = dotVector(sphereToRay, sphereToRay) - sphere.radius * sphere.radius; double determinant = b * b - 4 * a * c; if (determinant >= 0) { double root1 = (-b + sqrt(determinant)) / (2.0 * a); double root2 = (-b - sqrt(determinant)) / (2.0 * a); if (root1 >= 0 && root2 >= 0) { return findPointFromRoot(min(root1, root2), ray); } else if (root1 >= 0 || root2 >= 0) { return findPointFromRoot(max(root1, root2), ray); } return (Point *) NULL; } return (Point *) NULL; }
Color shadeWithMaterial(struct Scene* scene, struct HitRecord* record, Ray ray, int depth) { Color result = {0,0,0}; Material material = *record->triangle->material; struct HitRecord temp_record = createHitRecord(); Vector position = record->point; Vector new_direction; if(depth == scene->max_depth) { return result; } if(material.is_light) { return material.color; } Vector normal = record->triangle->normal; float costheta = dotVector(normal, ray.direction); if(costheta > 0) { normal = negateVector(normal); } float path = (double)rand()/(double)RAND_MAX; // diffuse BRDF if(path < .33) { new_direction = getDiffuseDirection(normal); } // BRDF (which is also diffuse) else if(path < .66) { new_direction = getDiffuseDirection(normal); } // point to light else { new_direction = getLightDirection(scene, position); } Ray new_ray = {position, new_direction}; resetHitRecord(&temp_record); float cosphi = dotVector(normal, new_direction); if(cosphi > 0) { result = addColors(result, multiplyColorByNumber(hitScene(scene, &temp_record, new_ray, depth + 1), cosphi)); } return multiplyColors(result, material.color); }
void QgsDxfExport::writeDefaultLinestyles() { double das = dashSize(); double dos = dotSize(); double dss = dashSeparatorSize(); //continuous (Qt solid line) writeGroup( 0, "LTYPE" ); writeGroup( 2, "CONTINUOUS" ); writeGroup( 70, 64 ); writeGroup( 3, "Defaultstyle" ); writeGroup( 72, 65 ); writeGroup( 73, 0 ); writeGroup( 40, 0.0 ); QVector<qreal> dashVector( 2 ); dashVector[0] = das; dashVector[1] = dss; writeLinestyle( "DASH", dashVector, QgsSymbolV2::MapUnit ); QVector<qreal> dotVector( 2 ); dotVector[0] = dos; dotVector[1] = dss; writeLinestyle( "DOT", dotVector, QgsSymbolV2::MapUnit ); QVector<qreal> dashDotVector( 4 ); dashDotVector[0] = das; dashDotVector[1] = dss; dashDotVector[2] = dos; dashDotVector[3] = dss; writeLinestyle( "DASHDOT", dashDotVector, QgsSymbolV2::MapUnit ); QVector<qreal> dashDotDotVector( 6 ); dashDotDotVector[0] = das; dashDotDotVector[1] = dss; dashDotDotVector[2] = dos; dashDotDotVector[3] = dss; dashDotDotVector[4] = dos; dashDotDotVector[5] = dss; writeLinestyle( "DASHDOTDOT", dashDotDotVector, QgsSymbolV2::MapUnit ); }
double normVector(Vector3 a) { return sqrt(dotVector(a, a)); }