Declaring Attribute Primitives

[ LiB ]

Declaring Attribute Primitives

The data in each class can come in many forms. For example, element 1 in the list can be a number, element 2 can be a color attribute, and element 3 can be a vector. To read in the attributes of a class, you must declare a list of attribute read methods. Here is the list of methods you need:

  • Read vector reads in a vector in the following format: <0,0,0>.

  • Read scalar reads a number in as a floating point number (1.34334).

  • Read color reads in a color in the following format: (red, green, blue).

  • Read comma flags a new data element is listed (,).

Here are the function prototypes and code:

 // Attribute primitives cVector3    Read_Vector(ifstream& is); float       Read_Scalar(ifstream& is); color3      Read_Color (ifstream& is); void        Read_Comma (ifstream& is); 

Setting Up the Read Vector Method

The read vector method reads in a vector in the following format <0,0,0> . It uses the stream object to break up and extract the numbers into the cVector3 class.

 cVector3 cScene::Read_Vector(ifstream& is) {    char dummy;    cVector3 r;    // <0,0,0>    is >> dummy;    is >> r.x;    is >> dummy;    is >> r.y;    is >> dummy;    is >> r.z;    is >> dummy;    return r; } 

Setting Up the Read Scalar Method

The read scalar method reads in a scalar in the following format 23, 88.3, or 100. It uses the stream object to load an ASCII number into a float variable.

 float     cScene::Read_Scalar(ifstream& is) {    float  r;    // 256    is >> r;    return r; } 

Setting Up the Read Color Method

The read color method reads in a color in the following format (244, 45, 1). It uses the stream object to break up and extract the ASCII numbers into the color3 class.

 color3   cScene::Read_Color (ifstream& is) {    char dummy;    color3 r;    // (255,0,0)    is >> dummy;    is >> r.r;    is >> dummy;    is >> r.g;    is >> dummy;    is >> r.b;    is >> dummy;    return r; } 

Setting Up the Read Comma Method

The read comma method tells the stream object to keep pumping in data until it passes a slash (/) or to ignore all characters in the stream buffer that include a comma. This method is used to skip statements containing brackets and parentheses when parsing the scene definition file for class elements.

 void  cScene::Read_Comma (ifstream& is) {    char p;    // read {    is >>   p;    // if the letter { wasn't found find it    while(p !=   ',')       is >> p; } 

[ LiB ]


Focus On Photon Mapping
Focus On Photon Mapping (Premier Press Game Development)
ISBN: 1592000088
EAN: 2147483647
Year: 2005
Pages: 128
Authors: Marlon John

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net