SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneAnimNode.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneAnimNode.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, Marino von Wattenwyl
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 <AppCommon.h>
14 #include <AppDemoSceneAnimNode.h>
15 #include <AppDemoSceneFigure.h>
16 #include <SLAssetLoader.h>
17 #include <SLLightSpot.h>
18 #include <SLRectangle.h>
19 #include <SLSphere.h>
20 #include <SLCylinder.h>
21 
22 //-----------------------------------------------------------------------------
24  : SLScene("Node Animation Test Scene")
25 {
26  info("Node animations with different easing curves.");
27 }
28 //-----------------------------------------------------------------------------
29 //! All assets the should be loaded in parallel must be registered in here.
31 {
33  AppCommon::texturePath + "Checkerboard0512_C.png");
34 }
35 //-----------------------------------------------------------------------------
36 //! After parallel loading of the assets the scene gets assembled in here.
38 {
39  SLMaterial* m1 = new SLMaterial(am, "m1", _tex1);
40  m1->kr(0.5f);
41  SLMaterial* m2 = new SLMaterial(am, "m2", SLCol4f::WHITE * 0.5, SLCol4f::WHITE, 128, 0.5f, 0.0f, 1.0f);
42 
43  SLMesh* floorMesh = new SLRectangle(am, SLVec2f(-5, -5), SLVec2f(5, 5), 20, 20, "FloorMesh", m1);
44  SLNode* floorRect = new SLNode(floorMesh);
45  floorRect->rotate(90, -1, 0, 0);
46  floorRect->translate(0, 0, -5.5f);
47 
48  // Bouncing balls
49  SLNode* ball1 = new SLNode(new SLSphere(am, 0.3f, 16, 16, "Ball1", m2));
50  ball1->translate(0, 0, 4, TS_object);
51  SLAnimation* ball1Anim = animManager().createNodeAnimation("Ball1_anim", 1.0f, true, EC_linear, AL_pingPongLoop);
52  ball1Anim->createNodeAnimTrackForTranslation(ball1, SLVec3f(0.0f, -5.2f, 0.0f));
53 
54  SLNode* ball2 = new SLNode(new SLSphere(am, 0.3f, 16, 16, "Ball2", m2));
55  ball2->translate(-1.5f, 0, 4, TS_object);
56  SLAnimation* ball2Anim = animManager().createNodeAnimation("Ball2_anim", 1.0f, true, EC_inQuad, AL_pingPongLoop);
57  ball2Anim->createNodeAnimTrackForTranslation(ball2, SLVec3f(0.0f, -5.2f, 0.0f));
58 
59  SLNode* ball3 = new SLNode(new SLSphere(am, 0.3f, 16, 16, "Ball3", m2));
60  ball3->translate(-2.5f, 0, 4, TS_object);
61  SLAnimation* ball3Anim = animManager().createNodeAnimation("Ball3_anim", 1.0f, true, EC_outQuad, AL_pingPongLoop);
62  ball3Anim->createNodeAnimTrackForTranslation(ball3, SLVec3f(0.0f, -5.2f, 0.0f));
63 
64  SLNode* ball4 = new SLNode(new SLSphere(am, 0.3f, 16, 16, "Ball4", m2));
65  ball4->translate(1.5f, 0, 4, TS_object);
66  SLAnimation* ball4Anim = animManager().createNodeAnimation("Ball4_anim", 1.0f, true, EC_inOutQuad, AL_pingPongLoop);
67  ball4Anim->createNodeAnimTrackForTranslation(ball4, SLVec3f(0.0f, -5.2f, 0.0f));
68 
69  SLNode* ball5 = new SLNode(new SLSphere(am, 0.3f, 16, 16, "Ball5", m2));
70  ball5->translate(2.5f, 0, 4, TS_object);
71  SLAnimation* ball5Anim = animManager().createNodeAnimation("Ball5_anim", 1.0f, true, EC_outInQuad, AL_pingPongLoop);
72  ball5Anim->createNodeAnimTrackForTranslation(ball5, SLVec3f(0.0f, -5.2f, 0.0f));
73 
74  SLCamera* cam1 = new SLCamera("Camera 1");
75  cam1->translation(0, 0, 22);
76  cam1->lookAt(0, 0, 0);
77  cam1->focalDist(22);
78  cam1->setInitialState();
80 
81  SLCamera* cam2 = new SLCamera("Camera 2");
82  cam2->translation(5, 0, 0);
83  cam2->lookAt(0, 0, 0);
84  cam2->focalDist(5);
85  cam2->clipFar(10);
86  cam2->background().colors(SLCol4f(0, 0, 0.6f), SLCol4f(0, 0, 0.3f));
87  cam2->setInitialState();
89 
90  SLCamera* cam3 = new SLCamera("Camera 3");
91  cam3->translation(-5, -2, 0);
92  cam3->lookAt(0, 0, 0);
93  cam3->focalDist(5);
94  cam3->clipFar(10);
95  cam3->background().colors(SLCol4f(0.6f, 0, 0), SLCol4f(0.3f, 0, 0));
96  cam3->setInitialState();
98 
99  SLLightSpot* light1 = new SLLightSpot(am, this, 0, 2, 0, 0.5f);
100  light1->powers(0.2f, 1.0f, 1.0f);
101  light1->attenuation(1, 0, 0);
102  SLAnimation* light1Anim = this->animManager().createNodeAnimation("Light1_anim", 4.0f);
103  light1Anim->createNodeAnimTrackForEllipse(light1, 6, A_z, 6, A_x);
104 
105  SLLightSpot* light2 = new SLLightSpot(am, this, 0, 0, 0, 0.2f);
106  light2->powers(0.1f, 1.0f, 1.0f);
107  light2->attenuation(1, 0, 0);
108  light2->translate(-8, -4, 0, TS_world);
109  light2->setInitialState();
110  SLAnimation* light2Anim = animManager().createNodeAnimation("light2_anim", 2.0f, true, EC_linear, AL_pingPongLoop);
111  SLNodeAnimTrack* track = light2Anim->createNodeAnimTrack();
112  track->animatedNode(light2);
113  track->createNodeKeyframe(0.0f);
114  track->createNodeKeyframe(1.0f)->translation(SLVec3f(8, 8, 0));
115  track->createNodeKeyframe(2.0f)->translation(SLVec3f(16, 0, 0));
117 
118  SLNode* figure = AppDemoSceneFigure::BuildFigureGroup(am, this, m2, true);
119 
120  SLNode* scene = new SLNode("Scene");
121  root3D(scene);
122  scene->addChild(light1);
123  scene->addChild(light2);
124  scene->addChild(cam1);
125  scene->addChild(cam2);
126  scene->addChild(cam3);
127  scene->addChild(floorRect);
128  scene->addChild(ball1);
129  scene->addChild(ball2);
130  scene->addChild(ball3);
131  scene->addChild(ball4);
132  scene->addChild(ball5);
133  scene->addChild(figure);
134 
135  sv->camera(cam1);
136 }
137 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
Class declaration for an SLScene inherited class.
Class declaration for an SLScene inherited class.
@ A_z
Definition: SLEnums.h:82
@ A_x
Definition: SLEnums.h:80
@ AI_bezier
Definition: SLEnums.h:162
@ EC_outInQuad
quadratic easing out and then in
Definition: SLEnums.h:185
@ EC_inOutQuad
quadratic easing in and then out
Definition: SLEnums.h:184
@ EC_outQuad
quadratic easing out, decelerating to zero velocity
Definition: SLEnums.h:183
@ EC_linear
linear easing with constant velocity
Definition: SLEnums.h:181
@ EC_inQuad
quadratic easing in, acceleration from zero velocity
Definition: SLEnums.h:182
@ TS_world
Definition: SLEnums.h:208
@ TS_object
Definition: SLEnums.h:210
@ AL_pingPongLoop
loop forward and backwards
Definition: SLEnums.h:171
SLVec2< SLfloat > SLVec2f
Definition: SLVec2.h:141
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
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
static SLNode * BuildFigureGroup(SLAssetManager *am, SLScene *s, SLMaterial *mat, SLbool withAnimation)
Build a hierarchical figurine with arms and legs.
SLAnimation * createNodeAnimation(SLfloat duration)
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
SLNodeAnimTrack * createNodeAnimTrack()
Definition: SLAnimation.cpp:94
SLNodeAnimTrack * createNodeAnimTrackForTranslation(SLNode *target, const SLVec3f &endPos)
SLNodeAnimTrack * createNodeAnimTrackForEllipse(SLNode *target, SLfloat radiusA, SLAxis axisA, SLfloat radiusB, SLAxis axisB)
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.
Toplevel holder of the assets meshes, materials, textures and shaders.
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
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 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 kr(SLfloat kr)
Definition: SLMaterial.h:184
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
Specialized animation track for node animations.
Definition: SLAnimTrack.h:66
void animatedNode(SLNode *target)
Definition: SLAnimTrack.h:73
SLTransformKeyframe * createNodeKeyframe(SLfloat time)
void translationInterpolation(SLAnimInterpolation interp)
Definition: SLAnimTrack.h:82
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
SLRectangle creates a rectangular mesh with a certain resolution.
Definition: SLRectangle.h:29
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
SLAnimManager & animManager()
Definition: SLScene.h:97
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
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
void translation(const SLVec3f &t)
static SLVec4 WHITE
Definition: SLVec4.h:215