1 /************************************************************************************ 2 3 AstroMenace 4 Hardcore 3D space scroll-shooter with spaceship upgrade possibilities. 5 Copyright (c) 2006-2019 Mikhail Kurinnoi, Viewizard 6 7 8 AstroMenace is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 AstroMenace is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with AstroMenace. If not, see <https://www.gnu.org/licenses/>. 20 21 22 Website: https://viewizard.com/ 23 Project: https://github.com/viewizard/astromenace 24 E-mail: viewizard@viewizard.com 25 26 *************************************************************************************/ 27 28 // TODO class cLight should use encapsulation 29 30 #ifndef CORE_LIGHT_LIGHT_H 31 #define CORE_LIGHT_LIGHT_H 32 33 #include "../base.h" 34 35 namespace viewizard { 36 37 struct sVECTOR3D; 38 39 enum class eLightType { 40 Directional, // located far (sun, stars, etc) 41 Point // located close (engines, weapon flashes, etc) 42 }; 43 44 class cLight { 45 friend std::weak_ptr<cLight> vw_CreateLight(eLightType Type); 46 47 public: 48 // Activate and setup for proper light type (OpenGL-related). 49 bool Activate(int CurrentLightNum, const float (&Matrix)[16]); 50 // Deactivate (OpenGL-related). 51 void DeActivate(); 52 // Set location. 53 void SetLocation(sVECTOR3D NewLocation); 54 55 // Light's color. 56 float Diffuse[4]{0.0f, 0.0f, 0.0f, 1.0f}; 57 float Specular[4]{0.0f, 0.0f, 0.0f, 1.0f}; 58 float Ambient[4]{0.0f, 0.0f, 0.0f, 1.0f}; 59 // Maximum color (for color deviation calculations). 60 float DiffuseMax[4]; 61 float SpecularMax[4]; 62 // Attenuations. 63 float ConstantAttenuation{0.0f}; 64 float LinearAttenuation{0.0f}; 65 float QuadraticAttenuation{0.0f}; 66 // Attenuations base (for particle system effects). 67 float LinearAttenuationBase{0.0f}; 68 float QuadraticAttenuationBase{0.0f}; 69 // Direction. 70 sVECTOR3D Direction{0.0f, 0.0f, 0.0f}; 71 // Location (for point lights only). 72 sVECTOR3D Location{0.0f, 0.0f, 0.0f}; 73 // On/Off switch, in this case Off mean On=false. 74 bool On{true}; 75 76 private: 77 // OpenGL-related. 78 int RealLightNum{-1}; 79 // Store LightType for fast access (we also use it as key for LightsMap). 80 eLightType LightType{eLightType::Point}; 81 82 // Don't allow direct new/delete usage in code, only vw_CreateLight() 83 // allowed for light creation and release setup (deleter must be provided). 84 cLight() = default; 85 ~cLight() = default; 86 }; 87 88 89 // Activate proper lights for particular object (presented by location and radius^2). 90 int vw_CheckAndActivateAllLights(int &Type1, int &Type2, const sVECTOR3D &Location, float Radius2, 91 int DirLimit, int PointLimit, const float (&Matrix)[16]); 92 // Calculate affected lights counter and create sorted map with affected lights. 93 int vw_CalculateAllPointLightsAttenuation(const sVECTOR3D &Location, float Radius2, 94 std::multimap<float, cLight*> *AffectedLightsMap); 95 // Deactivate all lights. 96 void vw_DeActivateAllLights(); 97 // Release light. 98 void vw_ReleaseLight(std::weak_ptr<cLight> &Light); 99 // Release all lights. 100 void vw_ReleaseAllLights(); 101 // Create light. 102 std::weak_ptr<cLight> vw_CreateLight(eLightType Type); 103 // Create point light with initialization. 104 std::weak_ptr<cLight> vw_CreatePointLight(const sVECTOR3D &Location, 105 float R, float G, float B, 106 float Linear, float Quadratic); 107 // Get main direct light. Usually, first one is the main. 108 bool vw_GetMainDirectLight(std::weak_ptr<cLight> &Light); 109 110 } // viewizard namespace 111 112 #endif // CORE_LIGHT_LIGHT_H 113