1/* 2 * Copyright (C) 2016 Google, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef SIMULATION_H 18#define SIMULATION_H 19 20#include <memory> 21#include <random> 22#include <vector> 23 24#include <glm/glm.hpp> 25 26#include "Meshes.h" 27 28class Animation { 29 public: 30 Animation(unsigned rng_seed, float scale); 31 32 glm::mat4 transformation(float t); 33 34 private: 35 struct Data { 36 glm::vec3 axis; 37 float speed; 38 float scale; 39 40 glm::mat4 matrix; 41 }; 42 43 std::mt19937 rng_; 44 std::uniform_real_distribution<float> dir_; 45 std::uniform_real_distribution<float> speed_; 46 47 Data current_; 48}; 49 50class Curve; 51 52class Path { 53 public: 54 Path(unsigned rng_seed); 55 56 glm::vec3 position(float t); 57 58 private: 59 struct Subpath { 60 glm::vec3 origin; 61 float start; 62 float end; 63 float now; 64 65 std::shared_ptr<Curve> curve; 66 }; 67 68 void generate_subpath(); 69 70 std::mt19937 rng_; 71 std::uniform_int_distribution<> type_; 72 std::uniform_real_distribution<float> duration_; 73 74 Subpath current_; 75}; 76 77class Simulation { 78 public: 79 Simulation(int object_count); 80 81 struct Object { 82 Meshes::Type mesh; 83 glm::vec3 light_pos; 84 glm::vec3 light_color; 85 86 Animation animation; 87 Path path; 88 89 uint32_t frame_data_offset; 90 91 glm::mat4 model; 92 }; 93 94 const std::vector<Object> &objects() const { return objects_; } 95 96 unsigned int rng_seed() { return random_dev_(); } 97 98 void set_frame_data_size(uint32_t size); 99 void update(float time, int begin, int end); 100 101 private: 102 std::random_device random_dev_; 103 std::vector<Object> objects_; 104}; 105 106#endif // SIMULATION_H 107