dms::Util

Source Code

Specification

#include <dms/Util.h>

void dms::checkGLError(const char *prefix);
void dms::drawString(char *s,void *font=GLUT_BITMAP_TIMES_ROMAN_24);
void dms::drawString(char *s,const Vector3& position,void *font=GLUT_BITMAP_TIMES_ROMAN_24);
void dms::drawString(char *s,const Vector2& position,void *font=GLUT_BITMAP_TIMES_ROMAN_24);
void dms::drawAxes(void);

float dms::currentTime(void);
void dms::beginFrame(void);
float dms::frameTime(void);
float dms::deltaTime(void);

void dms::computeNormal(const GLfloat *v0, const GLfloat *v1, const GLfloat *v2,
                   GLfloat *normal);
void dms::computeNormal(const Vector3& v0, const Vector3& v1, const Vector3& v2,
                   Vector3& normal);

GLfloat dms::degreesToRadians(GLfloat);
GLfloat dms::radiansToDegrees(GLfloat);

Description

void checkGLError(const char *prefix)

Checks the current OpenGL error flag. If the flag is set, the error string is printed to stdout, prefixed by the supplied string prefix.
Example:

dms::checkGLError("end-of-frame");
void drawString(char *s,void *font)
void drawString(char *s,const Vector2& position,void *font)
void drawString(char *s,const Vector3& position,void *font)

Draws a text string, using the function glutBitmapCharacter(). If a position argument is given, the string is drawn at that 2D or 3D position. The optional font argument is the GLUT font to use; options available include GLUT_BITMAP_8_BY_13, GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10, GLUT_BITMAP_TIMES_ROMAN_24, GLUT_BITMAP_HELVETICA_10, GLUT_BITMAP_HELVETICA_12, and GLUT_BITMAP_HELVETICA_18.
Example:

dms::Vector2 pos(0.3, 0.01);
dms::drawString("Subtitle", pos, GLUT_BITMAP_HELVETICA_10);
void drawAxes(void)

Draws the X/Y/Z coordinate axes as three lines, with labels.
Example:

glColor3f(1.0, 1.0, 1.0);
dms::drawAxes();
float currentTime(void)

Returns the current time, in seconds. When currentTime() is first called, its return value will be 0.
Example:

glRotatef(dms::currentTime()*30.0, 1.0, 0.0, 0.0);
void beginFrame(void)
float frameTime(void)
float deltaTime(void)

frameTime() returns the starting time for the current frame, in seconds. This time will be constant, throughout the course of drawing the frame, whereas the return value of currentTime() would vary slightly, each time it's called.
deltaTime() returns the number of seconds between the beginning of the previous frame and the beginning of the current frame. On the very first frame, its value will be 1.
beginFrame() must be called at the start of drawing each frame, in order for the new frameTime and deltaTime values to be computed and saved.
Example:

dms::Vector3 position;

void mydraw(void)
    {
    dms::beginFrame();
    ...
    dms::Vector3 velocity(0, 0, 2);
    position += velocity * dms::deltaTime();
void computeNormal(const GLfloat *v0, const GLfloat *v1, const GLfloat *v2,
                   GLfloat *normal)
void computeNormal(const Vector3& v0, const Vector3& v1, const Vector3& v2,
                   Vector3& normal)

Computes a unit-length normal vector for a triangle (or polygon) with the vertex positions v0, v1, and v2. The three vertices should be given in counter-clockwise order, for the normal to point in the correct direction.
Example:

dms::Vector3 a(0,0,0), b(1, 0, 0), c(1, 1, 0.5), normal;
dms::computeNormal(a,b,c,normal);
glNormal3fv(normal.vec);
float degreesToRadians(GLfloat angle)
float radiansToDegrees(GLfloat angle)

Converts an angle from degrees to radians, or vice versa. OpenGL and libdms functions expect angles in degrees, but standard math functions, such as sin(), expect angles in radians.
Example:

x = sin(dms::degreesToRadians(camera.yRotation()));