}
void rotate2D(double angle)
{
glMatrixMode(GL_MODELVIEW); glRotated(angle. 0.0. 0.0. 1.0):
}
void translate2D(double dx. double dy)
{
glMatrixMode(GL MODELVIEW): glTranslatedtdx. dy. 0.0);
}
void scale2D(double sx. double sy) {
glMatrixMode(GL MODELVIEW): glScaled(sx. sy. 1.0):
}
void pushCT(void) {
glMatrixMode(GL_MODELVIEW): glPushMatrix();
}
void popCT(void) {
glMatrixMode(GL MODELVIEW); glPopMatrix();
}
void ngon(int n. float ex. float cy, float radius):
}:
#endif
// end of graphics2d.h

// конец файла graphics2d.h

// graphics2d.cpp - use #include "graphics2d.h"

// graphics2d.cpp - используется #include "graphics2d.h" Приложение В. Некоторые полезные классы и служебные подпрограммы

// Some methods for the classes defined in graphics2d.h // Некоторые методы для классов. // определенных в graphics2d.h #include "graphics2d.h"

Canvas :: Canvas(int width, int height, char* title) {

char* list: // dummy list for glutlnit // пустой список для glutlnit

int numArgs - 1: // dummy value for glutlnit // пустая величина для glutlnit

glutlnitC&numArgs, &list):
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB):
glutlnitWindowSize(width. height):
glutlnitWindowPositiondOO. 100):

glutCreateWindow(title): CP.x - СР.у - 0.0: windowAspect - 1.0:

}
void Canvas :: setWindowCfloat 1. float r. float b. float t) {
g1 Mat rі xMode(GL_PR0J ECTI0N): glLoadldentityO:
glu0rtho2D((GLdouble)l. (GLdouble)r. (GLdouble)b. (GLdouble)t): іf(t - b) return: windowAspect = (r - l)/(t - b):
}
void Canvas :: setViewportCint 1, int r. int b, int t) {glViewport((GLint)l. (GLint)b. (GLint)Cr-l), (GLint){t-b)):} void Canvas :: lineTo(float x. float y) {
glBegin(GL_LINES):

glVertex2f((GLfloat)CP.x. (GLfloat)CP.y): CP.x - x: СР.у - у:

glVertex2f((GLf1 oat)CP.x, (GLfloat)CP.y): glEndO: glFlushO:
}
void Canvas :: forward(float dist. int vis) {

#define RadPerDeg 0.017453393 // radians per degree // радиан на градус

float x - CP.x + dist * cosCRadPerDeg * CD):

float у - CP.y + dist * sin(RadPerDeg * CD):

if(vis) lineToCx, y):

⇐ Предыдущая| |Следующая ⇒