10 //#include <GL/glut.h>
13 #pragma comment(lib, "ws2_32.lib")
16 #define M_PI 3.14159265357989
22 const int KEY_UP_BIT = 1 << 0;
23 const int KEY_DOWN_BIT = 1 << 1;
24 const int KEY_RIGHT_BIT = 1 << 2;
25 const int KEY_LEFT_BIT = 1 << 3;
27 CClientUI* CClientUI::sm_pUI = NULL;
29 ////////////////////////////////////////////////////////////////////////////////
31 ////////////////////////////////////////////////////////////////////////////////
32 CClientUI::CClientUI()
37 m_CriticalSectionOfEvent = createCriticalSectionID();
40 ////////////////////////////////////////////////////////////////////////////////
42 ////////////////////////////////////////////////////////////////////////////////
43 CClientUI::~CClientUI()
45 deleteCriticalSectionID(m_CriticalSectionOfEvent);
49 ////////////////////////////////////////////////////////////////////////////////
50 //
\89æ
\96Ê
\82ð
\95`
\89æ
\82·
\82é
51 ////////////////////////////////////////////////////////////////////////////////
52 void CClientUI::display()
55 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
57 // initialize modelview matrix
60 //
\8dÀ
\95W
\8cn
\82Ì
\92è
\8b`
61 // x-y
\95½
\96Ê
\82ð
\92n
\96Ê
62 // z = 0
\82ð
\95W
\8d\820
65 //
\8c»
\8fó
\82Í
\8fã
\82©
\82ç
\8e\8b\93_
\81i
\8fã
\8bó5m
\81j
\82Æ
\82·
\82é
67 0, 0, 5, //
\8e\8b\93_
\82Ì
\88Ê
\92u
68 0, 0, 0, //
\8e\8b\93_
\82Ì
\96Ú
\95W
\92n
\93_
69 0, 1, 0 //
\93ª
\82Ì
\8cü
\82«
72 GLfloat position[] = {-1.0, 1.0, 1.0, 0.0};
73 glLightfv(GL_LIGHT0, GL_POSITION, position);
75 //
\83A
\83o
\83^
\81[
\95`
\89æ
77 GLfloat a_AmbientDiffuse[] = {1.0, 0.0, 0.0, 1.0};
78 GLfloat a_Specular[] = {1.0, 1.0, 1.0, 1.0};
79 GLfloat a_Shininess[] = {20.0};
80 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, a_AmbientDiffuse);
81 glMaterialfv(GL_FRONT, GL_SPECULAR, a_Specular);
82 glMaterialfv(GL_FRONT, GL_SHININESS, a_Shininess);
83 // set avatar color to white
84 glColor3f(1.0, 1.0, 1.0);
87 const AvatarInformationList* a_pAvatarInformations = sm_pUI->m_pModel->getAvatarInformationList();
88 for(AvatarInformationList::const_iterator p = a_pAvatarInformations->begin(); p != a_pAvatarInformations->end(); p++){
91 glTranslated(p->m_Position[0], p->m_Position[1], p->m_Position[2]);
92 glutSolidSphere(p->m_Radias, 10, 10);
95 glVertex3d(0.0, 0.0, 0.0);
96 glVertex3d(p->m_Direction[0], p->m_Direction[1], p->m_Direction[2]);
106 ////////////////////////////////////////////////////////////////////////////////
107 //
\8f\89\8aú
\89»
\82·
\82é
108 ////////////////////////////////////////////////////////////////////////////////
109 void CClientUI::init()
111 // background color is black
112 glClearColor(0.0, 0.0, 0.0, 1.0);
114 //
\8aÂ
\8b«
\95Ï
\90\94\90Ý
\92è
115 GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
116 GLfloat diffuse[] = {0.6, 0.6, 0.6, 1.0};
117 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
118 GLfloat position[] = {-1.0, 1.0, 1.0, 0.0};
120 //glEnable(GL_LIGHTING);
121 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
122 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
123 glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
124 glLightfv(GL_LIGHT0, GL_POSITION, position);
125 //glEnable(GL_LIGHT0);
127 GLfloat material_ambient_diffuse[] = {1.0, 0.0, 0.0, 1.0};
128 GLfloat material_specular[] = {1.0, 1.0, 1.0, 1.0};
129 GLfloat material_shininess[] = {20.0};
131 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material_ambient_diffuse);
132 glMaterialfv(GL_FRONT, GL_SPECULAR, material_specular);
133 glMaterialfv(GL_FRONT, GL_SHININESS, material_shininess);
135 glEnable(GL_DEPTH_TEST);
136 glEnable(GL_CULL_FACE);
138 //glShadeModel(GL_FLAT);
140 srand(static_cast<unsigned int>(time(NULL)));
143 ////////////////////////////////////////////////////////////////////////////////
144 //
\88ê
\94Ê
\83L
\81[
\93ü
\97Í
145 ////////////////////////////////////////////////////////////////////////////////
146 void CClientUI::keyboard(unsigned char in_Key, int in_x, int in_y)
151 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
152 sm_pUI->m_Events.push_back("CONNECT");
153 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
158 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
159 sm_pUI->m_Events.push_back("DISCONNECT");
160 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
165 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
166 sm_pUI->m_Events.push_back("LOGIN");
167 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
172 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
173 sm_pUI->m_Events.push_back("LOGOUT");
174 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
179 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
180 sm_pUI->m_Events.push_back("POSITION");
181 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
187 case '\033': /* '\033'
\82Í ESC
\82Ì ASCII
\83R
\81[
\83h */
188 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
189 sm_pUI->m_Events.push_back("END");
190 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
197 ////////////////////////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////////////
200 void CClientUI::downSpecialKey(int in_Key, int in_x, int in_y)
204 g_KeyStatus |= KEY_UP_BIT;
207 g_KeyStatus |= KEY_DOWN_BIT;
210 g_KeyStatus |= KEY_RIGHT_BIT;
213 g_KeyStatus |= KEY_LEFT_BIT;
218 ////////////////////////////////////////////////////////////////////////////////
220 ////////////////////////////////////////////////////////////////////////////////
221 void CClientUI::upSpecialKey(int in_Key, int in_x, int in_y)
225 g_KeyStatus &= ~KEY_UP_BIT;
228 g_KeyStatus &= ~KEY_DOWN_BIT;
231 g_KeyStatus &= ~KEY_RIGHT_BIT;
234 g_KeyStatus &= ~KEY_LEFT_BIT;
239 ////////////////////////////////////////////////////////////////////////////////
241 ////////////////////////////////////////////////////////////////////////////////
242 void CClientUI::timer(int value)
244 // 1
\95b
\8aÔ
\82É60
\89ñ
\8cÄ
\82Ñ
\8fo
\82³
\82ê
\82é
245 glutTimerFunc(1000 / 60, timer, 0);
247 //
\83L
\81[
\93ü
\97Í
\82Ì
\8fó
\91Ô
\82É
\82æ
\82è
\83A
\83o
\83^
\81[
\81ii = 0
\82Ì
\82Ý
\81j
\82ð
\93®
\82©
\82·
249 if((g_KeyStatus & KEY_UP_BIT) && !(g_KeyStatus & KEY_DOWN_BIT)){
250 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
251 sm_pUI->m_Events.push_back("FRONT");
252 sm_pUI->m_Events.push_back("POSITION");
253 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
256 else if(!(g_KeyStatus & KEY_UP_BIT) && (g_KeyStatus & KEY_DOWN_BIT)){
257 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
258 sm_pUI->m_Events.push_back("BACK");
259 sm_pUI->m_Events.push_back("POSITION");
260 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
263 if((g_KeyStatus & KEY_RIGHT_BIT) && !(g_KeyStatus & KEY_LEFT_BIT)){
264 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
265 sm_pUI->m_Events.push_back("TURN_RIGHT");
266 sm_pUI->m_Events.push_back("POSITION");
267 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
270 else if(!(g_KeyStatus & KEY_RIGHT_BIT) && (g_KeyStatus & KEY_LEFT_BIT)){
271 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
272 sm_pUI->m_Events.push_back("TURN_LEFT");
273 sm_pUI->m_Events.push_back("POSITION");
274 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
277 sm_pUI->enterCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
278 sm_pUI->m_Events.push_back("POSITION");
279 sm_pUI->leaveCriticalSectionID(sm_pUI->m_CriticalSectionOfEvent);
285 ////////////////////////////////////////////////////////////////////////////////
286 //
\83T
\83C
\83Y
\95Ï
\8dX
287 ////////////////////////////////////////////////////////////////////////////////
288 void CClientUI::reshape(int w, int h)
290 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
291 glMatrixMode(GL_PROJECTION);
294 glFrustum(-1.0, 1.0, -1.0 * (GLfloat)h / (GLfloat)w, 1.0 * (GLfloat)h / (GLfloat)w, 1.0, 30.0);
297 glFrustum(-1.0 * (GLfloat)w / (GLfloat)h, 1.0 * (GLfloat)w / (GLfloat)h, -1.0, 1.0, 1.0, 30.0);
299 glMatrixMode(GL_MODELVIEW);
302 ////////////////////////////////////////////////////////////////////////////////
304 ////////////////////////////////////////////////////////////////////////////////
305 bool CClientUI::initialize()
310 ////////////////////////////////////////////////////////////////////////////////
312 ////////////////////////////////////////////////////////////////////////////////
313 bool CClientUI::uninitialize()
319 ////////////////////////////////////////////////////////////////////////////////
321 ////////////////////////////////////////////////////////////////////////////////
322 void CClientUI::run()
324 glutInit(m_pArgc, m_ppArgv);
325 glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
326 glutInitWindowSize(512, 512);
327 glutCreateWindow("internetcity");
328 glutDisplayFunc(display);
329 glutKeyboardFunc(keyboard);
330 glutSpecialFunc(downSpecialKey);
331 glutSpecialUpFunc(upSpecialKey);
332 glutTimerFunc(1000 / 60, timer, 0);
333 glutReshapeFunc(reshape);