Cheetah Software  1.0
Checkerboard Class Reference

#include <Checkerboard.h>

+ Collaboration diagram for Checkerboard:

Public Member Functions

 Checkerboard (float xSize, float ySize, size_t xSquares, size_t ySquares)
 
void setDarkColor (const float *dark)
 
void setLightColor (const float *light)
 
const float * getSize ()
 
void computeVertices (std::vector< float > &vertices, std::vector< float > &normals, std::vector< float > &colors)
 

Private Attributes

const float * _darkColor = checkerboardDark
 
const float * _lightColor = checkerboardLight
 
float _size [2]
 
size_t _squares [2]
 

Detailed Description

Definition at line 15 of file Checkerboard.h.

Constructor & Destructor Documentation

Checkerboard::Checkerboard ( float  xSize,
float  ySize,
size_t  xSquares,
size_t  ySquares 
)

Construct a new checkerboard at the origin

Parameters
xSize: width, meters
ySize: height, meters
xSquares: number of squares along x (must be at least 1)
ySquares: number of squares along y (must be at least 2)

Definition at line 17 of file Checkerboard.cpp.

References _size, and _squares.

18  {
19  _size[0] = xSize;
20  _size[1] = ySize;
21  _squares[0] = xSquares;
22  _squares[1] = ySquares;
23  // computeVertices();
24 }
size_t _squares[2]
Definition: Checkerboard.h:43
float _size[2]
Definition: Checkerboard.h:42

Member Function Documentation

void Checkerboard::computeVertices ( std::vector< float > &  vertices,
std::vector< float > &  normals,
std::vector< float > &  colors 
)

Update the checkerboard vertices for the current sizees

Definition at line 29 of file Checkerboard.cpp.

References _darkColor, _lightColor, _size, and _squares.

31  {
32  // 3 channels, n*m squares, 2 triangles, 3 vertices per triangle
33  size_t dataSize = 3 * _squares[0] * _squares[1] * 3 * 2;
34  vertices.clear();
35  normals.clear();
36  colors.clear();
37  vertices.reserve(dataSize);
38  normals.reserve(dataSize);
39  colors.reserve(dataSize);
40 
41  const float xStep = _size[0] / (float)_squares[0];
42  const float yStep = _size[1] / (float)_squares[1];
43 
44  for (size_t i = 0; i < _squares[0]; i++) {
45  for (size_t j = 0; j < _squares[1]; j++) {
46  // add normals and color
47  const float* squareColor = (i + j) % 2 ? _darkColor : _lightColor;
48  for (size_t k = 0; k < 6; k++) {
49  for (size_t m = 0; m < 3; m++) {
50  colors.push_back(squareColor[m]);
51  normals.push_back(m == 2 ? 1 : 0);
52  }
53  }
54 
55  const float xStart = xStep * i;
56  const float yStart = yStep * j;
57 
58  // tri 1
59  vertices.push_back(xStart);
60  vertices.push_back(yStart);
61  vertices.push_back(0);
62 
63  vertices.push_back(xStart);
64  vertices.push_back(yStart + yStep);
65  vertices.push_back(0);
66 
67  vertices.push_back(xStart + xStep);
68  vertices.push_back(yStart);
69  vertices.push_back(0);
70 
71  // tri 2
72  vertices.push_back(xStart);
73  vertices.push_back(yStart + yStep);
74  vertices.push_back(0);
75 
76  vertices.push_back(xStart + xStep);
77  vertices.push_back(yStart + yStep);
78  vertices.push_back(0);
79 
80  vertices.push_back(xStart + xStep);
81  vertices.push_back(yStart);
82  vertices.push_back(0);
83  }
84  }
85 }
const float * _lightColor
Definition: Checkerboard.h:41
size_t _squares[2]
Definition: Checkerboard.h:43
float _size[2]
Definition: Checkerboard.h:42
const float * _darkColor
Definition: Checkerboard.h:40

+ Here is the caller graph for this function:

const float* Checkerboard::getSize ( )
inline

Get an array of x,y size (in the plane's coordinates, meters)

Definition at line 34 of file Checkerboard.h.

References _size, and computeVertices().

34 { return _size; }
float _size[2]
Definition: Checkerboard.h:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Checkerboard::setDarkColor ( const float *  dark)
inline

Set the color of the dark squares Do this before computeVertices

Definition at line 23 of file Checkerboard.h.

References _darkColor.

23 { _darkColor = dark; }
const float * _darkColor
Definition: Checkerboard.h:40
void Checkerboard::setLightColor ( const float *  light)
inline

Set the color of the light squares Do this before computeVertices

Definition at line 29 of file Checkerboard.h.

References _lightColor.

29 { _lightColor = light; }
const float * _lightColor
Definition: Checkerboard.h:41

Member Data Documentation

const float* Checkerboard::_darkColor = checkerboardDark
private

Definition at line 40 of file Checkerboard.h.

const float* Checkerboard::_lightColor = checkerboardLight
private

Definition at line 41 of file Checkerboard.h.

float Checkerboard::_size[2]
private

Definition at line 42 of file Checkerboard.h.

size_t Checkerboard::_squares[2]
private

Definition at line 43 of file Checkerboard.h.


The documentation for this class was generated from the following files: