You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

641 lines
21 KiB

  1. //
  2. // BtPhysTest
  3. //
  4. // Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  5. // (c) 2012-2013 Sam Hocevar <sam@hocevar.net>
  6. //
  7. #if defined HAVE_CONFIG_H
  8. # include "config.h"
  9. #endif
  10. #include "core.h"
  11. #include "loldebug.h"
  12. using namespace lol;
  13. #ifndef HAVE_PHYS_USE_BULLET
  14. #define HAVE_PHYS_USE_BULLET
  15. #endif /* HAVE_PHYS_USE_BULLET */
  16. #include "physics/lolphysics.h"
  17. #include "physics/easyphysics.h"
  18. #define CAT_MODE 1
  19. #define OBJ_SIZE 2.f
  20. #include "physicobject.h"
  21. #include "btphystest.h"
  22. using namespace lol::phys;
  23. #define CUBE_HALF_EXTENTS .5f
  24. #define EXTRA_HEIGHT 1.f
  25. #define BASE_TIME 2.f
  26. #define ZERO_TIME (BASE_TIME + rand(-BASE_TIME * .4f, BASE_TIME * .4f))
  27. #define ZERO_SPEED 3.5f
  28. #define JUMP_HEIGHT 30.f
  29. #define JUMP_STRAFE .5f
  30. int gNumObjects = 64;
  31. #if CAT_MODE
  32. #define USE_WALL 1
  33. #define USE_BODIES 1
  34. #else
  35. #define USE_WALL 1
  36. #define USE_PLATFORM 1
  37. #define USE_ROPE 0
  38. #define USE_BODIES 1
  39. #define USE_ROTATION 0
  40. #define USE_CHARACTER 0
  41. #define USE_STAIRS 0
  42. #endif
  43. LOLFX_RESOURCE_DECLARE(front_camera_sprite);
  44. BtPhysTest::BtPhysTest(bool editor)
  45. {
  46. m_loop_value = .0f;
  47. #if CAT_MODE
  48. /* cat datas setup */
  49. m_cat_texture = Tiler::Register("data/CatsSheet.png", ivec2(0), ivec2(0,1));
  50. #endif //CAT_MODE
  51. /* Register an input controller for the keyboard */
  52. m_controller = new Controller(KEY_MAX, 0);
  53. m_controller->GetKey(KEY_MOVE_FORWARD).Bind("Keyboard", "Up");
  54. m_controller->GetKey(KEY_MOVE_BACK).Bind("Keyboard", "Down");
  55. m_controller->GetKey(KEY_MOVE_LEFT).Bind("Keyboard", "Left");
  56. m_controller->GetKey(KEY_MOVE_RIGHT).Bind("Keyboard", "Right");
  57. m_controller->GetKey(KEY_MOVE_JUMP).Bind("Keyboard", "Space");
  58. m_controller->GetKey(KEY_MOVE_UP).Bind("Keyboard", "PageUp");
  59. m_controller->GetKey(KEY_MOVE_DOWN).Bind("Keyboard", "PageDown");
  60. m_controller->GetKey(KEY_QUIT).Bind("Keyboard", "Escape");
  61. /* Create a camera that matches the settings of XNA BtPhysTest */
  62. m_camera = new Camera();
  63. #if CAT_MODE
  64. m_camera->SetView(vec3(70.f, 50.f, 0.f),
  65. vec3(0.f, 0.f, 0.f),
  66. vec3(0, 1, 0));
  67. m_camera->SetProjection(mat4::perspective(60.f, 1280.f, 960.f, .1f, 1000.f));
  68. #else
  69. m_camera->SetView(vec3(50.f, 50.f, 0.f),
  70. vec3(0.f, 0.f, 0.f),
  71. vec3(0, 1, 0));
  72. m_camera->SetProjection(mat4::perspective(45.f, 1280.f, 960.f, .1f, 1000.f));
  73. #endif
  74. g_scene->PushCamera(m_camera);
  75. m_ready = false;
  76. m_simulation = new Simulation();
  77. m_simulation->SetWorldLimit(vec3(-1000.0f, -1000.0f, -1000.0f), vec3(1000.0f, 1000.0f, 1000.0f));
  78. m_simulation->Init();
  79. vec3 NewGravity = vec3(.0f, -10.0f, .0f);
  80. m_simulation->SetGravity(NewGravity);
  81. m_simulation->SetContinuousDetection(true);
  82. m_simulation->SetTimestep(1.f / 120.f);
  83. Ticker::Ref(m_simulation);
  84. /* Add a white directional light */
  85. m_light1 = new Light();
  86. m_light1->SetPosition(vec4(0.2f, 0.2f, 0.f, 0.f));
  87. m_light1->SetColor(vec4(0.5f, 0.5f, 0.5f, 1.f));
  88. Ticker::Ref(m_light1);
  89. /* Add an orangeish point light */
  90. m_light2 = new Light();
  91. m_light2->SetPosition(vec4(-15.f, 15.f, 15.f, 1.f));
  92. m_light2->SetColor(vec4(0.4f, 0.3f, 0.2f, 1.f));
  93. Ticker::Ref(m_light2);
  94. float offset = 29.5f;
  95. vec3 pos_offset = vec3(.0f, 30.f, .0f);
  96. #if USE_STAIRS
  97. {
  98. vec3 new_offset = vec3(1.0f, .125f, .0f);
  99. quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
  100. vec3 NewPosition = pos_offset + vec3(5.0f, -29.f, 15.0f);
  101. {
  102. NewRotation = quat::fromeuler_xyz(0.f, 0.f, 30.f);
  103. NewPosition += vec3(4.0f, .0f, -4.0f);
  104. PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3);
  105. Ticker::Ref(NewPhyobj);
  106. m_stairs_list << NewPhyobj;
  107. }
  108. {
  109. NewRotation = quat::fromeuler_xyz(0.f, 0.f, 40.f);
  110. NewPosition += vec3(4.0f, .0f, -4.0f);
  111. PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3);
  112. Ticker::Ref(NewPhyobj);
  113. m_stairs_list << NewPhyobj;
  114. }
  115. NewPosition = pos_offset + vec3(5.0f, -29.5f, 15.0f);
  116. NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
  117. for (int i=0; i < 15; i++)
  118. {
  119. NewPosition += new_offset;
  120. PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3);
  121. Ticker::Ref(NewPhyobj);
  122. m_stairs_list << NewPhyobj;
  123. }
  124. }
  125. #endif //USE_STAIRS
  126. #if USE_WALL
  127. {
  128. for (int i=0; i < 6; i++)
  129. {
  130. vec3 NewPosition = vec3(.0f);
  131. quat NewRotation = quat(1.f);
  132. PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation);
  133. int idx = i/2;
  134. NewPosition = pos_offset;
  135. NewPosition[idx] += offset;
  136. offset *= -1.f;
  137. if (idx != 1)
  138. {
  139. vec3 NewAxis = vec3(.0f);
  140. NewAxis[2 - idx] = 1;
  141. NewRotation = quat::rotate(90.f, NewAxis);
  142. }
  143. NewPhyobj->SetTransform(NewPosition, NewRotation);
  144. Ticker::Ref(NewPhyobj);
  145. m_ground_list << NewPhyobj;
  146. }
  147. }
  148. #endif //USE_WALL
  149. PhysicsObject* BasePhyobj = NULL;
  150. #if USE_PLATFORM
  151. {
  152. quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
  153. vec3 NewPosition = pos_offset + vec3(5.0f, -25.0f, -15.0f);
  154. PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
  155. m_platform_list << NewPhyobj;
  156. Ticker::Ref(NewPhyobj);
  157. NewPosition = pos_offset + vec3(-15.0f, -25.0f, 5.0f);
  158. NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
  159. BasePhyobj = NewPhyobj;
  160. m_platform_list << NewPhyobj;
  161. Ticker::Ref(NewPhyobj);
  162. NewRotation = quat::fromeuler_xyz(0.f, 0.f, 90.f);
  163. NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f);
  164. NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
  165. NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, true);
  166. m_platform_list << NewPhyobj;
  167. Ticker::Ref(NewPhyobj);
  168. //NewPosition += vec3(-0.0f, .0f, .0f);
  169. //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
  170. //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), true, false);
  171. //m_platform_list << NewPhyobj;
  172. //Ticker::Ref(NewPhyobj);
  173. //NewPosition += vec3(-2.0f, .0f, .0f);
  174. //NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1);
  175. //NewPhyobj->GetPhysic()->AttachTo(BasePhyobj->GetPhysic(), false, false);
  176. //m_platform_list << NewPhyobj;
  177. //Ticker::Ref(NewPhyobj);
  178. }
  179. #endif //USE_PLATFORM
  180. #if USE_CHARACTER
  181. {
  182. quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f);
  183. vec3 NewPosition = pos_offset + vec3(-5.0f, -10.0f, 15.0f);
  184. PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 2);
  185. m_character_list << NewPhyobj;
  186. Ticker::Ref(NewPhyobj);
  187. //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true);
  188. }
  189. #endif //USE_CHARACTER
  190. #if USE_BODIES
  191. {
  192. for (int x=0; x < 6; x++)
  193. {
  194. for (int y=0; y < 2; y++)
  195. {
  196. for (int z=0; z < 5; z++)
  197. {
  198. PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f,
  199. vec3(-20.f, 15.f, -20.f) +
  200. vec3(8.f * (float)x, 8.f * (float)y, 8.f * (float)z));
  201. m_physobj_list.Push(new_physobj, ZERO_TIME);
  202. Ticker::Ref(new_physobj);
  203. }
  204. }
  205. }
  206. }
  207. #endif //USE_BODIES
  208. #if USE_ROPE
  209. {
  210. Array<PhysicsObject*> RopeElements;
  211. for (int i = 0; i < 14; i++)
  212. {
  213. PhysicsObject* new_physobj = new PhysicsObject(m_simulation, 1000.f,
  214. vec3(0.f, 15.f, -20.f) +
  215. vec3(0.f, 0.f, 2.f * (float)i), 1);
  216. RopeElements << new_physobj;
  217. m_physobj_list.Push(new_physobj, ZERO_TIME);
  218. Ticker::Ref(new_physobj);
  219. if (RopeElements.Count() > 1)
  220. {
  221. EasyConstraint* new_constraint = new EasyConstraint();
  222. vec3 A2B = .5f * (RopeElements[i]->GetPhysic()->GetTransform().v3.xyz -
  223. RopeElements[i - 1]->GetPhysic()->GetTransform().v3.xyz);
  224. new_constraint->SetPhysObjA(RopeElements[i - 1]->GetPhysic(), lol::mat4::translate(A2B));
  225. new_constraint->SetPhysObjB(RopeElements[i]->GetPhysic(), lol::mat4::translate(-A2B));
  226. new_constraint->InitConstraintToPoint2Point();
  227. new_constraint->DisableCollisionBetweenObjs(true);
  228. new_constraint->AddToSimulation(m_simulation);
  229. m_constraint_list << new_constraint;
  230. }
  231. }
  232. }
  233. #endif //USE_ROPE
  234. }
  235. void BtPhysTest::TickGame(float seconds)
  236. {
  237. WorldEntity::TickGame(seconds);
  238. if (m_controller->GetKey(KEY_QUIT).IsReleased())
  239. Ticker::Shutdown();
  240. m_loop_value += seconds;
  241. if (m_loop_value > F_PI * 2.0f)
  242. m_loop_value -= F_PI * 2.0f;
  243. vec3 GroundBarycenter = vec3(.0f);
  244. vec3 PhysObjBarycenter = vec3(.0f);
  245. float factor = .0f;
  246. #if CAT_MODE
  247. #if USE_BODIES
  248. vec3 cam_center(0.f);
  249. float cam_factor = .0f;
  250. vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
  251. vec3 cam_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
  252. mat4 world_cam = g_scene->GetCamera()->GetView();
  253. mat4 cam_screen = g_scene->GetCamera()->GetProjection();
  254. for (int i = 0; i < m_physobj_list.Count(); i++)
  255. {
  256. PhysicsObject* PhysObj = m_physobj_list[i].m1;
  257. float &Timer = m_physobj_list[i].m2;
  258. vec3 obj_loc = PhysObj->GetPhysic()->GetTransform().v3.xyz;
  259. cam_center += obj_loc;
  260. cam_factor += 1.f;
  261. mat4 LocalPos = mat4::translate(obj_loc);
  262. vec3 vpos;
  263. LocalPos = world_cam * LocalPos;
  264. vpos = LocalPos.v3.xyz;
  265. cam_min_max[0] = min(vpos.xyz, cam_min_max[0]);
  266. cam_min_max[1] = max(vpos.xyz, cam_min_max[1]);
  267. LocalPos = cam_screen * LocalPos;
  268. vpos = (LocalPos.v3 / LocalPos.v3.w).xyz;
  269. screen_min_max[0] = min(vpos.xy, screen_min_max[0]);
  270. screen_min_max[1] = max(vpos.xy, screen_min_max[1]);
  271. //if (length(PhysObj->GetPhysic()->GetLinearVelocity()) < ZERO_SPEED)
  272. if (lol::abs(PhysObj->GetPhysic()->GetLinearVelocity().y) < ZERO_SPEED)
  273. Timer -= seconds;
  274. if (Timer < .0f)
  275. {
  276. PhysObj->GetPhysic()->AddImpulse(JUMP_HEIGHT *
  277. vec3(JUMP_STRAFE, 1.f, JUMP_STRAFE) *
  278. vec3(rand(-1.f, 1.f), 1.0f, rand(-1.f, 1.f)) *
  279. PhysObj->GetPhysic()->GetMass());
  280. Timer = ZERO_TIME;
  281. }
  282. }
  283. vec3 min_max_diff = (cam_min_max[1] - cam_min_max[0]);
  284. float screen_size = max(max(lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)),
  285. max( lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)));
  286. float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
  287. max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
  288. //m_camera->SetProjection(mat4::perspective(30.f * fov_ratio * 1.1f, 1280.f, 960.f, .1f, 1000.f));
  289. m_camera->SetView((mat4::rotate(10.f * seconds, vec3(.0f, 1.f, .0f)) * vec4(m_camera->GetPosition(), 1.0f)).xyz,
  290. //vec3(70.f, 30.f, 0.f),
  291. cam_center / cam_factor, vec3(0, 1, 0));
  292. #endif //USE_BODIES
  293. #endif //CAT_MODE
  294. #if USE_WALL
  295. {
  296. for (int i = 0; i < m_ground_list.Count(); i++)
  297. {
  298. PhysicsObject* PhysObj = m_ground_list[i];
  299. mat4 GroundMat = PhysObj->GetTransform();
  300. GroundBarycenter += GroundMat.v3.xyz;
  301. factor += 1.f;
  302. }
  303. GroundBarycenter /= factor;
  304. for (int i = 0; i < m_ground_list.Count(); i++)
  305. {
  306. PhysicsObject* PhysObj = m_ground_list[i];
  307. mat4 GroundMat = PhysObj->GetTransform();
  308. vec3 CenterToGround = GroundMat.v3.xyz - GroundBarycenter;
  309. vec3 CenterToCam = m_camera->GetPosition() - GroundBarycenter;
  310. if (dot(normalize(CenterToCam - CenterToGround),
  311. normalize(CenterToGround)) > 0.f)
  312. PhysObj->SetRender(false);
  313. else
  314. PhysObj->SetRender(true);
  315. }
  316. }
  317. #endif //USE_WALL
  318. #if USE_ROTATION
  319. {
  320. for (int i = 0; i < m_ground_list.Count(); i++)
  321. {
  322. PhysicsObject* PhysObj = m_ground_list[i];
  323. mat4 GroundMat = PhysObj->GetTransform();
  324. mat4 CenterMx = mat4::translate(GroundBarycenter);
  325. GroundMat = inverse(CenterMx) * GroundMat;
  326. GroundMat = CenterMx *
  327. mat4(quat::fromeuler_xyz(vec3(.0f, 20.f, 20.0f) * seconds))
  328. * GroundMat;
  329. PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
  330. }
  331. }
  332. #endif //USE_ROTATION
  333. #if USE_PLATFORM
  334. {
  335. for (int i = 0; i < m_platform_list.Count(); i++)
  336. {
  337. PhysicsObject* PhysObj = m_platform_list[i];
  338. mat4 GroundMat = PhysObj->GetTransform();
  339. if (i == 0)
  340. {
  341. GroundMat = GroundMat * mat4(quat::fromeuler_xyz(vec3(20.f, .0f, .0f) * seconds));
  342. PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
  343. }
  344. else if (i == 1)
  345. {
  346. GroundMat =
  347. mat4::translate(vec3(-15.0f, 5.0f, lol::cos(m_loop_value) * 8.f)) *
  348. mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * 20.f, .0f)));
  349. PhysObj->SetTransform(GroundMat.v3.xyz, quat(GroundMat));
  350. }
  351. }
  352. }
  353. #endif //USE_PLATFORM
  354. #if USE_CHARACTER
  355. {
  356. for (int i = 0; i < m_character_list.Count(); i++)
  357. {
  358. PhysicsObject* PhysObj = m_character_list[i];
  359. EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter();
  360. mat4 CtlrMx = Character->GetTransform();
  361. vec3 movement(0.f);
  362. movement.z = (m_controller->GetKey(KEY_MOVE_RIGHT).IsDown() ? 1.f : 0.f)
  363. - (m_controller->GetKey(KEY_MOVE_LEFT).IsDown() ? 1.f : 0.f);
  364. movement.x = (m_controller->GetKey(KEY_MOVE_FORWARD).IsDown() ? 1.f : 0.f)
  365. - (m_controller->GetKey(KEY_MOVE_BACK).IsDown() ? 1.f : 0.f);
  366. movement.y = (m_controller->GetKey(KEY_MOVE_UP).IsDown() ? 1.f : 0.f)
  367. - (m_controller->GetKey(KEY_MOVE_DOWN).IsDown() ? 1.f : 0.f);
  368. vec3 CharMove = movement * seconds * vec3(4.f, 10.f, 4.f);
  369. if (m_controller->GetKey(KEY_MOVE_JUMP).IsReleased())
  370. Character->Jump();
  371. Character->SetMovementForFrame(CharMove);
  372. RayCastResult HitResult;
  373. if (m_simulation->RayHits(HitResult, ERT_Closest, Character->GetTransform().v3.xyz, (Character->GetTransform().v3.xyz + vec3(.0f, -1.f, .0f)), Character))
  374. Character->AttachTo(HitResult.m_collider_list[0], true, true);
  375. else
  376. Character->AttachTo(NULL);
  377. }
  378. }
  379. #endif //USE_CHARACTER
  380. #if USE_CHARACTER
  381. {
  382. PhysObjBarycenter = vec3(.0f);
  383. factor = .0f;
  384. for (int i = 0; i < m_character_list.Count(); i++)
  385. {
  386. PhysicsObject* PhysObj = m_character_list[i];
  387. mat4 GroundMat = PhysObj->GetTransform();
  388. PhysObjBarycenter += GroundMat.v3.xyz;
  389. factor += 1.f;
  390. }
  391. PhysObjBarycenter /= factor;
  392. #if 0
  393. m_camera->SetTarget(m_camera->GetTarget() + (seconds / (seconds + 0.18f)) * (PhysObjBarycenter - m_camera->GetTarget()));
  394. vec3 CamPosCenter = m_camera->GetTarget() + vec3(.0f, 5.0f, .0f);
  395. m_camera->SetPosition(CamPosCenter + normalize(m_camera->GetPosition() - CamPosCenter) * 20.0f);
  396. #endif
  397. }
  398. #else
  399. {
  400. PhysObjBarycenter = vec3(.0f);
  401. for (int i = 0; i < m_physobj_list.Count(); i++)
  402. {
  403. PhysicsObject* PhysObj = m_physobj_list[i].m1;
  404. mat4 GroundMat = PhysObj->GetTransform();
  405. PhysObjBarycenter += GroundMat.v3.xyz;
  406. factor += 1.f;
  407. }
  408. PhysObjBarycenter /= factor;
  409. #if 0
  410. m_camera->SetTarget(PhysObjBarycenter);
  411. m_camera->SetPosition(GroundBarycenter + normalize(GroundBarycenter - PhysObjBarycenter) * 60.0f);
  412. #endif
  413. }
  414. #endif //USE_CHARACTER
  415. }
  416. void BtPhysTest::TickDraw(float seconds)
  417. {
  418. WorldEntity::TickDraw(seconds);
  419. if (!m_ready)
  420. {
  421. #if CAT_MODE
  422. /* cat datas setup */
  423. m_cat_shader = Shader::Create(LOLFX_RESOURCE_NAME(front_camera_sprite));
  424. #if USE_BODIES
  425. for (int i = 0; i < m_physobj_list.Count(); i++)
  426. {
  427. PhysicsObject* PhysObj = m_physobj_list[i].m1;
  428. m_cat_sdata = new CatShaderData(((1 << VertexUsage::Position) |
  429. (1 << VertexUsage::Color) |
  430. (1 << VertexUsage::TexCoord) |
  431. (1 << VertexUsage::TexCoordExt)),
  432. m_cat_shader);
  433. m_cat_sdata->m_shader_texture = m_cat_texture->GetTexture();
  434. PhysObj->SetCustomShaderData(m_cat_sdata);
  435. }
  436. #endif //USE_BODIES
  437. #endif //CAT_MODE
  438. /* FIXME: this object never cleans up */
  439. m_ready = true;
  440. }
  441. //Video::SetClearColor(vec4(0.0f, 0.0f, 0.12f, 1.0f));
  442. }
  443. BtPhysTest::~BtPhysTest()
  444. {
  445. g_scene->PopCamera(m_camera);
  446. Ticker::Unref(m_light1);
  447. Ticker::Unref(m_light2);
  448. #if CAT_MODE
  449. /* cat datas setup */
  450. delete(m_cat_sdata);
  451. Shader::Destroy(m_cat_shader);
  452. Tiler::Deregister(m_cat_texture);
  453. #endif //CAT_MODE
  454. while (m_constraint_list.Count())
  455. {
  456. EasyConstraint* CurPop = m_constraint_list.Last();
  457. m_constraint_list.Pop();
  458. CurPop->RemoveFromSimulation(m_simulation);
  459. delete CurPop;
  460. }
  461. while (m_ground_list.Count())
  462. {
  463. PhysicsObject* CurPop = m_ground_list.Last();
  464. m_ground_list.Pop();
  465. CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
  466. Ticker::Unref(CurPop);
  467. }
  468. while (m_stairs_list.Count())
  469. {
  470. PhysicsObject* CurPop = m_stairs_list.Last();
  471. m_stairs_list.Pop();
  472. CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
  473. Ticker::Unref(CurPop);
  474. }
  475. while (m_character_list.Count())
  476. {
  477. PhysicsObject* CurPop = m_character_list.Last();
  478. m_character_list.Pop();
  479. CurPop->GetCharacter()->RemoveFromSimulation(m_simulation);
  480. Ticker::Unref(CurPop);
  481. }
  482. while (m_platform_list.Count())
  483. {
  484. PhysicsObject* CurPop = m_platform_list.Last();
  485. m_platform_list.Pop();
  486. CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
  487. Ticker::Unref(CurPop);
  488. }
  489. while (m_physobj_list.Count())
  490. {
  491. PhysicsObject* CurPop = m_physobj_list.Last().m1;
  492. m_physobj_list.Pop();
  493. CurPop->GetPhysic()->RemoveFromSimulation(m_simulation);
  494. Ticker::Unref(CurPop);
  495. }
  496. Ticker::Unref(m_simulation);
  497. }
  498. //-----------------------------------------------------------------------------
  499. // CShaderData
  500. //-----------------------------------------------------------------------------
  501. CatShaderData::CatShaderData(uint32_t vert_decl_flags, Shader* shader)
  502. : GpuShaderData(vert_decl_flags, shader, DebugRenderMode::Default)
  503. {
  504. SetupDefaultData();
  505. }
  506. //-----------------------------------------------------------------------------
  507. void CatShaderData::SetupDefaultData()
  508. {
  509. AddUniform("in_model_view");
  510. AddUniform("in_normal_mat");
  511. AddUniform("in_proj");
  512. AddUniform("in_texture");
  513. }
  514. //-----------------------------------------------------------------------------
  515. void CatShaderData::SetupShaderDatas(mat4 const &model)
  516. {
  517. mat4 proj = g_scene->GetCamera()->GetProjection();
  518. mat4 view = g_scene->GetCamera()->GetView();
  519. mat4 modelview = view * model;
  520. mat3 normalmat = transpose(inverse(mat3(view)));
  521. m_shader->SetUniform(*GetUniform("in_model_view"), modelview);
  522. m_shader->SetUniform(*GetUniform("in_normal_mat"), normalmat);
  523. m_shader->SetUniform(*GetUniform("in_proj"), proj);
  524. }
  525. int main(int argc, char **argv)
  526. {
  527. System::Init(argc, argv);
  528. Application app("BtPhysTest", ivec2(1280, 960), 60.0f);
  529. new BtPhysTest(argc > 1);
  530. app.ShowPointer(false);
  531. app.Run();
  532. return EXIT_SUCCESS;
  533. }