SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneRevolver Class Reference

Class for revolver mesh scene. More...

#include <AppDemoSceneRevolver.h>

Inheritance diagram for AppDemoSceneRevolver:
[legend]

Public Member Functions

 AppDemoSceneRevolver ()
 
void registerAssetsToLoad (SLAssetLoader &al) override
 All scene specific assets have to be registered for async loading in here. More...
 
void assemble (SLAssetManager *am, SLSceneView *sv) override
 After parallel loading of the assets the scene gets assembled in here. More...
 
- Public Member Functions inherited from SLScene
 SLScene (const SLstring &name)
 
 ~SLScene () override
 
void initOculus (SLstring shaderDir)
 
void root3D (SLNode *root3D)
 
void root2D (SLNode *root2D)
 
void skybox (SLSkybox *skybox)
 
void stopAnimations (SLbool stop)
 
void info (SLstring i)
 
void loadTimeMS (SLfloat loadTimeMS)
 
SLAnimManageranimManager ()
 
SLAssetManagerassetManager ()
 
SLNoderoot3D ()
 
SLNoderoot2D ()
 
SLSkyboxskybox ()
 
SLstringinfo ()
 
SLfloat elapsedTimeMS () const
 
SLfloat elapsedTimeSec () const
 
SLVEventHandlereventHandlers ()
 
SLfloat loadTimeMS () const
 
SLVLightlights ()
 
SLfloat fps () const
 
AvgFloatframeTimesMS ()
 
AvgFloatupdateTimesMS ()
 
AvgFloatupdateAnimTimesMS ()
 
AvgFloatupdateAABBTimesMS ()
 
AvgFloatupdateDODTimesMS ()
 
SLNodesingleNodeSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLMeshsingleMeshFullSelected ()
 Returns the node if only one is selected. See also SLMesh::selectNodeMesh. More...
 
SLVNodeselectedNodes ()
 
SLVMeshselectedMeshes ()
 
SLbool stopAnimations () const
 
SLint numSceneCameras ()
 Returns the number of camera nodes in the scene. More...
 
SLCameranextCameraInScene (SLCamera *activeSVCam)
 Returns the next camera in the scene if there is one. More...
 
bool onUpdate (bool renderTypeIsRT, bool voxelsAreShown, bool forceCPUSkinning)
 Updates animations and AABBs. More...
 
void init (SLAssetManager *am)
 
virtual void unInit ()
 
void selectNodeMesh (SLNode *nodeToSelect, SLMesh *meshToSelect)
 Handles the full mesh selection from double-clicks. More...
 
void deselectAllNodesAndMeshes ()
 Deselects all nodes and its meshes. More...
 
SLGLOculusoculus ()
 
- Public Member Functions inherited from SLObject
 SLObject (const SLstring &Name="", const SLstring &url="")
 
virtual ~SLObject ()
 
void name (const SLstring &Name)
 
void url (const SLstring &url)
 
const SLstringname () const
 
const SLstringurl () const
 

Private Attributes

SLGLTexture_tex1C
 
SLGLTexture_tex1N
 
SLGLTexture_tex2
 
SLGLTexture_tex3
 
SLGLTexture_tex4
 
SLGLTexture_tex5
 
SLGLProgram_sp1
 

Additional Inherited Members

- Protected Attributes inherited from SLScene
SLVLight _lights
 Vector of all lights. More...
 
SLVEventHandler _eventHandlers
 Vector of all event handler. More...
 
SLAnimManager _animManager
 Animation manager instance. More...
 
SLAssetManager_assetManager
 Pointer to the external assetManager. More...
 
SLNode_root3D
 Root node for 3D scene. More...
 
SLNode_root2D
 Root node for 2D scene displayed in ortho projection. More...
 
SLSkybox_skybox
 pointer to skybox More...
 
SLstring _info
 scene info string More...
 
SLVNode _selectedNodes
 Vector of selected nodes. See SLMesh::selectNodeMesh. More...
 
SLVMesh _selectedMeshes
 Vector of selected meshes. See SLMesh::selectNodeMesh. More...
 
SLfloat _loadTimeMS
 time to load scene in ms More...
 
SLfloat _frameTimeMS
 Last frame time in ms. More...
 
SLfloat _lastUpdateTimeMS
 Last time after update in ms. More...
 
SLfloat _fps
 Averaged no. of frames per second. More...
 
AvgFloat _frameTimesMS
 Averaged total time per frame in ms. More...
 
AvgFloat _updateTimesMS
 Averaged time for update in ms. More...
 
AvgFloat _updateAABBTimesMS
 Averaged time for update the nodes AABB in ms. More...
 
AvgFloat _updateAnimTimesMS
 Averaged time for update the animations in ms. More...
 
