Mesh Class Reference

Mesh class. More...

#include <mesh.h>


Public Member Functions

 Mesh ()
 Constructor for mesh.
 ~Mesh ()
 Destructor for mesh.
void GenerateGrid (int resX, int resY, float x0, float x1, float y0, float y1, bool vertical)
 Generates a grid.
bool LoadHeightMap (const char *filename, float x0, float x1, float y0, float y1, float h0, float h1)
 Generate grid from heightmap texture.
void CreateVBO ()
 Creates a Vertex Buffer Object (VBO).
void DeleteVBO ()
 Deletes a Vertex Buffer Object (VBO).
void DrawOpenGL ()
 Draws the grid in OpenGL.
void DrawVBO ()
 Draws the grid as a Vertex Buffer Object (VBO).
unsigned int GetNumTriangles ()
 Calculates the number of triangles (faces) in the grid.

Data Fields

float hmin
float hmax

Private Member Functions

void m_AddVertex (float x, float y, float z, Vec3f &normal)
 Adds a vertex in the list of vertices.
void m_Clear ()
 Clears the vertex list and the face list.
void m_ReadHeight (int x, int z, float dx, float dz, float h0, float h1, unsigned char *data, int bytesPerPixel, int width, int height, float &h, Vec3f &n)
 Convert pixel values to a height value and a normal.

Private Attributes

int m_numVertices
int m_numFaces
GLfloat * m_vertArray
GLuint * m_faceArray
GLuint m_vertexVBO
GLuint m_indexVBO


Detailed Description

Mesh class.

Defines a horizontal or vertical grid. Support for VBO also included.


Constructor & Destructor Documentation

Mesh::Mesh (  ) 

Constructor for mesh.

Mesh::~Mesh (  ) 

Destructor for mesh.


Member Function Documentation

void Mesh::GenerateGrid ( int  resX,
int  resY,
float  x0,
float  x1,
float  y0,
float  y1,
bool  vertical 
)

Generates a grid.

Generates a rectangular grid between (x0,y0) and (x1,y1). If vertical is TRUE the grid will be in the xy-plane, otherwise it will be in the xz-plane.

Parameters:
resX the resolution in the x direction.
resY the resolution in the y(z) direction.
x0 the x component of the starting point.
x1 the x component of the ending point.
y0 the y component of the starting point.
y1 the y component of the ending point.
vertical decides if the grid is vertical or horizontal.
See also:
m_AddVertex()

bool Mesh::LoadHeightMap ( const char *  filename,
float  x0,
float  x1,
float  z0,
float  z1,
float  h0,
float  h1 
)

Generate grid from heightmap texture.

Load a TGA-image and create a mesh with the same resolution and set the gray-scale values as height.

Parameters:
filename filename
x0 x lower bound
x1 x upper bound
z0 z lower bound
z1 z upper bound
h0 y lower bound
h1 y upper bound
Returns:
TRUE if mesh is successfully loaded

void Mesh::CreateVBO (  ) 

Creates a Vertex Buffer Object (VBO).

void Mesh::DeleteVBO (  ) 

Deletes a Vertex Buffer Object (VBO).

void Mesh::DrawOpenGL (  ) 

Draws the grid in OpenGL.

void Mesh::DrawVBO (  ) 

Draws the grid as a Vertex Buffer Object (VBO).

unsigned int Mesh::GetNumTriangles (  ) 

Calculates the number of triangles (faces) in the grid.

Returns:
the number of triangles.

void Mesh::m_AddVertex ( float  x,
float  y,
float  z,
Vec3f normal 
) [private]

Adds a vertex in the list of vertices.

Parameters:
x x position
y y position
z z position
normal normal vector

void Mesh::m_Clear (  )  [private]

Clears the vertex list and the face list.

void Mesh::m_ReadHeight ( int  x,
int  z,
float  dx,
float  dz,
float  h0,
float  h1,
unsigned char *  data,
int  bytesPerPixel,
int  width,
int  height,
float &  h,
Vec3f n 
) [private]

Convert pixel values to a height value and a normal.

Parameters:
x x position
z z position
dx x scale
dz z scale
h0 lower bound for mesh
h1 upper bound for mesh
data pointer to pixel data
bytesPerPixel format of pixel data
width width of height texture
height height of height texture
h height at given point
n normal at given point


Field Documentation

float Mesh::hmin

float Mesh::hmax

int Mesh::m_numVertices [private]

Number of vertices

int Mesh::m_numFaces [private]

Number of triangles

GLfloat* Mesh::m_vertArray [private]

List of vertices

GLuint* Mesh::m_faceArray [private]

List of faces

GLuint Mesh::m_vertexVBO [private]

Identification for VBO

GLuint Mesh::m_indexVBO [private]

Identification for VBO


The documentation for this class was generated from the following files:
Generated on Thu May 17 20:28:04 2007 for Ocean View by  doxygen 1.5.2