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>
41int main(
int argc,
char **argv) {
45 const std::string file = resource::directory() +
"/data/room.obj";
48 TutorialHardShadow viewer(EXAMPLE_TITLE);
50 Model *model = viewer.add_model(file,
true);
52 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
58 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_HARD_SHADOW_H
28#define EASY3D_TUTORIAL_HARD_SHADOW_H
30#include <easy3d/viewer/viewer.h>
42 explicit TutorialHardShadow(
const std::string& title =
"");
43 ~TutorialHardShadow()
override;
46 bool key_press_event(
int key,
int modifiers)
override;
47 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/shadow.h>
31#include <easy3d/renderer/camera.h>
32#include <easy3d/renderer/renderer.h>
37TutorialHardShadow::TutorialHardShadow(
const std::string& title) :
Viewer(title) {
38 camera()->setUpVector(
vec3(0, 1, 0));
39 camera()->setViewDirection(
vec3(0, 0, 1));
41 shadow_ =
new Shadow(camera());
43 shadow_enabled_ =
true;
46 "----------------------- Hard Shadow usage ----------------------- \n"
47 "Press key 'space' to switch between Shadowing and normal rendering\n"
48 "----------------------------------------------------------------- \n";
52TutorialHardShadow::~TutorialHardShadow() {
60bool TutorialHardShadow::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 TutorialHardShadow::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);
vec4 background_color
background color of the viewer
Definition: setting.cpp:36