highlight colliding drones
This commit is contained in:
parent
14b5993f0f
commit
ec4017bb0f
@ -3,6 +3,7 @@ varying vec2 uv;
|
|||||||
varying vec3 frag_pos;
|
varying vec3 frag_pos;
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
uniform bool highlight;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 light_col = vec3(1, .964, .783);
|
vec3 light_col = vec3(1, .964, .783);
|
||||||
@ -12,5 +13,10 @@ void main() {
|
|||||||
float diff = max(dot(normalize(norm), light_dir), 0.0);
|
float diff = max(dot(normalize(norm), light_dir), 0.0);
|
||||||
vec3 diffuse = diff * light_col;
|
vec3 diffuse = diff * light_col;
|
||||||
|
|
||||||
gl_FragColor = texture2D(tex, uv) * vec4(ambient + diffuse, 1);
|
vec4 col = texture2D(tex, uv) * vec4(ambient + diffuse, 1);
|
||||||
|
|
||||||
|
if (highlight) {
|
||||||
|
col = mix(col, vec4(1, 0, 0, 1), .5);
|
||||||
|
}
|
||||||
|
gl_FragColor = col;
|
||||||
}
|
}
|
||||||
|
@ -45,14 +45,21 @@ DroneController::DroneController(const QJsonObject &json)
|
|||||||
|
|
||||||
|
|
||||||
void DroneController::draw(QOpenGLExtraFunctions *f) const {
|
void DroneController::draw(QOpenGLExtraFunctions *f) const {
|
||||||
|
const QVector<QPair<int, int>> &col = collisions[frame];
|
||||||
for (const Drone &d : drones) {
|
for (const Drone &d : drones) {
|
||||||
QMatrix4x4 mat;
|
QMatrix4x4 mat;
|
||||||
mat.translate(d.getPos());
|
mat.translate(d.getPos());
|
||||||
|
for (const QPair<int, int> &p : col) {
|
||||||
|
if (d.getId() == p.first || d.getId() == p.second) {
|
||||||
|
OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
d.getMesh()->draw(f, mat);
|
d.getMesh()->draw(f, mat);
|
||||||
if (draw_spheres) {
|
if (draw_spheres) {
|
||||||
mat.scale(sphere_radius);
|
mat.scale(sphere_radius);
|
||||||
sphere->draw(f, mat);
|
sphere->draw(f, mat);
|
||||||
}
|
}
|
||||||
|
OpenGLWidget::instance->getMainProgram()->setUniformValue("highlight", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +123,7 @@ void DroneController::seek(int frame) {
|
|||||||
|
|
||||||
|
|
||||||
void DroneController::computeCollisions(double sphere_radius) {
|
void DroneController::computeCollisions(double sphere_radius) {
|
||||||
|
collisions.clear();
|
||||||
double sqDist = sphere_radius * sphere_radius * 4;
|
double sqDist = sphere_radius * sphere_radius * 4;
|
||||||
for (int i = 0; i < duration; i++) {
|
for (int i = 0; i < duration; i++) {
|
||||||
for (Drone &a : drones) {
|
for (Drone &a : drones) {
|
||||||
@ -124,6 +132,7 @@ void DroneController::computeCollisions(double sphere_radius) {
|
|||||||
b.setTo(i);
|
b.setTo(i);
|
||||||
if (&a == &b) continue;
|
if (&a == &b) continue;
|
||||||
if (collides(a, b, sqDist)) {
|
if (collides(a, b, sqDist)) {
|
||||||
|
collisions[i].append(QPair<int, int>(a.getId(), b.getId()));
|
||||||
emit collision(a.getId(), b.getId(), i);
|
emit collision(a.getId(), b.getId(), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ class DroneController : public QObject, public Painter {
|
|||||||
bool draw_spheres = false;
|
bool draw_spheres = false;
|
||||||
double sphere_radius = 0;
|
double sphere_radius = 0;
|
||||||
QTimer sphere_timer;
|
QTimer sphere_timer;
|
||||||
|
QMap<int, QVector<QPair<int, int>>> collisions;
|
||||||
|
|
||||||
static OpenGLMesh *sphere;
|
static OpenGLMesh *sphere;
|
||||||
static const unsigned char sphere_neutral[];
|
static const unsigned char sphere_neutral[];
|
||||||
|
@ -186,6 +186,7 @@ void OpenGLWidget::paintGL() {
|
|||||||
main_program.bind();
|
main_program.bind();
|
||||||
main_program.setUniformValue("proj", proj);
|
main_program.setUniformValue("proj", proj);
|
||||||
main_program.setUniformValue("view", view);
|
main_program.setUniformValue("view", view);
|
||||||
|
main_program.setUniformValue("highlight", false);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
ground->draw(this, QMatrix4x4());
|
ground->draw(this, QMatrix4x4());
|
||||||
if (painter) painter->draw(this);
|
if (painter) painter->draw(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user