Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Turri <enricoturri@seznam.cz>2018-08-23 16:37:38 +0300
committerEnrico Turri <enricoturri@seznam.cz>2018-08-23 16:37:38 +0300
commit66ce6384392a7a748e1535a8d84671ffe9f01ef7 (patch)
tree2b5b5c805171667fab51db69f6620f061c066003 /xs/src/slic3r/GUI/3DScene.cpp
parenta5fcdeec23dd7a4ac17f1331310e6275cd4ef2ca (diff)
parent76d60070eb8ccb10f60aebb8036075a2065a9fb8 (diff)
Fixed conflicts after merging with branch eigenize
Diffstat (limited to 'xs/src/slic3r/GUI/3DScene.cpp')
-rw-r--r--xs/src/slic3r/GUI/3DScene.cpp244
1 files changed, 119 insertions, 125 deletions
diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp
index dd7a3fb4a..a3f7e0a4c 100644
--- a/xs/src/slic3r/GUI/3DScene.cpp
+++ b/xs/src/slic3r/GUI/3DScene.cpp
@@ -26,11 +26,6 @@
#include "GUI.hpp"
-static const float UNIT_MATRIX[] = { 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f };
-
namespace Slic3r {
void GLIndexedVertexArray::load_mesh_flat_shading(const TriangleMesh &mesh)
@@ -44,7 +39,7 @@ void GLIndexedVertexArray::load_mesh_flat_shading(const TriangleMesh &mesh)
for (int i = 0; i < mesh.stl.stats.number_of_facets; ++ i) {
const stl_facet &facet = mesh.stl.facet_start[i];
for (int j = 0; j < 3; ++ j)
- this->push_geometry(facet.vertex[j].x, facet.vertex[j].y, facet.vertex[j].z, facet.normal.x, facet.normal.y, facet.normal.z);
+ this->push_geometry(facet.vertex[j](0), facet.vertex[j](1), facet.vertex[j](2), facet.normal(0), facet.normal(1), facet.normal(2));
}
}
@@ -60,7 +55,7 @@ void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh &mesh)
for (int i = 0; i < mesh.stl.stats.number_of_facets; ++i) {
const stl_facet &facet = mesh.stl.facet_start[i];
for (int j = 0; j < 3; ++j)
- this->push_geometry(facet.vertex[j].x, facet.vertex[j].y, facet.vertex[j].z, facet.normal.x, facet.normal.y, facet.normal.z);
+ this->push_geometry(facet.vertex[j](0), facet.vertex[j](1), facet.vertex[j](2), facet.normal(0), facet.normal(1), facet.normal(2));
this->push_triangle(vertices_count, vertices_count + 1, vertices_count + 2);
vertices_count += 3;
@@ -200,7 +195,8 @@ const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f };
const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f };
GLVolume::GLVolume(float r, float g, float b, float a)
- : m_angle_z(0.0f)
+ : m_origin(0, 0, 0)
+ , m_angle_z(0.0f)
, m_scale_factor(1.0f)
, m_transformed_bounding_box_dirty(true)
, m_transformed_convex_hull_bounding_box_dirty(true)
@@ -257,12 +253,12 @@ void GLVolume::set_render_color()
set_render_color(color, 4);
}
-const Pointf3& GLVolume::get_origin() const
+const Vec3d& GLVolume::get_origin() const
{
return m_origin;
}
-void GLVolume::set_origin(const Pointf3& origin)
+void GLVolume::set_origin(const Vec3d& origin)
{
if (m_origin != origin)
{
@@ -297,15 +293,13 @@ void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
m_convex_hull = &convex_hull;
}
-std::vector<float> GLVolume::world_matrix() const
+Transform3d GLVolume::world_matrix() const
{
- std::vector<float> world_mat(UNIT_MATRIX, std::end(UNIT_MATRIX));
- Eigen::Transform<float, 3, Eigen::Affine> m = Eigen::Transform<float, 3, Eigen::Affine>::Identity();
- m.translate(Eigen::Vector3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z));
- m.rotate(Eigen::AngleAxisf(m_angle_z, Eigen::Vector3f::UnitZ()));
- m.scale(m_scale_factor);
- ::memcpy((void*)world_mat.data(), (const void*)m.data(), 16 * sizeof(float));
- return world_mat;
+ Transform3d matrix = Transform3d::Identity();
+ matrix.translate(m_origin);
+ matrix.rotate(Eigen::AngleAxisd((double)m_angle_z, Vec3d::UnitZ()));
+ matrix.scale((double)m_scale_factor);
+ return matrix;
}
BoundingBoxf3 GLVolume::transformed_bounding_box() const
@@ -376,7 +370,7 @@ void GLVolume::render() const
::glCullFace(GL_BACK);
::glPushMatrix();
- ::glTranslated(m_origin.x, m_origin.y, m_origin.z);
+ ::glTranslated(m_origin(0), m_origin(1), m_origin(2));
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
if (this->indexed_vertex_array.indexed())
@@ -410,7 +404,7 @@ void GLVolume::render_using_layer_height() const
glUniform1f(z_texture_row_to_normalized_id, (GLfloat)(1.0f / layer_height_texture_height()));
if (z_cursor_id >= 0)
- glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max.z * layer_height_texture_data.z_cursor_relative));
+ glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max(2) * layer_height_texture_data.z_cursor_relative));
if (z_cursor_band_width_id >= 0)
glUniform1f(z_cursor_band_width_id, (GLfloat)layer_height_texture_data.edit_band_width);
@@ -502,7 +496,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr);
::glPushMatrix();
- ::glTranslated(m_origin.x, m_origin.y, m_origin.z);
+ ::glTranslated(m_origin(0), m_origin(1), m_origin(2));
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
@@ -547,7 +541,7 @@ void GLVolume::render_legacy() const
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data());
::glPushMatrix();
- ::glTranslated(m_origin.x, m_origin.y, m_origin.z);
+ ::glTranslated(m_origin(0), m_origin(1), m_origin(2));
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
@@ -562,7 +556,7 @@ void GLVolume::render_legacy() const
double GLVolume::layer_height_texture_z_to_row_id() const
{
- return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max.z);
+ return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max(2));
}
void GLVolume::generate_layer_height_texture(PrintObject *print_object, bool force)
@@ -667,7 +661,7 @@ std::vector<int> GLVolumeCollection::load_object(
}
v.is_modifier = model_volume->modifier;
v.shader_outside_printer_detection_enabled = !model_volume->modifier;
- v.set_origin(Pointf3(instance->offset.x, instance->offset.y, 0.0));
+ v.set_origin(Vec3d(instance->offset(0), instance->offset(1), 0.0));
v.set_angle_z(instance->rotation);
v.set_scale_factor(instance->scaling_factor);
}
@@ -698,16 +692,16 @@ int GLVolumeCollection::load_wipe_tower_preview(
// We'll now create the box with jagged edge. y-coordinates of the pre-generated model are shifted so that the front
// edge has y=0 and centerline of the back edge has y=depth:
Pointf3s points;
- std::vector<Point3> facets;
+ std::vector<Vec3crd> facets;
float out_points_idx[][3] = {{0, -depth, 0}, {0, 0, 0}, {38.453, 0, 0}, {61.547, 0, 0}, {100, 0, 0}, {100, -depth, 0}, {55.7735, -10, 0}, {44.2265, 10, 0},
{38.453, 0, 1}, {0, 0, 1}, {0, -depth, 1}, {100, -depth, 1}, {100, 0, 1}, {61.547, 0, 1}, {55.7735, -10, 1}, {44.2265, 10, 1}};
int out_facets_idx[][3] = {{0, 1, 2}, {3, 4, 5}, {6, 5, 0}, {3, 5, 6}, {6, 2, 7}, {6, 0, 2}, {8, 9, 10}, {11, 12, 13}, {10, 11, 14}, {14, 11, 13}, {15, 8, 14},
{8, 10, 14}, {3, 12, 4}, {3, 13, 12}, {6, 13, 3}, {6, 14, 13}, {7, 14, 6}, {7, 15, 14}, {2, 15, 7}, {2, 8, 15}, {1, 8, 2}, {1, 9, 8},
{0, 9, 1}, {0, 10, 9}, {5, 10, 0}, {5, 11, 10}, {4, 11, 5}, {4, 12, 11}};
for (int i=0;i<16;++i)
- points.push_back(Pointf3(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]));
+ points.push_back(Vec3d(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]));
for (int i=0;i<28;++i)
- facets.push_back(Point3(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]));
+ facets.push_back(Vec3crd(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]));
TriangleMesh tooth_mesh(points, facets);
// We have the mesh ready. It has one tooth and width of min_width. We will now append several of these together until we are close to
@@ -718,7 +712,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
tooth_mesh.translate(min_width, 0.f, 0.f);
}
- mesh.scale(Pointf3(width/(n*min_width), 1.f, height)); // Scaling to proper width
+ mesh.scale(Vec3d(width/(n*min_width), 1.f, height)); // Scaling to proper width
}
else
mesh = make_cube(width, depth, height);
@@ -738,7 +732,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
else
v.indexed_vertex_array.load_mesh_flat_shading(mesh);
- v.set_origin(Pointf3(pos_x, pos_y, 0.));
+ v.set_origin(Vec3d(pos_x, pos_y, 0.));
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
v.bounding_box = v.indexed_vertex_array.bounding_box();
@@ -824,9 +818,9 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M
return false;
BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values));
- BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config->opt_float("max_print_height")));
+ BoundingBoxf3 print_volume(unscale(bed_box_2D.min(0), bed_box_2D.min(1), 0.0), unscale(bed_box_2D.max(0), bed_box_2D.max(1), unscale<double>(config->opt_float("max_print_height"))));
// Allow the objects to protrude below the print bed
- print_volume.min.z = -1e10;
+ print_volume.min(2) = -1e10;
ModelInstance::EPrintVolumeState state = ModelInstance::PVS_Inside;
bool all_contained = true;
@@ -989,8 +983,8 @@ static void thick_lines_to_indexed_vertex_array(
// right, left, top, bottom
int idx_prev[4] = { -1, -1, -1, -1 };
double bottom_z_prev = 0.;
- Pointf b1_prev;
- Vectorf v_prev;
+ Vec2d b1_prev(Vec2d::Zero());
+ Vec2d v_prev(Vec2d::Zero());
int idx_initial[4] = { -1, -1, -1, -1 };
double width_initial = 0.;
double bottom_z_initial = 0.0;
@@ -1000,7 +994,7 @@ static void thick_lines_to_indexed_vertex_array(
for (size_t ii = 0; ii < lines_end; ++ ii) {
size_t i = (ii == lines.size()) ? 0 : ii;
const Line &line = lines[i];
- double len = unscale(line.length());
+ double len = unscale<double>(line.length());
double inv_len = 1.0 / len;
double bottom_z = top_z - heights[i];
double middle_z = 0.5 * (top_z + bottom_z);
@@ -1010,29 +1004,29 @@ static void thick_lines_to_indexed_vertex_array(
bool is_last = (ii == lines_end - 1);
bool is_closing = closed && is_last;
- Vectorf v = Vectorf::new_unscale(line.vector());
- v.scale(inv_len);
+ Vec2d v = unscale(line.vector());
+ v *= inv_len;
- Pointf a = Pointf::new_unscale(line.a);
- Pointf b = Pointf::new_unscale(line.b);
- Pointf a1 = a;
- Pointf a2 = a;
- Pointf b1 = b;
- Pointf b2 = b;
+ Vec2d a = unscale(line.a);
+ Vec2d b = unscale(line.b);
+ Vec2d a1 = a;
+ Vec2d a2 = a;
+ Vec2d b1 = b;
+ Vec2d b2 = b;
{
double dist = 0.5 * width; // scaled
- double dx = dist * v.x;
- double dy = dist * v.y;
- a1.translate(+dy, -dx);
- a2.translate(-dy, +dx);
- b1.translate(+dy, -dx);
- b2.translate(-dy, +dx);
+ double dx = dist * v(0);
+ double dy = dist * v(1);
+ a1 += Vec2d(+dy, -dx);
+ a2 += Vec2d(-dy, +dx);
+ b1 += Vec2d(+dy, -dx);
+ b2 += Vec2d(-dy, +dx);
}
// calculate new XY normals
Vector n = line.normal();
- Vectorf3 xy_right_normal = Vectorf3::new_unscale(n.x, n.y, 0);
- xy_right_normal.scale(inv_len);
+ Vec3d xy_right_normal = unscale(n(0), n(1), 0);
+ xy_right_normal *= inv_len;
int idx_a[4];
int idx_b[4];
@@ -1050,7 +1044,7 @@ static void thick_lines_to_indexed_vertex_array(
// Share top / bottom vertices if possible.
if (is_first) {
idx_a[TOP] = idx_last++;
- volume.push_geometry(a.x, a.y, top_z , 0., 0., 1.);
+ volume.push_geometry(a(0), a(1), top_z , 0., 0., 1.);
} else {
idx_a[TOP] = idx_prev[TOP];
}
@@ -1058,11 +1052,11 @@ static void thick_lines_to_indexed_vertex_array(
if (is_first || bottom_z_different) {
// Start of the 1st line segment or a change of the layer thickness while maintaining the print_z.
idx_a[BOTTOM] = idx_last ++;
- volume.push_geometry(a.x, a.y, bottom_z, 0., 0., -1.);
+ volume.push_geometry(a(0), a(1), bottom_z, 0., 0., -1.);
idx_a[LEFT ] = idx_last ++;
- volume.push_geometry(a2.x, a2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z);
+ volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), -xy_right_normal(2));
idx_a[RIGHT] = idx_last ++;
- volume.push_geometry(a1.x, a1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z);
+ volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), xy_right_normal(2));
}
else {
idx_a[BOTTOM] = idx_prev[BOTTOM];
@@ -1076,16 +1070,16 @@ static void thick_lines_to_indexed_vertex_array(
} else {
// Continuing a previous segment.
// Share left / right vertices if possible.
- double v_dot = dot(v_prev, v);
+ double v_dot = v_prev.dot(v);
bool sharp = v_dot < 0.707; // sin(45 degrees)
if (sharp) {
if (!bottom_z_different)
{
// Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn.
idx_a[RIGHT] = idx_last++;
- volume.push_geometry(a1.x, a1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z);
+ volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), xy_right_normal(2));
idx_a[LEFT] = idx_last++;
- volume.push_geometry(a2.x, a2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z);
+ volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), -xy_right_normal(2));
}
}
if (v_dot > 0.9) {
@@ -1101,32 +1095,32 @@ static void thick_lines_to_indexed_vertex_array(
{
// Create a sharp corner with an overshot and average the left / right normals.
// At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc.
- Pointf intersection;
+ Vec2d intersection(Vec2d::Zero());
Geometry::ray_ray_intersection(b1_prev, v_prev, a1, v, intersection);
a1 = intersection;
a2 = 2. * a - intersection;
- assert(length(a1.vector_to(a)) < width);
- assert(length(a2.vector_to(a)) < width);
+ assert((a - a1).norm() < width);
+ assert((a - a2).norm() < width);
float *n_left_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT ] * 6;
float *p_left_prev = n_left_prev + 3;
float *n_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6;
float *p_right_prev = n_right_prev + 3;
- p_left_prev [0] = float(a2.x);
- p_left_prev [1] = float(a2.y);
- p_right_prev[0] = float(a1.x);
- p_right_prev[1] = float(a1.y);
- xy_right_normal.x += n_right_prev[0];
- xy_right_normal.y += n_right_prev[1];
- xy_right_normal.scale(1. / length(xy_right_normal));
- n_left_prev [0] = float(-xy_right_normal.x);
- n_left_prev [1] = float(-xy_right_normal.y);
- n_right_prev[0] = float( xy_right_normal.x);
- n_right_prev[1] = float( xy_right_normal.y);
+ p_left_prev [0] = float(a2(0));
+ p_left_prev [1] = float(a2(1));
+ p_right_prev[0] = float(a1(0));
+ p_right_prev[1] = float(a1(1));
+ xy_right_normal(0) += n_right_prev[0];
+ xy_right_normal(1) += n_right_prev[1];
+ xy_right_normal *= 1. / xy_right_normal.norm();
+ n_left_prev [0] = float(-xy_right_normal(0));
+ n_left_prev [1] = float(-xy_right_normal(1));
+ n_right_prev[0] = float( xy_right_normal(0));
+ n_right_prev[1] = float( xy_right_normal(1));
idx_a[LEFT ] = idx_prev[LEFT ];
idx_a[RIGHT] = idx_prev[RIGHT];
}
}
- else if (cross(v_prev, v) > 0.) {
+ else if (cross2(v_prev, v) > 0.) {
// Right turn. Fill in the right turn wedge.
volume.push_triangle(idx_prev[RIGHT], idx_a [RIGHT], idx_prev[TOP] );
volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a [RIGHT] );
@@ -1162,20 +1156,20 @@ static void thick_lines_to_indexed_vertex_array(
idx_b[TOP] = idx_initial[TOP];
} else {
idx_b[TOP] = idx_last ++;
- volume.push_geometry(b.x, b.y, top_z , 0., 0., 1.);
+ volume.push_geometry(b(0), b(1), top_z , 0., 0., 1.);
}
if (is_closing && (width == width_initial) && (bottom_z == bottom_z_initial)) {
idx_b[BOTTOM] = idx_initial[BOTTOM];
} else {
idx_b[BOTTOM] = idx_last ++;
- volume.push_geometry(b.x, b.y, bottom_z, 0., 0., -1.);
+ volume.push_geometry(b(0), b(1), bottom_z, 0., 0., -1.);
}
// Generate new vertices for the end of this line segment.
idx_b[LEFT ] = idx_last ++;
- volume.push_geometry(b2.x, b2.y, middle_z, -xy_right_normal.x, -xy_right_normal.y, -xy_right_normal.z);
+ volume.push_geometry(b2(0), b2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), -xy_right_normal(2));
idx_b[RIGHT ] = idx_last ++;
- volume.push_geometry(b1.x, b1.y, middle_z, xy_right_normal.x, xy_right_normal.y, xy_right_normal.z);
+ volume.push_geometry(b1(0), b1(1), middle_z, xy_right_normal(0), xy_right_normal(1), xy_right_normal(2));
memcpy(idx_prev, idx_b, 4 * sizeof(int));
bottom_z_prev = bottom_z;
@@ -1234,15 +1228,15 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
int idx_initial[4] = { -1, -1, -1, -1 };
int idx_prev[4] = { -1, -1, -1, -1 };
double z_prev = 0.0;
- Vectorf3 n_right_prev;
- Vectorf3 n_top_prev;
- Vectorf3 unit_v_prev;
+ Vec3d n_right_prev = Vec3d::Zero();
+ Vec3d n_top_prev = Vec3d::Zero();
+ Vec3d unit_v_prev = Vec3d::Zero();
double width_initial = 0.0;
// new vertices around the line endpoints
// left, right, top, bottom
- Pointf3 a[4];
- Pointf3 b[4];
+ Vec3d a[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() };
+ Vec3d b[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() };
// loop once more in case of closed loops
size_t lines_end = closed ? (lines.size() + 1) : lines.size();
@@ -1254,29 +1248,29 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
double height = heights[i];
double width = widths[i];
- Vectorf3 unit_v = normalize(Vectorf3::new_unscale(line.vector()));
+ Vec3d unit_v = unscale(line.vector()).normalized();
- Vectorf3 n_top;
- Vectorf3 n_right;
- Vectorf3 unit_positive_z(0.0, 0.0, 1.0);
+ Vec3d n_top = Vec3d::Zero();
+ Vec3d n_right = Vec3d::Zero();
+ Vec3d unit_positive_z(0.0, 0.0, 1.0);
- if ((line.a.x == line.b.x) && (line.a.y == line.b.y))
+ if ((line.a(0) == line.b(0)) && (line.a(1) == line.b(1)))
{
// vertical segment
- n_right = (line.a.z < line.b.z) ? Vectorf3(-1.0, 0.0, 0.0) : Vectorf3(1.0, 0.0, 0.0);
- n_top = Vectorf3(0.0, 1.0, 0.0);
+ n_right = (line.a(2) < line.b(2)) ? Vec3d(-1.0, 0.0, 0.0) : Vec3d(1.0, 0.0, 0.0);
+ n_top = Vec3d(0.0, 1.0, 0.0);
}
else
{
// generic segment
- n_right = normalize(cross(unit_v, unit_positive_z));
- n_top = normalize(cross(n_right, unit_v));
+ n_right = unit_v.cross(unit_positive_z).normalized();
+ n_top = n_right.cross(unit_v).normalized();
}
- Vectorf3 rl_displacement = 0.5 * width * n_right;
- Vectorf3 tb_displacement = 0.5 * height * n_top;
- Pointf3 l_a = Pointf3::new_unscale(line.a);
- Pointf3 l_b = Pointf3::new_unscale(line.b);
+ Vec3d rl_displacement = 0.5 * width * n_right;
+ Vec3d tb_displacement = 0.5 * height * n_top;
+ Vec3d l_a = unscale(line.a);
+ Vec3d l_b = unscale(line.b);
a[RIGHT] = l_a + rl_displacement;
a[LEFT] = l_a - rl_displacement;
@@ -1287,15 +1281,15 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
b[TOP] = l_b + tb_displacement;
b[BOTTOM] = l_b - tb_displacement;
- Vectorf3 n_bottom = -n_top;
- Vectorf3 n_left = -n_right;
+ Vec3d n_bottom = -n_top;
+ Vec3d n_left = -n_right;
int idx_a[4];
int idx_b[4];
int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6);
- bool z_different = (z_prev != l_a.z);
- z_prev = l_b.z;
+ bool z_different = (z_prev != l_a(2));
+ z_prev = l_b(2);
// Share top / bottom vertices if possible.
if (ii == 0)
@@ -1329,9 +1323,9 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
{
// Continuing a previous segment.
// Share left / right vertices if possible.
- double v_dot = dot(unit_v_prev, unit_v);
+ double v_dot = unit_v_prev.dot(unit_v);
bool is_sharp = v_dot < 0.707; // sin(45 degrees)
- bool is_right_turn = dot(n_top_prev, cross(unit_v_prev, unit_v)) > 0.0;
+ bool is_right_turn = n_top_prev.dot(unit_v_prev.cross(unit_v)) > 0.0;
if (is_sharp)
{
@@ -1354,9 +1348,9 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
// At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc.
// averages normals
- Vectorf3 average_n_right = normalize(0.5 * (n_right + n_right_prev));
- Vectorf3 average_n_left = -average_n_right;
- Vectorf3 average_rl_displacement = 0.5 * width * average_n_right;
+ Vec3d average_n_right = 0.5 * (n_right + n_right_prev).normalized();
+ Vec3d average_n_left = -average_n_right;
+ Vec3d average_rl_displacement = 0.5 * width * average_n_right;
// updates vertices around a
a[RIGHT] = l_a + average_rl_displacement;
@@ -1364,25 +1358,25 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
// updates previous line normals
float* normal_left_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT] * 6;
- normal_left_prev[0] = float(average_n_left.x);
- normal_left_prev[1] = float(average_n_left.y);
- normal_left_prev[2] = float(average_n_left.z);
+ normal_left_prev[0] = float(average_n_left(0));
+ normal_left_prev[1] = float(average_n_left(1));
+ normal_left_prev[2] = float(average_n_left(2));
float* normal_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6;
- normal_right_prev[0] = float(average_n_right.x);
- normal_right_prev[1] = float(average_n_right.y);
- normal_right_prev[2] = float(average_n_right.z);
+ normal_right_prev[0] = float(average_n_right(0));
+ normal_right_prev[1] = float(average_n_right(1));
+ normal_right_prev[2] = float(average_n_right(2));
// updates previous line's vertices around b
float* b_left_prev = normal_left_prev + 3;
- b_left_prev[0] = float(a[LEFT].x);
- b_left_prev[1] = float(a[LEFT].y);
- b_left_prev[2] = float(a[LEFT].z);
+ b_left_prev[0] = float(a[LEFT](0));
+ b_left_prev[1] = float(a[LEFT](1));
+ b_left_prev[2] = float(a[LEFT](2));
float* b_right_prev = normal_right_prev + 3;
- b_right_prev[0] = float(a[RIGHT].x);
- b_right_prev[1] = float(a[RIGHT].y);
- b_right_prev[2] = float(a[RIGHT].z);
+ b_right_prev[0] = float(a[RIGHT](0));
+ b_right_prev[1] = float(a[RIGHT](1));
+ b_right_prev[2] = float(a[RIGHT](2));
idx_a[LEFT] = idx_prev[LEFT];
idx_a[RIGHT] = idx_prev[RIGHT];
@@ -1479,14 +1473,14 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
#undef BOTTOM
}
-static void point_to_indexed_vertex_array(const Point3& point,
+static void point_to_indexed_vertex_array(const Vec3crd& point,
double width,
double height,
GLIndexedVertexArray& volume)
{
// builds a double piramid, with vertices on the local axes, around the point
- Pointf3 center = Pointf3::new_unscale(point);
+ Vec3d center = unscale(point);
double scale_factor = 1.0;
double w = scale_factor * width;
@@ -1500,13 +1494,13 @@ static void point_to_indexed_vertex_array(const Point3& point,
idxs[i] = idx_last + i;
}
- Vectorf3 displacement_x(w, 0.0, 0.0);
- Vectorf3 displacement_y(0.0, w, 0.0);
- Vectorf3 displacement_z(0.0, 0.0, h);
+ Vec3d displacement_x(w, 0.0, 0.0);
+ Vec3d displacement_y(0.0, w, 0.0);
+ Vec3d displacement_z(0.0, 0.0, h);
- Vectorf3 unit_x(1.0, 0.0, 0.0);
- Vectorf3 unit_y(0.0, 1.0, 0.0);
- Vectorf3 unit_z(0.0, 0.0, 1.0);
+ Vec3d unit_x(1.0, 0.0, 0.0);
+ Vec3d unit_y(0.0, 1.0, 0.0);
+ Vec3d unit_z(0.0, 0.0, 1.0);
// vertices
volume.push_geometry(center - displacement_x, -unit_x); // idxs[0]
@@ -1549,7 +1543,7 @@ void _3DScene::thick_lines_to_verts(const Lines3& lines,
thick_lines_to_indexed_vertex_array(lines, widths, heights, closed, volume.indexed_vertex_array);
}
-static void thick_point_to_verts(const Point3& point,
+static void thick_point_to_verts(const Vec3crd& point,
double width,
double height,
GLVolume& volume)
@@ -1655,7 +1649,7 @@ void _3DScene::polyline3_to_verts(const Polyline3& polyline, double width, doubl
thick_lines_to_verts(lines, widths, heights, false, volume);
}
-void _3DScene::point3_to_verts(const Point3& point, double width, double height, GLVolume& volume)
+void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume)
{
thick_point_to_verts(point, width, height, volume);
}