/project/Naruto_ninja_story/Scene_game.cpp
C++ | 1736 lines | 1059 code | 242 blank | 435 comment | 217 complexity | 6330e7ab88bc223741be11c3aa9df114 MD5 | raw file
1#include <conio.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <math.h>
5
6#include "Scene_game.h"
7
8#include "tools/Speedometr.h"
9#include "tools/tools.h"
10#include "Graphick/Texture/Texture.h"
11#include "Graphick/Texture/TextureContainer.h"
12#include "Core/Core.h"
13#include "Game/GhostCharacter.h"
14#include "Graphick/Graphick.h"
15#include "Graphick/OpenGL/OpenGl.h"
16#include "Graphick/OpenGL/vertex_shader.h"
17#include "Graphick/OpenGL/fragment_shader.h"
18#include "Game/PlayerContainer.h"
19
20Scene_game::Scene_game()
21{
22 m_time = 0.0;
23 m_duration = 0.0;
24
25 m_alfa = 0;
26 m_beta = -60.0f;
27 m_length = 120;
28
29 m_sky = 0;
30 m_sun = 0;
31
32 m_cam_x = 0.0f;
33 m_cam_y = 0.0f;
34 m_cam_z = 0.0f;
35 m_call_back_count = 0;
36 m_glsl_sample_shader = 0;
37 m_glsl_particle_shader = 0;
38
39 m_glsl_vertex_light_shader = 0;
40 m_glsl_pixel_light_shader = 0;
41 m_glsl_skinning_shader = 0;
42
43 m_glsl_outline_shader = 0;
44
45 m_player = 0;
46 m_player1 = 0;
47 m_player2 = 0;
48
49 m_live_texture = 0;
50 m_chakra_texture = 0;
51
52 m_test_particle = 0;
53
54 m_track_a_id = -1;
55 m_track_a_volume = 0.0;
56 m_track_a_state = 0;
57
58 m_track_b_id = -1;
59 m_track_b_volume = 0.0;
60 m_track_b_state = 0;
61
62 m_next_state = MUSIC_NONE;
63 m_current_state = MUSIC_NONE;
64 m_in_combat = false;
65 m_test_particle = 0;
66 m_perticle_smoke = 0;
67
68 for (int i = 0; i < MUSIC_COUNT; i ++)
69 {
70 m_track_position[i] = 0;
71 }
72
73 m_player_container = 0;
74};
75
76Scene_game::~Scene_game()
77{
78
79};
80
81void Scene_game::CreateCloud(float x, float y, float z)
82{
83 ParticleAlpha* particle = m_particle_list.add();
84 particle->SetTexture(m_perticle_smoke, 1, 1);
85 particle->Create(64);
86 particle->SetLiveTime(4000.0);
87 for (int i = 0; i < 64; i ++)
88 {
89 float r = rndf(8.0f, 12.0f);
90 float v = rndf(1.0f, 4.0f);
91
92 float a = rndf(0.0f, 6.28f);
93 float b = rndf(0.0f, 6.28f);
94 particle->add_particle(rndf(6.0f, 16.0f),
95 x + cos(a)*sin(b)*r, y + sin(a)*sin(b)*r, z + cos(b)*r*2.0f,
96 cos(a)*sin(b)*v, sin(a)*sin(b)*v, cos(b)*v,
97 1.0f, -0.8f, rndf(200.0f, 500.0f), 9000.0f);
98 }
99}
100
101void Scene_game::ControlCloud(double time)
102{
103 bool recheck = false;
104 for (int i = 0; i < m_particle_list.count; i ++)
105 {
106 ParticleAlpha* particle = m_particle_list.item[i];
107 particle->caclulate(time);
108 if (!particle->IsLive())
109 {
110 recheck = true;
111 particle->Destroy();
112 delete particle;
113 m_particle_list.item[i] = 0;
114 }
115 }
116
117 if (recheck)
118 {
119 m_particle_list.recheck();
120 }
121};
122
123void Scene_game::ActivateMusic(MUSIC_SITUATION music)
124{
125 if (m_current_state != music)
126 m_next_state = music;
127};
128
129void Scene_game::ControlMusic(double duration)
130{
131 if (!m_sound_engine)
132 return;
133
134 if (m_next_state != MUSIC_NONE && m_track_b_state == 0)
135 {
136 //move current track to gain down (b)
137 m_track_b_id = m_track_a_id;
138 m_track_b_volume = m_track_a_volume;
139 m_track_b_state = m_track_a_state;
140 m_track_a_id = -1;
141 m_track_a_state = 0;
142
143 if (m_sound_engine)
144 {
145 if (m_next_state == MUSIC_NORMAL)
146 {
147 m_track_a_state = 1;
148 m_track_a_volume = 0.0;
149 } else
150 if (m_next_state == MUSIC_FIGHT)
151 {
152 m_track_a_state = 1;
153 m_track_a_id = m_sound_engine->PlayTrack("../../data/music/Naruto Main Theme.ogg", true);
154 m_sound_engine->SetTrackPosition(m_track_a_id, m_track_position[MUSIC_FIGHT]);
155 printf(" Position set %.3f\n", m_track_position[MUSIC_FIGHT]);
156 if (m_track_a_id == -1)
157 m_track_a_state = 0;
158 m_track_a_volume = 0.0;
159 } else
160 if (m_next_state == MUSIC_DIE)
161 {
162 m_track_a_state = 1;
163 m_track_a_id = m_sound_engine->PlayTrack("../../data/music/Sangeki no Ato.ogg", true);
164 m_sound_engine->SetTrackPosition(m_track_a_id, m_track_position[MUSIC_DIE]);
165 if (m_track_a_id == -1)
166 m_track_a_state = 0;
167 m_track_a_volume = 0.0;
168 };
169 }
170
171 if (m_track_b_id > -1)
172 {
173 //Save track position
174 m_track_position[m_current_state] = m_sound_engine->TrackPosition(m_track_b_id);
175 printf(" Position save %.3f\n", m_track_position[m_current_state]);
176 }
177
178 m_current_state = m_next_state;
179 m_next_state = MUSIC_NONE;
180 }
181 //control volume
182 if (m_track_a_state != 0 && m_track_a_id > -1)
183 {
184 double old_volume = m_track_a_volume;
185 m_track_a_volume += (duration / 1000.0)/5.0;
186 if (m_track_a_volume > 1.0)
187 m_track_a_volume = 1.0;
188 if (old_volume != m_track_a_volume)
189 {
190 m_sound_engine->SetTrackVolume(m_track_a_id, m_track_a_volume);
191 }
192 };
193
194 if (m_track_b_state != 0 && m_track_b_id > -1)
195 {
196 double old_volume = m_track_b_volume;
197 m_track_b_volume -= (duration / 1000.0)/5.0;
198 if (old_volume != m_track_b_volume)
199 {
200 m_sound_engine->SetTrackVolume(m_track_b_id, m_track_b_volume);
201 }
202 if (m_track_b_volume < 0.0)
203 {
204 m_track_b_volume = 0.0;
205 m_sound_engine->StopTrack(m_track_b_id);
206 m_track_b_state = 0;
207 m_track_b_id = -1;
208 };
209 };
210 if (m_track_b_state != 0 && m_track_b_id == -1)
211 m_track_b_state = 0;
212};
213
214/*static void nearCallback (void *data, dGeomID o1, dGeomID o2)
215{
216 Scene_game* scene = (Scene_game*) data;
217 scene->m_call_back_count++;
218 int i;
219 // if (o1->body && o2->body) return;
220
221 // exit without doing anything if the two bodies are connected by a joint
222 dBodyID b1 = dGeomGetBody(o1);
223 dBodyID b2 = dGeomGetBody(o2);
224 if (b1 && b2 && !dBodyIsEnabled(b1) && !dBodyIsEnabled(b2))
225 return;
226
227 //Don't process 2 height field
228 if (dGeomGetClass(o1) == dHeightfieldClass && dGeomGetClass(o2) == dHeightfieldClass)
229 return;
230
231 if (b1 && b2 && dAreConnectedExcluding (b1, b2, dJointTypeContact)) return;
232
233 Body_physic* body_1 = 0;
234 if (b1)
235 body_1 = (Body_physic*)dBodyGetData(b1);
236 Body_physic* body_2 = 0;
237 if (b2)
238 body_2 = (Body_physic*)dBodyGetData(b2);
239 if (body_1 && body_2 && body_1->PhIsExclud(body_2))
240 {
241 return;
242 };
243
244 //Ignored group check
245 if (body_1 && body_2 && body_1->IgnoredGroup() == body_2->IgnoredGroup() && body_1->IgnoredGroup() > -1)
246 {
247 return;
248 };
249
250 //float cfm1 = dWorldGetCFM(scene->m_world);
251 //float cfm2 = cfm1;
252
253 //if (body_1)
254 // cfm1 = body_1->Cfm();
255 //if (body_2)
256 // cfm2 = body_2->Cfm();
257
258 const int MAX_CONTACTS = 32;
259 dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box
260 for (i = 0; i < MAX_CONTACTS; i ++)
261 {
262
263 //dContactApprox1_1
264 //dContactSoftCFM
265 contact[i].surface.mode = dContactBounce | dContactMu2 | dContactApprox1_1 | dContactApprox1_2; //dContactBounce | dContactSoftCFM |
266 contact[i].surface.mu = dInfinity; //Ice
267 contact[i].surface.mu2 = dInfinity;
268
269 contact[i].surface.bounce = 0.0; //0.1
270 contact[i].surface.bounce_vel = 0.0; //0.1
271
272 contact[i].surface.motion1 = 0.0;
273 contact[i].surface.motion2 = 0.0;
274 contact[i].surface.motionN = 0.0;
275
276 //contact[i].surface.soft_erp = 0.5f;
277 contact[i].surface.soft_cfm = dInfinity;//(cfm1 + cfm2) / 2.0f;
278 }
279
280 if (int numc = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact)))
281 {
282 if (body_1 && body_1->DebugContact())
283 {
284 //Store all contacts
285 body_1->SetContact(contact, numc);
286 };
287 if (body_2 && body_2->DebugContact())
288 {
289 //Store all contacts
290 body_2->SetContact(contact, numc);
291 };
292
293 if (body_1 && body_2)
294 {
295 Body_action* action_1 = body_1->BindAction();
296 Body_action* action_2 = body_2->BindAction();
297
298 if (action_1 && body_2->ProcessCollision())
299 action_1->ExecAction(body_1, body_2);
300 if (action_2 && body_1->ProcessCollision())
301 action_2->ExecAction(body_2, body_1);
302 };
303
304 for (i = 0; i < numc; i++)
305 {
306 if (body_1)
307 {
308 if (contact[i].geom.normal[2] > 0.01f)
309 body_1->OnGround(true);
310
311 if (!body_1->ProcessCollision())
312 {
313 //Skip collision
314 break;
315 };
316 };
317 if (body_2)
318 {
319 if (contact[i].geom.normal[2] > 0.01f)
320 body_2->OnGround(true);
321
322 if (!body_2->ProcessCollision())
323 {
324 //Skip collision
325 break;
326 };
327 };
328 dJointID c = dJointCreateContact (scene->m_world, scene->m_contactgroup, contact+i);
329 if (!b1 || dBodyIsKinematic(b1) > 0)
330 dJointAttach (c, 0, b2);
331 else
332 if (!b2 || dBodyIsKinematic(b2) > 0)
333 dJointAttach (c, b1, 0);
334 else
335 dJointAttach (c, b1, b2);
336 };
337 }
338}*/
339
340void Scene_game::BotTargetControl()
341{
342 //Prepare position
343 for (int i = 0; i < m_player_container->m_player.count; i ++)
344 {
345 Player* player = m_player_container->m_player.item[i];
346 player->m_posx = 0.0;
347 player->m_posy = 0.0;
348 player->m_posz = 0.0;
349
350 Ghost* ghost = player->GetGhost();
351 if (!ghost)
352 continue;
353 Model* model = ghost->GetModel();
354 if (!model)
355 continue;
356
357 player->m_enable = model->IsEnable();
358 model->GetPosition(player->m_posx, player->m_posy, player->m_posz);
359 };
360
361 for (int i = 0; i < m_player_container->m_player.count; i ++)
362 {
363 Player* player_a = m_player_container->m_player.item[i];
364 if (!player_a->m_enable)
365 continue;
366
367 if (player_a->Type() == Player::PLT_LOCAL)
368 continue;
369
370 if (((PlayerBot*)player_a)->Enemy() != 0)
371 {
372 if (Probability(95.0))
373 continue;
374 }
375
376 for (int j = 0; j < m_player_container->m_player.count; j ++)
377 {
378 if (i == j)
379 continue;
380
381 Player* player_b = m_player_container->m_player.item[j];
382 if (!player_b->m_enable)
383 continue;
384
385 if (player_a->Fraction() != player_b->Fraction()) //if enemy
386 {
387 float length = line_len(player_a->m_posx, player_a->m_posy, player_a->m_posz,
388 player_b->m_posx, player_b->m_posy, player_b->m_posz);
389 if (length < 500.0 && Probability(30.0))
390 {
391 Ghost* ghost = player_b->GetGhost();
392 if (ghost)
393 {
394 ((PlayerBot*)player_a)->SetEnemy(ghost->GetModel());
395 break;
396 }
397 };
398 } else //if friends
399 {
400
401 }
402 };
403 };
404};
405
406void Scene_game::Control()
407{
408 m_time = m_speedometer->GetTime();
409 m_duration = m_speedometer->GetFrameDuration();
410 //m_duration /= 10.0;
411
412 if (m_key_controller->is_pressed(&m_mouse_left))
413 {
414 m_alfa += float(m_key_controller->get_axis_delta(&m_mouse_x))*0.5f;
415 m_beta += float(m_key_controller->get_axis_delta(&m_mouse_y))*0.5f;
416 };
417
418 if (m_key_controller->is_pressed(&m_mouse_right))
419 {
420 m_length += float(m_key_controller->get_axis_delta(&m_mouse_y))*0.5f;
421 };
422
423 //Enable area around players
424 float range = 1000.0f;
425
426 //1. Disable All, Break, Reset
427 bool removed = false;
428 for (int i = 0; i < m_player_container->m_player.count; i ++)
429 {
430 Player* player = m_player_container->m_player.item[i];
431 Ghost* ghost = player->GetGhost();
432 if (!ghost)
433 continue;
434 Model* model = ghost->GetModel();
435 if (!model)
436 continue;
437
438 if (model->IsDead() && model->DisapearOnDie())
439 {
440 CreateCloud(player->m_posx, player->m_posy, player->m_posz);
441 RemovePlayer(player);
442 removed = true;
443 continue;
444 };
445
446 if (player->Type() == Player::PLT_BOT && model)
447 model->Disable();
448 if (ghost)
449 ghost->Reset();
450 if (model)
451 model->Break();
452 }
453 if (removed)
454 m_player_container->m_player.recheck();
455 m_object->Disable();
456 m_object->Break();
457
458 //2. Enable areas
459 for (int i = 0; i < m_player_container->m_player.count; i ++)
460 {
461 Player* player = m_player_container->m_player.item[i];
462 Ghost* ghost = player->GetGhost();
463 if (!ghost)
464 continue;
465 Model* model = ghost->GetModel();
466 if (!model)
467 continue;
468 if (player->Type() == Player::PLT_LOCAL && model)
469 {
470 Body_base* body = model->GetBaseBody();
471 if (body)
472 {
473 float x, y, z;
474 body->GetPosition(x, y, z);
475 m_object->AutioEnable(x, y, z, range);
476 for (int j = 0; j < m_player_container->m_player.count; j ++)
477 {
478 Player* player_bot = m_player_container->m_player.item[j];
479 Ghost* ghost_bot = player_bot->GetGhost();
480 if (!ghost_bot)
481 continue;
482 Model* model_bot = ghost_bot->GetModel();
483 if (!model_bot)
484 continue;
485 if (player_bot->Type() == Player::PLT_BOT && model_bot)
486 {
487 model_bot->AutioEnable(x, y, z, range);
488 }
489 }
490 };
491 };
492 }
493
494 m_call_back_count = 0;
495
496 if (m_key_controller->is_hit(&m_test_y))
497 {
498 CreateClone(m_player);
499 //m_sound_engine->PlayAtom("../../data/Sound/sfx/00.wav");
500 //ActivateMusic(MUSIC_FIGHT);
501// Body_base* body = m_model->FindBody("objHucked");
502// Mesh_base * mesh = 0;
503// if (body)
504// mesh = body->GetMesh();
505// if (mesh)
506// {
507// mesh->Exchange(0.1f);
508// }
509 };
510
511 if (m_key_controller->is_hit(&m_test_t))
512 {
513 //m_sound_engine->PlayAtom("../../data/Sound/sfx/29.wav");
514 ActivateMusic(MUSIC_NORMAL);
515// Body_base* body = m_model->FindBody("objHucked");
516// Mesh_base * mesh = 0;
517// if (body)
518// mesh = body->GetMesh();
519// if (mesh)
520// {
521// mesh->Exchange(-0.1f);
522// }
523 };
524
525 m_time_phisick = m_speedometer->GetTime();
526
527 if (m_duration < 0.001)
528 m_duration = 0.001;
529
530 if (m_duration > 40.0)
531 m_duration = 40.0;
532
533 double step_floor = 100.0;
534 double time_scale = 200.0;
535 int ph_iterations = 10;
536
537 //Need to do full control circle dSpaceCollide, dWorldStepFast1, body control
538 /*if (m_duration > step_floor)
539 {
540 int step = 2;//int (m_duration / step_floor) + 1;
541 double step_mul = m_duration / double(step);
542 for (int i = 0; i < step; i ++)
543 {
544 dSpaceCollide(m_space, this, &nearCallback);
545 dWorldStepFast1(m_world, float(step_mul/time_scale), ph_iterations);
546 }
547 } else*/
548 {
549 //dSpaceCollide(m_space, this, &nearCallback);
550 m_time_phisick_b = m_speedometer->GetTime();
551 //dWorldStepFast1(m_world, float(m_duration/time_scale), ph_iterations);
552 //dWorldQuickStep(m_world, float(m_duration/time_scale));
553 //dWorldStep(m_world, float(m_duration/time_scale));
554
555 //printf("%3.0f", m_duration);
556 };
557 //dWorldQuickStep(m_world, float(m_duration/300.0));
558 //dWorldStep(m_world, float(m_duration/300.0));
559
560 //Process contact, to get "OnGround" status
561
562 //Clear all contacts
563 //dJointGroupEmpty(m_contactgroup);
564
565 //printf("%d\n", m_call_back_count);
566
567 m_time_model = m_speedometer->GetTime();
568
569 //Control all
570 m_object->Control(m_duration);
571
572 m_player_container->Control();
573 for (int i = 0; i < m_player_container->m_player.count; i ++)
574 {
575 Player* player = m_player_container->m_player.item[i];
576 Ghost* ghost = player->GetGhost();
577 if (!ghost)
578 continue;
579 Model* model = ghost->GetModel();
580 if (!model)
581 continue;
582 if (model)
583 {
584 model->Control(m_duration);
585 };
586 }
587
588 BotTargetControl();
589
590
591 /*if (m_model->IsDead())
592 {
593 ActivateMusic(MUSIC_DIE);
594 } else
595 if (m_in_combat && !in_fight)
596 {
597 ActivateMusic(MUSIC_NORMAL);
598 m_in_combat = false;
599 } else
600 if (!m_in_combat && in_fight)
601 {
602 ActivateMusic(MUSIC_FIGHT);
603 m_in_combat = true;
604 };*/
605
606 //Live regeneration
607 for (int i = 0; i < m_player_container->m_player.count; i ++)
608 {
609 Player* player = m_player_container->m_player.item[i];
610 Ghost* ghost = player->GetGhost();
611 if (!ghost)
612 continue;
613 Model* model = ghost->GetModel();
614 if (!model)
615 continue;
616
617 if (player->Type() == Player::PLT_LOCAL && model && !model->IsDead())
618 {
619 model->m_live += 1.0 * m_duration/1000.0;
620 if (model->m_live > model->m_live_max)
621 model->m_live = model->m_live_max;
622 };
623 }
624
625 ControlCloud(m_duration);
626
627 /*if (m_test_particle)
628 {
629 m_test_particle->AddParticle(50.0f, 0.0f, -1.2f,
630 0.0f,0.0f,0.0f,
631 rndf(-5.0f, 5.0f),rndf(-5.0f, 5.0f),rndf(1.0f, 5.0f),
632 rndf(-1.0f, 1.0f),rndf(-1.0f, 1.0f),rndf(0.1f, 1.0f),
633 rndf(-15.0f, 15.0f), rndf(-8.0f, 8.0f), 10000.0f);
634 m_test_particle->Caclulate(m_duration);
635 }*/
636
637 if (m_core->GLightModel() == 1)
638 m_object->CalculateVertexLightDynamic(m_sun);
639
640 if (m_sky)
641 m_sky->SetRotation(90.0f, float(m_time) / 100.0f);
642
643
644 //Track control
645 ControlMusic(m_duration);
646
647 m_time_control_end = m_speedometer->GetTime();
648};
649
650void Scene_game::DrawLive(double live, double live_max, int texture)
651{
652 m_graphick->SetTexture(false, -1);
653
654 int green = int((live/live_max) * 255.0);
655 int red = int((1.0 - live/live_max) * 255.0);
656
657 glColor4ub(red, green, 0, 255);
658
659 double len = (0.49375 - 0.06875) * (live/live_max);
660 glBegin(GL_QUADS);
661 glVertex3f(float(0.49375 - len), -0.01428f, -1.0f);
662 glVertex3f(0.49375f, -0.01428f, -1.0f);
663 glVertex3f(0.49375f, -0.05f, -1.0f);
664 glVertex3f(float(0.49375 - len), -0.05f, -1.0f);
665 glEnd();
666
667 /*glBegin(GL_QUADS);
668 glVertex3f(0.06875, -0.01428, -1.0f);
669 glVertex3f(0.49375, -0.01428, -1.0f);
670 glVertex3f(0.49375, -0.05f, -1.0f);
671 glVertex3f(0.06875, -0.05f, -1.0f);
672 glEnd();*/
673
674 glColor4ub(255, 255, 255, 255);
675 m_graphick->SetTexture(true, texture);
676
677 //if (rand()%5 == 0)
678 {
679 glBegin(GL_QUADS);
680 glTexCoord2f(0.0f, 0.0f);
681 glVertex3f(0.0f, -0.1f, -1.0f);
682
683 glTexCoord2f(0.69f, 0.0f);
684 glVertex3f(0.55f, -0.1f, -1.0f);
685
686 glTexCoord2f(0.69f, 1.0f);
687 glVertex3f(0.55f, 0.0f, -1.0f);
688
689 glTexCoord2f(0.0f, 1.0f);
690 glVertex3f(0.0f, 0.0f, -1.0f);
691 glEnd();
692 };
693}
694
695void Scene_game::DrawChakra()
696{
697 glColor4ub(255, 255, 255, 255);
698 glBegin(GL_QUADS);
699 glTexCoord2f(0.0f, 0.4f);
700 glVertex3f(0.0f, -0.1f, -1.0f);
701
702 glTexCoord2f(0.64f, 0.4f);
703 glVertex3f(0.55f, -0.1f, -1.0f);
704
705 glTexCoord2f(0.64f, 1.0f);
706 glVertex3f(0.55f, 0.0f, -1.0f);
707
708 glTexCoord2f(0.0f, 1.0f);
709 glVertex3f(0.0f, 0.0f, -1.0f);
710 glEnd();
711}
712
713void Scene_game::PaintPlayerUi(Model* model, Player* player, float x, float y)
714{
715 m_graphick->SetAlphaTest(false);
716 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
717 m_graphick->PushMatrix();
718
719 Body_physic* phb = model->GetBaseBody();
720 if (phb)
721 {
722 char str[MAX_CORE_STRING];
723 sprintf_s(str, MAX_CORE_STRING, "%2.2f;%2.2f;%2.2f", -m_cam_x, -m_cam_y, m_cam_z);
724 if (model->OnGround())
725 strcat_s(str, 1024, " *");
726 if (m_in_combat)
727 strcat_s(str, 1024, " C");
728 m_core->TextDraw(Core_base::FONT_DEFAULT, str, -m_graphick->GetVirtualWidth()/2.0f + 0.1f+x, 0.60f+y, -1.0f, 0.02f, 0xffffffff);
729
730 //output live
731 m_graphick->SetBlend(false);
732 m_graphick->SetAlphaTest(true);
733
734 m_graphick->PushMatrix();
735
736 glTranslatef(-m_graphick->GetVirtualWidth()/2.0f + 0.1f+x, 0.7f+y, 0.0f);
737 glScalef(0.7f, 0.7f, 1.0f);
738 DrawLive(model->m_live, model->m_live_max, m_live_texture->m_texture);
739 m_graphick->PopMatrix();
740
741 m_graphick->SetTexture(true, m_chakra_texture->m_texture);
742 m_graphick->PushMatrix();
743 glTranslatef(-m_graphick->GetVirtualWidth()/2.0f + 0.06f+x, 0.68f+y, 0.0f);
744 glScalef(0.7f, 0.7f, 1.0f);
745 DrawChakra();
746 m_graphick->PopMatrix();
747 };
748
749 m_graphick->PopMatrix();
750}
751
752void Scene_game::PaintUi()
753{
754 if (m_player)
755 {
756 Ghost* ghost = m_player->GetGhost();
757 Model* model = ghost->GetModel();
758 PaintPlayerUi(model, m_player, 0.0f, 0.0f);
759 }
760
761 if (m_player1)
762 {
763 Ghost* ghost = m_player1->GetGhost();
764 Model* model = ghost->GetModel();
765 PaintPlayerUi(model, m_player1, 0.0f, -0.1f);
766 }
767
768 if (m_player2)
769 {
770 Ghost* ghost = m_player2->GetGhost();
771 Model* model = ghost->GetModel();
772 PaintPlayerUi(model, m_player2, 0.0f, -0.2f);
773 }
774};
775
776void Scene_game::Paint()
777{
778 m_graphick->PushMatrix();
779
780 if (m_core->GFbo())
781 {
782 m_graphick->StartBaseRender(0);
783 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
784 }
785
786 Model* model = 0;
787 if (m_player)
788 {
789 Ghost* ghost = m_player->GetGhost();
790 model = ghost->GetModel();
791 }
792
793 if (model)
794 //if (false)
795 {
796 float x, y, z;
797 model->GetPosition(x, y, z);
798 m_cam_x = -x;
799 m_cam_y = -y;
800 m_cam_z = -z;
801 Body_physic* phb = model->GetBaseBody();
802 if (phb)
803 {
804 float xr, yr, zr, wr;
805 phb->PhGetRotate(xr, yr, zr, wr);
806 float angle = -2*GetAngel(xr, wr) + 180.0f;
807
808 while (angle < 0.0f)
809 angle = 360.0f + angle;
810 while (angle > 360.0f)
811 angle = angle - 360.0f;
812
813 while (m_alfa < 0.0f)
814 m_alfa = 360.0f + m_alfa;
815 while (m_alfa > 360.0f)
816 m_alfa = m_alfa - 360.0f;
817
818 float delta = (m_alfa - angle);
819 if (abs(delta) > abs(m_alfa - (angle + 360)))
820 delta = m_alfa - (angle + 360);
821 if (abs(delta) > abs(m_alfa + 360 - angle))
822 delta = m_alfa + 360 - angle;
823
824 //m_alfa = (m_alfa + 720)*0.95f + (angle + 720)*0.05f;
825 if (model->IsMove())
826 m_alfa -= delta/10.0f;
827
828 while (m_alfa < 0.0f)
829 m_alfa = 360.0f + m_alfa;
830 while (m_alfa > 360.0f)
831 m_alfa = m_alfa - 360.0f;
832 //m_alfa = angle;
833
834 if (model && m_player1)
835 {
836 float x2, y2, z2;
837 Ghost* ghost = m_player1->GetGhost();
838 Model* model1 = ghost->GetModel();
839 model1->GetPosition(x2, y2, z2);
840 float angle = -GetAngel(x2-x, y2-y) + 90.0f;
841 m_alfa = angle;
842 };
843 }
844 };
845
846 m_time_paint_start = m_speedometer->GetTime();
847 glTranslatef(0,0,-m_length);
848
849 glRotatef(m_beta, 1, 0, 0);
850 glRotatef(m_alfa, 0, 0, 1);
851
852 //glPushMatrix();
853 //glTranslatef(m_cam_x/10.0f, m_cam_y/10.0f, m_cam_z/10.0f);
854 if (m_sky)
855 m_sky->Paint();
856 //glPopMatrix();
857 glTranslatef(m_cam_x, m_cam_y, m_cam_z);
858
859
860 //Apply lights
861 m_sun->m_position.x = (float)(cos(m_time / 1000.0) * 100.0);
862 m_sun->m_position.y = (float)(sin(m_time / 1000.0) * 100.0);
863 m_sun->m_position.z = 20.0;
864 m_sun->ApplyWorldPosition(m_graphick);
865
866 if (m_glsl_sample_shader)
867 {
868 m_glsl_sample_shader->Enable();
869 m_glsl_sample_shader->SetLight0(m_sun->m_world_position.x, m_sun->m_world_position.y, m_sun->m_world_position.z, 1.0);
870 m_glsl_sample_shader->Disable();
871 };
872
873 if (m_glsl_simple_light_shader)
874 {
875 m_glsl_simple_light_shader->Enable();
876 m_glsl_simple_light_shader->SetLight0(m_sun->m_world_position.x, m_sun->m_world_position.y, m_sun->m_world_position.z, 1.0);
877 m_glsl_simple_light_shader->Disable();
878 };
879
880 if (m_glsl_vertex_light_shader)
881 {
882 m_glsl_vertex_light_shader->Enable();
883 m_glsl_vertex_light_shader->SetLight0(m_sun->m_world_position.x, m_sun->m_world_position.y, m_sun->m_world_position.z, 1.0);
884 m_glsl_vertex_light_shader->Disable();
885 }
886
887 if (m_glsl_pixel_light_shader)
888 {
889 m_glsl_pixel_light_shader->Enable();
890 m_glsl_pixel_light_shader->SetLight0(m_sun->m_world_position.x, m_sun->m_world_position.y, m_sun->m_world_position.z, 1.0);
891 m_glsl_pixel_light_shader->Disable();
892 }
893
894
895 //Draw SUN
896 glBegin(GL_LINES);
897 float r = 10.0f;
898 glColor4f(0.0, 1.0, 0.0, 1.0);
899 glVertex3f(m_sun->m_position.x-r, m_sun->m_position.y, m_sun->m_position.z);
900 glVertex3f(m_sun->m_position.x+r, m_sun->m_position.y, m_sun->m_position.z);
901
902 glVertex3f(m_sun->m_position.x, m_sun->m_position.y-r, m_sun->m_position.z);
903 glVertex3f(m_sun->m_position.x, m_sun->m_position.y+r, m_sun->m_position.z);
904
905 glVertex3f(m_sun->m_position.x, m_sun->m_position.y, m_sun->m_position.z-r);
906 glVertex3f(m_sun->m_position.x, m_sun->m_position.y, m_sun->m_position.z+r);
907 glEnd();
908
909 Scene_base::Paint();
910
911 m_time_paint_model = m_speedometer->GetTime();
912
913 //if (m_glsl_outline_shader && m_glsl_sample_shader)
914 if (false)
915 {
916 glEnable(GL_CULL_FACE);
917
918 //Paint players and bots
919 for (int i = 0; i < m_player_container->m_player.count; i ++)
920 {
921 Player* player = m_player_container->m_player.item[i];
922 Ghost* ghost = player->GetGhost();
923 if (!ghost)
924 continue;
925 Model* model = ghost->GetModel();
926 if (!model || !model->IsEnable())
927 continue;
928 if (model->InvalidNormals())
929 glCullFace(GL_FRONT);
930 else
931 glCullFace(GL_BACK);
932 model->SetShader(m_glsl_sample_shader);
933 model->paint();
934
935 if (model->InvalidNormals())
936 glCullFace(GL_BACK);
937 else
938 glCullFace(GL_FRONT);
939 model->SetShader(m_glsl_outline_shader);
940 model->paint();
941 }
942 glDisable(GL_CULL_FACE);
943 } else
944 {
945 for (int i = 0; i < m_player_container->m_player.count; i ++)
946 {
947 Player* player = m_player_container->m_player.item[i];
948 Ghost* ghost = player->GetGhost();
949 if (!ghost)
950 continue;
951 Model* model = ghost->GetModel();
952 if (!model || !model->IsEnable())
953 continue;
954 model->SetShader(m_glsl_skinning_shader);
955 model->paint();
956 }
957 }
958
959 /*m_graphick->SetTexture(false, -1);
960 m_graphick->SetBlend(false);
961 m_graphick->SetAlphaTest(false);
962 glColor3ub(0, 255, 0);
963 glBegin(GL_LINES);
964 int index = 0;
965 for (int i = 0; i < LineDebugArrayCount/6; i ++)
966 {
967 glVertex3f(LineDebugArray[index]-250, -LineDebugArray[index+2]+250, LineDebugArray[index+1]);
968 index += 3;
969 glVertex3f(LineDebugArray[index]-250, -LineDebugArray[index+2]+250, LineDebugArray[index+1]);
970 index += 3;
971 }
972 glEnd();
973 LineDebugArrayCount = 0; */
974
975 if (m_glsl_particle_shader)
976 m_glsl_particle_shader->Enable();
977
978 glDepthMask(false);
979 /*if (m_test_particle)
980 {
981 m_test_particle->PrepareToDraw();
982 m_test_particle->Paint();
983 };*/
984 for (int i = 0; i < m_particle_list.count; i ++)
985 {
986 ParticleAlpha* particle = m_particle_list.item[i];
987 particle->prepare_to_draw();
988 particle->paint();
989 }
990
991 for (int i = 0; i < m_player_container->m_player.count; i ++)
992 {
993 Player* player = m_player_container->m_player.item[i];
994 Ghost* ghost = player->GetGhost();
995 if (!ghost)
996 continue;
997 Model* model = ghost->GetModel();
998 if (!model || !model->IsEnable())
999 continue;
1000 model->PaintParticle();
1001 };
1002 glDepthMask(true);
1003
1004 if (m_glsl_particle_shader)
1005 m_glsl_particle_shader->Disable();
1006
1007 if (m_core->GFbo())
1008 PaintPostProcess();
1009
1010
1011 m_graphick->PopMatrix();
1012
1013 m_time_paint_end = m_speedometer->GetTime();
1014
1015 PaintUi();
1016
1017 char string[1024];
1018 sprintf_s(string, 1024, "%dp %dm", m_particle_list.count, m_player_container->m_player.count);
1019 m_core->TextDraw(Core_base::FONT_DEFAULT, string, m_graphick->GetVirtualWidth()/2.0f - 0.355f, 0.60f, -1.0f, 0.04f, 0xffffffff);
1020
1021 sprintf_s(string, 1024, "R%.0f P%.0f(%.0f %.0f) M%.0f", m_time_phisick - m_time, m_time_model - m_time_phisick,
1022 m_time_phisick_b - m_time_phisick, m_time_model - m_time_phisick_b,
1023 m_time_control_end - m_time_model);
1024 m_core->TextDraw(Core_base::FONT_DEFAULT, string, m_graphick->GetVirtualWidth()/2.0f - 0.355f, 0.55f, -1.0f, 0.04f, 0xffffffff);
1025
1026 sprintf_s(string, 1024, "S%.0f M%.0f", m_time_paint_model - m_time_paint_start, m_time_paint_end - m_time_paint_model);
1027 m_core->TextDraw(Core_base::FONT_DEFAULT, string, m_graphick->GetVirtualWidth()/2.0f - 0.355f, 0.50f, -1.0f, 0.04f, 0xffffffff);
1028
1029};
1030
1031void Scene_game::PaintPostProcess()
1032{
1033 m_graphick->StartBaseRender(1);
1034 //render to second texture
1035 m_graphick->SetTexture(true, ((graphick_OpenGl*)m_graphick)->m_fbo_color_texture[0]);
1036 m_graphick->DrawScreenBar();
1037
1038 m_graphick->StartBaseRender(0);
1039 //Draw post objects
1040 //m_graphick->SetTexture(true, m_twirl_test->m_texture);
1041 m_graphick->SetTexture(true, m_twirl_test->m_texture, ((graphick_OpenGl*)m_graphick)->m_fbo_color_texture[1]);
1042 if (m_glsl_post_object_shader)
1043 m_glsl_post_object_shader->Enable();
1044
1045 glRotatef(float(-m_time)/2.0f, 0.0, 0.0, 1.0);
1046 m_graphick->SetBlend(false);
1047 glColor4f(1.0, 1.0, 1.0, 1.0);
1048
1049 glBegin(GL_QUADS);
1050 glTexCoord2f(0.0f, 0.0f);
1051 glVertex3f(-40.0, -40.0, 20.0f);
1052
1053 glTexCoord2f(1.0f, 0.0f);
1054 glVertex3f(40.0, -40.0, 20.0f);
1055
1056 glTexCoord2f(1.0f, 1.0f);
1057 glVertex3f(40.0, 40.0, 20.0f);
1058
1059 glTexCoord2f(0.0f, 1.0f);
1060 glVertex3f(-40.0, 40.0, 20.0f);
1061 glEnd();
1062
1063 //m_glsl_post_object_shader->Debug();
1064 if (m_glsl_post_object_shader)
1065 m_glsl_post_object_shader->Disable();
1066
1067 m_graphick->StopBaseRender();
1068 //Swap to main context
1069 if (m_glsl_glow_shader)
1070 m_glsl_glow_shader->Enable();
1071 glColor4f(1.0, 1.0, 1.0, 1.0);
1072 //m_graphick->SetTexture(false, -1);
1073 m_graphick->SetTexture(true, ((graphick_OpenGl*)m_graphick)->m_fbo_color_texture[0]);
1074 m_graphick->DrawScreenBar();
1075 if (m_glsl_glow_shader)
1076 m_glsl_glow_shader->Disable();
1077};
1078
1079void Scene_game::Paint_2()
1080{
1081};
1082
1083void Scene_game::ApplyObjectLightModel()
1084{
1085 int light_mode = m_core->GLightModel();
1086
1087 for (int i = 0; i < m_object->m_body_list.count; i ++)
1088 {
1089 Body_base* body = m_object->m_body_list.item[i];
1090 if (body)
1091 {
1092 if (light_mode == 0 || light_mode == 1) //disable shaders
1093 {
1094 body->CalculateVertexLight(m_sun);
1095 body->SetShader(0);
1096 } else
1097 if (light_mode == 2) //Vertex lighting shader
1098 {
1099 body->SetShader(m_glsl_vertex_light_shader);
1100 } else
1101 if (light_mode == 3) //Pixel or bump shader
1102 {
1103 body->SetShader(m_glsl_pixel_light_shader);
1104 };
1105 };
1106 };
1107};
1108
1109void Scene_game::LinkBody(char* body_a, char* body_b)
1110{
1111 Body_base* b1 = m_object->FindBody(body_a);
1112 Body_base* b2 = m_object->FindBody(body_b);
1113 if (!b1 || !b2)
1114 return;
1115 if (b1->IsPhysic() == false || b2->IsPhysic() == false)
1116 return;
1117
1118 float x, y, z;
1119 b1->GetPosition(x, y, z);
1120 //((Body_physic*)b1)->PhJointLinkTo(m_world, m_joint_group, ((Body_physic*)b2), x, y, z);
1121};
1122
1123void Scene_game::TestSphereAdd()
1124{
1125 /*Body_physic* bd_1 = new Body_physic;
1126
1127 dBodyID body_1 = dBodyCreate(m_world);
1128 dMass m_1;
1129 dMassSetBox(&m_1, 1.0f, 20.0f, 20.0f, 20.0f);
1130 dBodySetMass(body_1, &m_1);
1131 dGeomID geom_1 = dCreateBox(0, 20.0f, 20.0f, 20.0f);
1132 dGeomSetBody(geom_1, body_1);
1133 dSpaceAdd(m_space, geom_1);
1134 dBodySetMaxAngularSpeed(body_1, 0.0f);
1135
1136 bd_1->SetPhysicBody(body_1, geom_1);
1137 bd_1->PhBodySetOffset(0.0f, 0.0f, 0.0f);
1138 bd_1->PhBodySetMatrix();
1139 bd_1->PhSetPosition(60.0f, -80.0f, 100.0f);
1140 bd_1->DebugContact(true);
1141
1142 Mesh_base* mesh_1 = new Mesh_base;
1143 mesh_1->CreateBox(10.0f, 10, 10);
1144 bd_1->SetMesh(mesh_1);
1145 bd_1->SetColorDiffuse(0, 255, 0, 255);
1146 m_object->insert_body(bd_1);*/
1147};
1148
1149void Scene_game::TestSliderAdd()
1150{
1151 /*Body_physic* bd_1 = new Body_physic;
1152
1153 dBodyID body_1 = dBodyCreate(m_world);
1154 dMass m_1;
1155 dMassSetBox(&m_1, 1.0f, 20.0f, 20.0f, 20.0f);
1156 dBodySetMass(body_1, &m_1);
1157 dGeomID geom_1 = dCreateBox(0, 20.0f, 20.0f, 20.0f);
1158 dGeomSetBody(geom_1, body_1);
1159 dSpaceAdd(m_space, geom_1);
1160 bd_1->SetPhysicBody(body_1, geom_1);
1161 bd_1->PhBodySetOffset(0.0f, 0.0f, 0.0f);
1162 bd_1->PhBodySetMatrix();
1163 bd_1->PhSetPosition(100.0f, 0.0f, 100.0f);
1164 bd_1->DebugContact(true);
1165
1166 Mesh_base* mesh_1 = new Mesh_base;
1167 mesh_1->CreateBox(20.0f, 20.0f, 20.0f);
1168 bd_1->SetMesh(mesh_1);
1169 bd_1->SetColorDiffuse(0, 255, 255, 255);
1170 m_object->insert_body(bd_1);
1171
1172
1173 Body_physic* bd_2 = new Body_physic;
1174
1175 dBodyID body_2 = dBodyCreate(m_world);
1176 dMass m_2;
1177 dMassSetBox(&m_2, 1.0f, 20.0f, 20.0f, 20.0f);
1178 dBodySetMass(body_2, &m_2);
1179 dGeomID geom_2 = dCreateBox(0, 20.0f, 20.0f, 20.0f);
1180 dGeomSetBody(geom_2, body_2);
1181 dSpaceAdd(m_space, geom_2);
1182 bd_2->SetPhysicBody(body_2, geom_2);
1183 bd_2->PhBodySetOffset(0.0f, 0.0f, 0.0f);
1184 bd_2->PhBodySetMatrix();
1185 bd_2->PhSetPosition(60.0f, 0.0f, 100.0f);
1186 bd_2->DebugContact(true);
1187
1188 Mesh_base* mesh_2 = new Mesh_base;
1189 mesh_2->CreateBox(20.0f, 20.0f, 20.0f);
1190 bd_2->SetMesh(mesh_2);
1191 bd_2->SetColorDiffuse(255, 255, 0, 255);
1192 m_object->insert_body(bd_2);
1193
1194
1195 //slide joint
1196 dJointID joint = dJointCreateSlider(m_world, 0);
1197 dJointAttach(joint, body_1, body_2);
1198 dJointSetSliderAxis(joint, 1.0f, 0.0f, 0.0f);
1199 //dJointSetSliderParam(joint, dParamFMax, 4000.0);
1200 dJointSetSliderParam(joint, dParamLoStop, 0.0f);
1201 dJointSetSliderParam(joint, dParamHiStop, +20.0f);*/
1202};
1203
1204bool Scene_game::InsertPlayer(PlayerLocal** player_prt, int player_number)
1205{
1206 *player_prt = PlayerCreateLocal();
1207 PlayerLocal* player = *player_prt;
1208
1209 if (player_number == 0)
1210 {
1211 player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_KEYBOARD, 0, VK_UP);
1212 player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_KEYBOARD, 0, VK_DOWN);
1213 player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_KEYBOARD, 0, VK_LEFT);
1214 player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_KEYBOARD, 0, VK_RIGHT);
1215 player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_KEYBOARD, 0, VK_SPACE);
1216 player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, 0x5A);
1217 player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_KEYBOARD, 0, 0x58);
1218 /*player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 1, 1002);
1219 player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 1, 1003);
1220 player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 1, 1000);
1221 player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 1, 1001);
1222
1223 player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 1, 0);
1224 player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 1, 1);
1225 player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 1, 2);*/
1226 } else
1227 if (player_number == 1)
1228 {
1229 player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_KEYBOARD, 0, 0x68);
1230 player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_KEYBOARD, 0, 0x65);
1231 player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_KEYBOARD, 0, 0x64);
1232 player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_KEYBOARD, 0, 0x66);
1233 player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_KEYBOARD, 0, 0x60);
1234 player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, 0x63);
1235 player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_KEYBOARD, 0, 0x6e);
1236
1237 /*player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 0, 1002);
1238 player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 0, 1003);
1239 player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 0, 1000);
1240 player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 0, 1001);
1241
1242 player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 0, 0);
1243 player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 0, 1);
1244 player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 0, 2);*/
1245 };
1246
1247 if (player_number == 2)
1248 {
1249 /*player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_KEYBOARD, 0, 0x68);
1250 player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_KEYBOARD, 0, 0x65);
1251 player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_KEYBOARD, 0, 0x64);
1252 player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_KEYBOARD, 0, 0x66);
1253 player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_KEYBOARD, 0, 0x60);
1254 player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, 0x63);
1255 player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_KEYBOARD, 0, 0x6e);*/
1256
1257 player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 0, 1002);
1258 player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 0, 1003);
1259 player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 0, 1000);
1260 player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 0, 1001);
1261
1262 player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 0, 0);
1263 player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 0, 1);
1264 player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 0, 2);
1265 };
1266
1267 //find startup position
1268 char str_startup_name[2048];
1269 sprintf_s(str_startup_name, 2048, "###STARTUP%.2d", player_number);
1270 Body_base* start_up_body = m_object->FindBody(str_startup_name);
1271 if (!start_up_body)
1272 {
1273 m_core->OnCoreWarning("Scene_game: Cant find startup body");
1274 m_core->OnCoreWarning(str_startup_name);
1275 m_core->OnCoreWarning("\n");
1276 }
1277
1278 //Model* model = new ModelNaruto;
1279 Model* model = new ModelSasuke;
1280 model->m_live = 300;
1281 model->m_live_max = 300;
1282 model->SetShader(m_glsl_outline_shader);
1283 model->set_texture_container(m_texture);
1284 //model->set_ph_world(m_world);
1285 //model->set_ph_space(m_space);
1286 //model->set_ph_joint(m_joint_group);
1287 model->SetCore(m_core);
1288 model->SetSoundEngine(m_sound_engine);
1289 model->Initialize();
1290 if (start_up_body)
1291 {
1292 float x, y, z;
1293 start_up_body->GetPosition(x, y, z);
1294 model->MoveTo(x, y, z+model->GetOverGround());
1295
1296 Tmatrix matrix;
1297 start_up_body->GetMatrix(matrix);
1298 x = 1.0;
1299 y = 0.0;
1300 z = 0.0;
1301 UseMatrixRotate(matrix.matrix.elements_16, x, y, z);
1302
1303 float angle = GetAngel(x, y);
1304 model->SetRotation(angle+180);
1305 }
1306
1307 GhostCharacter* ghost = new GhostCharacter;
1308 player->SetGhost(ghost);
1309 ghost->SetModel(model);
1310
1311 player->SetFraction(FractionType::FR_GOOD);
1312
1313 return true;
1314}
1315
1316bool EqualPart(char* full_string, char* str_part)
1317{
1318 if (strlen(full_string) < strlen(str_part))
1319 return false;
1320
1321 for (int i = 0; i < int(strlen(str_part)); i ++)
1322 {
1323 if (full_string[i] != str_part[i])
1324 return false;
1325 }
1326 return true;
1327}
1328
1329void Scene_game::InitializeBot(PlayerBot* bot_player, Model* bot_model, Body_base* body)
1330{
1331 float x, y, z;
1332 body->GetPosition(x, y, z);
1333
1334 Tmatrix matrix;
1335 body->GetMatrix(matrix);
1336 float xm = 1.0;
1337 float ym = 0.0;
1338 float zm = 0.0;
1339 UseMatrixRotate(matrix.matrix.elements_16, xm, ym, zm);
1340 float angle = GetAngel(x, y);
1341
1342 InitializeBot(bot_player, bot_model, x, y, z + bot_model->GetOverGround(), angle);
1343}
1344
1345void Scene_game::InitializeBot(PlayerBot* bot_player, Model* bot_model, float x, float y, float z, float angle)
1346{
1347 bot_model->SetShader(m_glsl_sample_shader);
1348 bot_model->set_texture_container(m_texture);
1349 //bot_model->set_ph_world(m_world);
1350 //bot_model->set_ph_space(m_space);
1351 //bot_model->set_ph_joint(m_joint_group);
1352 bot_model->Initialize();
1353 bot_model->SetCore(m_core);
1354 bot_model->SetSoundEngine(m_sound_engine);
1355
1356 bot_model->MoveTo(x, y, z);
1357
1358 bot_model->SetRotation(angle+180);
1359
1360 GhostCharacter* ghost = new GhostCharacter;
1361 ghost->SetModel(bot_model);
1362 bot_player->SetGhost(ghost);
1363
1364 bot_player->SetFraction(FractionType::FR_BAD);
1365}
1366
1367void Scene_game::FindAndInsertBot()
1368{
1369 for (int i = 0; i < m_object->m_body_list.count; i ++)
1370 {
1371 Body_base* body = m_object->m_body_list.item[i];
1372 if (!body)
1373 continue;
1374 if (EqualPart(body->Name(), "###BOT00"))
1375 {
1376 PlayerBot* bot_player = PlayerCreateBot();
1377 Model* bot_model = new BadNinja;
1378 InitializeBot(bot_player, bot_model, body);
1379 }
1380 if (EqualPart(body->Name(), "###BOT01"))
1381 {
1382 PlayerBot* bot_player = PlayerCreateBot();
1383 Model* bot_model = new ModelRogueNinja;
1384 InitializeBot(bot_player, bot_model, body);
1385 bot_model->m_power_scale = 1.0;
1386 bot_model->m_live = 300.0;
1387 bot_model->m_live_max = 300.0;
1388
1389 bot_player->m_punch_probability = 7.0;
1390 bot_player->m_ran_away_probability = 0.0;
1391 bot_player->m_attack_probability = 5.0;
1392 }
1393 if (EqualPart(body->Name(), "###BOT02"))
1394 {
1395 /*PlayerBot* bot_player = PlayerCreateBot();
1396 Model* bot_model = new ModelNaruto;
1397 InitializeBot(bot_player, bot_model, body);
1398 bot_model->m_power_scale = 1.0;
1399 bot_model->m_live = 300.0;
1400 bot_model->m_live_max = 300.0;
1401
1402 bot_player->m_punch_probability = 9.0;
1403 bot_player->m_ran_away_probability = 0.0;
1404 bot_player->m_attack_probability = 8.0;
1405
1406 bot_player->SetFraction(FractionType::FR_GOOD);
1407
1408 bot_player->SetAssistantPlayer(m_player);*/
1409 }
1410 }
1411};
1412
1413void Scene_game::CreateClone(Player* player)
1414{
1415 PlayerBot* bot_player = PlayerCreateBot();
1416 Model* bot_model = new ModelNaruto;
1417 InitializeBot(bot_player, bot_model, player->m_posx + 50, player->m_posy, player->m_posz, 0.0);
1418 bot_model->m_power_scale = 0.5;
1419 bot_model->m_live = 10.0;
1420 bot_model->m_live_max = 10.0;
1421
1422 bot_player->m_punch_probability = 9.0;
1423 bot_player->m_ran_away_probability = 0.0;
1424 bot_player->m_attack_probability = 8.0;
1425
1426 bot_player->SetFraction(FractionType::FR_GOOD);
1427
1428 bot_player->SetAssistantPlayer(player);
1429
1430 bot_model->SetDisapearOnDie(true);
1431
1432 CreateCloud(player->m_posx + 50, player->m_posy, player->m_posz);
1433}
1434
1435PlayerLocal* Scene_game::PlayerCreateLocal()
1436{
1437 PlayerLocal* player = new PlayerLocal;
1438 player->SetPlayerContainer(m_player_container);
1439 m_player_container->AddPlayer(player);
1440 return player;
1441};
1442
1443PlayerBot* Scene_game::PlayerCreateBot()
1444{
1445 PlayerBot* player = new PlayerBot;
1446 player->SetPlayerContainer(m_player_container);
1447 m_player_container->AddPlayer(player);
1448 return player;
1449};
1450
1451void Scene_game::RemovePlayer(Player * player)
1452{
1453 Ghost* ghost = player->GetGhost();
1454 Model* model = 0;
1455 if (ghost)
1456 model = ghost->GetModel();
1457
1458 for (int i = 0; i < m_player_container->m_player.count; i ++)
1459 {
1460 if (m_player_container->m_player.item[i])
1461 m_player_container->m_player.item[i]->NotifyDelete(player, model);
1462 }
1463
1464 //Find player to delete
1465 m_player_container->Remove(player->GetId());
1466};
1467
1468bool Scene_game::Initialize()
1469{
1470 if (!Scene_base::Initialize())
1471 return false;
1472
1473 /*dInitODE();
1474 m_world = dWorldCreate();
1475 m_space = dHashSpaceCreate(0);
1476 //m_space = dSweepAndPruneSpaceCreate(0, dSAP_AXES_XYZ);
1477 //dHashSpaceSetLevels(m_space, 0, 20);
1478 m_contactgroup = dJointGroupCreate(0);
1479 m_joint_group = dJointGroupCreate(0);
1480
1481 dWorldSetGravity(m_world, 0.0f, 0.0f, -9.8f);
1482 dWorldSetERP(m_world, 0.1f);
1483 dWorldSetCFM(m_world, 0.00001f);
1484 dWorldSetQuickStepNumIterations(m_world, 320);
1485 dWorldSetContactSurfaceLayer(m_world, 0.0f);
1486 dWorldSetAutoDisableFlag(m_world, true);
1487 dWorldSetAutoDisableAngularThreshold(m_world, 1.0f);
1488 dWorldSetAutoDisableLinearThreshold(m_world, 1.0f);
1489
1490 dWorldSetMaxAngularSpeed(m_world, 80.0f);
1491 dWorldSetContactMaxCorrectingVel(m_world, 100.0f);
1492
1493 dWorldSetMaxLinearSpeed(m_world, 60.0f);*/
1494
1495 m_player_container = new PlayerContainer;
1496
1497 if (((graphick_OpenGl*)m_graphick)->GlslSupport())
1498 {
1499 m_glsl_sample_shader = new GlslShader;
1500 if (!m_glsl_sample_shader->Create(vertex_cartoon_shader, fragment_cartoon_shader))
1501 {
1502 delete m_glsl_sample_shader;
1503 m_glsl_sample_shader = 0;
1504 }
1505 m_glsl_particle_shader = new GlslShader;
1506 if (!m_glsl_particle_shader->Create(vertex_particle_shader, 0))
1507 {
1508 delete m_glsl_particle_shader;
1509 m_glsl_particle_shader = 0;
1510 }
1511
1512 m_glsl_outline_shader = new GlslShader;
1513 if (!m_glsl_outline_shader->Create(vertex_contur_shader, fragment_contur_shader))
1514 {
1515 delete m_glsl_outline_shader;
1516 m_glsl_outline_shader = 0;
1517 }
1518
1519 m_glsl_glow_shader = new GlslShader;
1520 if (!m_glsl_glow_shader->Create(0, fragment_glow_shader))
1521 {
1522 delete m_glsl_glow_shader;
1523 m_glsl_glow_shader = 0;
1524 }
1525
1526
1527 m_glsl_post_object_shader = new GlslShader;
1528 if (!m_glsl_post_object_shader->Create(vertex_post_object_shader, fragment_post_object_shader))
1529 {
1530 delete m_glsl_post_object_shader;
1531 m_glsl_post_object_shader = 0;
1532 }
1533
1534 m_glsl_vertex_light_shader = new GlslShader;
1535 if (!m_glsl_vertex_light_shader->Create(vertex_vertrex_light_shader, 0))
1536 {
1537 delete m_glsl_vertex_light_shader;
1538 m_glsl_vertex_light_shader = 0;
1539 }
1540
1541 m_glsl_skinning_shader = new GlslShader;
1542 if (!m_glsl_skinning_shader->Create(vertex_skinning_shader, 0))
1543 {
1544 delete m_glsl_skinning_shader;
1545 m_glsl_skinning_shader = 0;
1546 }
1547
1548 m_glsl_simple_light_shader = new GlslShader;
1549 if (!m_glsl_simple_light_shader->Create(vertex_vertrex_light_shader, 0))
1550 //if (!m_glsl_simple_light_shader->Create(vertex_pixel_light_shader, fragment_pixel_light_shader))
1551 //if (!m_glsl_simple_light_shader->Create(vertex_bump_light_shader, fragment_bump_light_shader))
1552 {
1553 delete m_glsl_simple_light_shader;
1554 m_glsl_simple_light_shader = 0;
1555 }
1556
1557 m_glsl_pixel_light_shader = new GlslShader;
1558 if (!m_glsl_pixel_light_shader->Create(vertex_pixel_light_shader, fragment_pixel_light_shader))
1559 {
1560 delete m_glsl_pixel_light_shader;
1561 m_glsl_pixel_light_shader = 0;
1562 }
1563
1564 }
1565
1566 /*player_2->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 0, 1002);
1567 player_2->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 0, 1003);
1568 player_2->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 0, 1000);
1569 player_2->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 0, 1001);
1570
1571 player_2->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 0, 0);
1572 player_2->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 0, 1);
1573 player_2->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 0, 2);*/
1574 //player_2->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, VK_NUMPAD0);*/
1575
1576 /*m_object->set_ph_world(m_world);
1577 m_object->set_ph_space(m_space);
1578 m_object->set_ph_joint(m_joint_group);*/
1579
1580 //m_object->load("../../data/stage/demo_01.n3d");
1581 m_object->load("../../data/stage/test_05.n3d");
1582 m_object->InternalObjectLoad();
1583 double player_count = m_core->GetValue("game_player_count");
1584 InsertPlayer(&m_player, 0);
1585 if (player_count > 1.0)
1586 InsertPlayer(&m_player1, 1);
1587 if (player_count > 2.0)
1588 InsertPlayer(&m_player2, 2);
1589
1590 FindAndInsertBot();
1591
1592 Texture_instance* grass_txt = m_texture->load_texture("../../data/texture/grass/grass_01.bmp", Texture_instance::TXT_CLAMPING_EDGE);
1593
1594 m_object->BuildGrassMesh("#grass", 10.0f, m_core->GGrassDentisy()*40.0f, 1, grass_txt);
1595
1596 /*Body_base* bd = m_object->FindBody("Plane01");
1597 if (bd)
1598 bd->BuildGrassMesh(10.0f, 20.0f, 1, grass_txt);*/
1599
1600 m_sky = new Sky;
1601 m_sky->Initialize();
1602 Texture_instance* texture = m_texture->load_texture("../../data/texture/sky/sky_01.bmp", 0);//Texture_instance::TXT_CLAMPING
1603 m_sky->SetMainSkyTexture(texture);
1604
1605 Texture_instance* front = m_texture->load_texture("../../data/texture/skybox/02/front.jpg", Texture_instance::TXT_CLAMPING_EDGE);
1606 Texture_instance* left = m_texture->load_texture("../../data/texture/skybox/02/left.jpg", Texture_instance::TXT_CLAMPING_EDGE);
1607 Texture_instance* right = m_texture->load_texture("../../data/texture/skybox/02/right.jpg", Texture_instance::TXT_CLAMPING_EDGE);
1608 Texture_instance* back = m_texture->load_texture("../../data/texture/skybox/02/back.jpg", Texture_instance::TXT_CLAMPING_EDGE);
1609 Texture_instance* top = m_texture->load_texture("../../data/texture/skybox/02/top.jpg", Texture_instance::TXT_CLAMPING_EDGE);
1610 Texture_instance* bottom = m_texture->load_texture("../../data/texture/skybox/02/bottom.jpg", Texture_instance::TXT_CLAMPING_EDGE);
1611 m_sky->SetSkyBoxTextures(front, left, right, back, top, bottom);
1612
1613 m_sun = new LightBase;
1614
1615 m_sun->m_position.x = -5000.0f;
1616 m_sun->m_position.y = 5000.0f;
1617 m_sun->m_position.z = 5000.0f;
1618
1619 m_sun->m_lighting_max.x = 1.0f;
1620 m_sun->m_lighting_max.y = 1.0f;
1621 m_sun->m_lighting_max.z = 1.0f;
1622
1623 m_sun->m_lighting_normal.x = 0.5f;
1624 m_sun->m_lighting_normal.y = 0.5f;
1625 m_sun->m_lighting_normal.z = 0.5f;
1626
1627 m_sun->m_lighting_min.x = 0.0f;
1628 m_sun->m_lighting_min.y = 0.0f;
1629 m_sun->m_lighting_min.z = 0.0f;
1630
1631 m_perticle_smoke = m_texture->load_texture("../../data/texture/fx/smoke.bmp", Texture_instance::TXT_CLAMPING);
1632 m_twirl_test = m_texture->load_texture("../../data/texture/fx/twirl_00.bmp"/*, Texture_instance::TXT_CLAMPING*/);
1633
1634 ApplyObjectLightModel();
1635
1636 /*m_test_particle = new Particle;
1637 m_test_particle->Create(1024);
1638 Texture_instance* particle_texture = m_texture->load_texture("../../data/texture/fx/particle_test.jpg", Texture_instance::TXT_CLAMPING);
1639 m_test_particle->SetTexture(particle_texture, 2, 2);*/
1640
1641 /*m_object->load("../../data/object/Naruto_tst1.N3D");
1642 LinkBody("FootR", "LegRd");
1643 LinkBody("LegRd", "LegR");
1644
1645 LinkBody("FootL", "LegLd");
1646 LinkBody("LegLd", "LegL");
1647
1648 LinkBody("LegR", "Torso");
1649 LinkBody("LegL", "Torso");
1650 LinkBody("body", "Torso");
1651
1652 LinkBody("HandRd", "HandR");
1653 LinkBody("HandLd", "HandL");
1654
1655 LinkBody("HandR", "body");
1656 LinkBody("HandL", "body");
1657
1658 LinkBody("Head", "body");*/
1659
1660
1661 m_mouse_x.Set(Tkey::DV_MOUSE, 0, 1000);
1662 m_mouse_y.Set(Tkey::DV_MOUSE, 0, 1001);
1663 m_mouse_left.Set(Tkey::DV_MOUSE, 0, 1);
1664 m_mouse_right.Set(Tkey::DV_MOUSE, 0, 2);
1665
1666 m_test_y.Set(Tkey::DV_KEYBOARD, 0, VK_ADD);
1667 m_test_t.Set(Tkey::DV_KEYBOARD, 0, VK_SUBTRACT);
1668
1669 //Load GUI
1670 m_live_texture = m_texture->load_texture("../../data/texture/gui/game_ui/live.bmp", Texture_instance::TXT_CLAMPING_EDGE);
1671 m_chakra_texture = m_texture->load_texture("../../data/texture/gui/game_ui/chakra.bmp", Texture_instance::TXT_CLAMPING_EDGE);
1672
1673 SetClearColor(1.0f, 1.0f, 1.0f, 1.0f);
1674 m_speedometer->Reset();
1675
1676 return true;
1677};
1678
1679void Scene_game::Destroy()
1680{
1681 if (m_track_a_id != -1 && m_sound_engine)
1682 m_sound_engine->StopTrack(m_track_a_id);
1683 m_track_a_id = -1;
1684
1685 if (m_track_b_id != -1 && m_sound_engine)
1686 m_sound_engine->StopTrack(m_track_b_id);
1687 m_track_b_id = -1;
1688
1689 if (m_glsl_particle_shader)
1690 delete m_glsl_particle_shader;
1691 m_glsl_particle_shader = 0;
1692
1693 if (m_glsl_outline_shader)
1694 delete m_glsl_outline_shader;
1695 m_glsl_outline_shader = 0;
1696
1697 if (m_player_container)
1698 delete m_player_container;
1699 m_player_container;
1700
1701 /*if (m_joint_group)
1702 dJointGroupDestroy(m_contactgroup);
1703 if (m_contactgroup)
1704 dJointGroupDestroy(m_contactgroup);
1705 if (m_space)
1706 dSpaceDestroy(m_space);
1707 if (m_world)
1708 dWorldDestroy(m_world);
1709 dCloseODE();*/
1710
1711 if (m_sky)
1712 delete m_sky;
1713 m_sky = 0;
1714
1715 if (m_sun)
1716 delete m_sun;
1717 m_sun = 0;
1718
1719 if (m_live_texture)
1720 {
1721 m_live_texture->release_instance();
1722 m_live_texture = 0;
1723 };
1724
1725 if (m_chakra_texture)
1726 {
1727 m_chakra_texture->release_instance();
1728 m_chakra_texture = 0;
1729 };
1730
1731 if (m_test_particle)
1732 delete m_test_particle;
1733 m_test_particle = 0;
1734
1735 Scene_base::Destroy();
1736};