Радиус действия источника
This commit is contained in:
		
							parent
							
								
									0ce4cff80e
								
							
						
					
					
						commit
						95e33797c3
					
				@ -13,6 +13,7 @@ struct LightData
 | 
			
		||||
{
 | 
			
		||||
    alignas(16) glm::vec3 position; // Позиция
 | 
			
		||||
    alignas(16) glm::vec3 color; // Цвет 
 | 
			
		||||
    float radius; // Радиус действия источника   
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Источник света
 | 
			
		||||
@ -28,6 +29,9 @@ class Light : public Node
 | 
			
		||||
        const glm::vec3& c_color() const; // Константный доступ к цвету
 | 
			
		||||
        glm::vec3& e_color(); // Неконстантная ссылка для изменений цвета
 | 
			
		||||
 | 
			
		||||
        const float& c_radius() const; // Константный доступ к радиусу
 | 
			
		||||
        float& e_radius(); // Неконстантная ссылка для изменений радиуса
 | 
			
		||||
 | 
			
		||||
        static void render(ShaderProgram &shaderProgram, UBO &material_buffer); // Рисование отладочных лампочек
 | 
			
		||||
    private:
 | 
			
		||||
        Light(); // Конструктор без параметров
 | 
			
		||||
@ -36,6 +40,7 @@ class Light : public Node
 | 
			
		||||
        virtual ~Light(); 
 | 
			
		||||
 | 
			
		||||
        glm::vec3 color; // Цвет
 | 
			
		||||
        float radius; // Радиус действия источника
 | 
			
		||||
 | 
			
		||||
        int index; // Индекс в массиве отправки (может не совпадать с lights) для дефрагментированного доступа
 | 
			
		||||
        static Light& findByIndex(GLuint index); // Возвращает ссылку на источник с нужным индексом
 | 
			
		||||
 | 
			
		||||
@ -97,6 +97,7 @@ void Light::toData()
 | 
			
		||||
 | 
			
		||||
    data[index].position = glm::vec3(result_transform[3]); // Позиция из матрицы трансформации
 | 
			
		||||
    data[index].color = color; // Цвет
 | 
			
		||||
    data[index].radius = radius; // Радиус действия источника
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Возвращает ссылку на новый источник света
 | 
			
		||||
@ -143,7 +144,7 @@ Light& Light::findByIndex(GLuint index)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Конструктор без параметров
 | 
			
		||||
Light::Light() : Node(), index(-1), uploadReq(false), color(1.0f)
 | 
			
		||||
Light::Light() : Node(), index(-1), uploadReq(false), color(1.0f), radius(10.0f)
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
@ -157,6 +158,7 @@ Light& Light::operator=(const Light& other)
 | 
			
		||||
        index = other.index; // Переносим индекс
 | 
			
		||||
        uploadReq = other.uploadReq; // Необходимость загрузки 
 | 
			
		||||
        color = other.color;
 | 
			
		||||
        radius = other.radius;
 | 
			
		||||
 | 
			
		||||
        Node::operator=(other);
 | 
			
		||||
    }
 | 
			
		||||
@ -186,3 +188,17 @@ void Light::render(ShaderProgram &shaderProgram, UBO &material_buffer)
 | 
			
		||||
        bulb.render(shaderProgram, material_buffer);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Константный доступ к радиусу
 | 
			
		||||
const float& Light::c_radius() const
 | 
			
		||||
{
 | 
			
		||||
    return radius;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Неконстантная ссылка для изменений радиуса
 | 
			
		||||
float& Light::e_radius()
 | 
			
		||||
{
 | 
			
		||||
    uploadReq = true;
 | 
			
		||||
 | 
			
		||||
    return radius;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user