12 #include <SFML/Window.hpp>
13 #include <SFML/OpenGL.hpp>
14 #define GL_SILENCE_DEPRECATION
22 int main(
int argc,
char **argv)
82 void RunHOGGUI(
int argc,
char** argv,
int windowDimension)
84 RunHOGGUI(argc, argv, windowDimension, windowDimension);
87 void RunHOGGUI(
int argc,
char* argv[],
int xDimension,
int yDimension)
89 int mousePressCount = 0;
90 srandom(
unsigned(time(0)));
94 sf::Window window(sf::VideoMode(xDimension, yDimension),
"My window");
95 window.setFramerateLimit(30);
105 buildGL(xDimension, yDimension);
112 while (window.isOpen())
116 while (window.pollEvent(event))
121 case sf::Event::Closed:
124 case sf::Event::TextEntered:
125 if (event.text.unicode < 128)
128 case sf::Event::KeyPressed:
129 switch (event.key.code)
138 case sf::Event::Resized:
141 xDimension =
event.size.width;
142 yDimension =
event.size.height;
147 case sf::Event::MouseButtonPressed:
152 switch (event.mouseButton.button)
154 case sf::Mouse::Right:
159 case sf::Mouse::Left:
163 case sf::Mouse::Middle:
170 case sf::Event::MouseButtonReleased:
174 switch (event.mouseButton.button)
176 case sf::Mouse::Right:
179 case sf::Mouse::Left:
182 case sf::Mouse::Middle:
188 case sf::Event::MouseMoved:
192 if (mousePressCount == 0)
530 static double lastTime = ((double)clock()/CLOCKS_PER_SEC);
531 double currTime = ((double)clock()/CLOCKS_PER_SEC);
533 if ((currTime - lastTime) > (1/
fps)) {
597 GLdouble ratio, radians, wd2;
605 minVal = maxVal = viewPort;
607 for (
int x = minVal; x <= maxVal; x++)
672 void CrossProd(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float res[3])
674 res[0] = y1*z2 - y2*z1;
675 res[1] = x2*z1 - x1*z2;
676 res[2] = x1*y2 - x2*y1;
680 void MyGluLookAt(
float eyeX,
float eyeY,
float eyeZ,
float lookAtX,
float lookAtY,
float lookAtZ,
float upX,
float upY,
float upZ)
688 f[0] = lookAtX - eyeX;
689 f[1] = lookAtY - eyeY;
690 f[2] = lookAtZ - eyeZ;
693 fMag = sqrt(f[0]*f[0] + f[1]*f[1] + f[2]*f[2]);
694 upMag = sqrt(upX*upX + upY*upY + upZ*upZ);
715 CrossProd(f[0], f[1], f[2], upX, upY, upZ, s);
716 CrossProd(s[0], s[1], s[2], f[0], f[1], f[2], u);
720 s[0], u[0], -f[0], 0,
721 s[1], u[1], -f[1], 0,
722 s[2], u[2], -f[2], 0,
727 glTranslatef(-eyeX, -eyeY, -eyeZ);
737 glMatrixMode(GL_MODELVIEW);
784 glCallList (fontList + cstrOut[i++]);
877 -1*(1-yperc)+1*yperc);
882 for (
auto &i: commands)
885 if (i.viewport != port)
891 glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
907 glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
913 glBegin(GL_TRIANGLE_STRIP);
916 glVertex2f(r1.left, r1.bottom);
917 glVertex2f(r2.left, r2.bottom);
919 glVertex2f(r1.left, r1.top);
920 glVertex2f(r2.left, r2.top);
922 glVertex2f(r1.right, r1.top);
923 glVertex2f(r2.right, r2.top);
925 glVertex2f(r1.right, r1.bottom);
926 glVertex2f(r2.right, r2.bottom);
928 glVertex2f(r1.left, r1.bottom);
929 glVertex2f(r2.left, r2.bottom);
941 glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
949 glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
955 glColor3f(i.polygon.c.r, i.polygon.c.g, i.polygon.c.b);
958 DrawCircle((tmp.right+tmp.left)/2, (tmp.top+tmp.bottom)/2, fabs(tmp.top-tmp.bottom)/2.0, i.polygon.segments, i.polygon.rotate);
963 glColor3f(i.polygon.c.r, i.polygon.c.g, i.polygon.c.b);
966 FrameCircle((tmp.right+tmp.left)/2, (tmp.top+tmp.bottom)/2, fabs(tmp.top-tmp.bottom)/2.0,
ViewportToScreenX(i.polygon.width, i.viewport), i.polygon.segments, i.polygon.rotate);
971 glColor3f(i.triangle.c.r, i.triangle.c.g, i.triangle.c.b);
976 glBegin(GL_TRIANGLES);
977 glVertex3f(tmp1.
x, tmp1.
y, tmp1.
z);
978 glVertex3f(tmp2.
x, tmp2.
y, tmp2.
z);
979 glVertex3f(tmp3.
x, tmp3.
y, tmp3.
z);
985 glColor3f(i.triangle.c.r, i.triangle.c.g, i.triangle.c.b);
988 Line(i.triangle.p1, i.triangle.p2, i.triangle.width, i.viewport);
989 Line(i.triangle.p2, i.triangle.p3, i.triangle.width, i.viewport);
990 Line(i.triangle.p3, i.triangle.p1, i.triangle.width, i.viewport);
995 glColor3f(i.line.c.r, i.line.c.g, i.line.c.b);
997 Line(i.line.start, i.line.end, i.line.width, i.viewport);
1025 GLfloat xOff = tmp1.
x-tmp2.
x;
1026 GLfloat yOff = tmp2.
y-tmp1.
y;
1028 GLfloat ratio = wide/sqrt(xOff*xOff+yOff*yOff);
1031 glColor3f(i.c.r, i.c.g, i.c.b);
1032 glVertex3f(tmp1.
x-ratio*yOff, tmp1.
y-ratio*xOff, tmp1.
z);
1033 glVertex3f(tmp1.
x+ratio*yOff, tmp1.
y+ratio*xOff, tmp1.
z);
1034 glVertex3f(tmp2.
x+ratio*yOff, tmp2.
y+ratio*xOff, tmp1.
z);
1035 glVertex3f(tmp2.
x-ratio*yOff, tmp2.
y-ratio*xOff, tmp1.
z);
1046 GLfloat xOff = tmp1.
x-tmp2.
x;
1047 GLfloat yOff = tmp2.
y-tmp1.
y;
1050 glVertex3f(tmp1.
x-ratio*yOff, tmp1.
y-ratio*xOff, tmp1.
z);
1051 glVertex3f(tmp1.
x+ratio*yOff, tmp1.
y+ratio*xOff, tmp1.
z);
1052 glVertex3f(tmp2.
x+ratio*yOff, tmp2.
y+ratio*xOff, tmp1.
z);
1053 glVertex3f(tmp2.
x-ratio*yOff, tmp2.
y-ratio*xOff, tmp1.
z);
1071 if (i.viewport != port)
1073 glColor3f(i.c.r, i.c.g, i.c.b);
1076 for (
int t = 0; t < i.points.size()-1; t++)
1080 GLfloat xOff = tmp1.
x-tmp2.
x;
1081 GLfloat yOff = tmp2.
y-tmp1.
y;
1082 GLfloat ratio = 0.5f*i.size/sqrt(xOff*xOff+yOff*yOff);
1083 glVertex3f(tmp1.
x-ratio*yOff, tmp1.
y-ratio*xOff, tmp1.
z);
1084 glVertex3f(tmp1.
x+ratio*yOff, tmp1.
y+ratio*xOff, tmp1.
z);
1085 glVertex3f(tmp2.
x+ratio*yOff, tmp2.
y+ratio*xOff, tmp1.
z);
1086 glVertex3f(tmp2.
x-ratio*yOff, tmp2.
y-ratio*xOff, tmp1.
z);
1093 if (i.viewport != port)
1097 i.loc, i.s.c_str(), i.size,
1106 if (i.viewport != port)
1108 glColor3f(i.c.r, i.c.g, i.c.b);
1111 for (
int t = 0; t < i.points.size()-1; t++)
1113 Line(i.points[t], i.points[t+1], i.size, i.viewport);
1119 for (
auto &i : display.
text)
1121 if (i.viewport != port)
1125 i.loc, i.s.c_str(), i.size,
1143 glClear(GL_COLOR_BUFFER_BIT);
1144 glClear(GL_DEPTH_BUFFER_BIT);
1153 glMatrixMode(GL_PROJECTION);
1250 glDisable(GL_DEPTH_TEST);
1252 glShadeModel(GL_SMOOTH);
1253 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
1254 glFrontFace(GL_CCW);
1255 glPolygonOffset (1.0, 1.0);
1257 glClearColor(0.0,0.0,0.0,0.0);