Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. GLuint amt = 1000;
  2. glm::mat4* asteroidMatrices;
  3. asteroidMatrices = new glm::mat4[amt];
  4. srand(glfwGetTime());
  5. GLfloat rad = 50.0f;
  6. GLfloat offset = 5.0f;
  7. for (GLuint i = 0; i < amt; i++) {
  8. glm::mat4 model;
  9. GLfloat angle = (GLfloat)i / (GLfloat)amt * 360.0f;
  10. GLfloat displacement = (rand() % (GLint)(2 * offset * 100)) / 100.0f - offset;
  11. GLfloat x = -sin(angle) * rad + displacement * 10;
  12. displacement = (rand() % (GLint)(2 * offset * 100)) / 100.0f - offset;
  13. GLfloat y = displacement * 0.4f; // Keep height of asteroid field smaller compared to width of x and z
  14. displacement = (rand() % (GLint)(2 * offset * 100)) / 100.0f - offset;
  15. GLfloat z = sin(angle) * rad + displacement * 25;
  16. model = glm::translate(model, glm::vec3(x, y, z));
  17. GLfloat scale = (rand() % 60) / 100.0f + 0.05;
  18. model = glm::scale(model, glm::vec3(scale));
  19. asteroidMatrices[i] = model;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement