Projects Inventory

Ray Tracing Gaming Project in C++

Explanation

  1. Vec3 Structure:
    • Vec3 is a structure representing a 3D vector with x, y, and z components. It includes various vector operations such as addition, subtraction, scalar multiplication, dot product, length, and normalization.
  2. Ray Structure:
    • The Ray structure represents a ray with an origin and a direction. The direction is normalized to ensure it’s a unit vector. The pointAtParameter()
      Advertisement
      function returns the point along the ray at distance t.
  3. Sphere Structure:
    • The Sphere structure defines a sphere with a center and a radius. The intersect() function checks if a given ray intersects with the sphere. It uses the quadratic formula to solve for the intersection points. If the discriminant is positive, there is an intersection, and the function returns true
      Advertisement
      with the intersection distance t.
  4. Main Function:
    • In the main() function, a sphere is defined at position (0, 0, -5) with a radius of 1. A ray is defined starting at (0, 0, 0) (camera position) and pointing in the negative z-direction. The program checks if the ray intersects with the sphere and prints the intersection point if it exists.
Exit mobile version