changed 3D rendering
added pan/zoom gesture
This commit is contained in:
@@ -47,8 +47,6 @@ static float cube_normals[] = {
|
||||
};
|
||||
|
||||
|
||||
//static Shader* shader = nullptr;
|
||||
|
||||
Cube::Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CUBE_H
|
||||
#define CUBE_H
|
||||
|
||||
#include "../../../fixC11.h"
|
||||
#include <Indoor/geo/Point3.h>
|
||||
#include "Renderable3D.h"
|
||||
|
||||
@@ -26,82 +27,6 @@ public:
|
||||
|
||||
void render(const RenderSettings& rs) override;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
void paintGL(Shader* shader);
|
||||
|
||||
TODO_GL
|
||||
|
||||
glColor3f(color.x, color.y, color.z);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
// 3) move to destination
|
||||
glTranslatef(pos.x, pos.z, pos.y); // swap yz
|
||||
|
||||
// 2) rotate
|
||||
glRotatef(rot.x, 1, 0, 0);
|
||||
glRotatef(rot.y, 0, 0, 1); // swap yz
|
||||
glRotatef(rot.z, 0, 1, 0);
|
||||
|
||||
// 1) scale
|
||||
glScalef(size.x, size.z, size.y); // swap yz
|
||||
|
||||
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
// bottom
|
||||
glNormal3f(0,-1,0);
|
||||
glVertex3f(+s, -s, -s);
|
||||
glVertex3f(+s, -s, +s);
|
||||
glVertex3f(-s, -s, +s);
|
||||
glVertex3f(-s, -s, -s);
|
||||
|
||||
// top
|
||||
glNormal3f(0,+1,0);
|
||||
glVertex3f(-s, +s, -s);
|
||||
glVertex3f(-s, +s, +s);
|
||||
glVertex3f(+s, +s, +s);
|
||||
glVertex3f(+s, +s, -s);
|
||||
|
||||
// left
|
||||
glNormal3f(-1,0,0);
|
||||
glVertex3f(-s, -s, -s);
|
||||
glVertex3f(-s, -s, +s);
|
||||
glVertex3f(-s, +s, +s);
|
||||
glVertex3f(-s, +s, -s);
|
||||
|
||||
// right
|
||||
glNormal3f(+1,0,0);
|
||||
glVertex3f(+s, +s, -s);
|
||||
glVertex3f(+s, +s, +s);
|
||||
glVertex3f(+s, -s, +s);
|
||||
glVertex3f(+s, -s, -s);
|
||||
|
||||
// front
|
||||
glNormal3f(0,0,+1);
|
||||
glVertex3f(+s, +s, +s);
|
||||
glVertex3f(-s, +s, +s);
|
||||
glVertex3f(-s, -s, +s);
|
||||
glVertex3f(+s, -s, +s);
|
||||
|
||||
// rear
|
||||
glNormal3f(0,0,-1);
|
||||
glVertex3f(+s, -s, -s);
|
||||
glVertex3f(-s, -s, -s);
|
||||
glVertex3f(-s, +s, -s);
|
||||
glVertex3f(+s, +s, -s);
|
||||
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
#endif // CUBE_H
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "../../../fixC11.h"
|
||||
|
||||
#include "Handrail.h"
|
||||
|
||||
#include <Indoor/geo/Point3.h>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "../../../fixC11.h"
|
||||
|
||||
#include "Outline.h"
|
||||
|
||||
#include <QMatrix4x4>
|
||||
@@ -19,17 +21,15 @@ void Outline::render(const RenderSettings& rs) {
|
||||
|
||||
// show both sides
|
||||
//glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
|
||||
rs.shader->setColor(color.x, color.y, color.z);
|
||||
rs.shader->setVertices(vertices.data());
|
||||
rs.shader->setNormals(normals.data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size() / 3);
|
||||
rs.shader->setVertices(triangles.getVertices().data());
|
||||
rs.shader->setNormals(triangles.getNormals().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, triangles.getVertices().size() / 3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
|
||||
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
@@ -39,8 +39,7 @@ void Outline::setColor(float r, float g, float b) {
|
||||
}
|
||||
|
||||
void Outline::clear() {
|
||||
normals.clear();
|
||||
vertices.clear();
|
||||
triangles.clear();
|
||||
}
|
||||
|
||||
void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
||||
@@ -54,18 +53,22 @@ void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
||||
|
||||
const Point3 n = cross(p2-p1, p3-p1);
|
||||
if (n.z < 0) {
|
||||
vertices.push_back(p1.x); vertices.push_back(p1.y); vertices.push_back(p1.z);
|
||||
vertices.push_back(p3.x); vertices.push_back(p3.y); vertices.push_back(p3.z);
|
||||
vertices.push_back(p2.x); vertices.push_back(p2.y); vertices.push_back(p2.z);
|
||||
} else {
|
||||
vertices.push_back(p1.x); vertices.push_back(p1.y); vertices.push_back(p1.z);
|
||||
vertices.push_back(p2.x); vertices.push_back(p2.y); vertices.push_back(p2.z);
|
||||
vertices.push_back(p3.x); vertices.push_back(p3.y); vertices.push_back(p3.z);
|
||||
}
|
||||
|
||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
||||
// upper side (floor)
|
||||
this->triangles.addTriangle(p1, p3, p2, Point3(0,0,+1));
|
||||
|
||||
// facing downwards (ceiling)
|
||||
this->triangles.addTriangle(p1, p2, p3, Point3(0,0,-1));
|
||||
|
||||
} else {
|
||||
|
||||
// upper side (floor)
|
||||
this->triangles.addTriangle(p1, p2, p3, Point3(0,0,+1));
|
||||
|
||||
// facing downwards (ceiling)
|
||||
this->triangles.addTriangle(p1, p3, p2, Point3(0,0,-1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include "Renderable3D.h"
|
||||
#include <vector>
|
||||
#include <Indoor/geo/Point3.h>
|
||||
#include "TriangleData.h"
|
||||
|
||||
class Outline : public Renderable3D {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
TriangleData triangles;
|
||||
Point3 color;
|
||||
|
||||
public:
|
||||
|
||||
77
mapview/3D/misc/TriangleData.h
Normal file
77
mapview/3D/misc/TriangleData.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef TRIANGLEDATA_H
|
||||
#define TRIANGLEDATA_H
|
||||
|
||||
#include <vector>
|
||||
#include <Indoor/geo/Point3.h>
|
||||
|
||||
class TriangleData {
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> rgba;
|
||||
|
||||
public:
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
|
||||
}
|
||||
|
||||
|
||||
void addLine(Point3 p1, Point3 p2, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
|
||||
}
|
||||
|
||||
void clear() {
|
||||
vertices.clear();
|
||||
normals.clear();
|
||||
rgba.clear();
|
||||
}
|
||||
|
||||
const std::vector<float>& getVertices() {return vertices;}
|
||||
|
||||
const std::vector<float>& getNormals() {return normals;}
|
||||
|
||||
const std::vector<float>& getRGBA() {return rgba;}
|
||||
|
||||
};
|
||||
|
||||
#endif // TRIANGLEDATA_H
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "../../../fixC11.h"
|
||||
|
||||
#include "Window.h"
|
||||
#include "Shader.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user