1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 
13 #ifndef CHIRRAPP_H
14 #define CHIRRAPP_H
15 
16 #include "chrono_irrlicht/ChApiIrr.h"
17 #include "chrono_irrlicht/ChIrrAppInterface.h"
18 #include "chrono_irrlicht/ChIrrAssetConverter.h"
19 
20 namespace chrono {
21 namespace irrlicht {
22 
23 /// @addtogroup irrlicht_module
24 /// @{
25 
26 /// Class to add some GUI to Irrlicht+ChronoEngine applications. \n Such basic
27 /// GUI can be used to monitor solver timings, to change physical system
28 /// settings easily, and so on.
29 class ChApiIrr ChIrrApp : public ChIrrAppInterface {
30   public:
31     /// Create the application with Irrlicht context (3D view, device, etc.).
32     ChIrrApp(ChSystem* psystem,
33              const std::wstring& title = L"Chrono",
34              const irr::core::dimension2d<irr::u32>& dimens = irr::core::dimension2d<irr::u32>(640, 480),
35              VerticalDir vert = VerticalDir::Y,
36              bool do_fullscreen = false,
37              bool do_shadows = false,
38              bool do_antialias = true,
39              irr::video::E_DRIVER_TYPE mydriver = irr::video::EDT_DIRECT3D9,
40              irr::ELOG_LEVEL log_level = irr::ELL_INFORMATION);
41 
42     /// Safely delete every Irrlicht item (including the Irrlicht scene nodes).
43     virtual ~ChIrrApp();
44 
45     /// Gets the asset converter
GetAssetConverter()46     ChIrrAssetConverter* GetAssetConverter() { return mconverter; }
47 
48     /// Shortcut to add and bind a ChIrrNodeAsset to an item, if it has not been added previously.
49     void AssetBind(std::shared_ptr<ChPhysicsItem> mitem);
50 
51     /// Shortcut to add and bind a ChIrrNodeAsset to all items in a ChSystem.
52     /// If it has been already added, the existing ChIrrNodeAsset is used.
53     /// NOTE. If you want a finer control on which item has an Irrlicht proxy,
54     /// and which other does not need it, just use Bind(myitem) on a per-item basis.
55     /// NOTE. This conversion should be done only if needed (ex. at the beginning
56     /// of an animation), i.e. not too often, for performance reasons.
57     void AssetBindAll();
58 
59     /// This function sets up the Irrlicht nodes corresponding to the geometric
60     /// assets that are found in the ChPhysicsItem 'mitem'. For example, if one
61     /// has added a ChSphereShape and a ChBoxShape to the assets of a ChBody, and
62     /// a ChIrrNodeAsset too, this Update() function will prepare a ISceneNode in
63     /// Irrlicht (precisely, a ChIrrNode node) and it will fill it with a
64     /// spherical triangle mesh, and a box triangle mesh.
65     /// NOTE. This must be done after the ChIrrNodeAsset has been created and
66     /// bound, for example via Bind().
67     /// NOTE. This conversion should be done only if needed (ex. at the beginning
68     /// of an animation or when a shape changes), i.e. not too often, for
69     /// performance reasons.
70     void AssetUpdate(std::shared_ptr<ChPhysicsItem> mitem);
71 
72     /// For all items in a ChSystem, this function sets up the Irrlicht nodes
73     /// corresponding to the geometric assets that have been added to the items.
74     /// NOTE. This must be done after the ChIrrNodeAsset has been created and
75     /// bound, for example via Bind().
76     /// NOTE. This conversion should be done only if needed (ex. at the beginning
77     /// of an animation), i.e. not too often, for performance reasons.
78     void AssetUpdateAll();
79 
80     /// Shortcut to enable shadow maps for an item. Shadow maps in Irrlicht may
81     /// slow visualization a bit. Also, one must remember to add shadow-enabled
82     /// lights, using myapp.AddLightWithShadow(..)
83     void AddShadow(std::shared_ptr<ChPhysicsItem> mitem);
84 
85     /// Shortcut to enable shadow maps for all items in scene. Shadow maps in
86     /// Irrlicht may slow visualization a bit. Also, one must remember to add
87     /// shadow-enabled lights, using myapp.AddLightWithShadow(..)
88     void AddShadowAll();
89 
90   private:
91     void _recurse_add_shadow(irr::scene::ISceneNode* mnode);
92 
93     ChIrrAssetConverter* mconverter;
94 };
95 
96 /// @} irrlicht_module
97 
98 }  // end namespace irrlicht
99 }  // end namespace chrono
100 
101 #endif
102