Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
sstoyanova7 committed Nov 20, 2015
1 parent fb7dc86 commit e305e26
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 52 deletions.
Binary file modified bin/Debug/kanji.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion kanji.depend
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
1447929786 source:d:\okg\okg\uprajneniq\kanji\main.cpp
<GL/glfw.h>

1448029763 source:d:\okg\uprajneniq\kanji\main.cpp
1448056853 source:d:\okg\uprajneniq\kanji\main.cpp
<GL/glfw.h>
<cmath>
<iostream>
Expand Down
7 changes: 5 additions & 2 deletions kanji.layout
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2221" topLine="54" />
<Cursor1 position="10225" topLine="61" />
</Cursor>
<Folding>
<Collapse line="12" />
<Collapse line="70" />
<Collapse line="191" />
<Collapse line="212" />
</Folding>
</File>
</CodeBlocks_layout_file>
153 changes: 104 additions & 49 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}


Expand All @@ -243,34 +293,39 @@ 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()
{
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;
}
Binary file modified obj/Debug/main.o
Binary file not shown.

0 comments on commit e305e26

Please sign in to comment.