3DScene axes moved to c++

This commit is contained in:
Enrico Turri 2018-05-18 13:02:47 +02:00
parent 1e0a8de5b1
commit 5fc8fdee11
10 changed files with 244 additions and 94 deletions

View file

@ -1782,17 +1782,6 @@ void _3DScene::set_auto_bed_shape(wxGLCanvas* canvas)
return s_canvas_mgr.set_auto_bed_shape(canvas);
}
Pointf _3DScene::get_bed_origin(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_bed_origin(canvas);
}
void _3DScene::set_bed_origin(wxGLCanvas* canvas, const Pointf* origin)
{
if (origin != nullptr)
s_canvas_mgr.set_bed_origin(canvas, *origin);
}
BoundingBoxf3 _3DScene::get_bed_bounding_box(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_bed_bounding_box(canvas);
@ -1808,6 +1797,27 @@ BoundingBoxf3 _3DScene::get_max_bounding_box(wxGLCanvas* canvas)
return s_canvas_mgr.get_max_bounding_box(canvas);
}
Pointf3 _3DScene::get_axes_origin(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_axes_origin(canvas);
}
void _3DScene::set_axes_origin(wxGLCanvas* canvas, const Pointf3* origin)
{
if (origin != nullptr)
s_canvas_mgr.set_axes_origin(canvas, *origin);
}
float _3DScene::get_axes_length(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_axes_length(canvas);
}
void _3DScene::set_axes_length(wxGLCanvas* canvas, float length)
{
s_canvas_mgr.set_axes_length(canvas, length);
}
void _3DScene::set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons)
{
return s_canvas_mgr.set_cutting_plane(canvas, z, polygons);
@ -1898,6 +1908,11 @@ void _3DScene::render_bed(wxGLCanvas* canvas)
s_canvas_mgr.render_bed(canvas);
}
void _3DScene::render_axes(wxGLCanvas* canvas)
{
s_canvas_mgr.render_axes(canvas);
}
void _3DScene::render_cutting_plane(wxGLCanvas* canvas)
{
s_canvas_mgr.render_cutting_plane(canvas);

View file

@ -555,13 +555,16 @@ public:
static void set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape);
static void set_auto_bed_shape(wxGLCanvas* canvas);
static Pointf get_bed_origin(wxGLCanvas* canvas);
static void set_bed_origin(wxGLCanvas* canvas, const Pointf* origin);
static BoundingBoxf3 get_bed_bounding_box(wxGLCanvas* canvas);
static BoundingBoxf3 get_volumes_bounding_box(wxGLCanvas* canvas);
static BoundingBoxf3 get_max_bounding_box(wxGLCanvas* canvas);
static Pointf3 get_axes_origin(wxGLCanvas* canvas);
static void set_axes_origin(wxGLCanvas* canvas, const Pointf3* origin);
static float get_axes_length(wxGLCanvas* canvas);
static void set_axes_length(wxGLCanvas* canvas, float length);
static void set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons);
static unsigned int get_camera_type(wxGLCanvas* canvas);
@ -588,6 +591,7 @@ public:
static void select_view(wxGLCanvas* canvas, const std::string& direction);
static void render_bed(wxGLCanvas* canvas);
static void render_axes(wxGLCanvas* canvas);
static void render_cutting_plane(wxGLCanvas* canvas);
static void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);

View file

