SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneErlebARBielCBB.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneErlebARBielCBB.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \authors Marcus Hudritsch
8  * \copyright http://opensource.org/licenses/GPL-3.0
9  * \remarks Please use clangformat to format the code. See more code style on
10  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
11  */
12 
13 #include "SLVec3.h"
15 #include <CVCapture.h>
16 #include <AppCommon.h>
17 #include <SLAssetLoader.h>
18 #include <SLLightDirect.h>
19 #include <SLCoordAxis.h>
20 
21 // Global pointers declared in AppDemoVideo
23 
24 //-----------------------------------------------------------------------------
26  : SLScene("Biel-CBB AR")
27 {
28  info("Augmented Reality at Biel-CBB");
29 }
30 //-----------------------------------------------------------------------------
31 //! All assets the should be loaded in parallel must be registered in here.
33 {
34  // Create video texture on global pointer updated in AppDemoVideo
36  AppCommon::texturePath + "LiveVideoError.png",
37  GL_LINEAR,
38  GL_LINEAR);
39 
41  AppCommon::dataPath + "erleb-AR/models/biel/Biel-CBB-AR.gltf",
42  nullptr,
43  false,
44  true,
45  nullptr,
46  0.5f);
47 
49  AppCommon::shaderPath + "PerPixTmBackground.vert",
50  AppCommon::shaderPath + "PerPixTmBackground.frag");
51 
52  // Glass shader for reflections on window
54  AppCommon::dataPath + "erleb-AR/models/biel/Sea1+X1024.jpg",
55  AppCommon::dataPath + "erleb-AR/models/biel/Sea1-X1024.jpg",
56  AppCommon::dataPath + "erleb-AR/models/biel/Sea1+Y1024.jpg",
57  AppCommon::dataPath + "erleb-AR/models/biel/Sea1-Y1024.jpg",
58  AppCommon::dataPath + "erleb-AR/models/biel/Sea1+Z1024.jpg",
59  AppCommon::dataPath + "erleb-AR/models/biel/Sea1-Z1024.jpg");
61  AppCommon::shaderPath + "RefractReflect.vert",
62  AppCommon::shaderPath + "RefractReflect.frag");
63 
64  // initialize sensor stuff before loading the geotiff
65  // See also locationMapBiel-CBB.yml
66  AppCommon::devLoc.originLatLonAlt(47.130569, 7.2412200, 432.6); // Origin CBB https://s.geo.admin.ch/hd6yp3mxe2sz
67  AppCommon::devLoc.defaultLatLonAlt(47.130911, 7.241060, 433.0); // Ecke BFB: https://s.geo.admin.ch/q4sl4pv9ptil
68  AppCommon::devLoc.nameLocations().push_back(SLLocation("CBB-Origin",
69  SLVec3d(47.130569, 7.2412200, 432.6))); // https://s.geo.admin.ch/hd6yp3mxe2sz
70  AppCommon::devLoc.nameLocations().push_back(SLLocation("Ecke BFB",
71  SLVec3d(47.130922, 7.241056, 433.1))); // https://s.geo.admin.ch/q4sl4pv9ptil
72  AppCommon::devLoc.nameLocations().push_back(SLLocation("Seite BFB",
73  SLVec3d(47.131012, 7.241140, 433.1))); // https://s.geo.admin.ch/cugzflafv1nj
74  AppCommon::devLoc.nameLocations().push_back(SLLocation("Baum BFB",
75  SLVec3d(47.130964, 7.241163, 433.1))); // https://s.geo.admin.ch/oer6fbzdjahr
76  AppCommon::devLoc.nameLocations().push_back(SLLocation("Aarbergstr.13",
77  SLVec3d(47.129964, 7.240038, 432.7))); // https://s.geo.admin.ch/2iqvhce7nv0a
78  AppCommon::devLoc.nameLocations().push_back(SLLocation("Ecke Dr. Schneiterstr.",
79  SLVec3d(47.129740, 7.240179, 432.7))); // https://s.geo.admin.ch/o0al1e7s1a74
80  AppCommon::devLoc.nameLocations().push_back(SLLocation("Ecke Schule für Gestaltung",
81  SLVec3d(47.129369, 7.242822, 432.1))); // https://s.geo.admin.ch/4n41dnm2jibi
82  AppCommon::devLoc.nameLocations().push_back(SLLocation("SIPBB, 3. Stock, Project Space",
83  SLVec3d(47.130533, 7.240727, 433.1 + 15.8))); // https://s.geo.admin.ch/8rtmbyxy8hbs
84 
85  AppCommon::devLoc.originLatLonAlt(AppCommon::devLoc.nameLocations()[0].posWGS84LatLonAlt);
86  AppCommon::devLoc.activeNamedLocation(1); // This sets the location 1 as defaultENU
87  AppCommon::devLoc.locMaxDistanceM(1000.0f); // Max. Distanz. zum Origin
88  AppCommon::devLoc.improveOrigin(false); // Keine autom. Verbesserung vom Origin
94 }
95 //-----------------------------------------------------------------------------
96 //! After parallel loading of the assets the scene gets assembled in here.
98 {
100 
101  // Create see through video background material without shadow mapping
102  SLMaterial* matVideoBkgd = new SLMaterial(am,
103  "matVideoBkgd",
105  nullptr,
106  nullptr,
107  nullptr,
109  matVideoBkgd->reflectionModel(RM_Custom);
110 
111  // Create see through video background material with shadow mapping
112  SLMaterial* matVideoBkgdSM = new SLMaterial(am,
113  "matVideoBkgdSM",
114  gVideoTexture);
115  matVideoBkgdSM->reflectionModel(RM_Custom);
116  matVideoBkgdSM->ambient(SLCol4f(0.6f, 0.6f, 0.6f));
117  matVideoBkgdSM->getsShadows(true);
118 
119  SLCamera* cam1 = new SLCamera("Camera 1");
120  cam1->translation(0, 2, 0);
121  cam1->lookAt(-10, 2, 0);
122  cam1->clipNear(1);
123  cam1->clipFar(1000);
124  cam1->setInitialState();
127 
128  // Turn on main video
130 
131  // Create directional light for the sunlight
132  SLLightDirect* sunLight = new SLLightDirect(am, this, 5.0f);
133  sunLight->powers(1.0f, 1.0f, 1.0f);
134  sunLight->attenuation(1, 0, 0);
135  sunLight->doSunPowerAdaptation(true);
136  sunLight->createsShadows(true);
137  sunLight->createShadowMap(-100,
138  150,
139  SLVec2f(180, 180),
140  SLVec2i(4096, 4096));
141  sunLight->doSmoothShadows(true);
142  sunLight->castsShadows(false);
143  sunLight->translate(0, 30.5f, 90);
144 
145  // Let the sun be rotated by time and location
148  std::time(nullptr));
149 
150  // Rotate to the true geographic rotation because the model is not ENU aligned
151  // This angle comes from the swisstopo reference image in the blend file
152  _cbb->rotate(-52.77f, 0, 1, 0, TS_parent);
153 
154  // Make city with hard edges and without shadow mapping
155  SLNode* Umgebung = _cbb->findChild<SLNode>("Umgebung");
156  Umgebung->setMeshMat(matVideoBkgdSM, true);
157  Umgebung->setDrawBitsRec(SL_DB_WITHEDGES, true);
158  Umgebung->castsShadows(false);
159 
160  // Set glas material w.
161  SLMaterial* matGlas = new SLMaterial(am,
162  "Glas",
165  100,
166  0.5f,
167  0.25f,
168  1.5f);
169  matGlas->translucency(1000);
170  matGlas->transmissive(SLCol4f::WHITE);
171  matGlas->addTexture(_cubemap);
172  matGlas->program(_spRefr);
173  _cbb->findChild<SLNode>("Fassade_Glas.001")->setMeshMat(matGlas, true);
174  _cbb->findChild<SLNode>("Fassade_Glas.002")->setMeshMat(matGlas, true);
175  _cbb->findChild<SLNode>("Fassade_Glas.003")->setMeshMat(matGlas, true);
176  _cbb->findChild<SLNode>("Fassade_Glas.004")->setMeshMat(matGlas, true);
177  _cbb->findChild<SLNode>("Fassade_Glas.005")->setMeshMat(matGlas, true);
178  _cbb->findChild<SLNode>("Fassade_Glas.006")->setMeshMat(matGlas, true);
179  _cbb->findChild<SLNode>("Fassade_Glas.007")->setMeshMat(matGlas, true);
180  _cbb->findChild<SLNode>("Fassade_Glas.008")->setMeshMat(matGlas, true);
181  _cbb->findChild<SLNode>("Fassade_Glas.009")->setMeshMat(matGlas, true);
182  _cbb->findChild<SLNode>("Fassade_Glas.010")->setMeshMat(matGlas, true);
183  _cbb->findChild<SLNode>("Fassade_Glas.011")->setMeshMat(matGlas, true);
184  _cbb->findChild<SLNode>("Fassade_Glas.012")->setMeshMat(matGlas, true);
185  _cbb->findChild<SLNode>("Fassade_Glas.013")->setMeshMat(matGlas, true);
186 
187  // Add axis object a world origin
188  SLNode* axis = new SLNode(new SLCoordAxis(am), "Axis Node");
189  axis->scale(2);
190  axis->rotate(-90, 1, 0, 0);
191 
192  SLNode* scene = new SLNode("Scene");
193  root3D(scene);
194  scene->addChild(sunLight);
195  scene->addChild(axis);
196  scene->addChild(_cbb);
197  scene->addChild(cam1);
198 
199 #if defined(SL_OS_MACIOS) || defined(SL_OS_ANDROID)
203 #else
204  AppCommon::devLoc.isUsed(false);
205  AppCommon::devRot.isUsed(false);
207  SLVec3f pos_f((SLfloat)pos_d.x, (SLfloat)pos_d.y + 1.7f, (SLfloat)pos_d.z);
208  cam1->translation(pos_f);
209  cam1->focalDist(pos_f.length());
210  cam1->lookAt(0, cam1->translationWS().y, 0);
212 #endif
213 
214  sv->doWaitOnIdle(false); // for constant video feed
215  sv->camera(cam1);
216 }
217 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
SLGLTexture * gVideoTexture
Class declaration for an SLScene inherited class.
@ VT_MAIN
Main camera on all on all all devices.
Definition: CVCapture.h:42
float SLfloat
Definition: SL.h:173
@ LOM_twoFingerY
@ ROM_oneFingerX
#define SL_DB_WITHEDGES
Draw faces with hard edges.
Definition: SLDrawBits.h:30
@ CA_turntableYUp
Orbiting around central object w. turntable rotation around y & right axis.
Definition: SLEnums.h:122
@ CA_deviceRotLocYUp
The device rotation controls the camera rotation and the GPS controls the Camera Translation.
Definition: SLEnums.h:128
@ TS_parent
Definition: SLEnums.h:209
@ RM_Custom
Definition: SLEnums.h:292
@ TT_videoBkgd
Definition: SLGLTexture.h:94
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
SLVec3< double > SLVec3d
Definition: SLVec3.h:323
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
static SLstring dataPath
Path to data directory (it is set platform dependent)
Definition: AppCommon.h:83
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
void videoType(CVVideoType vt)
Setter for video type also sets the active calibration.
Definition: CVCapture.cpp:866
static CVCapture * instance()
Public static instance getter for singleton pattern.
Definition: CVCapture.h:65
void addProgramToLoad(SLGLProgram *&program, const SLstring &vertShaderFile, const SLstring &fragShaderFile)
Add generic GLSL program with shader files to load.
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.
void addNodeToLoad(SLNode *&node, const SLstring &modelPath, SLSkybox *skybox=nullptr, SLbool deleteTexImgAfterBuild=false, SLbool loadMeshesOnly=true, SLMaterial *overrideMat=nullptr, float ambientFactor=0.5f, SLbool forceCookTorranceRM=false, SLuint flags=SLProcess_Triangulate|SLProcess_JoinIdenticalVertices|SLProcess_RemoveRedundantMaterials|SLProcess_FindDegenerates|SLProcess_FindInvalidData|SLProcess_SplitLargeMeshes)
Add mesh from file to load via assimp loader.
Toplevel holder of the assets meshes, materials, textures and shaders.
void texture(SLGLTexture *backgroundTexture, bool fixAspectRatio=false)
If flag _repeatBlurred is true the texture is not distorted if its size does not fit to screen aspect...
Active or visible camera node class.
Definition: SLCamera.h:54
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
void clipNear(const SLfloat cNear)
Definition: SLCamera.h:108
void devRotLoc(SLDeviceRotation *devRot, SLDeviceLocation *devLoc)
Definition: SLCamera.h:120
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
void camAnim(SLCamAnim ca)
Definition: SLCamera.h:103
Axis aligned coordinate axis mesh.
Definition: SLCoordAxis.h:31
void defaultLatLonAlt(int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
Default coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds.
void useOriginAltitude(SLbool useGLA)
void improveOrigin(SLbool impO)
void originLatLonAlt(int degreesLat, int minutesLat, double secondsLat, int degreesLon, int minutesLon, double secondsLon, double altitudeM)
Origin coordinate setter in WGS84 Lat-Lon in degrees, minutes and seconds.
SLbool calculateSolarAngles(SLVec3d locationLatLonAlt, std::time_t time)
Calculates the solar angles at origin at local time.
SLVec3d defaultENU() const
void activeNamedLocation(SLint locIndex)
void sunLightNode(SLLightDirect *sln)
void isUsed(SLbool isUsed)
Setter that turns on the device rotation sensor.
SLVec3d originENU() const
SLVLocation & nameLocations()
void locMaxDistanceM(SLfloat maxDist)
void offsetMode(SLLocOffsetMode lom)
void hasOrigin(SLbool hasOL)
void offsetMode(SLRotOffsetMode rom)
void zeroYawAtStart(SLbool zeroYaw)
void isUsed(SLbool isUsed)
Setter that turns on the device rotation sensor.
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
void texType(SLTextureType bt)
Definition: SLGLTexture.h:200
SLLightDirect class for a directional light source.
Definition: SLLightDirect.h:40
void createShadowMap(float clipNear=0.1f, float clipFar=20.0f, SLVec2f size=SLVec2f(8, 8), SLVec2i texSize=SLVec2i(1024, 1024)) override
void doSunPowerAdaptation(SLbool enabled)
Definition: SLLightDirect.h:82
void createsShadows(SLbool createsShadows)
Definition: SLLight.cpp:98
void doSmoothShadows(SLbool doSS)
Definition: SLLight.h:126
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
void powers(SLfloat ambiPow, SLfloat diffPow, SLfloat specPow, const SLCol4f &ambiDiffSpecCol=SLCol4f::WHITE)
Sets the ambient, diffuse and specular powers all with the same color.
Definition: SLLight.h:74
class for a named location with lat-lon-Alt WGS84 position
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
void translucency(SLfloat transl)
Definition: SLMaterial.h:176
void reflectionModel(SLReflectionModel rm)
Definition: SLMaterial.h:169
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348
void ambient(const SLCol4f &ambi)
Definition: SLMaterial.h:170
void transmissive(const SLCol4f &transm)
Definition: SLMaterial.h:175
void program(SLGLProgram *sp)
Definition: SLMaterial.h:205
void getsShadows(SLbool receivesShadows)
Definition: SLMaterial.h:204
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:148
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void rotate(const SLQuat4f &rot, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:945
void scale(SLfloat s)
Definition: SLNode.h:641
void castsShadows(SLbool castsShadows)
Definition: SLNode.h:283
SLVec3f translationWS() const
Definition: SLNode.h:532
T * findChild(const SLstring &name="", SLbool findRecursive=true)
Definition: SLNode.h:389
void setMeshMat(SLMaterial *mat, bool recursive)
Set the mesh material recursively.
Definition: SLNode.cpp:1172
void setInitialState()
Definition: SLNode.cpp:1084
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:653
void setDrawBitsRec(SLuint bit, SLbool state)
Definition: SLNode.cpp:804
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLstring & info()
Definition: SLScene.h:102
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149
T y
Definition: SLVec3.h:43
T x
Definition: SLVec3.h:43
T length() const
Definition: SLVec3.h:122
T z
Definition: SLVec3.h:43
static SLVec4 BLACK
Definition: SLVec4.h:213
static SLVec4 WHITE
Definition: SLVec4.h:215