Определение угла и рисование части отладочной сферы
This commit is contained in:
@@ -104,6 +104,10 @@ void Light::toData()
|
||||
data[index].attenuation[1] = 4.5/radius; // Линейный коэф. угасания
|
||||
data[index].attenuation[2] = 4 * data[index].attenuation[1] * data[index].attenuation[1]; // Квадратичный коэф. угасания
|
||||
}
|
||||
// Направление и угол источника
|
||||
data[index].direction_angle = glm::vec4( glm::normalize(glm::vec3(result_transform * DEFAULT_LIGHT_DIRECTION))
|
||||
, angle / 2 // Половинный угол для вычислений на шейдере
|
||||
);
|
||||
}
|
||||
|
||||
// Возвращает ссылку на новый источник света
|
||||
@@ -150,7 +154,7 @@ Light& Light::findByIndex(GLuint index)
|
||||
}
|
||||
|
||||
// Конструктор без параметров
|
||||
Light::Light() : Node(), index(-1), uploadReq(false), color(1.0f), radius(10.0f)
|
||||
Light::Light() : Node(), index(-1), uploadReq(false), color(1.0f), radius(10.0f), angle(360.0f)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -165,6 +169,7 @@ Light& Light::operator=(const Light& other)
|
||||
uploadReq = other.uploadReq; // Необходимость загрузки
|
||||
color = other.color;
|
||||
radius = other.radius;
|
||||
angle = other.angle;
|
||||
|
||||
Node::operator=(other);
|
||||
}
|
||||
@@ -183,9 +188,17 @@ void Light::render(ShaderProgram &shaderProgram, UBO &material_buffer)
|
||||
static Scene bulb = loadOBJtoScene("../resources/models/bulb.obj", "../resources/models/", "../resources/textures/");
|
||||
static Model sphere = genShpere(1, 16, &bulb.root);
|
||||
|
||||
GLuint angle_uniform = shaderProgram.getUniformLoc("angle");
|
||||
GLuint direction_uniform = shaderProgram.getUniformLoc("direction");
|
||||
|
||||
// Цикл по источникам света
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
// Загрузим направление
|
||||
glUniform3fv(direction_uniform, 1, &data[i].direction_angle.x);
|
||||
// Угол для лампочки = 180 (рисуем целую модель)
|
||||
glUniform1f(angle_uniform, 180); // Зададим параметры материала сфере действия
|
||||
|
||||
// Сдвиг на позицию источника
|
||||
bulb.root.e_position() = data[i].position;
|
||||
sphere.e_scale() = glm::vec3(data[i].attenuation.r); // Масштабирование сферы
|
||||
@@ -195,6 +208,9 @@ void Light::render(ShaderProgram &shaderProgram, UBO &material_buffer)
|
||||
// Вызов отрисовки
|
||||
bulb.render(shaderProgram, material_buffer);
|
||||
|
||||
// Угол для сферы (рисуем направленный конус)
|
||||
glUniform1f(angle_uniform, data[i].direction_angle.a);
|
||||
|
||||
// Рисование сферы покрытия источника в режиме линий
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
sphere.render(shaderProgram, material_buffer);
|
||||
@@ -215,3 +231,17 @@ float& Light::e_radius()
|
||||
|
||||
return radius;
|
||||
}
|
||||
|
||||
// Константный доступ к углу освещенности
|
||||
const float& Light::c_angle() const
|
||||
{
|
||||
return angle;
|
||||
}
|
||||
|
||||
// Неконстантная ссылка для изменений угла освещенности
|
||||
float& Light::e_angle()
|
||||
{
|
||||
uploadReq = true;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ int main(void)
|
||||
Light& first = Light::getNew();
|
||||
first.e_color() = {1.0f, 0.0f, 0.0f}; // цвет
|
||||
first.e_position() = {0.3f, 0.1f, 0.5f}; // Позиция
|
||||
first.e_angle() = 70.0f;
|
||||
Light& second = Light::getNew();
|
||||
second.e_color() = {0.0f, 0.0f, 1.0f}; // цвет
|
||||
second.e_position() = {-0.3f, -0.1f, 0.5f}; // Позиция
|
||||
|
||||
Reference in New Issue
Block a user