Graphics Reference
In-Depth Information
a superset of C and can be compiled directly as native (nonmanaged) C#. For all
of these reasons, and because there is a significant tools and library ecosystem
built for it, C++ happens to be the dominant language for implementing renderers
today. Thus, our choice is consistent with showing you how renderers are really
implemented.
Note that many hardware APIs also have wrappers for higher-level languages,
provided by either the API vendor or third parties. Once you are familiar with
the basic functionality, we suggest that it may be more productive to use such a
wrapper for extensive software development on a hardware API.
15.3.2 Utility Classes
This chapter assumes the existence of obvious utility classes, such as those
sketched in Listing 15.4. For these, you can use equivalents of the WPF classes,
the Direct3D API versions, the built-in GLSL, Cg, and HLSL shading language
versions, or the ones in G3D, or you can simply write your own. Following com-
mon practice, the Vector3 and Color3 classes denote the axes over which a
quantity varies, but not its units. For example, Vector3 always denotes three spa-
tial axes but may represent a unitless direction vector at one code location and a
position in meters at another. We use a type alias to at least distinguish points from
vectors (which are differences of points).
Listing 15.4: Utility classes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define INFINITY (numeric_limits< float >::infinity())
... };
class Vector2 { public : float x, y;
... };
class Vector3 { public : float x, y, z;
typedef Vector2 Point2 ;
typedef Vector3 Point3 ;
class Color3 { public : float r, g, b;
... };
class Radiance3 Color3 ;
class Power3 Color3 ;
class Ray {
private :
Point3 m_origin;
Vector3 m_direction;
public :
Ray ( const Point3 & org, const Vector3 & dir) :
m_origin(org), m_direction(dir) {}
const Point3 & origin() const { return m_origin; }
const Vector3 & direction() const { return m_direction; }
...
};
Observe that some classes, such as Vector3 , expose their representation
through public member variables, while others, such as Ray , have a stronger
abstraction that protects the internal representation behind methods. The exposed
classes are the workhorses of computer graphics. Invoking methods to access their
fields would add significant syntactic distraction to the implementation of any
function. Since the byte layouts of these classes must be known and fixed to inter-
act directly with hardware APIs, they cannot be strong abstractions and it makes
 
 
 
 
Search WWH ::




Custom Search