The source file containing the main() function:
28#include <easy3d/core/model.h>
29#include <easy3d/renderer/drawable_triangles.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
42int main(
int argc,
char **argv) {
46 const std::string file = resource::directory() +
"/data/room.obj";
49 TutorialSoftShadow viewer(EXAMPLE_TITLE);
51 Model *model = viewer.add_model(file,
true);
53 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
59 drawable->set_smooth_shading(
true);
The base class of renderable 3D models.
Definition: model.h:49
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
TrianglesDrawable * get_triangles_drawable(const std::string &name) const
Definition: renderer.cpp:304
void set_uniform_coloring(const vec4 &color)
Definition: state.cpp:89
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35
The header file of the viewer class:
27#ifndef EASY3D_TUTORIAL_SOFT_SHADOW_H
28#define EASY3D_TUTORIAL_SOFT_SHADOW_H
30#include <easy3d/viewer/viewer.h>
43 explicit TutorialSoftShadow(
const std::string& title =
"");
44 ~TutorialSoftShadow()
override;
47 bool key_press_event(
int key,
int modifiers)
override;
48 void draw()
const override;
Shadow implements the standard shadow map (hard shadow) algorithm.
Definition: shadow.h:50
The built-in Easy3D viewer.
Definition: viewer.h:61
The source file of the viewer class:
28#include <easy3d/core/surface_mesh.h>
29#include <easy3d/renderer/drawable_triangles.h>
30#include <easy3d/renderer/soft_shadow.h>
31#include <easy3d/renderer/camera.h>
32#include <easy3d/renderer/renderer.h>
37TutorialSoftShadow::TutorialSoftShadow(
const std::string& title) :
Viewer(title) {
38 camera()->setUpVector(
vec3(0, 1, 0));
39 camera()->setViewDirection(
vec3(0, 0, 1));
43 shadow_enabled_ =
true;
46 "------------ Soft Shadow usage ------------- \n"
47 "Press key 'space' to toggle Shadowing \n"
48 "-------------------------------------------- \n";
52TutorialSoftShadow::~TutorialSoftShadow() {
60bool TutorialSoftShadow::key_press_event(
int key,
int modifiers) {
61 if (key == KEY_SPACE) {
62 shadow_enabled_ = !shadow_enabled_;
67 return Viewer::key_press_event(key, modifiers);
71void TutorialSoftShadow::draw()
const {
72 if (!current_model()) {
76 std::vector<TrianglesDrawable*> surfaces;
77 for (
auto m : models_) {
78 for (
auto d : m->renderer()->triangles_drawables()) {
79 surfaces.push_back(d);
83 shadow_->draw(surfaces);
An implementation of the Percentage-Closer Soft Shadows.
Definition: soft_shadow.h:70
vec4 background_color
background color of the viewer
Definition: setting.cpp:36