INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
rt::Renderer Struct Reference

This structure takes care of rendering a scene. More...

#include <Renderer.h>

Public Member Functions

 Renderer (Scene &scene)
 
void setScene (rt::Scene &aScene)
 
void setViewBox (Point3 origin, Vector3 dirUL, Vector3 dirUR, Vector3 dirLL, Vector3 dirLR)
 
void setResolution (int width, int height)
 
void render (Image2D< Color > &image, int max_depth)
 The main rendering routine.
 
Color trace (const Ray &ray)
 

Public Attributes

SceneptrScene
 The scene to render.
 
Point3 myOrigin
 The origin of the camera in space.
 
Vector3 myDirUL
 
Vector3 myDirUR
 
Vector3 myDirLL
 
Vector3 myDirLR
 
int myWidth
 
int myHeight
 

Detailed Description

This structure takes care of rendering a scene.

Definition at line 49 of file Renderer.h.

Constructor & Destructor Documentation

◆ Renderer() [1/2]

rt::Renderer::Renderer ( )
inline

Definition at line 71 of file Renderer.h.

71: ptrScene( 0 ) {}
Scene * ptrScene
The scene to render.
Definition Renderer.h:52

◆ Renderer() [2/2]

rt::Renderer::Renderer ( Scene scene)
inline

Definition at line 72 of file Renderer.h.

72: ptrScene( &scene ) {}

Member Function Documentation

◆ render()

void rt::Renderer::render ( Image2D< Color > &  image,
int  max_depth 
)
inline

The main rendering routine.

Definition at line 93 of file Renderer.h.

94 {
95 std::cout << "Rendering into image ... might take a while." << std::endl;
96 image = Image2D<Color>( myWidth, myHeight );
97 for ( int y = 0; y < myHeight; ++y )
98 {
99 Real ty = (Real) y / (Real)(myHeight-1);
100 progressBar( std::cout, ty, 1.0 );
101 Vector3 dirL = (1.0f - ty) * myDirUL + ty * myDirLL;
102 Vector3 dirR = (1.0f - ty) * myDirUR + ty * myDirLR;
103 dirL /= dirL.norm();
104 dirR /= dirR.norm();
105 for ( int x = 0; x < myWidth; ++x )
106 {
107 Real tx = (Real) x / (Real)(myWidth-1);
108 Vector3 dir = (1.0f - tx) * dirL + tx * dirR;
109 Ray eye_ray = Ray( myOrigin, dir, max_depth );
110 Color result = trace( eye_ray );
111 image.at( x, y ) = result.clamp();
112 }
113 }
114 std::cout << "Done." << std::endl;
115 }
float Real
the type for representing a real number.
PointVector< Real, 3 > Vector3
The type for representing a 3d point.
Vector3 myDirUR
Definition Renderer.h:60
Vector3 myDirUL
Definition Renderer.h:57
Vector3 myDirLL
Definition Renderer.h:63
Color trace(const Ray &ray)
Definition Renderer.h:120
Vector3 myDirLR
Definition Renderer.h:66
Point3 myOrigin
The origin of the camera in space.
Definition Renderer.h:54

◆ setResolution()

void rt::Renderer::setResolution ( int  width,
int  height 
)
inline

Definition at line 85 of file Renderer.h.

86 {
87 myWidth = width;
88 myHeight = height;
89 }

◆ setScene()

void rt::Renderer::setScene ( rt::Scene aScene)
inline

Definition at line 73 of file Renderer.h.

73{ ptrScene = &aScene; }

◆ setViewBox()

void rt::Renderer::setViewBox ( Point3  origin,
Vector3  dirUL,
Vector3  dirUR,
Vector3  dirLL,
Vector3  dirLR 
)
inline

Definition at line 75 of file Renderer.h.

77 {
78 myOrigin = origin;
79 myDirUL = dirUL;
80 myDirUR = dirUR;
81 myDirLL = dirLL;
82 myDirLR = dirLR;
83 }

◆ trace()

Color rt::Renderer::trace ( const Ray ray)
inline

The rendering routine for one ray.

Returns
the color for the given ray.

Definition at line 120 of file Renderer.h.

121 {
122 assert( ptrScene != 0 );
123 Color result = Color( 0.0, 0.0, 0.0 );
124 GraphicalObject* obj_i = 0; // pointer to intersected object
125 Point3 p_i; // point of intersection
126
127 // Look for intersection in this direction.
128 Real ri = ptrScene->rayIntersection( ray, obj_i, p_i );
129 // Nothing was intersected
130 if ( ri >= 0.0f ) return result; // some background color
131 return Color( 1.0, 1.0, 1.0 );
132 }
PointVector< Real, 3 > Point3
The type for representing a 3d vector;.
Real rayIntersection(const Ray &ray, GraphicalObject *&object, Point3 &p)
Definition Scene.h:93

Member Data Documentation

◆ myDirLL

Vector3 rt::Renderer::myDirLL

(myOrigin, myOrigin+myDirLL) forms a ray going through the lower-left corner pixel of the viewport, i.e. pixel (0,height)

Definition at line 63 of file Renderer.h.

◆ myDirLR

Vector3 rt::Renderer::myDirLR

(myOrigin, myOrigin+myDirLR) forms a ray going through the lower-right corner pixel of the viewport, i.e. pixel (width,height)

Definition at line 66 of file Renderer.h.

◆ myDirUL

Vector3 rt::Renderer::myDirUL

(myOrigin, myOrigin+myDirUL) forms a ray going through the upper-left corner pixel of the viewport, i.e. pixel (0,0)

Definition at line 57 of file Renderer.h.

◆ myDirUR

Vector3 rt::Renderer::myDirUR

(myOrigin, myOrigin+myDirUR) forms a ray going through the upper-right corner pixel of the viewport, i.e. pixel (width,0)

Definition at line 60 of file Renderer.h.

◆ myHeight

int rt::Renderer::myHeight

Definition at line 69 of file Renderer.h.

◆ myOrigin

Point3 rt::Renderer::myOrigin

The origin of the camera in space.

Definition at line 54 of file Renderer.h.

◆ myWidth

int rt::Renderer::myWidth

Definition at line 68 of file Renderer.h.

◆ ptrScene

Scene* rt::Renderer::ptrScene

The scene to render.

Definition at line 52 of file Renderer.h.


The documentation for this struct was generated from the following file: