worked on android port

opengl1 -> es
This commit is contained in:
root
2018-01-31 17:15:11 +01:00
parent a9bab839b2
commit e5e19779d5
53 changed files with 884 additions and 203 deletions

View File

@@ -5,6 +5,8 @@
#include <Indoor/math/Math.h>
#include "misc/Cube.h"
#include "misc/Window.h"
#include "MV3DElement.h"
@@ -37,7 +39,7 @@ protected:
Wall(const Point2 from, const Point2 to, const float thickness_m, const Floorplan::Material mat, float atHeight, float height) :
from(from), to(to), thickness_m(thickness_m), mat(mat), atHeight(atHeight), height(height) {;}
void paintGL() {
void render(const RenderSettings& rs) {
const float rad = -std::atan2(to.y - from.y, to.x - from.x);
const float deg = rad * 180 / M_PI;
@@ -50,154 +52,27 @@ protected:
const Point3 pos(cen2.x, cen2.y, atHeight + height/2);
// div by 2.01 to prevent overlapps and z-fi
const float sx = from.getDistance(to) / 2.01f;
const float sy = thickness_m / 2.01f;
const float sz = height / 2.01f; // prevent overlaps
const float sx = from.getDistance(to) / 2.02f;
const float sy = thickness_m / 2.02f;
const float sz = height / 2.02f; // prevent overlaps
const Point3 size(sx, sy, sz);
const Point3 rot(0,0,deg);
// fill color
if (mat == Floorplan::Material::CONCRETE) {
glColor3f(0.5, 0.5, 0.5);
} else {
glColor3f(0.75, 0.75, 0.75);
}
// build
Cube cube(pos, size, rot);
cube.paintGL();
/*
float y1 = atHeight;
float y2 = atHeight + height;
const Point2 p01 = from + dirPerp * w;
const Point2 p02 = from - dirPerp * w;
const Point2 p03 = to - dirPerp * w;
const Point2 p04 = to + dirPerp * w;
// fill the wall
if (mat == Floorplan::Material::CONCRETE) {
glColor3f(0.5, 0.5, 0.5);
cube.setColor(0.5, 0.5, 0.5);
} else {
glColor3f(0.75, 0.75, 0.75);
cube.setColor(0.75, 0.75, 0.75);
}
cube.render(rs);
auto renderQuad = [&] (const Point2 p1, const Point2 p2) {
glVertex3f(p1.x, y1, p1.y);
glVertex3f(p2.x, y1, p2.y);
glVertex3f(p2.x, y2, p2.y);
glVertex3f(p1.x, y2, p1.y);
};
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
//glNormal3f(n.x, n.y, n.z);
// short
renderQuad(p01, p02);
renderQuad(p03, p04);
// long
renderQuad(p02, p03);
renderQuad(p04, p01);
//glVertex3f(p1.x, p1.y, p1.z);
//glVertex3f(p2.x, p2.y, p2.z);
//glVertex3f(p3.x, p3.y, p3.z);
//glVertex3f(p4.x, p4.y, p4.z);
glEnd();
glBegin(GL_CULL_FACE);
*/
/*
// polygon edges
Point3 p1 = Point3(from.x, y1, from.y);
Point3 p2 = Point3(to.x, y1, to.y);
Point3 p3 = Point3(to.x, y2, to.y);
Point3 p4 = Point3(from.x, y2, from.y);
// calculate normal
// Point3 v1 = p2-p1;
// Point3 v2 = p3-p1;
// Point3 n = cross(v1, v2);
// n/=n.length();
Point3 n = Math::normal(p2-p1, p3-p1);
// align normals to virtual viewport
Point3 view(99,99,99);
if ((view-n).length() > (view+n).length()) {n = -n;}
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
glNormal3f(n.x, n.y, n.z);
glVertex3f(p1.x, p1.y, p1.z);
glVertex3f(p2.x, p2.y, p2.z);
glVertex3f(p3.x, p3.y, p3.z);
glVertex3f(p4.x, p4.y, p4.z);
glEnd();
glEnable(GL_CULL_FACE);
*/
}
};
struct Window {
Point2 from;
Point2 to;
float atHeight;
float height;
Window(const Point2 from, const Point2 to, float atHeight, float height) :
from(from), to(to), atHeight(atHeight), height(height) {;}
void paintGL() {
float y1 = atHeight;
float y2 = atHeight + height;
// polygon edges
Point3 p1 = Point3(from.x, y1, from.y);
Point3 p2 = Point3(to.x, y1, to.y);
Point3 p3 = Point3(to.x, y2, to.y);
Point3 p4 = Point3(from.x, y2, from.y);
// calculate normal
Point3 n = Math::normal(p2-p1, p3-p1);
// align normals to virtual viewport
Point3 view(99,99,99);
if ((view-n).length() > (view+n).length()) {n = -n;}
glColor4f(0.75, 0.85, 1.0, 0.35);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
glBegin(GL_QUADS);
glNormal3f(n.x, n.y, n.z);
glVertex3f(p1.x, p1.y, p1.z);
glVertex3f(p2.x, p2.y, p2.z);
glVertex3f(p3.x, p3.y, p3.z);
glVertex3f(p4.x, p4.y, p4.z);
glEnd();
glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
}
};
struct Handrail {
struct Handrail : public Renderable3D {
Point2 from;
Point2 to;
@@ -207,7 +82,7 @@ protected:
Handrail(const Point2 from, const Point2 to, float atHeight, float height) :
from(from), to(to), atHeight(atHeight), height(height) {;}
void paintGL() {
void render(const RenderSettings& rs) override {
float y1 = atHeight;
float y2 = atHeight + height;
@@ -219,6 +94,10 @@ protected:
Point3 p3 = Point3(from.x, y2, from.y);
Point3 p4 = Point3(to.x, y2, to.y);
/*
TODO_GL
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
@@ -252,27 +131,29 @@ protected:
glEnd();
glEnable(GL_LIGHTING);
*/
}
};
/** repaint me */
void paintGL() override {
void render(const RenderSettings& rs) override {
if (fo->material == Floorplan::Material::GLASS) {
Window win(fo->from, fo->to, f->atHeight, f->height);
win.paintGL();
win.render(rs);
} else if (fo->type == Floorplan::ObstacleType::WALL) {
Wall wall(fo->from, fo->to, fo->thickness_m, fo->material, f->atHeight, f->height);
wall.paintGL();
wall.render(rs);
} else if (fo->type == Floorplan::ObstacleType::HANDRAIL) {
Handrail rail(fo->from, fo->to, f->atHeight, 1.0);
rail.paintGL();
rail.render(rs);
}