particles.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "./common.h"
  2. /* === Resources === */
  3. static Mesh sphere = { 0 };
  4. static Material material = { 0 };
  5. static R3D_Skybox skybox = { 0 };
  6. static Camera3D camera = { 0 };
  7. static R3D_InterpolationCurve curve = { 0 };
  8. static R3D_ParticleSystem particles = { 0 };
  9. static BoundingBox particlesAabb = { 0 };
  10. /* === Examples === */
  11. const char* Init(void)
  12. {
  13. R3D_Init(GetScreenWidth(), GetScreenHeight(), 0);
  14. SetTargetFPS(60);
  15. R3D_SetBloomMode(R3D_BLOOM_ADDITIVE);
  16. R3D_SetBackgroundColor((Color) { 4, 4, 4 });
  17. R3D_SetAmbientColor(BLACK);
  18. sphere = GenMeshSphere(0.1f, 16, 32);
  19. material = LoadMaterialDefault();
  20. R3D_SetMaterialEmission(&material, NULL, (Color) { 255, 0, 0, 255 }, 1.0f);
  21. curve = R3D_LoadInterpolationCurve(3);
  22. R3D_AddKeyframe(&curve, 0.0f, 0.0f);
  23. R3D_AddKeyframe(&curve, 0.5f, 1.0f);
  24. R3D_AddKeyframe(&curve, 1.0f, 0.0f);
  25. particles = R3D_LoadParticleSystem(2048);
  26. particles.initialVelocity = (Vector3){ 0, 10.0f, 0 };
  27. particles.scaleOverLifetime = &curve;
  28. particles.spreadAngle = 45.0f;
  29. particles.emissionRate = 2048;
  30. particles.lifetime = 2.0f;
  31. particlesAabb = R3D_GetParticleSystemBoundingBox(&particles);
  32. camera = (Camera3D) {
  33. .position = (Vector3) { -7, 7, -7 },
  34. .target = (Vector3) { 0, 1, 0 },
  35. .up = (Vector3) { 0, 1, 0 },
  36. .fovy = 60.0f,
  37. .projection = CAMERA_PERSPECTIVE
  38. };
  39. return "[r3d] - particles example";
  40. }
  41. void Update(float delta)
  42. {
  43. UpdateCamera(&camera, CAMERA_ORBITAL);
  44. R3D_UpdateParticleSystem(&particles, GetFrameTime());
  45. }
  46. void Draw(void)
  47. {
  48. R3D_Begin(camera);
  49. R3D_DrawParticleSystem(&particles, sphere, material);
  50. R3D_End();
  51. BeginMode3D(camera);
  52. DrawBoundingBox(particlesAabb, GREEN);
  53. EndMode3D();
  54. DrawFPS(10, 10);
  55. }
  56. void Close(void)
  57. {
  58. R3D_UnloadInterpolationCurve(curve);
  59. R3D_UnloadParticleSystem(&particles);
  60. UnloadMesh(sphere);
  61. UnloadMaterial(material);
  62. R3D_Close();
  63. }