AvgFloat _updateDODTimesMS
 Averaged time for update the SLEntities graph. More...
 
SLbool _stopAnimations
 Global flag for stopping all animations. More...
 
std::unique_ptr< SLGLOculus_oculus
 Oculus Rift interface. More...
 
- Protected Attributes inherited from SLObject
SLstring _name
 name of an object More...
 
SLstring _url
 uniform resource locator More...
 

Detailed Description

Class for revolver mesh scene.

Definition at line 20 of file AppDemoSceneRevolver.h.

Constructor & Destructor Documentation

◆ AppDemoSceneRevolver()

AppDemoSceneRevolver::AppDemoSceneRevolver ( )

Definition at line 24 of file AppDemoSceneRevolver.cpp.

24  : SLScene("Revolving Mesh Test")
25 {
26  info("Examples of revolving mesh objects constructed by rotating a 2D curve. "
27  "The glass shader reflects and refracts the environment map. "
28  "Try ray tracing with key R and come back with the ESC key.");
29 }
SLScene(const SLstring &name)
Definition: SLScene.cpp:39
SLstring & info()
Definition: SLScene.h:102

Member Function Documentation

◆ assemble()

void AppDemoSceneRevolver::assemble ( SLAssetManager am,
SLSceneView sv 
)
overridevirtual

After parallel loading of the assets the scene gets assembled in here.

Remarks
All scene-specific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread. It is important that all object instantiations within SLScene::assemble do NOT call any OpenGL functions (gl*) because they happen in a parallel thread. All objects that get rendered have to do their initialization when they are used the first time during rendering in the main thread.

Reimplemented from SLScene.

Definition at line 62 of file AppDemoSceneRevolver.cpp.

63 {
64  // Test map material
65  SLMaterial* mat1 = new SLMaterial(am, "mat1", _tex1C, _tex1N);
66 
67  // floor material
68  SLMaterial* mat2 = new SLMaterial(am, "mat2", _tex2);
69  mat2->specular(SLCol4f::BLACK);
70 
71  // Back wall material
72  SLMaterial* mat3 = new SLMaterial(am, "mat3", _tex3);
73  mat3->specular(SLCol4f::BLACK);
74 
75  // Left wall material
76  SLMaterial* mat4 = new SLMaterial(am, "mat4", _tex4);
77  mat4->specular(SLCol4f::BLACK);
78 
79  // Glass material
80  SLMaterial* mat5 = new SLMaterial(am,
81  "glass",
84  255,
85  0.1f,
86  0.9f,
87  1.5f);
88  mat5->addTexture(_tex5);
89  mat5->program(_sp1);
90 
91  // Wine material
92  SLMaterial* mat6 = new SLMaterial(am,
93  "wine",
94  SLCol4f(0.4f, 0.0f, 0.2f),
96  255,
97  0.2f,
98  0.7f,
99  1.3f);
100  mat6->addTexture(_tex5);
101  mat6->program(_sp1);
102 
103  // camera
104  SLCamera* cam1 = new SLCamera();
105  cam1->name("cam1");
106  cam1->translation(0, 1, 17);
107  cam1->lookAt(0, 1, 0);
108  cam1->focalDist(17);
109  cam1->background().colors(SLCol4f(0.7f, 0.7f, 0.7f),
110  SLCol4f(0.2f, 0.2f, 0.2f));
111  cam1->setInitialState();
113 
114  // light
115  SLLightSpot* light1 = new SLLightSpot(am,
116  this,
117  0,
118  4,
119  0,
120  0.3f);
121  light1->powers(0.2f, 1.0f, 1.0f);
122  light1->attenuation(1, 0, 0);
123  SLAnimation* anim = this->animManager().createNodeAnimation("light1_anim", 4.0f);
124  anim->createNodeAnimTrackForEllipse(light1,
125  6.0f,
126  A_z,
127  6.0f,
128  A_x);
129 
130  // glass 2D polygon definition for revolution
131  SLVVec3f revG;
132  revG.push_back(SLVec3f(0.00f, 0.00f)); // foot
133  revG.push_back(SLVec3f(2.00f, 0.00f));
134  revG.push_back(SLVec3f(2.00f, 0.00f));
135  revG.push_back(SLVec3f(2.00f, 0.10f));
136  revG.push_back(SLVec3f(1.95f, 0.15f));
137  revG.push_back(SLVec3f(0.40f, 0.50f)); // stand
138  revG.push_back(SLVec3f(0.25f, 0.60f));
139  revG.push_back(SLVec3f(0.20f, 0.70f));
140  revG.push_back(SLVec3f(0.30f, 3.00f));
141  revG.push_back(SLVec3f(0.30f, 3.00f)); // crack
142  revG.push_back(SLVec3f(0.20f, 3.10f));
143  revG.push_back(SLVec3f(0.20f, 3.10f));
144  revG.push_back(SLVec3f(1.20f, 3.90f)); // outer cup
145  revG.push_back(SLVec3f(1.60f, 4.30f));
146  revG.push_back(SLVec3f(1.95f, 4.80f));
147  revG.push_back(SLVec3f(2.15f, 5.40f));
148  revG.push_back(SLVec3f(2.20f, 6.20f));
149  revG.push_back(SLVec3f(2.10f, 7.10f));
150  revG.push_back(SLVec3f(2.05f, 7.15f));
151  revG.push_back(SLVec3f(2.00f, 7.10f)); // inner cup
152  revG.push_back(SLVec3f(2.05f, 6.00f));
153  SLuint res = 30;
154  SLNode* glass = new SLNode(new SLRevolver(am,
155  revG,
156  SLVec3f(0, 1, 0),
157  res,
158  true,
159  false,
160  "GlassRev",
161  mat5));
162  glass->translate(0.0f, -3.5f, 0.0f, TS_object);
163 
164  // wine 2D polyline definition for revolution with two sided material
165  SLVVec3f revW;
166  revW.push_back(SLVec3f(0.00f, 3.82f));
167  revW.push_back(SLVec3f(0.20f, 3.80f));
168  revW.push_back(SLVec3f(0.80f, 4.00f));
169  revW.push_back(SLVec3f(1.30f, 4.30f));
170  revW.push_back(SLVec3f(1.70f, 4.80f));
171  revW.push_back(SLVec3f(1.95f, 5.40f));
172  revW.push_back(SLVec3f(2.05f, 6.00f));
173  SLMesh* wineMesh = new SLRevolver(am, revW, SLVec3f(0, 1, 0), res, true, false, "WineRev", mat6);
174  wineMesh->matOut(mat5);
175  SLNode* wine = new SLNode(wineMesh);
176  wine->translate(0.0f, -3.5f, 0.0f, TS_object);
177 
178  // wine fluid top
179  SLNode* wineTop = new SLNode(new SLDisk(am, 2.05f, -SLVec3f::AXISY, res, false, "WineRevTop", mat6));
180  wineTop->translate(0.0f, 2.5f, 0.0f, TS_object);
181 
182  // Other revolver objects
183  SLNode* sphere = new SLNode(new SLSphere(am, 1, 16, 16, "sphere", mat1));
184  sphere->translate(3, 0, 0, TS_object);
185  SLNode* cylinder = new SLNode(new SLCylinder(am, 0.1f, 7, 3, 16, true, true, "cylinder", mat1));
186  cylinder->translate(0, 0.5f, 0);
187  cylinder->rotate(90, -1, 0, 0);
188  cylinder->rotate(30, 0, 1, 0);
189  SLNode* cone = new SLNode(new SLCone(am, 1, 3, 3, 16, true, "cone", mat1));
190  cone->translate(-3, -1, 0, TS_object);
191  cone->rotate(90, -1, 0, 0);
192 
193  // Cube dimensions
194  SLfloat pL = -9.0f, pR = 9.0f; // left/right
195  SLfloat pB = -3.5f, pT = 14.5f; // bottom/top
196  SLfloat pN = 9.0f, pF = -9.0f; // near/far
197 
198  // bottom rectangle
199  SLNode* b = new SLNode(new SLRectangle(am, SLVec2f(pL, -pN), SLVec2f(pR, -pF), 10, 10, "PolygonFloor", mat2));
200  b->rotate(90, -1, 0, 0);
201  b->translate(0, 0, pB, TS_object);
202 
203  // top rectangle
204  SLNode* t = new SLNode(new SLRectangle(am, SLVec2f(pL, pF), SLVec2f(pR, pN), 10, 10, "top", mat2));
205  t->rotate(90, 1, 0, 0);
206  t->translate(0, 0, -pT, TS_object);
207 
208  // far rectangle
209  SLNode* f = new SLNode(new SLRectangle(am, SLVec2f(pL, pB), SLVec2f(pR, pT), 10, 10, "far", mat3));
210  f->translate(0, 0, pF, TS_object);
211 
212  // left rectangle
213  SLNode* l = new SLNode(new SLRectangle(am, SLVec2f(-pN, pB), SLVec2f(-pF, pT), 10, 10, "left", mat4));
214  l->rotate(90, 0, 1, 0);
215  l->translate(0, 0, pL, TS_object);
216 
217  // right rectangle
218  SLNode* r = new SLNode(new SLRectangle(am, SLVec2f(pF, pB), SLVec2f(pN, pT), 10, 10, "right", mat4));
219  r->rotate(90, 0, -1, 0);
220  r->translate(0, 0, -pR, TS_object);
221 
222  SLNode* scene = new SLNode;
223  this->root3D(scene);
224  scene->addChild(light1);
225  scene->addChild(glass);
226  scene->addChild(wine);
227  scene->addChild(wineTop);
228  scene->addChild(sphere);
229  scene->addChild(cylinder);
230  scene->addChild(cone);
231  scene->addChild(b);
232  scene->addChild(f);
233  scene->addChild(t);
234  scene->addChild(l);
235  scene->addChild(r);
236  scene->addChild(cam1);
237 
238  sv->camera(cam1);
239 }
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
@ A_z
Definition: SLEnums.h:82
@ A_x
Definition: SLEnums.h:80
@ TS_object
Definition: SLEnums.h:210
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
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
SLAnimation * createNodeAnimation(SLfloat duration)
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
SLNodeAnimTrack * createNodeAnimTrackForEllipse(SLNode *target, SLfloat radiusA, SLAxis axisA, SLfloat radiusB, SLAxis axisB)
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
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
SLCone creates a cone mesh based on SLRevolver.
Definition: SLCone.h:27
SLCylinder is creates sphere mesh based on its SLRevolver methods.
Definition: SLCylinder.h:27
SLDisk creates a disk mesh based on SLRevolver.
Definition: SLDisk.h:27
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
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
void specular(const SLCol4f &spec)
Definition: SLMaterial.h:173
void addTexture(SLGLTexture *texture)
Adds the passed texture to the equivalent texture type vector.
Definition: SLMaterial.cpp:348
void program(SLGLProgram *sp)
Definition: SLMaterial.h:205
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLMaterial * matOut() const
Definition: SLMesh.h:178
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
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 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:652
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
void name(const SLstring &Name)
Definition: SLObject.h:34
SLRectangle creates a rectangular mesh with a certain resolution.
Definition: SLRectangle.h:29
SLRevolver is an SLMesh object built out of revolving points.
Definition: SLRevolver.h:38
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLAnimManager & animManager()
Definition: SLScene.h:97
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
static SLVec3 AXISY
Definition: SLVec3.h:298
static SLVec4 BLACK
Definition: SLVec4.h:213
static SLVec4 WHITE
Definition: SLVec4.h:215

