Ray direction refers to the direction in which a ray is pointed. In computer graphics, rays are used in rendering techniques such as ray tracing and path tracing to simulate the behavior of light in a scene. The direction of a ray is typically defined by a 3D vector representing its x, y, and z components.
Here are some code examples in C++ using the ray direction vector:
// Define a ray pointing in the positive x-direction Vector3 rayDir = Vector3(1, 0, 0);
// Normalize the ray direction vector to ensure it has unit length rayDir.normalize();
// Compute the reflected direction of a ray off a surface normal Vector3 reflectDir = (rayDir - 2 * surfaceNormal.dot(rayDir) * surfaceNormal).normalized();
// Compute the refracted direction of a ray passing through a transparent material float eta = 1.5; // Index of refraction of material float cosThetaI = dot(-rayDir, surfaceNormal); float sinThetaI = sqrt(1 - cosThetaI * cosThetaI); float sinThetaT = eta * sinThetaI; float cosThetaT = sqrt(1 - sinThetaT * sinThetaT); Vector3 refractDir = eta * rayDir + (eta * cosThetaI - cosThetaT) * surfaceNormal;
These examples use a Vector3 class to represent 3D vectors and include operations such as normalization, dot product, and reflection/refraction calculation. The package/library used for these examples is not specified as it could be custom-made or from a number of existing libraries such as the Eigen library or glm library.
C++ (Cpp) ray::direction - 7 examples found. These are the top rated real world C++ (Cpp) examples of ray::direction extracted from open source projects. You can rate examples to help us improve the quality of examples.