Rube Goldberg Machine 1.0
This is the base code for Rube Goldberg designed for the CS296 Software Systems Lab
|
This class implements debug drawing callbacks that are invoked inside b2World::Step. More...
#include <render.hpp>
Public Member Functions | |
void | DrawPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color) |
void | DrawSolidPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color) |
void | DrawCircle (const b2Vec2 ¢er, float32 radius, const b2Color &color) |
void | DrawSolidCircle (const b2Vec2 ¢er, float32 radius, const b2Vec2 &axis, const b2Color &color) |
void | DrawSegment (const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color) |
void | DrawTransform (const b2Transform &xf) |
void | DrawPoint (const b2Vec2 &p, float32 size, const b2Color &color) |
void | DrawString (int x, int y, const char *string,...) |
void | DrawAABB (b2AABB *aabb, const b2Color &color) |
This class implements debug drawing callbacks that are invoked inside b2World::Step.
Definition at line 35 of file render.hpp.
void debug_draw_t::DrawAABB | ( | b2AABB * | aabb, |
const b2Color & | color | ||
) |
Definition at line 195 of file render.cpp.
{ glColor3f(c.r, c.g, c.b); glBegin(GL_LINE_LOOP); glVertex2f(aabb->lowerBound.x, aabb->lowerBound.y); glVertex2f(aabb->upperBound.x, aabb->lowerBound.y); glVertex2f(aabb->upperBound.x, aabb->upperBound.y); glVertex2f(aabb->lowerBound.x, aabb->upperBound.y); glEnd(); }
void debug_draw_t::DrawCircle | ( | const b2Vec2 & | center, |
float32 | radius, | ||
const b2Color & | color | ||
) |
Definition at line 72 of file render.cpp.
{ const float32 k_segments = 16.0f; const float32 k_increment = 2.0f * b2_pi / k_segments; float32 theta = 0.0f; glColor3f(color.r, color.g, color.b); glBegin(GL_LINE_LOOP); for (int32 i = 0; i < k_segments; ++i) { b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); glVertex2f(v.x, v.y); theta += k_increment; } glEnd(); }
void debug_draw_t::DrawPoint | ( | const b2Vec2 & | p, |
float32 | size, | ||
const b2Color & | color | ||
) |
Definition at line 152 of file render.cpp.
{ glPointSize(size); glBegin(GL_POINTS); glColor3f(color.r, color.g, color.b); glVertex2f(p.x, p.y); glEnd(); glPointSize(1.0f); }
void debug_draw_t::DrawPolygon | ( | const b2Vec2 * | vertices, |
int32 | vertexCount, | ||
const b2Color & | color | ||
) |
Definition at line 39 of file render.cpp.
{
glColor3f(color.r, color.g, color.b);
glBegin(GL_LINE_LOOP);
for (int32 i = 0; i < vertexCount; ++i)
{
glVertex2f(vertices[i].x, vertices[i].y);
}
glEnd();
}
void debug_draw_t::DrawSegment | ( | const b2Vec2 & | p1, |
const b2Vec2 & | p2, | ||
const b2Color & | color | ||
) |
Definition at line 124 of file render.cpp.
{ glColor3f(color.r, color.g, color.b); glBegin(GL_LINES); glVertex2f(p1.x, p1.y); glVertex2f(p2.x, p2.y); glEnd(); }
void debug_draw_t::DrawSolidCircle | ( | const b2Vec2 & | center, |
float32 | radius, | ||
const b2Vec2 & | axis, | ||
const b2Color & | color | ||
) |
Definition at line 88 of file render.cpp.
{ const float32 k_segments = 16.0f; const float32 k_increment = 2.0f * b2_pi / k_segments; float32 theta = 0.0f; glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f); glBegin(GL_TRIANGLE_FAN); for (int32 i = 0; i < k_segments; ++i) { b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); glVertex2f(v.x, v.y); theta += k_increment; } glEnd(); glDisable(GL_BLEND); theta = 0.0f; glColor4f(color.r, color.g, color.b, 1.0f); glBegin(GL_LINE_LOOP); for (int32 i = 0; i < k_segments; ++i) { b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta)); glVertex2f(v.x, v.y); theta += k_increment; } glEnd(); b2Vec2 p = center + radius * axis; glBegin(GL_LINES); glVertex2f(center.x, center.y); glVertex2f(p.x, p.y); glEnd(); }
void debug_draw_t::DrawSolidPolygon | ( | const b2Vec2 * | vertices, |
int32 | vertexCount, | ||
const b2Color & | color | ||
) |
Definition at line 50 of file render.cpp.
{ glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f); glBegin(GL_TRIANGLE_FAN); for (int32 i = 0; i < vertexCount; ++i) { glVertex2f(vertices[i].x, vertices[i].y); } glEnd(); glDisable(GL_BLEND); glColor4f(color.r, color.g, color.b, 1.0f); glBegin(GL_LINE_LOOP); for (int32 i = 0; i < vertexCount; ++i) { glVertex2f(vertices[i].x, vertices[i].y); } glEnd(); }
void debug_draw_t::DrawString | ( | int | x, |
int | y, | ||
const char * | string, | ||
... | |||
) |
Definition at line 162 of file render.cpp.
{ char buffer[128]; va_list arg; va_start(arg, string); vsprintf(buffer, string, arg); va_end(arg); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); int w = glutGet(GLUT_WINDOW_WIDTH); int h = glutGet(GLUT_WINDOW_HEIGHT); gluOrtho2D(0, w, h, 0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glColor3f(0.9f, 0.6f, 0.6f); glRasterPos2i(x, y); int32 length = (int32)strlen(buffer); for (int32 i = 0; i < length; ++i) { glutBitmapCharacter(GLUT_BITMAP_8_BY_13, buffer[i]); } glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); }
void debug_draw_t::DrawTransform | ( | const b2Transform & | xf | ) |
Definition at line 133 of file render.cpp.
{
b2Vec2 p1 = xf.p, p2;
const float32 k_axisScale = 0.4f;
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(p1.x, p1.y);
p2 = p1 + k_axisScale * xf.q.GetXAxis();
glVertex2f(p2.x, p2.y);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(p1.x, p1.y);
p2 = p1 + k_axisScale * xf.q.GetYAxis();
glVertex2f(p2.x, p2.y);
glEnd();
}