◆ registerAssetsToLoad()

void AppDemoSceneRevolver::registerAssetsToLoad ( SLAssetLoader al)
overridevirtual

All scene specific assets have to be registered for async loading in here.

All assets the should be loaded in parallel must be registered in here.

Remarks
All scene sspecific assets have to be loaded async by overriding SLScene::registerAssetsToLoad and SLScene::assemble. Async loading and assembling means that it happens in a parallel thread and that in there are no OpenGL calls allowed. OpenGL calls are only allowed in the main thread.

Reimplemented from SLScene.

Definition at line 32 of file AppDemoSceneRevolver.cpp.

33 {
36  "Testmap_1024_C.jpg");
39  "Testmap_1024_N.jpg");
42  "wood0_0512_C.jpg");
45  "bricks1_0256_C.jpg");
48  "wood2_0512_C.jpg");
50  AppCommon::texturePath + "wood2_0256_C.jpg",
51  AppCommon::texturePath + "wood2_0256_C.jpg",
52  AppCommon::texturePath + "gray_0256_C.jpg",
53  AppCommon::texturePath + "wood0_0256_C.jpg",
54  AppCommon::texturePath + "gray_0256_C.jpg",
55  AppCommon::texturePath + "bricks1_0256_C.jpg");
57  AppCommon::shaderPath + "RefractReflect.vert",
58  AppCommon::shaderPath + "RefractReflect.frag");
59 }
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
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.

Member Data Documentation

◆ _sp1

SLGLProgram* AppDemoSceneRevolver::_sp1
private

Definition at line 51 of file AppDemoSceneRevolver.h.

◆ _tex1C

SLGLTexture* AppDemoSceneRevolver::_tex1C
private

Definition at line 45 of file AppDemoSceneRevolver.h.

◆ _tex1N

SLGLTexture* AppDemoSceneRevolver::_tex1N
private

Definition at line 46 of file AppDemoSceneRevolver.h.

◆ _tex2

SLGLTexture* AppDemoSceneRevolver::_tex2
private

Definition at line 47 of file AppDemoSceneRevolver.h.

◆ _tex3

SLGLTexture* AppDemoSceneRevolver::_tex3
private

Definition at line 48 of file AppDemoSceneRevolver.h.

◆ _tex4

SLGLTexture* AppDemoSceneRevolver::_tex4
private

Definition at line 49 of file AppDemoSceneRevolver.h.

◆ _tex5

SLGLTexture* AppDemoSceneRevolver::_tex5
private

Definition at line 50 of file AppDemoSceneRevolver.h.


The documentation for this class was generated from the following files: