This repository has been archived by the owner on Jul 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathball.cpp
executable file
·149 lines (136 loc) · 6.18 KB
/
ball.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "ball.h"
using namespace std;
#pragma comment(lib, "glaux")
//------------------------------------------------------------------------------------
GLfloat color1_ambient[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.7, 0.0, 0.0, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.7, 0.0, 0.0, 1.0 }, { 1.0, 1.0, 1.0, 1.0 } }; //第一种颜色
GLfloat color1_diffuse[][5] = { { 0.7, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 1.0, 0.0, 0.0, 1.0 } };
GLfloat color1_specular[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.7, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 1.0, 0.0, 1.0 } };
GLfloat color1_shine[] = { 10.0, 10.0, 20.0, 20.0 ,10.0 };
GLfloat color2_ambient[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.7, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 } }; //第二中颜色
GLfloat color2_diffuse[][5] = { { 0.0, 0.0, 0.7, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.7, 0.0, 0.0, 1.0 }, { 1.0, 1.0, 1.0, 1.0 } };
GLfloat color2_specular[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.7, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 1.0, 0.0, 0.0, 1.0 } };
GLfloat color2_shine[] = { 10.0, 10.0, 20.0, 20.0, 10.0 };
GLfloat color3_ambient[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.7, 0.0, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 1.0, 0.0, 1.0 } }; //第三种颜色
GLfloat color3_diffuse[][5] = { { 0.0, 0.7, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 1.0, 1.0, 1.0, 1.0 } };
GLfloat color3_specular[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.7, 0.0, 1.0 }, { 0.7, 0.0, 0.0, 1.0 }, { 1.0, 1.0, 1.0, 1.0 } };
GLfloat color3_shine[] = { 10.0, 10.0, 20.0, 20.0, 10.0 };
GLfloat color4_ambient[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.7, 0.0, 0.7, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.9, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 1.0, 1.0 } }; //第四种颜色
GLfloat color4_diffuse[][5] = { { 0.7, 0.0, 0.7, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.1, 0.1, 0.1, 1.0 }, { 0.9, 0.0, 0.0, 1.0 }, { 0.0, 1.0, 0.0, 1.0 } };
GLfloat color4_specular[][5] = { { 0.0, 0.0, 0.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 }, { 0.7, 0.0, 0.7, 1.0 }, { 0.9, 0.0, 0.0, 1.0 }, { 1.0, 0.0, 0.0, 1.0 } };
GLfloat color4_shine[] = { 10.0, 10.0, 20.0, 20.0, 10.0 };
//----------------------------------------------------------------------------------------------
ball::ball(float position[3], int color, float radius, bool appear)
{
for (int i = 0; i <= 2; i++)
{
ball_position[i] = position[i]; //一定要loop才可以传进去,传入位置
}
ball_color = color;
ball_appear = appear;
ball_r = radius;
ball_level = 1;
}
void ball::ball_drawself()
{
if (ball_r > 0.1) //如果显示就画
{
if (endlessmode == false)
{
glPushMatrix();
glTranslatef(ball_position[0], ball_position[1], ball_position[2]);
if (ball_color == 0) //看是什么颜色的球就画什么颜色的
{
glMaterialfv(GL_FRONT, GL_AMBIENT, color1_ambient[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, color1_diffuse[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_SPECULAR, color1_specular[ball_level - 1]);
glMaterialf(GL_FRONT, GL_SHININESS, color1_shine[ball_level - 1]);
}
else if (ball_color == 1)
{
glMaterialfv(GL_FRONT, GL_AMBIENT, color2_ambient[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, color2_diffuse[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_SPECULAR, color2_specular[ball_level - 1]);
glMaterialf(GL_FRONT, GL_SHININESS, color2_shine[ball_level - 1]);
}
else if (ball_color == 2)
{
glMaterialfv(GL_FRONT, GL_AMBIENT, color3_ambient[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, color3_diffuse[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_SPECULAR, color3_specular[ball_level - 1]);
glMaterialf(GL_FRONT, GL_SHININESS, color3_shine[ball_level - 1]);
}
else if (ball_color == 3)
{
glMaterialfv(GL_FRONT, GL_AMBIENT, color4_ambient[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, color4_diffuse[ball_level - 1]);
glMaterialfv(GL_FRONT, GL_SPECULAR, color4_specular[ball_level - 1]);
glMaterialf(GL_FRONT, GL_SHININESS, color4_shine[ball_level - 1]);
}
glutSolidSphere(ball_r, 80, 80);
glPopMatrix();
}
else if (endlessmode == true)
{
glPushMatrix();
glTranslatef(ball_position[0], ball_position[1], ball_position[2]);
if (ball_color == 0) //看是什么颜色的球就画什么颜色的
{
glMaterialfv(GL_FRONT, GL_AMBIENT, endless_color_ambient[0]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, endless_color_diffuse[0]);
glMaterialfv(GL_FRONT, GL_SPECULAR, endless_color_specular[0]);
glMaterialf(GL_FRONT, GL_SHININESS, endless_color_shine[0]);
}
else if (ball_color == 1)
{
glMaterialfv(GL_FRONT, GL_AMBIENT, endless_color_ambient[1]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, endless_color_diffuse[1]);
glMaterialfv(GL_FRONT, GL_SPECULAR, endless_color_specular[1]);
glMaterialf(GL_FRONT, GL_SHININESS, endless_color_shine[1]);
}
else if (ball_color == 2)
{
glMaterialfv(GL_FRONT, GL_AMBIENT, endless_color_ambient[2]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, endless_color_diffuse[2]);
glMaterialfv(GL_FRONT, GL_SPECULAR, endless_color_specular[2]);
glMaterialf(GL_FRONT, GL_SHININESS, endless_color_shine[2]);
}
else if (ball_color == 3)
{
glMaterialfv(GL_FRONT, GL_AMBIENT, endless_color_ambient[3]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, endless_color_diffuse[3]);
glMaterialfv(GL_FRONT, GL_SPECULAR, endless_color_specular[3]);
glMaterialf(GL_FRONT, GL_SHININESS, endless_color_shine[3]);
}
glutSolidSphere(ball_r, 80, 80);
glPopMatrix();
}
}
}
void ball::ball_turnsmall()
{
if (ball_appear == false && ball_r > 0.0)
{
ball_r -= ball_r*0.1;
}
}
void ball::ball_turnbig()
{
if (ball_appear == true && ball_r < 1.5)
{
ball_r += -0.1*ball_r + 0.15;
}
}
void ball::click_small()
{
if (ball_appear == true && ball_click == false && ball_r > 1.5)
{
ball_r -= 0.2*ball_r - 0.3;
}
}
void ball::click_big()
{
if (ball_appear == true && ball_click == true && ball_r < 1.75)
{
ball_r += -0.2*ball_r + 0.35;
}
}