@ -196,8 +196,6 @@ void GLCanvas3D::Bed::set_shape(const Pointfs& shape)
_calc_gridlines(poly, bed_bbox);
m_polygon = offset_ex(poly.contour, bed_bbox.radius() * 1.7, jtRound, scale_(0.5))[0].contour;
set_origin(Pointf(0.0, 0.0));
}
const BoundingBoxf3& GLCanvas3D::Bed::get_bounding_box() const
@ -205,16 +203,6 @@ const BoundingBoxf3& GLCanvas3D::Bed::get_bounding_box() const
return m_bounding_box;
}
const Pointf& GLCanvas3D::Bed::get_origin() const
{
return m_origin;
}
void GLCanvas3D::Bed::set_origin(const Pointf& origin)
{
m_origin = origin;
}
void GLCanvas3D::Bed::render()
{
unsigned int triangles_vcount = m_triangles.get_data_size() / 3;
@ -297,6 +285,56 @@ void GLCanvas3D::Bed::_calc_gridlines(const ExPolygon& poly, const BoundingBox&
printf("Unable to create bed grid lines\n");
}
GLCanvas3D::Axes::Axes()
: m_length(0.0f)
{
}
const Pointf3& GLCanvas3D::Axes::get_origin() const
{
return m_origin;
}
void GLCanvas3D::Axes::set_origin(const Pointf3& origin)
{
m_origin = origin;
}
float GLCanvas3D::Axes::get_length() const
{
return m_length;
}
void GLCanvas3D::Axes::set_length(float length)
{
m_length = length;
}
void GLCanvas3D::Axes::render()
{
// disable depth testing so that axes are not covered by ground
::glDisable(GL_DEPTH_TEST);
::glLineWidth(2.0f);
::glBegin(GL_LINES);
// draw line for x axis
::glColor3f(1.0f, 0.0f, 0.0f);
::glVertex3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z);
::glVertex3f((float)m_origin.x + m_length, (float)m_origin.y, (float)m_origin.z);
// draw line for y axis
::glColor3f(0.0f, 1.0f, 0.0f);
::glVertex3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z);
::glVertex3f((float)m_origin.x, (float)m_origin.y + m_length, (float)m_origin.z);
::glEnd();
// draw line for Z axis
// (re-enable depth test so that axis is correctly shown when objects are behind it)
::glEnable(GL_DEPTH_TEST);
::glBegin(GL_LINES);
::glColor3f(0.0f, 0.0f, 1.0f);
::glVertex3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z);
::glVertex3f((float)m_origin.x, (float)m_origin.y, (float)m_origin.z + m_length);
::glEnd();
}
GLCanvas3D::CuttingPlane::CuttingPlane()
: m_z(-1.0f)
{
@ -472,6 +510,10 @@ void GLCanvas3D::set_volumes(GLVolumeCollection* volumes)
void GLCanvas3D::set_bed_shape(const Pointfs& shape)
{
m_bed.set_shape(shape);
// Set the origin and size for painting of the coordinate system axes.
set_axes_origin(Pointf3(0.0, 0.0, (coordf_t)GROUND_Z));
set_axes_length(0.3f * (float)bed_bounding_box().max_size());
}
void GLCanvas3D::set_auto_bed_shape()
@ -491,17 +533,27 @@ void GLCanvas3D::set_auto_bed_shape()
set_bed_shape(bed_shape);
// Set the origin for painting of the coordinate system axes.
set_bed_origin(Pointf(center.x, center.y));
set_axes_origin(Pointf3(center.x, center.y, (coordf_t)GROUND_Z));
}
const Pointf& GLCanvas3D::get_bed_origin() const
const Pointf3& GLCanvas3D::get_axes_origin() const
{
return m_bed.get_origin();
return m_axes.get_origin();
}
void GLCanvas3D::set_bed_origin(const Pointf& origin)
void GLCanvas3D::set_axes_origin(const Pointf3& origin)
{
m_bed.set_origin(origin);
m_axes.set_origin(origin);
}
float GLCanvas3D::get_axes_length() const
{
return m_axes.get_length();
}
void GLCanvas3D::set_axes_length(float length)
{
return m_axes.set_length(length);
}
void GLCanvas3D::set_cutting_plane(float z, const ExPolygons& polygons)
@ -645,9 +697,16 @@ void GLCanvas3D::select_view(const std::string& direction)
void GLCanvas3D::render_bed()
{
::glDisable(GL_LIGHTING);
m_bed.render();
}
void GLCanvas3D::render_axes()
{
::glDisable(GL_LIGHTING);
m_axes.render();
}
void GLCanvas3D::render_cutting_plane()
{
m_cutting_plane.render_plane(volumes_bounding_box());

View file

@ -79,7 +79,6 @@ public:
{
Pointfs m_shape;
BoundingBoxf3 m_bounding_box;
Pointf m_origin;
Polygon m_polygon;
GeometryBuffer m_triangles;
GeometryBuffer m_gridlines;
@ -90,9 +89,6 @@ public:
const BoundingBoxf3& get_bounding_box() const;
const Pointf& get_origin() const;
void set_origin(const Pointf& origin);
void render();
private:
@ -101,6 +97,23 @@ public:
void _calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox);
};
class Axes
{
Pointf3 m_origin;
float m_length;
public:
Axes();
const Pointf3& get_origin() const;
void set_origin(const Pointf3& origin);
float get_length() const;
void set_length(float length);
void render();
};
class CuttingPlane
{
float m_z;
@ -120,6 +133,7 @@ private:
wxGLContext* m_context;
Camera m_camera;
Bed m_bed;
Axes m_axes;
CuttingPlane m_cutting_plane;
GLVolumeCollection* m_volumes;
@ -153,8 +167,11 @@ public:
// Used by ObjectCutDialog and ObjectPartsPanel to generate a rectangular ground plane to support the scene objects.
void set_auto_bed_shape();
const Pointf& get_bed_origin() const;
void set_bed_origin(const Pointf& origin);
const Pointf3& get_axes_origin() const;
void set_axes_origin(const Pointf3& origin);
float get_axes_length() const;
void set_axes_length(float length);
void set_cutting_plane(float z, const ExPolygons& polygons);
@ -186,6 +203,7 @@ public:
void select_view(const std::string& direction);
void render_bed();
void render_axes();
void render_cutting_plane();
void register_on_viewport_changed_callback(void* callback);

View file

@ -201,19 +201,6 @@ void GLCanvas3DManager::set_auto_bed_shape(wxGLCanvas* canvas)
it->second->set_auto_bed_shape();
}
Pointf GLCanvas3DManager::get_bed_origin(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->get_bed_origin() : Pointf();
}
void GLCanvas3DManager::set_bed_origin(wxGLCanvas* canvas, const Pointf& origin)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_bed_origin(origin);
}
BoundingBoxf3 GLCanvas3DManager::get_bed_bounding_box(wxGLCanvas* canvas)
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
@ -232,6 +219,32 @@ BoundingBoxf3 GLCanvas3DManager::get_max_bounding_box(wxGLCanvas* canvas)
return (it != m_canvases.end()) ? it->second->max_bounding_box() : BoundingBoxf3();
}
Pointf3 GLCanvas3DManager::get_axes_origin(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->get_axes_origin() : Pointf3();
}
void GLCanvas3DManager::set_axes_origin(wxGLCanvas* canvas, const Pointf3& origin)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_axes_origin(origin);
}
float GLCanvas3DManager::get_axes_length(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second->get_axes_length() : 0.0f;
}
void GLCanvas3DManager::set_axes_length(wxGLCanvas* canvas, float length)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_axes_length(length);
}
void GLCanvas3DManager::set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons)
{
CanvasesMap::iterator it = _get_canvas(canvas);
@ -357,6 +370,13 @@ void GLCanvas3DManager::render_bed(wxGLCanvas* canvas)
it->second->render_bed();
}
void GLCanvas3DManager::render_axes(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->render_axes();
}
void GLCanvas3DManager::render_cutting_plane(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);

View file

@ -65,13 +65,16 @@ public:
void set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape);
void set_auto_bed_shape(wxGLCanvas* canvas);
Pointf get_bed_origin(wxGLCanvas* canvas) const;
void set_bed_origin(wxGLCanvas* canvas, const Pointf& origin);
BoundingBoxf3 get_bed_bounding_box(wxGLCanvas* canvas);
BoundingBoxf3 get_volumes_bounding_box(wxGLCanvas* canvas);
BoundingBoxf3 get_max_bounding_box(wxGLCanvas* canvas);
Pointf3 get_axes_origin(wxGLCanvas* canvas) const;
void set_axes_origin(wxGLCanvas* canvas, const Pointf3& origin);
float get_axes_length(wxGLCanvas* canvas) const;
void set_axes_length(wxGLCanvas* canvas, float length);
void set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons);
unsigned int get_camera_type(wxGLCanvas* canvas) const;
@ -98,6 +101,7 @@ public:
void select_view(wxGLCanvas* canvas, const std::string& direction);
void render_bed(wxGLCanvas* canvas);
void render_axes(wxGLCanvas* canvas);
void render_cutting_plane(wxGLCanvas* canvas);
void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);