Skip to content

Commit

Permalink
explicitly create checker sphere
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Jan 31, 2025
1 parent e991f0a commit 35ac69c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 70 deletions.
1 change: 0 additions & 1 deletion applications/Mapple/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <easy3d/core/poly_mesh.h>
#include <easy3d/core/random.h>
#include <easy3d/core/surface_mesh_builder.h>
#include <easy3d/renderer/camera.h>
#include <easy3d/renderer/renderer.h>
#include <easy3d/renderer/clipping_plane.h>
#include <easy3d/renderer/drawable_lines.h>
Expand Down
20 changes: 11 additions & 9 deletions applications/Mapple/widgets/widget_checker_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ void WidgetCheckerSphere::initializeGL()
func->initializeOpenGLFunctions();
OpenglUtil::init();

createSpheres();

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClearDepth(1.0f);
glClearColor(
static_cast<float>(backgroundColor_.redF()),
static_cast<float>(backgroundColor_.greenF()),
static_cast<float>(backgroundColor_.blueF()),
backgroundColor_.redF(),
backgroundColor_.greenF(),
backgroundColor_.blueF(),
1.0f
);

Expand Down Expand Up @@ -167,8 +169,8 @@ vec3 WidgetCheckerSphere::projectToSphere(const QPoint& p)

void WidgetCheckerSphere::updateLighting() {
setting::light_position = lightPos_;
update();
emit lightPositionChanged();
update();
}


Expand Down Expand Up @@ -203,15 +205,15 @@ void WidgetCheckerSphere::createSpheres() {

void WidgetCheckerSphere::paintGL() {
if (!checkerSphere_)
createSpheres();
return;

ShaderProgram* program = ShaderManager::get_program("surface/surface");
if (!program) {
std::vector<ShaderProgram::Attribute> attributes;
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::POSITION, "vtx_position"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::TEXCOORD, "vtx_texcoord"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::COLOR, "vtx_color"));
attributes.emplace_back(ShaderProgram::Attribute(ShaderProgram::NORMAL, "vtx_normal"));
attributes.emplace_back(ShaderProgram::POSITION, "vtx_position");
attributes.emplace_back(ShaderProgram::TEXCOORD, "vtx_texcoord");
attributes.emplace_back(ShaderProgram::COLOR, "vtx_color");
attributes.emplace_back(ShaderProgram::NORMAL, "vtx_normal");
program = ShaderManager::create_program_from_files("surface/surface", attributes);
}
if (!program)
Expand Down
9 changes: 6 additions & 3 deletions applications/Mapple/widgets/widget_global_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "main_window.h"
#include "paint_canvas.h"
#include "widgets/widget_drawable_triangles.h"
#include "widgets/widget_checker_sphere.h"

#include <ui_widget_global_setting.h>

Expand Down Expand Up @@ -86,11 +87,13 @@ WidgetGlobalSetting::WidgetGlobalSetting(QWidget *parent)
ui_->horizontalSliderShadowDarkness->setValue(setting::effect_shadow_darkness * 100);

//----------------------------------------------

QPalette::ColorRole role = parent->backgroundRole();
const QColor& bc = parent->palette().color(role);
ui_->checkerSphere->setBackgroundColor(bc);
connect(ui_->checkerSphere, SIGNAL(lightPositionChanged()), viewer_, SLOT(update()));
auto checkerSphere = new WidgetCheckerSphere(this);
checkerSphere->setBackgroundColor(bc);
checkerSphere->setFixedSize(120, 120);
connect(checkerSphere, SIGNAL(lightPositionChanged()), viewer_, SLOT(update()));
ui_->horizontalLayoutCheckerSphere->addWidget(checkerSphere);

connect(ui_->checkBoxClippingPlaneEnable, SIGNAL(toggled(bool)), this, SLOT(setEnableClippingPlane(bool)));
connect(ui_->checkBoxClippingPlaneVisible, SIGNAL(toggled(bool)), this, SLOT(setClippingPlaneVisible(bool)));
Expand Down
90 changes: 33 additions & 57 deletions applications/Mapple/widgets/widget_global_setting.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>277</width>
<height>876</height>
<width>276</width>
<height>777</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -18,24 +18,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="WidgetCheckerSphere" name="checkerSphere">
<property name="minimumSize">
<size>
<width>120</width>
<height>120</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>120</height>
</size>
</property>
</widget>
</item>
</layout>
<layout class="QHBoxLayout" name="horizontalLayoutCheckerSphere"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -63,14 +46,14 @@
<number>60</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -129,10 +112,10 @@
<item>
<spacer name="horizontalSpacer_24">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -154,14 +137,14 @@
<item row="17" column="0" colspan="2">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="0" rowspan="2" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -197,7 +180,7 @@
<item>
<widget class="QCheckBox" name="checkBoxGroundPlaneConstraint">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string/>
Expand All @@ -207,10 +190,10 @@
<item>
<spacer name="horizontalSpacer_19">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -278,10 +261,10 @@
<item>
<spacer name="horizontalSpacer_23">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -317,7 +300,7 @@
<number>4000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -377,10 +360,10 @@
<item>
<spacer name="horizontalSpacer_22">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -416,7 +399,7 @@
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -485,7 +468,7 @@
<item>
<widget class="QCheckBox" name="checkBoxGroundPlaneTexture">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string/>
Expand Down Expand Up @@ -514,10 +497,10 @@
<item>
<spacer name="horizontalSpacer_20">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand Down Expand Up @@ -560,7 +543,7 @@
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -591,7 +574,7 @@
<number>150</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -657,7 +640,7 @@
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -684,7 +667,7 @@
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -711,7 +694,7 @@
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -728,7 +711,7 @@
<item>
<widget class="QCheckBox" name="checkBoxGroundPlane">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string/>
Expand Down Expand Up @@ -757,10 +740,10 @@
<item>
<spacer name="horizontalSpacer_21">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
<enum>QSizePolicy::Policy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -775,7 +758,7 @@
<item row="4" column="0" colspan="2">
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -819,7 +802,7 @@
<number>200</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -868,7 +851,7 @@
<number>60</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
Expand All @@ -877,7 +860,7 @@
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -889,13 +872,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>WidgetCheckerSphere</class>
<extends>QOpenGLWidget</extends>
<header>widgets/widget_checker_sphere.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>checkBoxGroundPlane</tabstop>
<tabstop>spinBoxGroundPlaneSize</tabstop>
Expand Down

0 comments on commit 35ac69c

Please sign in to comment.