PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/project/Naruto_ninja_story/Scene_game.cpp

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