colobot/colobot-base/graphics/engine/lightning.h

119 lines
2.9 KiB
C
Raw Normal View History

/*
* This file is part of the Colobot: Gold Edition source code
2023-08-06 21:15:48 +00:00
* Copyright (C) 2001-2023, Daniel Roux, EPSITEC SA & TerranovaTeam
2015-08-22 14:40:02 +00:00
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
/**
* \file graphics/engine/lightning.h
2012-09-19 21:50:28 +00:00
* \brief Lightning rendering - CLightning class (aka blitz)
*/
#pragma once
#include <glm/glm.hpp>
#include <vector>
2012-06-25 14:37:03 +00:00
class CObject;
2012-10-05 13:26:24 +00:00
class CSoundInterface;
struct Event;
2012-06-25 14:37:03 +00:00
2012-09-19 21:50:28 +00:00
// Graphics module namespace
2015-08-02 09:40:47 +00:00
namespace Gfx
{
2012-06-25 14:37:03 +00:00
class CEngine;
class CTerrain;
class CCamera;
2012-10-05 13:26:24 +00:00
//! Radius of lightning protection
const float LTNG_PROTECTION_RADIUS = 200.0f;
2012-06-25 14:37:03 +00:00
/**
* \class CLightning
* \brief Lightning effect renderer
*
2012-10-05 13:26:24 +00:00
* TODO: documentation
*/
2012-06-25 14:37:03 +00:00
class CLightning
{
public:
CLightning(CEngine* engine);
~CLightning();
2012-06-25 14:37:03 +00:00
2012-10-05 13:26:24 +00:00
//! Triggers lightning
bool Create(float sleep, float delay, float magnetic);
2012-10-05 13:26:24 +00:00
//! Removes lightning
void Flush();
//! Gives the status of lightning
bool GetStatus(float &sleep, float &delay, float &magnetic, float &progress);
2012-10-05 13:26:24 +00:00
//! Specifies the status of lightning
bool SetStatus(float sleep, float delay, float magnetic, float progress);
2012-10-05 13:26:24 +00:00
//! Management of an event
bool EventProcess(const Event &event);
//! Draws lightning
void Draw();
2012-06-25 14:37:03 +00:00
2016-03-28 11:51:39 +00:00
//! Shoots lightning strike at given position
void StrikeAtPos(glm::vec3 pos);
2016-03-28 11:51:39 +00:00
2012-06-25 14:37:03 +00:00
protected:
2012-10-05 13:26:24 +00:00
//! Updates lightning
bool EventFrame(const Event &event);
2012-10-05 13:26:24 +00:00
//! Seeks for the object closest to the lightning
CObject* SearchObject(glm::vec3 pos);
2012-06-25 14:37:03 +00:00
protected:
CEngine* m_engine = nullptr;
CTerrain* m_terrain = nullptr;
CCamera* m_camera = nullptr;
CSoundInterface* m_sound = nullptr;
bool m_lightningExists = false;
float m_sleep = 0.0f;
float m_delay = 0.0f;
float m_magnetic = 0.0f;
float m_speed = 0.0f;
float m_progress = 0.0f;
glm::vec3 m_pos = { 0, 0, 0 };
2012-10-05 13:26:24 +00:00
enum class LightningPhase
2012-10-05 13:26:24 +00:00
{
Wait,
Flash,
2012-10-05 13:26:24 +00:00
};
LightningPhase m_phase = LightningPhase::Wait;
2012-10-05 13:26:24 +00:00
struct LightningSegment
{
glm::vec2 shift;
float width = 0.0f;
};
std::vector<LightningSegment> m_segments;
2012-06-25 14:37:03 +00:00
};
2012-09-19 21:50:28 +00:00
} // namespace Gfx