/project/Naruto_ninja_story/Scene_game.cpp
C++ | 1736 lines | 1059 code | 242 blank | 435 comment | 217 complexity | 6330e7ab88bc223741be11c3aa9df114 MD5 | raw file
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
-
- #include "Scene_game.h"
-
- #include "tools/Speedometr.h"
- #include "tools/tools.h"
- #include "Graphick/Texture/Texture.h"
- #include "Graphick/Texture/TextureContainer.h"
- #include "Core/Core.h"
- #include "Game/GhostCharacter.h"
- #include "Graphick/Graphick.h"
- #include "Graphick/OpenGL/OpenGl.h"
- #include "Graphick/OpenGL/vertex_shader.h"
- #include "Graphick/OpenGL/fragment_shader.h"
- #include "Game/PlayerContainer.h"
-
- Scene_game::Scene_game()
- {
- m_time = 0.0;
- m_duration = 0.0;
-
- m_alfa = 0;
- m_beta = -60.0f;
- m_length = 120;
-
- m_sky = 0;
- m_sun = 0;
-
- m_cam_x = 0.0f;
- m_cam_y = 0.0f;
- m_cam_z = 0.0f;
- m_call_back_count = 0;
- m_glsl_sample_shader = 0;
- m_glsl_particle_shader = 0;
-
- m_glsl_vertex_light_shader = 0;
- m_glsl_pixel_light_shader = 0;
- m_glsl_skinning_shader = 0;
-
- m_glsl_outline_shader = 0;
-
- m_player = 0;
- m_player1 = 0;
- m_player2 = 0;
-
- m_live_texture = 0;
- m_chakra_texture = 0;
-
- m_test_particle = 0;
-
- m_track_a_id = -1;
- m_track_a_volume = 0.0;
- m_track_a_state = 0;
-
- m_track_b_id = -1;
- m_track_b_volume = 0.0;
- m_track_b_state = 0;
-
- m_next_state = MUSIC_NONE;
- m_current_state = MUSIC_NONE;
- m_in_combat = false;
- m_test_particle = 0;
- m_perticle_smoke = 0;
-
- for (int i = 0; i < MUSIC_COUNT; i ++)
- {
- m_track_position[i] = 0;
- }
-
- m_player_container = 0;
- };
-
- Scene_game::~Scene_game()
- {
-
- };
-
- void Scene_game::CreateCloud(float x, float y, float z)
- {
- ParticleAlpha* particle = m_particle_list.add();
- particle->SetTexture(m_perticle_smoke, 1, 1);
- particle->Create(64);
- particle->SetLiveTime(4000.0);
- for (int i = 0; i < 64; i ++)
- {
- float r = rndf(8.0f, 12.0f);
- float v = rndf(1.0f, 4.0f);
-
- float a = rndf(0.0f, 6.28f);
- float b = rndf(0.0f, 6.28f);
- particle->add_particle(rndf(6.0f, 16.0f),
- x + cos(a)*sin(b)*r, y + sin(a)*sin(b)*r, z + cos(b)*r*2.0f,
- cos(a)*sin(b)*v, sin(a)*sin(b)*v, cos(b)*v,
- 1.0f, -0.8f, rndf(200.0f, 500.0f), 9000.0f);
- }
- }
-
- void Scene_game::ControlCloud(double time)
- {
- bool recheck = false;
- for (int i = 0; i < m_particle_list.count; i ++)
- {
- ParticleAlpha* particle = m_particle_list.item[i];
- particle->caclulate(time);
- if (!particle->IsLive())
- {
- recheck = true;
- particle->Destroy();
- delete particle;
- m_particle_list.item[i] = 0;
- }
- }
-
- if (recheck)
- {
- m_particle_list.recheck();
- }
- };
-
- void Scene_game::ActivateMusic(MUSIC_SITUATION music)
- {
- if (m_current_state != music)
- m_next_state = music;
- };
-
- void Scene_game::ControlMusic(double duration)
- {
- if (!m_sound_engine)
- return;
-
- if (m_next_state != MUSIC_NONE && m_track_b_state == 0)
- {
- //move current track to gain down (b)
- m_track_b_id = m_track_a_id;
- m_track_b_volume = m_track_a_volume;
- m_track_b_state = m_track_a_state;
- m_track_a_id = -1;
- m_track_a_state = 0;
-
- if (m_sound_engine)
- {
- if (m_next_state == MUSIC_NORMAL)
- {
- m_track_a_state = 1;
- m_track_a_volume = 0.0;
- } else
- if (m_next_state == MUSIC_FIGHT)
- {
- m_track_a_state = 1;
- m_track_a_id = m_sound_engine->PlayTrack("../../data/music/Naruto Main Theme.ogg", true);
- m_sound_engine->SetTrackPosition(m_track_a_id, m_track_position[MUSIC_FIGHT]);
- printf(" Position set %.3f\n", m_track_position[MUSIC_FIGHT]);
- if (m_track_a_id == -1)
- m_track_a_state = 0;
- m_track_a_volume = 0.0;
- } else
- if (m_next_state == MUSIC_DIE)
- {
- m_track_a_state = 1;
- m_track_a_id = m_sound_engine->PlayTrack("../../data/music/Sangeki no Ato.ogg", true);
- m_sound_engine->SetTrackPosition(m_track_a_id, m_track_position[MUSIC_DIE]);
- if (m_track_a_id == -1)
- m_track_a_state = 0;
- m_track_a_volume = 0.0;
- };
- }
-
- if (m_track_b_id > -1)
- {
- //Save track position
- m_track_position[m_current_state] = m_sound_engine->TrackPosition(m_track_b_id);
- printf(" Position save %.3f\n", m_track_position[m_current_state]);
- }
-
- m_current_state = m_next_state;
- m_next_state = MUSIC_NONE;
- }
- //control volume
- if (m_track_a_state != 0 && m_track_a_id > -1)
- {
- double old_volume = m_track_a_volume;
- m_track_a_volume += (duration / 1000.0)/5.0;
- if (m_track_a_volume > 1.0)
- m_track_a_volume = 1.0;
- if (old_volume != m_track_a_volume)
- {
- m_sound_engine->SetTrackVolume(m_track_a_id, m_track_a_volume);
- }
- };
-
- if (m_track_b_state != 0 && m_track_b_id > -1)
- {
- double old_volume = m_track_b_volume;
- m_track_b_volume -= (duration / 1000.0)/5.0;
- if (old_volume != m_track_b_volume)
- {
- m_sound_engine->SetTrackVolume(m_track_b_id, m_track_b_volume);
- }
- if (m_track_b_volume < 0.0)
- {
- m_track_b_volume = 0.0;
- m_sound_engine->StopTrack(m_track_b_id);
- m_track_b_state = 0;
- m_track_b_id = -1;
- };
- };
- if (m_track_b_state != 0 && m_track_b_id == -1)
- m_track_b_state = 0;
- };
-
- /*static void nearCallback (void *data, dGeomID o1, dGeomID o2)
- {
- Scene_game* scene = (Scene_game*) data;
- scene->m_call_back_count++;
- int i;
- // if (o1->body && o2->body) return;
-
- // exit without doing anything if the two bodies are connected by a joint
- dBodyID b1 = dGeomGetBody(o1);
- dBodyID b2 = dGeomGetBody(o2);
- if (b1 && b2 && !dBodyIsEnabled(b1) && !dBodyIsEnabled(b2))
- return;
-
- //Don't process 2 height field
- if (dGeomGetClass(o1) == dHeightfieldClass && dGeomGetClass(o2) == dHeightfieldClass)
- return;
-
- if (b1 && b2 && dAreConnectedExcluding (b1, b2, dJointTypeContact)) return;
-
- Body_physic* body_1 = 0;
- if (b1)
- body_1 = (Body_physic*)dBodyGetData(b1);
- Body_physic* body_2 = 0;
- if (b2)
- body_2 = (Body_physic*)dBodyGetData(b2);
- if (body_1 && body_2 && body_1->PhIsExclud(body_2))
- {
- return;
- };
-
- //Ignored group check
- if (body_1 && body_2 && body_1->IgnoredGroup() == body_2->IgnoredGroup() && body_1->IgnoredGroup() > -1)
- {
- return;
- };
-
- //float cfm1 = dWorldGetCFM(scene->m_world);
- //float cfm2 = cfm1;
-
- //if (body_1)
- // cfm1 = body_1->Cfm();
- //if (body_2)
- // cfm2 = body_2->Cfm();
-
- const int MAX_CONTACTS = 32;
- dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box
- for (i = 0; i < MAX_CONTACTS; i ++)
- {
-
- //dContactApprox1_1
- //dContactSoftCFM
- contact[i].surface.mode = dContactBounce | dContactMu2 | dContactApprox1_1 | dContactApprox1_2; //dContactBounce | dContactSoftCFM |
- contact[i].surface.mu = dInfinity; //Ice
- contact[i].surface.mu2 = dInfinity;
-
- contact[i].surface.bounce = 0.0; //0.1
- contact[i].surface.bounce_vel = 0.0; //0.1
-
- contact[i].surface.motion1 = 0.0;
- contact[i].surface.motion2 = 0.0;
- contact[i].surface.motionN = 0.0;
-
- //contact[i].surface.soft_erp = 0.5f;
- contact[i].surface.soft_cfm = dInfinity;//(cfm1 + cfm2) / 2.0f;
- }
-
- if (int numc = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact)))
- {
- if (body_1 && body_1->DebugContact())
- {
- //Store all contacts
- body_1->SetContact(contact, numc);
- };
- if (body_2 && body_2->DebugContact())
- {
- //Store all contacts
- body_2->SetContact(contact, numc);
- };
-
- if (body_1 && body_2)
- {
- Body_action* action_1 = body_1->BindAction();
- Body_action* action_2 = body_2->BindAction();
-
- if (action_1 && body_2->ProcessCollision())
- action_1->ExecAction(body_1, body_2);
- if (action_2 && body_1->ProcessCollision())
- action_2->ExecAction(body_2, body_1);
- };
-
- for (i = 0; i < numc; i++)
- {
- if (body_1)
- {
- if (contact[i].geom.normal[2] > 0.01f)
- body_1->OnGround(true);
-
- if (!body_1->ProcessCollision())
- {
- //Skip collision
- break;
- };
- };
- if (body_2)
- {
- if (contact[i].geom.normal[2] > 0.01f)
- body_2->OnGround(true);
-
- if (!body_2->ProcessCollision())
- {
- //Skip collision
- break;
- };
- };
- dJointID c = dJointCreateContact (scene->m_world, scene->m_contactgroup, contact+i);
- if (!b1 || dBodyIsKinematic(b1) > 0)
- dJointAttach (c, 0, b2);
- else
- if (!b2 || dBodyIsKinematic(b2) > 0)
- dJointAttach (c, b1, 0);
- else
- dJointAttach (c, b1, b2);
- };
- }
- }*/
-
- void Scene_game::BotTargetControl()
- {
- //Prepare position
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- player->m_posx = 0.0;
- player->m_posy = 0.0;
- player->m_posz = 0.0;
-
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model)
- continue;
-
- player->m_enable = model->IsEnable();
- model->GetPosition(player->m_posx, player->m_posy, player->m_posz);
- };
-
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player_a = m_player_container->m_player.item[i];
- if (!player_a->m_enable)
- continue;
-
- if (player_a->Type() == Player::PLT_LOCAL)
- continue;
-
- if (((PlayerBot*)player_a)->Enemy() != 0)
- {
- if (Probability(95.0))
- continue;
- }
-
- for (int j = 0; j < m_player_container->m_player.count; j ++)
- {
- if (i == j)
- continue;
-
- Player* player_b = m_player_container->m_player.item[j];
- if (!player_b->m_enable)
- continue;
-
- if (player_a->Fraction() != player_b->Fraction()) //if enemy
- {
- float length = line_len(player_a->m_posx, player_a->m_posy, player_a->m_posz,
- player_b->m_posx, player_b->m_posy, player_b->m_posz);
- if (length < 500.0 && Probability(30.0))
- {
- Ghost* ghost = player_b->GetGhost();
- if (ghost)
- {
- ((PlayerBot*)player_a)->SetEnemy(ghost->GetModel());
- break;
- }
- };
- } else //if friends
- {
-
- }
- };
- };
- };
-
- void Scene_game::Control()
- {
- m_time = m_speedometer->GetTime();
- m_duration = m_speedometer->GetFrameDuration();
- //m_duration /= 10.0;
-
- if (m_key_controller->is_pressed(&m_mouse_left))
- {
- m_alfa += float(m_key_controller->get_axis_delta(&m_mouse_x))*0.5f;
- m_beta += float(m_key_controller->get_axis_delta(&m_mouse_y))*0.5f;
- };
-
- if (m_key_controller->is_pressed(&m_mouse_right))
- {
- m_length += float(m_key_controller->get_axis_delta(&m_mouse_y))*0.5f;
- };
-
- //Enable area around players
- float range = 1000.0f;
-
- //1. Disable All, Break, Reset
- bool removed = false;
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model)
- continue;
-
- if (model->IsDead() && model->DisapearOnDie())
- {
- CreateCloud(player->m_posx, player->m_posy, player->m_posz);
- RemovePlayer(player);
- removed = true;
- continue;
- };
-
- if (player->Type() == Player::PLT_BOT && model)
- model->Disable();
- if (ghost)
- ghost->Reset();
- if (model)
- model->Break();
- }
- if (removed)
- m_player_container->m_player.recheck();
- m_object->Disable();
- m_object->Break();
-
- //2. Enable areas
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model)
- continue;
- if (player->Type() == Player::PLT_LOCAL && model)
- {
- Body_base* body = model->GetBaseBody();
- if (body)
- {
- float x, y, z;
- body->GetPosition(x, y, z);
- m_object->AutioEnable(x, y, z, range);
- for (int j = 0; j < m_player_container->m_player.count; j ++)
- {
- Player* player_bot = m_player_container->m_player.item[j];
- Ghost* ghost_bot = player_bot->GetGhost();
- if (!ghost_bot)
- continue;
- Model* model_bot = ghost_bot->GetModel();
- if (!model_bot)
- continue;
- if (player_bot->Type() == Player::PLT_BOT && model_bot)
- {
- model_bot->AutioEnable(x, y, z, range);
- }
- }
- };
- };
- }
-
- m_call_back_count = 0;
-
- if (m_key_controller->is_hit(&m_test_y))
- {
- CreateClone(m_player);
- //m_sound_engine->PlayAtom("../../data/Sound/sfx/00.wav");
- //ActivateMusic(MUSIC_FIGHT);
- // Body_base* body = m_model->FindBody("objHucked");
- // Mesh_base * mesh = 0;
- // if (body)
- // mesh = body->GetMesh();
- // if (mesh)
- // {
- // mesh->Exchange(0.1f);
- // }
- };
-
- if (m_key_controller->is_hit(&m_test_t))
- {
- //m_sound_engine->PlayAtom("../../data/Sound/sfx/29.wav");
- ActivateMusic(MUSIC_NORMAL);
- // Body_base* body = m_model->FindBody("objHucked");
- // Mesh_base * mesh = 0;
- // if (body)
- // mesh = body->GetMesh();
- // if (mesh)
- // {
- // mesh->Exchange(-0.1f);
- // }
- };
-
- m_time_phisick = m_speedometer->GetTime();
-
- if (m_duration < 0.001)
- m_duration = 0.001;
-
- if (m_duration > 40.0)
- m_duration = 40.0;
-
- double step_floor = 100.0;
- double time_scale = 200.0;
- int ph_iterations = 10;
-
- //Need to do full control circle dSpaceCollide, dWorldStepFast1, body control
- /*if (m_duration > step_floor)
- {
- int step = 2;//int (m_duration / step_floor) + 1;
- double step_mul = m_duration / double(step);
- for (int i = 0; i < step; i ++)
- {
- dSpaceCollide(m_space, this, &nearCallback);
- dWorldStepFast1(m_world, float(step_mul/time_scale), ph_iterations);
- }
- } else*/
- {
- //dSpaceCollide(m_space, this, &nearCallback);
- m_time_phisick_b = m_speedometer->GetTime();
- //dWorldStepFast1(m_world, float(m_duration/time_scale), ph_iterations);
- //dWorldQuickStep(m_world, float(m_duration/time_scale));
- //dWorldStep(m_world, float(m_duration/time_scale));
-
- //printf("%3.0f", m_duration);
- };
- //dWorldQuickStep(m_world, float(m_duration/300.0));
- //dWorldStep(m_world, float(m_duration/300.0));
-
- //Process contact, to get "OnGround" status
-
- //Clear all contacts
- //dJointGroupEmpty(m_contactgroup);
-
- //printf("%d\n", m_call_back_count);
-
- m_time_model = m_speedometer->GetTime();
-
- //Control all
- m_object->Control(m_duration);
-
- m_player_container->Control();
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model)
- continue;
- if (model)
- {
- model->Control(m_duration);
- };
- }
-
- BotTargetControl();
-
-
- /*if (m_model->IsDead())
- {
- ActivateMusic(MUSIC_DIE);
- } else
- if (m_in_combat && !in_fight)
- {
- ActivateMusic(MUSIC_NORMAL);
- m_in_combat = false;
- } else
- if (!m_in_combat && in_fight)
- {
- ActivateMusic(MUSIC_FIGHT);
- m_in_combat = true;
- };*/
-
- //Live regeneration
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model)
- continue;
-
- if (player->Type() == Player::PLT_LOCAL && model && !model->IsDead())
- {
- model->m_live += 1.0 * m_duration/1000.0;
- if (model->m_live > model->m_live_max)
- model->m_live = model->m_live_max;
- };
- }
-
- ControlCloud(m_duration);
-
- /*if (m_test_particle)
- {
- m_test_particle->AddParticle(50.0f, 0.0f, -1.2f,
- 0.0f,0.0f,0.0f,
- rndf(-5.0f, 5.0f),rndf(-5.0f, 5.0f),rndf(1.0f, 5.0f),
- rndf(-1.0f, 1.0f),rndf(-1.0f, 1.0f),rndf(0.1f, 1.0f),
- rndf(-15.0f, 15.0f), rndf(-8.0f, 8.0f), 10000.0f);
- m_test_particle->Caclulate(m_duration);
- }*/
-
- if (m_core->GLightModel() == 1)
- m_object->CalculateVertexLightDynamic(m_sun);
-
- if (m_sky)
- m_sky->SetRotation(90.0f, float(m_time) / 100.0f);
-
-
- //Track control
- ControlMusic(m_duration);
-
- m_time_control_end = m_speedometer->GetTime();
- };
-
- void Scene_game::DrawLive(double live, double live_max, int texture)
- {
- m_graphick->SetTexture(false, -1);
-
- int green = int((live/live_max) * 255.0);
- int red = int((1.0 - live/live_max) * 255.0);
-
- glColor4ub(red, green, 0, 255);
-
- double len = (0.49375 - 0.06875) * (live/live_max);
- glBegin(GL_QUADS);
- glVertex3f(float(0.49375 - len), -0.01428f, -1.0f);
- glVertex3f(0.49375f, -0.01428f, -1.0f);
- glVertex3f(0.49375f, -0.05f, -1.0f);
- glVertex3f(float(0.49375 - len), -0.05f, -1.0f);
- glEnd();
-
- /*glBegin(GL_QUADS);
- glVertex3f(0.06875, -0.01428, -1.0f);
- glVertex3f(0.49375, -0.01428, -1.0f);
- glVertex3f(0.49375, -0.05f, -1.0f);
- glVertex3f(0.06875, -0.05f, -1.0f);
- glEnd();*/
-
- glColor4ub(255, 255, 255, 255);
- m_graphick->SetTexture(true, texture);
-
- //if (rand()%5 == 0)
- {
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(0.0f, -0.1f, -1.0f);
-
- glTexCoord2f(0.69f, 0.0f);
- glVertex3f(0.55f, -0.1f, -1.0f);
-
- glTexCoord2f(0.69f, 1.0f);
- glVertex3f(0.55f, 0.0f, -1.0f);
-
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(0.0f, 0.0f, -1.0f);
- glEnd();
- };
- }
-
- void Scene_game::DrawChakra()
- {
- glColor4ub(255, 255, 255, 255);
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.4f);
- glVertex3f(0.0f, -0.1f, -1.0f);
-
- glTexCoord2f(0.64f, 0.4f);
- glVertex3f(0.55f, -0.1f, -1.0f);
-
- glTexCoord2f(0.64f, 1.0f);
- glVertex3f(0.55f, 0.0f, -1.0f);
-
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(0.0f, 0.0f, -1.0f);
- glEnd();
- }
-
- void Scene_game::PaintPlayerUi(Model* model, Player* player, float x, float y)
- {
- m_graphick->SetAlphaTest(false);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- m_graphick->PushMatrix();
-
- Body_physic* phb = model->GetBaseBody();
- if (phb)
- {
- char str[MAX_CORE_STRING];
- sprintf_s(str, MAX_CORE_STRING, "%2.2f;%2.2f;%2.2f", -m_cam_x, -m_cam_y, m_cam_z);
- if (model->OnGround())
- strcat_s(str, 1024, " *");
- if (m_in_combat)
- strcat_s(str, 1024, " C");
- m_core->TextDraw(Core_base::FONT_DEFAULT, str, -m_graphick->GetVirtualWidth()/2.0f + 0.1f+x, 0.60f+y, -1.0f, 0.02f, 0xffffffff);
-
- //output live
- m_graphick->SetBlend(false);
- m_graphick->SetAlphaTest(true);
-
- m_graphick->PushMatrix();
-
- glTranslatef(-m_graphick->GetVirtualWidth()/2.0f + 0.1f+x, 0.7f+y, 0.0f);
- glScalef(0.7f, 0.7f, 1.0f);
- DrawLive(model->m_live, model->m_live_max, m_live_texture->m_texture);
- m_graphick->PopMatrix();
-
- m_graphick->SetTexture(true, m_chakra_texture->m_texture);
- m_graphick->PushMatrix();
- glTranslatef(-m_graphick->GetVirtualWidth()/2.0f + 0.06f+x, 0.68f+y, 0.0f);
- glScalef(0.7f, 0.7f, 1.0f);
- DrawChakra();
- m_graphick->PopMatrix();
- };
-
- m_graphick->PopMatrix();
- }
-
- void Scene_game::PaintUi()
- {
- if (m_player)
- {
- Ghost* ghost = m_player->GetGhost();
- Model* model = ghost->GetModel();
- PaintPlayerUi(model, m_player, 0.0f, 0.0f);
- }
-
- if (m_player1)
- {
- Ghost* ghost = m_player1->GetGhost();
- Model* model = ghost->GetModel();
- PaintPlayerUi(model, m_player1, 0.0f, -0.1f);
- }
-
- if (m_player2)
- {
- Ghost* ghost = m_player2->GetGhost();
- Model* model = ghost->GetModel();
- PaintPlayerUi(model, m_player2, 0.0f, -0.2f);
- }
- };
-
- void Scene_game::Paint()
- {
- m_graphick->PushMatrix();
-
- if (m_core->GFbo())
- {
- m_graphick->StartBaseRender(0);
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- }
-
- Model* model = 0;
- if (m_player)
- {
- Ghost* ghost = m_player->GetGhost();
- model = ghost->GetModel();
- }
-
- if (model)
- //if (false)
- {
- float x, y, z;
- model->GetPosition(x, y, z);
- m_cam_x = -x;
- m_cam_y = -y;
- m_cam_z = -z;
- Body_physic* phb = model->GetBaseBody();
- if (phb)
- {
- float xr, yr, zr, wr;
- phb->PhGetRotate(xr, yr, zr, wr);
- float angle = -2*GetAngel(xr, wr) + 180.0f;
-
- while (angle < 0.0f)
- angle = 360.0f + angle;
- while (angle > 360.0f)
- angle = angle - 360.0f;
-
- while (m_alfa < 0.0f)
- m_alfa = 360.0f + m_alfa;
- while (m_alfa > 360.0f)
- m_alfa = m_alfa - 360.0f;
-
- float delta = (m_alfa - angle);
- if (abs(delta) > abs(m_alfa - (angle + 360)))
- delta = m_alfa - (angle + 360);
- if (abs(delta) > abs(m_alfa + 360 - angle))
- delta = m_alfa + 360 - angle;
-
- //m_alfa = (m_alfa + 720)*0.95f + (angle + 720)*0.05f;
- if (model->IsMove())
- m_alfa -= delta/10.0f;
-
- while (m_alfa < 0.0f)
- m_alfa = 360.0f + m_alfa;
- while (m_alfa > 360.0f)
- m_alfa = m_alfa - 360.0f;
- //m_alfa = angle;
-
- if (model && m_player1)
- {
- float x2, y2, z2;
- Ghost* ghost = m_player1->GetGhost();
- Model* model1 = ghost->GetModel();
- model1->GetPosition(x2, y2, z2);
- float angle = -GetAngel(x2-x, y2-y) + 90.0f;
- m_alfa = angle;
- };
- }
- };
-
- m_time_paint_start = m_speedometer->GetTime();
- glTranslatef(0,0,-m_length);
-
- glRotatef(m_beta, 1, 0, 0);
- glRotatef(m_alfa, 0, 0, 1);
-
- //glPushMatrix();
- //glTranslatef(m_cam_x/10.0f, m_cam_y/10.0f, m_cam_z/10.0f);
- if (m_sky)
- m_sky->Paint();
- //glPopMatrix();
- glTranslatef(m_cam_x, m_cam_y, m_cam_z);
-
-
- //Apply lights
- m_sun->m_position.x = (float)(cos(m_time / 1000.0) * 100.0);
- m_sun->m_position.y = (float)(sin(m_time / 1000.0) * 100.0);
- m_sun->m_position.z = 20.0;
- m_sun->ApplyWorldPosition(m_graphick);
-
- if (m_glsl_sample_shader)
- {
- m_glsl_sample_shader->Enable();
- 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);
- m_glsl_sample_shader->Disable();
- };
-
- if (m_glsl_simple_light_shader)
- {
- m_glsl_simple_light_shader->Enable();
- 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);
- m_glsl_simple_light_shader->Disable();
- };
-
- if (m_glsl_vertex_light_shader)
- {
- m_glsl_vertex_light_shader->Enable();
- 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);
- m_glsl_vertex_light_shader->Disable();
- }
-
- if (m_glsl_pixel_light_shader)
- {
- m_glsl_pixel_light_shader->Enable();
- 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);
- m_glsl_pixel_light_shader->Disable();
- }
-
-
- //Draw SUN
- glBegin(GL_LINES);
- float r = 10.0f;
- glColor4f(0.0, 1.0, 0.0, 1.0);
- glVertex3f(m_sun->m_position.x-r, m_sun->m_position.y, m_sun->m_position.z);
- glVertex3f(m_sun->m_position.x+r, m_sun->m_position.y, m_sun->m_position.z);
-
- glVertex3f(m_sun->m_position.x, m_sun->m_position.y-r, m_sun->m_position.z);
- glVertex3f(m_sun->m_position.x, m_sun->m_position.y+r, m_sun->m_position.z);
-
- glVertex3f(m_sun->m_position.x, m_sun->m_position.y, m_sun->m_position.z-r);
- glVertex3f(m_sun->m_position.x, m_sun->m_position.y, m_sun->m_position.z+r);
- glEnd();
-
- Scene_base::Paint();
-
- m_time_paint_model = m_speedometer->GetTime();
-
- //if (m_glsl_outline_shader && m_glsl_sample_shader)
- if (false)
- {
- glEnable(GL_CULL_FACE);
-
- //Paint players and bots
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model || !model->IsEnable())
- continue;
- if (model->InvalidNormals())
- glCullFace(GL_FRONT);
- else
- glCullFace(GL_BACK);
- model->SetShader(m_glsl_sample_shader);
- model->paint();
-
- if (model->InvalidNormals())
- glCullFace(GL_BACK);
- else
- glCullFace(GL_FRONT);
- model->SetShader(m_glsl_outline_shader);
- model->paint();
- }
- glDisable(GL_CULL_FACE);
- } else
- {
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model || !model->IsEnable())
- continue;
- model->SetShader(m_glsl_skinning_shader);
- model->paint();
- }
- }
-
- /*m_graphick->SetTexture(false, -1);
- m_graphick->SetBlend(false);
- m_graphick->SetAlphaTest(false);
- glColor3ub(0, 255, 0);
- glBegin(GL_LINES);
- int index = 0;
- for (int i = 0; i < LineDebugArrayCount/6; i ++)
- {
- glVertex3f(LineDebugArray[index]-250, -LineDebugArray[index+2]+250, LineDebugArray[index+1]);
- index += 3;
- glVertex3f(LineDebugArray[index]-250, -LineDebugArray[index+2]+250, LineDebugArray[index+1]);
- index += 3;
- }
- glEnd();
- LineDebugArrayCount = 0; */
-
- if (m_glsl_particle_shader)
- m_glsl_particle_shader->Enable();
-
- glDepthMask(false);
- /*if (m_test_particle)
- {
- m_test_particle->PrepareToDraw();
- m_test_particle->Paint();
- };*/
- for (int i = 0; i < m_particle_list.count; i ++)
- {
- ParticleAlpha* particle = m_particle_list.item[i];
- particle->prepare_to_draw();
- particle->paint();
- }
-
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- Player* player = m_player_container->m_player.item[i];
- Ghost* ghost = player->GetGhost();
- if (!ghost)
- continue;
- Model* model = ghost->GetModel();
- if (!model || !model->IsEnable())
- continue;
- model->PaintParticle();
- };
- glDepthMask(true);
-
- if (m_glsl_particle_shader)
- m_glsl_particle_shader->Disable();
-
- if (m_core->GFbo())
- PaintPostProcess();
-
-
- m_graphick->PopMatrix();
-
- m_time_paint_end = m_speedometer->GetTime();
-
- PaintUi();
-
- char string[1024];
- sprintf_s(string, 1024, "%dp %dm", m_particle_list.count, m_player_container->m_player.count);
- m_core->TextDraw(Core_base::FONT_DEFAULT, string, m_graphick->GetVirtualWidth()/2.0f - 0.355f, 0.60f, -1.0f, 0.04f, 0xffffffff);
-
- sprintf_s(string, 1024, "R%.0f P%.0f(%.0f %.0f) M%.0f", m_time_phisick - m_time, m_time_model - m_time_phisick,
- m_time_phisick_b - m_time_phisick, m_time_model - m_time_phisick_b,
- m_time_control_end - m_time_model);
- m_core->TextDraw(Core_base::FONT_DEFAULT, string, m_graphick->GetVirtualWidth()/2.0f - 0.355f, 0.55f, -1.0f, 0.04f, 0xffffffff);
-
- sprintf_s(string, 1024, "S%.0f M%.0f", m_time_paint_model - m_time_paint_start, m_time_paint_end - m_time_paint_model);
- m_core->TextDraw(Core_base::FONT_DEFAULT, string, m_graphick->GetVirtualWidth()/2.0f - 0.355f, 0.50f, -1.0f, 0.04f, 0xffffffff);
-
- };
-
- void Scene_game::PaintPostProcess()
- {
- m_graphick->StartBaseRender(1);
- //render to second texture
- m_graphick->SetTexture(true, ((graphick_OpenGl*)m_graphick)->m_fbo_color_texture[0]);
- m_graphick->DrawScreenBar();
-
- m_graphick->StartBaseRender(0);
- //Draw post objects
- //m_graphick->SetTexture(true, m_twirl_test->m_texture);
- m_graphick->SetTexture(true, m_twirl_test->m_texture, ((graphick_OpenGl*)m_graphick)->m_fbo_color_texture[1]);
- if (m_glsl_post_object_shader)
- m_glsl_post_object_shader->Enable();
-
- glRotatef(float(-m_time)/2.0f, 0.0, 0.0, 1.0);
- m_graphick->SetBlend(false);
- glColor4f(1.0, 1.0, 1.0, 1.0);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f);
- glVertex3f(-40.0, -40.0, 20.0f);
-
- glTexCoord2f(1.0f, 0.0f);
- glVertex3f(40.0, -40.0, 20.0f);
-
- glTexCoord2f(1.0f, 1.0f);
- glVertex3f(40.0, 40.0, 20.0f);
-
- glTexCoord2f(0.0f, 1.0f);
- glVertex3f(-40.0, 40.0, 20.0f);
- glEnd();
-
- //m_glsl_post_object_shader->Debug();
- if (m_glsl_post_object_shader)
- m_glsl_post_object_shader->Disable();
-
- m_graphick->StopBaseRender();
- //Swap to main context
- if (m_glsl_glow_shader)
- m_glsl_glow_shader->Enable();
- glColor4f(1.0, 1.0, 1.0, 1.0);
- //m_graphick->SetTexture(false, -1);
- m_graphick->SetTexture(true, ((graphick_OpenGl*)m_graphick)->m_fbo_color_texture[0]);
- m_graphick->DrawScreenBar();
- if (m_glsl_glow_shader)
- m_glsl_glow_shader->Disable();
- };
-
- void Scene_game::Paint_2()
- {
- };
-
- void Scene_game::ApplyObjectLightModel()
- {
- int light_mode = m_core->GLightModel();
-
- for (int i = 0; i < m_object->m_body_list.count; i ++)
- {
- Body_base* body = m_object->m_body_list.item[i];
- if (body)
- {
- if (light_mode == 0 || light_mode == 1) //disable shaders
- {
- body->CalculateVertexLight(m_sun);
- body->SetShader(0);
- } else
- if (light_mode == 2) //Vertex lighting shader
- {
- body->SetShader(m_glsl_vertex_light_shader);
- } else
- if (light_mode == 3) //Pixel or bump shader
- {
- body->SetShader(m_glsl_pixel_light_shader);
- };
- };
- };
- };
-
- void Scene_game::LinkBody(char* body_a, char* body_b)
- {
- Body_base* b1 = m_object->FindBody(body_a);
- Body_base* b2 = m_object->FindBody(body_b);
- if (!b1 || !b2)
- return;
- if (b1->IsPhysic() == false || b2->IsPhysic() == false)
- return;
-
- float x, y, z;
- b1->GetPosition(x, y, z);
- //((Body_physic*)b1)->PhJointLinkTo(m_world, m_joint_group, ((Body_physic*)b2), x, y, z);
- };
-
- void Scene_game::TestSphereAdd()
- {
- /*Body_physic* bd_1 = new Body_physic;
-
- dBodyID body_1 = dBodyCreate(m_world);
- dMass m_1;
- dMassSetBox(&m_1, 1.0f, 20.0f, 20.0f, 20.0f);
- dBodySetMass(body_1, &m_1);
- dGeomID geom_1 = dCreateBox(0, 20.0f, 20.0f, 20.0f);
- dGeomSetBody(geom_1, body_1);
- dSpaceAdd(m_space, geom_1);
- dBodySetMaxAngularSpeed(body_1, 0.0f);
-
- bd_1->SetPhysicBody(body_1, geom_1);
- bd_1->PhBodySetOffset(0.0f, 0.0f, 0.0f);
- bd_1->PhBodySetMatrix();
- bd_1->PhSetPosition(60.0f, -80.0f, 100.0f);
- bd_1->DebugContact(true);
-
- Mesh_base* mesh_1 = new Mesh_base;
- mesh_1->CreateBox(10.0f, 10, 10);
- bd_1->SetMesh(mesh_1);
- bd_1->SetColorDiffuse(0, 255, 0, 255);
- m_object->insert_body(bd_1);*/
- };
-
- void Scene_game::TestSliderAdd()
- {
- /*Body_physic* bd_1 = new Body_physic;
-
- dBodyID body_1 = dBodyCreate(m_world);
- dMass m_1;
- dMassSetBox(&m_1, 1.0f, 20.0f, 20.0f, 20.0f);
- dBodySetMass(body_1, &m_1);
- dGeomID geom_1 = dCreateBox(0, 20.0f, 20.0f, 20.0f);
- dGeomSetBody(geom_1, body_1);
- dSpaceAdd(m_space, geom_1);
- bd_1->SetPhysicBody(body_1, geom_1);
- bd_1->PhBodySetOffset(0.0f, 0.0f, 0.0f);
- bd_1->PhBodySetMatrix();
- bd_1->PhSetPosition(100.0f, 0.0f, 100.0f);
- bd_1->DebugContact(true);
-
- Mesh_base* mesh_1 = new Mesh_base;
- mesh_1->CreateBox(20.0f, 20.0f, 20.0f);
- bd_1->SetMesh(mesh_1);
- bd_1->SetColorDiffuse(0, 255, 255, 255);
- m_object->insert_body(bd_1);
-
-
- Body_physic* bd_2 = new Body_physic;
-
- dBodyID body_2 = dBodyCreate(m_world);
- dMass m_2;
- dMassSetBox(&m_2, 1.0f, 20.0f, 20.0f, 20.0f);
- dBodySetMass(body_2, &m_2);
- dGeomID geom_2 = dCreateBox(0, 20.0f, 20.0f, 20.0f);
- dGeomSetBody(geom_2, body_2);
- dSpaceAdd(m_space, geom_2);
- bd_2->SetPhysicBody(body_2, geom_2);
- bd_2->PhBodySetOffset(0.0f, 0.0f, 0.0f);
- bd_2->PhBodySetMatrix();
- bd_2->PhSetPosition(60.0f, 0.0f, 100.0f);
- bd_2->DebugContact(true);
-
- Mesh_base* mesh_2 = new Mesh_base;
- mesh_2->CreateBox(20.0f, 20.0f, 20.0f);
- bd_2->SetMesh(mesh_2);
- bd_2->SetColorDiffuse(255, 255, 0, 255);
- m_object->insert_body(bd_2);
-
-
- //slide joint
- dJointID joint = dJointCreateSlider(m_world, 0);
- dJointAttach(joint, body_1, body_2);
- dJointSetSliderAxis(joint, 1.0f, 0.0f, 0.0f);
- //dJointSetSliderParam(joint, dParamFMax, 4000.0);
- dJointSetSliderParam(joint, dParamLoStop, 0.0f);
- dJointSetSliderParam(joint, dParamHiStop, +20.0f);*/
- };
-
- bool Scene_game::InsertPlayer(PlayerLocal** player_prt, int player_number)
- {
- *player_prt = PlayerCreateLocal();
- PlayerLocal* player = *player_prt;
-
- if (player_number == 0)
- {
- player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_KEYBOARD, 0, VK_UP);
- player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_KEYBOARD, 0, VK_DOWN);
- player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_KEYBOARD, 0, VK_LEFT);
- player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_KEYBOARD, 0, VK_RIGHT);
- player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_KEYBOARD, 0, VK_SPACE);
- player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, 0x5A);
- player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_KEYBOARD, 0, 0x58);
- /*player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 1, 1002);
- player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 1, 1003);
- player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 1, 1000);
- player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 1, 1001);
-
- player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 1, 0);
- player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 1, 1);
- player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 1, 2);*/
- } else
- if (player_number == 1)
- {
- player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_KEYBOARD, 0, 0x68);
- player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_KEYBOARD, 0, 0x65);
- player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_KEYBOARD, 0, 0x64);
- player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_KEYBOARD, 0, 0x66);
- player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_KEYBOARD, 0, 0x60);
- player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, 0x63);
- player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_KEYBOARD, 0, 0x6e);
-
- /*player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 0, 1002);
- player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 0, 1003);
- player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 0, 1000);
- player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 0, 1001);
-
- player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 0, 0);
- player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 0, 1);
- player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 0, 2);*/
- };
-
- if (player_number == 2)
- {
- /*player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_KEYBOARD, 0, 0x68);
- player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_KEYBOARD, 0, 0x65);
- player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_KEYBOARD, 0, 0x64);
- player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_KEYBOARD, 0, 0x66);
- player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_KEYBOARD, 0, 0x60);
- player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, 0x63);
- player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_KEYBOARD, 0, 0x6e);*/
-
- player->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 0, 1002);
- player->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 0, 1003);
- player->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 0, 1000);
- player->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 0, 1001);
-
- player->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 0, 0);
- player->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 0, 1);
- player->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 0, 2);
- };
-
- //find startup position
- char str_startup_name[2048];
- sprintf_s(str_startup_name, 2048, "###STARTUP%.2d", player_number);
- Body_base* start_up_body = m_object->FindBody(str_startup_name);
- if (!start_up_body)
- {
- m_core->OnCoreWarning("Scene_game: Cant find startup body");
- m_core->OnCoreWarning(str_startup_name);
- m_core->OnCoreWarning("\n");
- }
-
- //Model* model = new ModelNaruto;
- Model* model = new ModelSasuke;
- model->m_live = 300;
- model->m_live_max = 300;
- model->SetShader(m_glsl_outline_shader);
- model->set_texture_container(m_texture);
- //model->set_ph_world(m_world);
- //model->set_ph_space(m_space);
- //model->set_ph_joint(m_joint_group);
- model->SetCore(m_core);
- model->SetSoundEngine(m_sound_engine);
- model->Initialize();
- if (start_up_body)
- {
- float x, y, z;
- start_up_body->GetPosition(x, y, z);
- model->MoveTo(x, y, z+model->GetOverGround());
-
- Tmatrix matrix;
- start_up_body->GetMatrix(matrix);
- x = 1.0;
- y = 0.0;
- z = 0.0;
- UseMatrixRotate(matrix.matrix.elements_16, x, y, z);
-
- float angle = GetAngel(x, y);
- model->SetRotation(angle+180);
- }
-
- GhostCharacter* ghost = new GhostCharacter;
- player->SetGhost(ghost);
- ghost->SetModel(model);
-
- player->SetFraction(FractionType::FR_GOOD);
-
- return true;
- }
-
- bool EqualPart(char* full_string, char* str_part)
- {
- if (strlen(full_string) < strlen(str_part))
- return false;
-
- for (int i = 0; i < int(strlen(str_part)); i ++)
- {
- if (full_string[i] != str_part[i])
- return false;
- }
- return true;
- }
-
- void Scene_game::InitializeBot(PlayerBot* bot_player, Model* bot_model, Body_base* body)
- {
- float x, y, z;
- body->GetPosition(x, y, z);
-
- Tmatrix matrix;
- body->GetMatrix(matrix);
- float xm = 1.0;
- float ym = 0.0;
- float zm = 0.0;
- UseMatrixRotate(matrix.matrix.elements_16, xm, ym, zm);
- float angle = GetAngel(x, y);
-
- InitializeBot(bot_player, bot_model, x, y, z + bot_model->GetOverGround(), angle);
- }
-
- void Scene_game::InitializeBot(PlayerBot* bot_player, Model* bot_model, float x, float y, float z, float angle)
- {
- bot_model->SetShader(m_glsl_sample_shader);
- bot_model->set_texture_container(m_texture);
- //bot_model->set_ph_world(m_world);
- //bot_model->set_ph_space(m_space);
- //bot_model->set_ph_joint(m_joint_group);
- bot_model->Initialize();
- bot_model->SetCore(m_core);
- bot_model->SetSoundEngine(m_sound_engine);
-
- bot_model->MoveTo(x, y, z);
-
- bot_model->SetRotation(angle+180);
-
- GhostCharacter* ghost = new GhostCharacter;
- ghost->SetModel(bot_model);
- bot_player->SetGhost(ghost);
-
- bot_player->SetFraction(FractionType::FR_BAD);
- }
-
- void Scene_game::FindAndInsertBot()
- {
- for (int i = 0; i < m_object->m_body_list.count; i ++)
- {
- Body_base* body = m_object->m_body_list.item[i];
- if (!body)
- continue;
- if (EqualPart(body->Name(), "###BOT00"))
- {
- PlayerBot* bot_player = PlayerCreateBot();
- Model* bot_model = new BadNinja;
- InitializeBot(bot_player, bot_model, body);
- }
- if (EqualPart(body->Name(), "###BOT01"))
- {
- PlayerBot* bot_player = PlayerCreateBot();
- Model* bot_model = new ModelRogueNinja;
- InitializeBot(bot_player, bot_model, body);
- bot_model->m_power_scale = 1.0;
- bot_model->m_live = 300.0;
- bot_model->m_live_max = 300.0;
-
- bot_player->m_punch_probability = 7.0;
- bot_player->m_ran_away_probability = 0.0;
- bot_player->m_attack_probability = 5.0;
- }
- if (EqualPart(body->Name(), "###BOT02"))
- {
- /*PlayerBot* bot_player = PlayerCreateBot();
- Model* bot_model = new ModelNaruto;
- InitializeBot(bot_player, bot_model, body);
- bot_model->m_power_scale = 1.0;
- bot_model->m_live = 300.0;
- bot_model->m_live_max = 300.0;
-
- bot_player->m_punch_probability = 9.0;
- bot_player->m_ran_away_probability = 0.0;
- bot_player->m_attack_probability = 8.0;
-
- bot_player->SetFraction(FractionType::FR_GOOD);
-
- bot_player->SetAssistantPlayer(m_player);*/
- }
- }
- };
-
- void Scene_game::CreateClone(Player* player)
- {
- PlayerBot* bot_player = PlayerCreateBot();
- Model* bot_model = new ModelNaruto;
- InitializeBot(bot_player, bot_model, player->m_posx + 50, player->m_posy, player->m_posz, 0.0);
- bot_model->m_power_scale = 0.5;
- bot_model->m_live = 10.0;
- bot_model->m_live_max = 10.0;
-
- bot_player->m_punch_probability = 9.0;
- bot_player->m_ran_away_probability = 0.0;
- bot_player->m_attack_probability = 8.0;
-
- bot_player->SetFraction(FractionType::FR_GOOD);
-
- bot_player->SetAssistantPlayer(player);
-
- bot_model->SetDisapearOnDie(true);
-
- CreateCloud(player->m_posx + 50, player->m_posy, player->m_posz);
- }
-
- PlayerLocal* Scene_game::PlayerCreateLocal()
- {
- PlayerLocal* player = new PlayerLocal;
- player->SetPlayerContainer(m_player_container);
- m_player_container->AddPlayer(player);
- return player;
- };
-
- PlayerBot* Scene_game::PlayerCreateBot()
- {
- PlayerBot* player = new PlayerBot;
- player->SetPlayerContainer(m_player_container);
- m_player_container->AddPlayer(player);
- return player;
- };
-
- void Scene_game::RemovePlayer(Player * player)
- {
- Ghost* ghost = player->GetGhost();
- Model* model = 0;
- if (ghost)
- model = ghost->GetModel();
-
- for (int i = 0; i < m_player_container->m_player.count; i ++)
- {
- if (m_player_container->m_player.item[i])
- m_player_container->m_player.item[i]->NotifyDelete(player, model);
- }
-
- //Find player to delete
- m_player_container->Remove(player->GetId());
- };
-
- bool Scene_game::Initialize()
- {
- if (!Scene_base::Initialize())
- return false;
-
- /*dInitODE();
- m_world = dWorldCreate();
- m_space = dHashSpaceCreate(0);
- //m_space = dSweepAndPruneSpaceCreate(0, dSAP_AXES_XYZ);
- //dHashSpaceSetLevels(m_space, 0, 20);
- m_contactgroup = dJointGroupCreate(0);
- m_joint_group = dJointGroupCreate(0);
-
- dWorldSetGravity(m_world, 0.0f, 0.0f, -9.8f);
- dWorldSetERP(m_world, 0.1f);
- dWorldSetCFM(m_world, 0.00001f);
- dWorldSetQuickStepNumIterations(m_world, 320);
- dWorldSetContactSurfaceLayer(m_world, 0.0f);
- dWorldSetAutoDisableFlag(m_world, true);
- dWorldSetAutoDisableAngularThreshold(m_world, 1.0f);
- dWorldSetAutoDisableLinearThreshold(m_world, 1.0f);
-
- dWorldSetMaxAngularSpeed(m_world, 80.0f);
- dWorldSetContactMaxCorrectingVel(m_world, 100.0f);
-
- dWorldSetMaxLinearSpeed(m_world, 60.0f);*/
-
- m_player_container = new PlayerContainer;
-
- if (((graphick_OpenGl*)m_graphick)->GlslSupport())
- {
- m_glsl_sample_shader = new GlslShader;
- if (!m_glsl_sample_shader->Create(vertex_cartoon_shader, fragment_cartoon_shader))
- {
- delete m_glsl_sample_shader;
- m_glsl_sample_shader = 0;
- }
- m_glsl_particle_shader = new GlslShader;
- if (!m_glsl_particle_shader->Create(vertex_particle_shader, 0))
- {
- delete m_glsl_particle_shader;
- m_glsl_particle_shader = 0;
- }
-
- m_glsl_outline_shader = new GlslShader;
- if (!m_glsl_outline_shader->Create(vertex_contur_shader, fragment_contur_shader))
- {
- delete m_glsl_outline_shader;
- m_glsl_outline_shader = 0;
- }
-
- m_glsl_glow_shader = new GlslShader;
- if (!m_glsl_glow_shader->Create(0, fragment_glow_shader))
- {
- delete m_glsl_glow_shader;
- m_glsl_glow_shader = 0;
- }
-
-
- m_glsl_post_object_shader = new GlslShader;
- if (!m_glsl_post_object_shader->Create(vertex_post_object_shader, fragment_post_object_shader))
- {
- delete m_glsl_post_object_shader;
- m_glsl_post_object_shader = 0;
- }
-
- m_glsl_vertex_light_shader = new GlslShader;
- if (!m_glsl_vertex_light_shader->Create(vertex_vertrex_light_shader, 0))
- {
- delete m_glsl_vertex_light_shader;
- m_glsl_vertex_light_shader = 0;
- }
-
- m_glsl_skinning_shader = new GlslShader;
- if (!m_glsl_skinning_shader->Create(vertex_skinning_shader, 0))
- {
- delete m_glsl_skinning_shader;
- m_glsl_skinning_shader = 0;
- }
-
- m_glsl_simple_light_shader = new GlslShader;
- if (!m_glsl_simple_light_shader->Create(vertex_vertrex_light_shader, 0))
- //if (!m_glsl_simple_light_shader->Create(vertex_pixel_light_shader, fragment_pixel_light_shader))
- //if (!m_glsl_simple_light_shader->Create(vertex_bump_light_shader, fragment_bump_light_shader))
- {
- delete m_glsl_simple_light_shader;
- m_glsl_simple_light_shader = 0;
- }
-
- m_glsl_pixel_light_shader = new GlslShader;
- if (!m_glsl_pixel_light_shader->Create(vertex_pixel_light_shader, fragment_pixel_light_shader))
- {
- delete m_glsl_pixel_light_shader;
- m_glsl_pixel_light_shader = 0;
- }
-
- }
-
- /*player_2->SetKey(PlayerLocal::PL_FORWARD, Tkey::DV_JOY, 0, 1002);
- player_2->SetKey(PlayerLocal::PL_BACK, Tkey::DV_JOY, 0, 1003);
- player_2->SetKey(PlayerLocal::PL_LEFT, Tkey::DV_JOY, 0, 1000);
- player_2->SetKey(PlayerLocal::PL_RIGHT, Tkey::DV_JOY, 0, 1001);
-
- player_2->SetKey(PlayerLocal::PL_JUMP, Tkey::DV_JOY, 0, 0);
- player_2->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_JOY, 0, 1);
- player_2->SetKey(PlayerLocal::PL_PUNCH2, Tkey::DV_JOY, 0, 2);*/
- //player_2->SetKey(PlayerLocal::PL_PUNCH, Tkey::DV_KEYBOARD, 0, VK_NUMPAD0);*/
-
- /*m_object->set_ph_world(m_world);
- m_object->set_ph_space(m_space);
- m_object->set_ph_joint(m_joint_group);*/
-
- //m_object->load("../../data/stage/demo_01.n3d");
- m_object->load("../../data/stage/test_05.n3d");
- m_object->InternalObjectLoad();
- double player_count = m_core->GetValue("game_player_count");
- InsertPlayer(&m_player, 0);
- if (player_count > 1.0)
- InsertPlayer(&m_player1, 1);
- if (player_count > 2.0)
- InsertPlayer(&m_player2, 2);
-
- FindAndInsertBot();
-
- Texture_instance* grass_txt = m_texture->load_texture("../../data/texture/grass/grass_01.bmp", Texture_instance::TXT_CLAMPING_EDGE);
-
- m_object->BuildGrassMesh("#grass", 10.0f, m_core->GGrassDentisy()*40.0f, 1, grass_txt);
-
- /*Body_base* bd = m_object->FindBody("Plane01");
- if (bd)
- bd->BuildGrassMesh(10.0f, 20.0f, 1, grass_txt);*/
-
- m_sky = new Sky;
- m_sky->Initialize();
- Texture_instance* texture = m_texture->load_texture("../../data/texture/sky/sky_01.bmp", 0);//Texture_instance::TXT_CLAMPING
- m_sky->SetMainSkyTexture(texture);
-
- Texture_instance* front = m_texture->load_texture("../../data/texture/skybox/02/front.jpg", Texture_instance::TXT_CLAMPING_EDGE);
- Texture_instance* left = m_texture->load_texture("../../data/texture/skybox/02/left.jpg", Texture_instance::TXT_CLAMPING_EDGE);
- Texture_instance* right = m_texture->load_texture("../../data/texture/skybox/02/right.jpg", Texture_instance::TXT_CLAMPING_EDGE);
- Texture_instance* back = m_texture->load_texture("../../data/texture/skybox/02/back.jpg", Texture_instance::TXT_CLAMPING_EDGE);
- Texture_instance* top = m_texture->load_texture("../../data/texture/skybox/02/top.jpg", Texture_instance::TXT_CLAMPING_EDGE);
- Texture_instance* bottom = m_texture->load_texture("../../data/texture/skybox/02/bottom.jpg", Texture_instance::TXT_CLAMPING_EDGE);
- m_sky->SetSkyBoxTextures(front, left, right, back, top, bottom);
-
- m_sun = new LightBase;
-
- m_sun->m_position.x = -5000.0f;
- m_sun->m_position.y = 5000.0f;
- m_sun->m_position.z = 5000.0f;
-
- m_sun->m_lighting_max.x = 1.0f;
- m_sun->m_lighting_max.y = 1.0f;
- m_sun->m_lighting_max.z = 1.0f;
-
- m_sun->m_lighting_normal.x = 0.5f;
- m_sun->m_lighting_normal.y = 0.5f;
- m_sun->m_lighting_normal.z = 0.5f;
-
- m_sun->m_lighting_min.x = 0.0f;
- m_sun->m_lighting_min.y = 0.0f;
- m_sun->m_lighting_min.z = 0.0f;
-
- m_perticle_smoke = m_texture->load_texture("../../data/texture/fx/smoke.bmp", Texture_instance::TXT_CLAMPING);
- m_twirl_test = m_texture->load_texture("../../data/texture/fx/twirl_00.bmp"/*, Texture_instance::TXT_CLAMPING*/);
-
- ApplyObjectLightModel();
-
- /*m_test_particle = new Particle;
- m_test_particle->Create(1024);
- Texture_instance* particle_texture = m_texture->load_texture("../../data/texture/fx/particle_test.jpg", Texture_instance::TXT_CLAMPING);
- m_test_particle->SetTexture(particle_texture, 2, 2);*/
-
- /*m_object->load("../../data/object/Naruto_tst1.N3D");
- LinkBody("FootR", "LegRd");
- LinkBody("LegRd", "LegR");
-
- LinkBody("FootL", "LegLd");
- LinkBody("LegLd", "LegL");
-
- LinkBody("LegR", "Torso");
- LinkBody("LegL", "Torso");
- LinkBody("body", "Torso");
-
- LinkBody("HandRd", "HandR");
- LinkBody("HandLd", "HandL");
-
- LinkBody("HandR", "body");
- LinkBody("HandL", "body");
-
- LinkBody("Head", "body");*/
-
-
- m_mouse_x.Set(Tkey::DV_MOUSE, 0, 1000);
- m_mouse_y.Set(Tkey::DV_MOUSE, 0, 1001);
- m_mouse_left.Set(Tkey::DV_MOUSE, 0, 1);
- m_mouse_right.Set(Tkey::DV_MOUSE, 0, 2);
-
- m_test_y.Set(Tkey::DV_KEYBOARD, 0, VK_ADD);
- m_test_t.Set(Tkey::DV_KEYBOARD, 0, VK_SUBTRACT);
-
- //Load GUI
- m_live_texture = m_texture->load_texture("../../data/texture/gui/game_ui/live.bmp", Texture_instance::TXT_CLAMPING_EDGE);
- m_chakra_texture = m_texture->load_texture("../../data/texture/gui/game_ui/chakra.bmp", Texture_instance::TXT_CLAMPING_EDGE);
-
- SetClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- m_speedometer->Reset();
-
- return true;
- };
-
- void Scene_game::Destroy()
- {
- if (m_track_a_id != -1 && m_sound_engine)
- m_sound_engine->StopTrack(m_track_a_id);
- m_track_a_id = -1;
-
- if (m_track_b_id != -1 && m_sound_engine)
- m_sound_engine->StopTrack(m_track_b_id);
- m_track_b_id = -1;
-
- if (m_glsl_particle_shader)
- delete m_glsl_particle_shader;
- m_glsl_particle_shader = 0;
-
- if (m_glsl_outline_shader)
- delete m_glsl_outline_shader;
- m_glsl_outline_shader = 0;
-
- if (m_player_container)
- delete m_player_container;
- m_player_container;
-
- /*if (m_joint_group)
- dJointGroupDestroy(m_contactgroup);
- if (m_contactgroup)
- dJointGroupDestroy(m_contactgroup);
- if (m_space)
- dSpaceDestroy(m_space);
- if (m_world)
- dWorldDestroy(m_world);
- dCloseODE();*/
-
- if (m_sky)
- delete m_sky;
- m_sky = 0;
-
- if (m_sun)
- delete m_sun;
- m_sun = 0;
-
- if (m_live_texture)
- {
- m_live_texture->release_instance();
- m_live_texture = 0;
- };
-
- if (m_chakra_texture)
- {
- m_chakra_texture->release_instance();
- m_chakra_texture = 0;
- };
-
- if (m_test_particle)
- delete m_test_particle;
- m_test_particle = 0;
-
- Scene_base::Destroy();
- };