diff --git a/bin/Debug/kanji.exe b/bin/Debug/kanji.exe index bfe2afd..79932e0 100644 Binary files a/bin/Debug/kanji.exe and b/bin/Debug/kanji.exe differ diff --git a/kanji.depend b/kanji.depend index 3a58265..05f45c8 100644 --- a/kanji.depend +++ b/kanji.depend @@ -11,7 +11,7 @@ 1447929786 source:d:\okg\okg\uprajneniq\kanji\main.cpp -1448029763 source:d:\okg\uprajneniq\kanji\main.cpp +1448056853 source:d:\okg\uprajneniq\kanji\main.cpp diff --git a/kanji.layout b/kanji.layout index be5066d..6044120 100644 --- a/kanji.layout +++ b/kanji.layout @@ -1,12 +1,15 @@ - + - + + + + diff --git a/main.cpp b/main.cpp index 3d02c75..7537698 100644 --- a/main.cpp +++ b/main.cpp @@ -5,8 +5,8 @@ using namespace std; const float originalBrush = 0.4, - brush = originalBrush/2, - depth = 5*originalBrush; + brush = originalBrush/2, + depth = 5*originalBrush; void drawHorizontal(float x, float y, float z, float length) @@ -128,71 +128,118 @@ void drawVertical(float x, float y, float z, float length) void drawRingPart(float x, float y, float z, float Rx, float Ry, float Rz, float angle, float R) { - //float R = sqrt(pow((x - Rx),2) + pow((z - Rz),2)); - double startAngle = acos((z - Rz)/R); + float startAngle = acos((z - Rz)/R); + float width = M_PI/180; startAngle = 0; angle+=startAngle; + glBegin(GL_POLYGON); - glNormal3f(sin(angle), 0, cos(angle)); - glVertex3f(x+(R-brush)*cos(startAngle), y + depth, z-(R-brush)*sin(startAngle)); - glVertex3f(x+(R+brush)*cos(startAngle), y + depth, z-(R+brush)*sin(startAngle)); - glVertex3f(x+(R+brush)*cos(startAngle), y - depth, z-(R+brush)*sin(startAngle)); - glVertex3f(x+(R-brush)*cos(startAngle), y - depth, z-(R-brush)*sin(startAngle)); + glNormal3f(sin(angle), 0.0, cos(angle)); + glVertex3f(x+(R-brush)*cos(startAngle), y+depth, z-(R-brush)*sin(startAngle)); + glVertex3f(x+(R+brush)*cos(startAngle), y+depth, z-(R+brush)*sin(startAngle)); + glVertex3f(x+(R+brush)*cos(startAngle), y-depth, z-(R+brush)*sin(startAngle)); + glVertex3f(x+(R-brush)*cos(startAngle), y-depth, z-(R-brush)*sin(startAngle)); glEnd(); - float width = M_PI/180; - //for(float i = startAngle; i < angle; i += width) + for (float i = startAngle; fabs(i) < fabs(angle); i += width) { glBegin(GL_POLYGON); //front glNormal3f(0.0, +1.0, 0.0); - glVertex3f(x+(R-brush)*cos(i-width), y + depth, z-(R-brush)*sin(i-width)); - glVertex3f(x+(R+brush)*cos(i-width), y + depth, z-(R+brush)*sin(i-width)); - glVertex3f(x+(R+brush)*cos(i+width), y + depth, z-(R+brush)*sin(i+width)); - glVertex3f(x+(R-brush)*cos(i+width), y + depth, z-(R-brush)*sin(i+width)); + glVertex3f(x+(R-brush)*cos(i-width), y+depth, z-(R-brush)*sin(i-width)); + glVertex3f(x+(R+brush)*cos(i-width), y+depth, z-(R+brush)*sin(i-width)); + glVertex3f(x+(R+brush)*cos(i+width), y+depth, z-(R+brush)*sin(i+width)); + glVertex3f(x+(R-brush)*cos(i+width), y+depth, z-(R-brush)*sin(i+width)); glEnd(); glBegin(GL_POLYGON); // back glNormal3f(0.0, -1.0, 0.0); - glVertex3f(x+(R-brush)*cos(i-width), y - depth, z-(R-brush)*sin(i-width)); - glVertex3f(x+(R+brush)*cos(i-width), y - depth, z-(R+brush)*sin(i-width)); - glVertex3f(x+(R+brush)*cos(i+width), y - depth, z-(R+brush)*sin(i+width)); - glVertex3f(x+(R-brush)*cos(i+width), y - depth, z-(R-brush)*sin(i+width)); + glVertex3f(x+(R-brush)*cos(i-width), y-depth, z-(R-brush)*sin(i-width)); + glVertex3f(x+(R+brush)*cos(i-width), y-depth, z-(R+brush)*sin(i-width)); + glVertex3f(x+(R+brush)*cos(i+width), y-depth, z-(R+brush)*sin(i+width)); + glVertex3f(x+(R-brush)*cos(i+width), y-depth, z-(R-brush)*sin(i+width)); glEnd(); glBegin(GL_POLYGON); // inside - glNormal3f(-cos(i+width), 0.0, sin (i+width)); - glVertex3f(x+(R-brush)*cos(i-width), y + depth, z-(R-brush)*sin(i-width)); - glVertex3f(x+(R-brush)*cos(i+width), y + depth, z-(R-brush)*sin(i+width)); - glVertex3f(x+(R-brush)*cos(i+width), y - depth, z-(R-brush)*sin(i+width)); - glVertex3f(x+(R-brush)*cos(i-width), y - depth, z-(R-brush)*sin(i-width)); + glNormal3f(-cos(i+width), 0.0, +sin(i+width)); + glVertex3f(x+(R-brush)*cos(i-width), y+depth, z-(R-brush)*sin(i-width)); + glVertex3f(x+(R-brush)*cos(i+width), y+depth, z-(R-brush)*sin(i+width)); + glVertex3f(x+(R-brush)*cos(i+width), y-depth, z-(R-brush)*sin(i+width)); + glVertex3f(x+(R-brush)*cos(i-width), y-depth, z-(R-brush)*sin(i-width)); glEnd(); glBegin(GL_POLYGON); // outside - glNormal3f(+cos(i+width), 0.0, -sin (i+width)); - glVertex3f(x+(R+brush)*cos(i-width), y + depth, z-(R+brush)*sin(i-width)); - glVertex3f(x+(R+brush)*cos(i+width), y + depth, z-(R+brush)*sin(i+width)); - glVertex3f(x+(R+brush)*cos(i+width), y - depth, z-(R+brush)*sin(i+width)); - glVertex3f(x+(R+brush)*cos(i-width), y - depth, z-(R+brush)*sin(i-width)); + glNormal3f(+cos(i+width), 0.0, -sin(i+width)); + glVertex3f(x+(R+brush)*cos(i-width), y+depth, z-(R+brush)*sin(i-width)); + glVertex3f(x+(R+brush)*cos(i+width), y+depth, z-(R+brush)*sin(i+width)); + glVertex3f(x+(R+brush)*cos(i+width), y-depth, z-(R+brush)*sin(i+width)); + glVertex3f(x+(R+brush)*cos(i-width), y-depth, z-(R+brush)*sin(i-width)); glEnd(); } + glBegin(GL_POLYGON); - glNormal3f(-1.0, 0, 0); + glNormal3f(-1.0, 0.0, 0.0); glVertex3f(x+(R-brush)*cos(angle), y + depth, z+(R-brush)*sin(angle)); glVertex3f(x+(R+brush)*cos(angle), y + depth, z+(R+brush)*sin(angle)); glVertex3f(x+(R+brush)*cos(angle), y - depth, z+(R+brush)*sin(angle)); glVertex3f(x+(R-brush)*cos(angle), y - depth, z+(R-brush)*sin(angle)); glEnd(); +} +void drawPolygon (float x, float y, float z, float angle, float R) +{ + glBegin(GL_POLYGON); //front + glNormal3f(0.0, -1.0, 0.0); + glVertex3f(x+(R-brush)*cos(angle), y-depth, z+(R-brush)*sin(angle)); + glVertex3f(x+(R+brush)*cos(angle), y - depth, z+(R+brush)*sin(angle)); + glVertex3f(x-1.6*originalBrush, y-depth, z+(R+brush)*sin(angle)); + glVertex3f(x-2*originalBrush, y-depth, z-0.55*originalBrush); + glEnd(); + glBegin(GL_POLYGON); //back + glNormal3f(0.0, 1.0, 0.0); + glVertex3f(x+(R-brush)*cos(angle), y+depth, z+(R-brush)*sin(angle)); + glVertex3f(x+(R+brush)*cos(angle), y+depth, z+(R+brush)*sin(angle)); + glVertex3f(x-1.6*originalBrush, y+depth, z+(R+brush)*sin(angle)); + glVertex3f(x-2*originalBrush, y+depth, z-0.55*originalBrush); + glEnd(); + glBegin(GL_POLYGON); //left + glNormal3f(-1.0, 0.0, 0.0); + glVertex3f(x-2*originalBrush, y-depth, z-0.55*originalBrush); + glVertex3f(x-1.6*originalBrush, y-depth, z+(R+brush)*sin(angle)); + glVertex3f(x-1.6*originalBrush, y+depth, z+(R+brush)*sin(angle)); + glVertex3f(x-2*originalBrush, y+depth, z-0.55*originalBrush); + glEnd(); + glBegin(GL_POLYGON); //right + glNormal3f(1.0, 0.0, 0.0); + glVertex3f(x+(R-brush)*cos(angle), y+depth, z+(R-brush)*sin(angle)); + glVertex3f(x+(R+brush)*cos(angle), y+depth, z+(R+brush)*sin(angle)); + glVertex3f(x+(R+brush)*cos(angle), y-depth, z+(R+brush)*sin(angle)); + glVertex3f(x+(R-brush)*cos(angle), y+depth, z+(R-brush)*sin(angle)); + glEnd(); + glBegin(GL_POLYGON); //top + glNormal3f(0.0, 0.0, 1.0); + glVertex3f(x+(R-brush)*cos(angle), y-depth, z+(R-brush)*sin(angle)); + glVertex3f(x-2*originalBrush, y-depth, z-0.55*originalBrush); + glVertex3f(x-2*originalBrush, y+depth, z-0.55*originalBrush); + glVertex3f(x+(R-brush)*cos(angle), y+depth, z+(R-brush)*sin(angle)); + glEnd(); + + glBegin(GL_POLYGON); //bottom + glNormal3f(0.0, 0.0, -1.0); + glVertex3f(x+(R+brush)*cos(angle), y-depth, z+(R+brush)*sin(angle)); + glVertex3f(x-1.6*originalBrush, y-depth, z+(R+brush)*sin(angle)); + glVertex3f(x-1.6*originalBrush, y+depth, z+(R+brush)*sin(angle)); + glVertex3f(x+(R+brush)*cos(angle), y+depth, z+(R+brush)*sin(angle)); + glEnd(); } void drawLeftPart(float x, float y, float z) { - drawVertical( x - 2.3*originalBrush + brush, y, z, 7.2); + drawVertical( x - 2.3*originalBrush + brush, y, z, 7.2); drawHorizontal(x, y, z + 3.6*originalBrush - brush, 2.6); drawVertical( x + 2.3*originalBrush - brush, y, z+0.6*originalBrush, 6.0); drawHorizontal(x, y, z + 1.2*originalBrush - brush, 2.6); @@ -202,22 +249,25 @@ void drawLeftPart(float x, float y, float z) void drawRightPart(float x, float y, float z) { drawVertical( x - 2.85*originalBrush + brush, y, z + 0.35*originalBrush, 5.6); - drawRingPart( x - 6.25*originalBrush + brush, y, z - 1.45*originalBrush, x - 5*originalBrush, y, z - 3.5*originalBrush, -M_PI/2.75, 3.5*originalBrush); + drawRingPart( x - 6.25*originalBrush + brush, y, z - 1.45*originalBrush, x - 5*originalBrush, y, + z - 3.5*originalBrush, -M_PI/2.75, 3.5*originalBrush); drawHorizontal(x, y, z + 3.15*originalBrush - brush, 3.7); drawVertical( x + 2.85*originalBrush - brush, y, z, 6.3); - drawRingPart( x + 1.15*originalBrush,y,z-3*originalBrush,0,0,0, -M_PI/2, 1.2*originalBrush); + drawRingPart( x + 1.15*originalBrush, y, z-3*originalBrush, 0, 0, + 0, -M_PI/2, 1.2*originalBrush); + drawPolygon ( x + 1.15*originalBrush, y, z-3*originalBrush, -M_PI/2, 1.2*originalBrush); drawHorizontal(x, y, z + 0.85*originalBrush - brush, 3.7); drawHorizontal(x, y, z - 2.45*originalBrush + brush, 3.7); } void drawBottomPart(float x, float y, float z) { - drawVertical( x - 4*originalBrush - brush, y, z, 2); - drawHorizontal(x, y, z + 1*originalBrush + brush, 10); - drawVertical( x + 4*originalBrush + brush, y, z, 2); - drawVertical( x - 1*originalBrush - brush, y, z, 2); - drawVertical( x + 1*originalBrush + brush, y, z, 2); - drawHorizontal(x, y, z - 1*originalBrush - brush, 13); + drawVertical( x - 4*originalBrush - brush, y, z, 2); + drawHorizontal(x, y, z + 1*originalBrush + brush, 10); + drawVertical( x + 4*originalBrush + brush, y, z, 2); + drawVertical( x - 1*originalBrush - brush, y, z, 2); + drawVertical( x + 1*originalBrush + brush, y, z, 2); + drawHorizontal(x, y, z - 1*originalBrush - brush, 13); } @@ -243,6 +293,13 @@ void init() gluLookAt(0.0f, -10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); + + glfwSetWindowTitle("Kanji"); + + glEnable( GL_DEPTH_TEST ); + glEnable( GL_LIGHTING ); + glEnable( GL_COLOR_MATERIAL ); + glEnable( GL_LIGHT0 ); } int main() @@ -250,27 +307,25 @@ int main() bool running = 1; init(); - glfwSetWindowTitle("Kanji"); - glEnable( GL_DEPTH_TEST ); - glEnable( GL_LIGHTING ); - glEnable( GL_COLOR_MATERIAL ); - glEnable( GL_LIGHT0 ); while(running) { glClear(GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT); + glRotatef( 0.005, 0.4, -0.2, 0.7); glRotatef( 0.04, 0.6, -0.2, 0.7); - glColor3ub(255,0,0); - drawLeftPart(-3.4*originalBrush, 0 , 1.5*originalBrush); - drawRightPart(3.5*originalBrush,0,2.5*originalBrush); - drawBottomPart(0,0,-5*originalBrush); - glfwSwapBuffers(); + glColor3ub(128, 128, 64); + drawLeftPart( -3.4*originalBrush, 0, 1.5*originalBrush); + drawRightPart( 3.5*originalBrush, 0, 2.5*originalBrush); + drawBottomPart(0, 0, -5*originalBrush); + glfwSwapBuffers(); running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); } + glfwTerminate(); + return 0; } diff --git a/obj/Debug/main.o b/obj/Debug/main.o index d1ea3d0..d23ac19 100644 Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