diff options
Diffstat (limited to 'src/gpu/effects/hybrid_3d_effect.cc')
| -rw-r--r-- | src/gpu/effects/hybrid_3d_effect.cc | 109 |
1 files changed, 45 insertions, 64 deletions
diff --git a/src/gpu/effects/hybrid_3d_effect.cc b/src/gpu/effects/hybrid_3d_effect.cc index c3e9190..51dec52 100644 --- a/src/gpu/effects/hybrid_3d_effect.cc +++ b/src/gpu/effects/hybrid_3d_effect.cc @@ -50,98 +50,79 @@ void Hybrid3DEffect::init(MainSequence* demo) { if (i % 3 == 2) type = ObjectType::BOX; - Object3D obj(type); + Object3D obj(type); - float angle = (i / 8.0f) * 6.28318f; + float angle = (i / 8.0f) * 6.28318f; - obj.position = vec3(std::cos(angle) * 4.0f, 0, std::sin(angle) * 4.0f); + obj.position = vec3(std::cos(angle) * 4.0f, 0, std::sin(angle) * 4.0f); - obj.scale = vec3(0.7f, 0.7f, 0.7f); // Increased scale by 40% + obj.scale = vec3(0.7f, 0.7f, 0.7f); // Increased scale by 40% - + if (type == ObjectType::SPHERE) + obj.color = vec4(0, 1, 0, 1); - if (type == ObjectType::SPHERE) obj.color = vec4(0, 1, 0, 1); - - else if (type == ObjectType::TORUS) obj.color = vec4(0, 0.5, 1, 1); + else if (type == ObjectType::TORUS) + obj.color = vec4(0, 0.5, 1, 1); else obj.color = vec4(1, 1, 0, 1); - scene_.add_object(obj); - - } - - } - - - - // Cubic ease-in/out function for non-linear motion - - static float ease_in_out_cubic(float t) { - - t *= 2.0f; - - if (t < 1.0f) { - - return 0.5f * t * t * t; - - } - - t -= 2.0f; - - return 0.5f * (t * t * t + 2.0f); - - } - - - - void Hybrid3DEffect::render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) { - - // Animate Objects - - for (size_t i = 1; i < scene_.objects.size(); ++i) { + scene_.add_object(obj); + } +} - scene_.objects[i].rotation = quat::from_axis(vec3(0, 1, 0), time * 2.0f + i); +// Cubic ease-in/out function for non-linear motion - scene_.objects[i].position.y = std::sin(time * 3.0f + i) * 1.5f; +static float ease_in_out_cubic(float t) { + t *= 2.0f; - } + if (t < 1.0f) { + return 0.5f * t * t * t; + } - + t -= 2.0f; - // Create erratic, eased time variables for camera motion + return 0.5f * (t * t * t + 2.0f); +} - float erratic_time_radius = ease_in_out_cubic(fmodf(time * 0.2f, 1.0f)); +void Hybrid3DEffect::render(WGPURenderPassEncoder pass, float time, float beat, + float intensity, float aspect_ratio) { + // Animate Objects - float erratic_time_height = ease_in_out_cubic(fmodf(time * 0.3f, 1.0f)); + for (size_t i = 1; i < scene_.objects.size(); ++i) { + scene_.objects[i].rotation = + quat::from_axis(vec3(0, 1, 0), time * 2.0f + i); - float erratic_time_orbit = ease_in_out_cubic(fmodf(time * 0.1f, 1.0f)); + scene_.objects[i].position.y = std::sin(time * 3.0f + i) * 1.5f; + } - + // Create erratic, eased time variables for camera motion - // Animate Camera + float erratic_time_radius = ease_in_out_cubic(fmodf(time * 0.2f, 1.0f)); - float cam_radius = 10.0f + std::sin(erratic_time_radius * 6.28318f) * 4.0f; + float erratic_time_height = ease_in_out_cubic(fmodf(time * 0.3f, 1.0f)); - float cam_height = 5.0f + std::cos(erratic_time_height * 6.28318f) * 3.0f; + float erratic_time_orbit = ease_in_out_cubic(fmodf(time * 0.1f, 1.0f)); - camera_.set_look_at( + // Animate Camera - vec3(std::sin(erratic_time_orbit * 6.28318f) * cam_radius, cam_height, std::cos(erratic_time_orbit * 6.28318f) * cam_radius), + float cam_radius = 10.0f + std::sin(erratic_time_radius * 6.28318f) * 4.0f; - vec3(0, 0, 0), + float cam_height = 5.0f + std::cos(erratic_time_height * 6.28318f) * 3.0f; - vec3(0, 1, 0) + camera_.set_look_at( - ); + vec3(std::sin(erratic_time_orbit * 6.28318f) * cam_radius, cam_height, + std::cos(erratic_time_orbit * 6.28318f) * cam_radius), - + vec3(0, 0, 0), - camera_.aspect_ratio = aspect_ratio; + vec3(0, 1, 0) - + ); - // Draw + camera_.aspect_ratio = aspect_ratio; - renderer_.draw(pass, scene_, camera_, time); + // Draw - } + renderer_.draw(pass, scene_, camera_, time); +} |
