|
| | FloatingEnergySphereWidget (bool is_first_time, QWidget *parent=nullptr) |
| | Constructs a FloatingEnergySphereWidget. Initializes OpenGL settings, timers, audio components, interaction variables, and sets up the window appearance (frameless, transparent background).
|
| |
| void | SetClosable (bool closable) |
| | Sets whether the widget can be closed by the user or programmatically. Used to prevent closing during the destruction animation.
|
| |
| | ~FloatingEnergySphereWidget () override |
| | Destructor. Cleans up OpenGL resources (VBO, VAO, shader), stops timers, and stops audio playback/decoding.
|
| |
|
| void | closeEvent (QCloseEvent *event) override |
| | Handles the widget close event. Stops timers and audio, emits widgetClosed() if allowed (closable_ is true), otherwise ignores the event.
|
| |
| void | initializeGL () override |
| | Initializes OpenGL resources (functions, shaders, geometry, VAO/VBO) and audio setup. Called once before the first paintGL call.
|
| |
| void | keyPressEvent (QKeyEvent *event) override |
| | Handles key press events. Detects the Konami code sequence.
|
| |
| void | mouseMoveEvent (QMouseEvent *event) override |
| | Handles mouse move events. Rotates the sphere based on mouse dragging when the left button is pressed. Updates angular velocity for inertia effect.
|
| |
| void | mousePressEvent (QMouseEvent *event) override |
| | Handles mouse press events. Accepts the event, but the primary logic is in mouseMoveEvent.
|
| |
| void | mouseReleaseEvent (QMouseEvent *event) override |
| | Handles mouse release events. Stops direct rotation tracking and allows inertia to take over.
|
| |
| void | paintGL () override |
| | Renders the OpenGL scene. Called whenever the widget needs to be repainted. Binds shaders and VAO, sets uniforms (matrices, time, audio amplitude, impact data, destruction progress), and draws the sphere points.
|
| |
| void | resizeGL (int w, int h) override |
| | Handles resizing of the OpenGL viewport and updates the projection matrix. Calculates the field of view dynamically to keep the sphere's clear size consistent.
|
| |
| void | wheelEvent (QWheelEvent *event) override |
| | Handles mouse wheel events. Zooms the camera in or out by adjusting camera_distance_.
|
| |
|
| void | AudioDecodingFinished () const |
| | Slot called by the audio decoder when it finishes decoding the entire source file.
|
| |
| void | HandleAudioDecoderError () |
| | Slot called when the QAudioDecoder encounters an error. Logs the error.
|
| |
| void | HandleMediaPlayerError () const |
| | Slot called when the QMediaPlayer encounters an error. Logs the error.
|
| |
| void | HandlePlayerStateChanged (QMediaPlayer::State state) |
| | Slot called when the QMediaPlayer's state changes (e.g., Playing, Stopped). Used to detect the end of the initial audio to start the hint timer, and the end of the destruction audio to close the widget.
|
| |
| void | PlayKonamiHint () const |
| | Slot called by hint_timer_ after a period of inactivity to play the Konami code audio hint.
|
| |
| void | ProcessAudioBuffer () |
| | Slot called by the audio decoder when a new buffer of decoded audio data is ready. Calculates the RMS amplitude for the buffer and stores it. Sets audio_ready_ flag.
|
| |
| void | SimulateClick () |
| | Slot called periodically by click_simulation_timer_ to trigger random impacts on the sphere.
|
| |
| void | StartDestructionSequence () |
| | Initiates the destruction animation sequence. Sets the is_destroying_ flag, resets progress, plays the destruction sound, and prevents the widget from being closed prematurely.
|
| |
| void | UpdateAnimation () |
| | Slot called periodically by timer_ to update animation state. Advances time, updates audio amplitude interpolation, handles rotation/inertia, updates destruction progress if active, and schedules a repaint.
|
| |
|
| float | CalculateRMSAmplitude (const QAudioBuffer &buffer) const |
| | Calculates the Root Mean Square (RMS) amplitude for a given audio buffer. Used to quantify the energy level in the audio signal for visualization. Handles different audio sample formats.
|
| |
| void | SetupAudio () |
| | Initializes audio components (QMediaPlayer, QAudioDecoder), connects signals, selects the appropriate audio file based on is_first_time_, and starts playback/decoding.
|
| |
| void | SetupShaders () |
| | Compiles and links the vertex and fragment shaders into shader_program_.
|
| |
| void | SetupSphereGeometry (int rings, int sectors) |
| | Creates the vertex data (positions) for the sphere geometry using rings and sectors. Populates the vertices_ vector.
|
| |
| void | TriggerImpactAtScreenPos (const QPoint &screen_position) |
| | Triggers a visual impact effect at a point on the sphere corresponding to a screen position. Performs ray casting from the screen position to find the intersection point on the sphere and activates an ImpactInfo entry.
|
| |
|
| QVector3D | angular_velocity_ |
| | Current angular velocity used for inertial rotation.
|
| |
| std::vector< float > | audio_amplitudes_ |
| | Stores calculated RMS amplitude values for each decoded audio buffer.
|
| |
| qint64 | audio_buffer_duration_ms_ |
| | Duration of a single audio buffer processed by the decoder, in milliseconds.
|
| |
| QAudioDecoder * | audio_decoder_ |
| | Decoder for extracting audio data from files for amplitude analysis.
|
| |
| QAudioFormat | audio_format_ |
| | Format of the decoded audio data (sample rate, channels, etc.).
|
| |
| bool | audio_ready_ |
| | Flag indicating if audio data has been successfully decoded and is ready for visualization.
|
| |
| float | camera_distance_ |
| | Distance from the camera to the origin (center of the sphere). Used for zooming.
|
| |
| QVector3D | camera_position_ |
| | Position of the camera in world space.
|
| |
| QTimer * | click_simulation_timer_ |
| | Timer triggering simulated random clicks/impacts on the sphere.
|
| |
| bool | closable_ |
| | Flag indicating if the widget can be closed.
|
| |
| float | current_audio_amplitude_ |
| | Current audio amplitude value used for rendering (smoothed).
|
| |
| float | damping_factor_ |
| | Damping factor applied to angular velocity for inertia decay.
|
| |
| float | destruction_progress_ |
| | Progress of the destruction animation (0.0 to 1.0).
|
| |
| QElapsedTimer | elapsed_timer_ |
| | Timer used for calculating delta time between animation frames.
|
| |
| QTimer * | hint_timer_ |
| | Timer triggering the Konami code audio hints after inactivity.
|
| |
| std::vector< ImpactInfo > | impacts_ |
| | Stores information about active impact effects.
|
| |
| bool | is_destroying_ |
| | Flag indicating if the destruction animation is currently active.
|
| |
| bool | is_first_time_ |
| | Flag indicating if this is the first time the widget/app is run (affects initial audio).
|
| |
| std::deque< int > | key_sequence_ |
| | Stores the sequence of recently pressed keys for Konami code detection.
|
| |
| const QString | kGoodbyeSoundFilename = "goodbye.wav" |
| | Filename of the audio played during the destruction sequence.
|
| |
| const std::vector< int > | konami_code_ |
| | The target key sequence for the Konami code.
|
| |
| float | last_frame_time_secs_ |
| | Timestamp of the last animation frame in seconds.
|
| |
| QPoint | last_mouse_position_ |
| | Stores the last mouse position during dragging for rotation calculation.
|
| |
| QMediaPlayer * | media_player_ |
| | Media player for playing audio files (initial sound, hint, destruction).
|
| |
| QMatrix4x4 | model_matrix_ |
| | Model matrix transforming model space to world space (includes rotation).
|
| |
| bool | mouse_pressed_ |
| | Flag indicating if the left mouse button is currently pressed.
|
| |
| int | next_impact_index_ |
| | Index of the next slot to use in the impacts_ vector (circular).
|
| |
| QMatrix4x4 | projection_matrix_ |
| | Projection matrix transforming view space to clip space.
|
| |
| QQuaternion | rotation_ |
| | Current rotation of the sphere as a quaternion.
|
| |
| QOpenGLShaderProgram * | shader_program_ |
| | The compiled and linked OpenGL shader program.
|
| |
| float | target_audio_amplitude_ {} |
| | Target audio amplitude based on the currently playing audio buffer.
|
| |
| float | time_value_ |
| | Time value passed to shaders, incremented in UpdateAnimation.
|
| |
| QTimer | timer_ |
| | Timer driving the main animation loop (UpdateAnimation).
|
| |
| QOpenGLVertexArrayObject | vao_ |
| | OpenGL Vertex Array Object managing vertex buffer state.
|
| |
| QOpenGLBuffer | vbo_ |
| | OpenGL Vertex Buffer Object storing sphere vertex data.
|
| |
| int | vertex_count_ |
| | Total number of vertices in the sphere geometry.
|
| |
| std::vector< GLfloat > | vertices_ |
| | Raw vertex data (positions) for the sphere points.
|
| |
| QMatrix4x4 | view_matrix_ |
| | View matrix transforming world space to view space.
|
| |
An OpenGL widget displaying a floating, interactive energy sphere.
This widget renders a sphere composed of points using OpenGL shaders. The sphere deforms dynamically based on time, audio amplitude (visualizing audio playback), and simulated impacts triggered by clicks or automatically. It supports mouse interaction for rotation and zooming. It also includes an Easter egg triggered by the Konami code, which initiates a destruction animation sequence with accompanying sound. The widget plays different initial audio files based on whether it's the first time the application is run.
| void FloatingEnergySphereWidget::paintGL |
( |
| ) |
|
|
overrideprotected |
Renders the OpenGL scene. Called whenever the widget needs to be repainted. Binds shaders and VAO, sets uniforms (matrices, time, audio amplitude, impact data, destruction progress), and draws the sphere points.