summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Rodin <mrodin@de.adit-jv.com>2018-11-20 13:56:35 +0100
committerMichael Rodin <mrodin@de.adit-jv.com>2018-12-03 10:27:08 +0100
commit3c4b3a7c25c57d00b1d2e1c01327f355ed96e5fc (patch)
treedc7adfb49687fd66925a2c0469a6b6d9d79bca93
parent55e57c0cf51d814066d8be81b76e593ddde9771d (diff)
downloadwayland-ivi-extension-3c4b3a7c25c57d00b1d2e1c01327f355ed96e5fc.tar.gz
EGLWLMockNavigation: add Sky class
Add the Sky class for rendering the sky with different colors. Signed-off-by: Michael Rodin <mrodin@de.adit-jv.com>
-rw-r--r--ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt2
-rw-r--r--ivi-layermanagement-examples/EGLWLMockNavigation/include/Sky.h57
-rw-r--r--ivi-layermanagement-examples/EGLWLMockNavigation/src/Sky.cpp115
3 files changed, 174 insertions, 0 deletions
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt b/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt
index cd98351..f669506 100644
--- a/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt
+++ b/ivi-layermanagement-examples/EGLWLMockNavigation/CMakeLists.txt
@@ -77,6 +77,7 @@ set (HEADER_FILES
include/ShaderLighting.h
include/TextureLoader.h
include/ShaderTexture.h
+ include/Sky.h
include/ShaderGradient.h
)
@@ -94,6 +95,7 @@ set (SRC_FILES
src/main.cpp
src/TextureLoader.cpp
src/ShaderTexture.cpp
+ src/Sky.cpp
src/ShaderGradient.cpp
)
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/include/Sky.h b/ivi-layermanagement-examples/EGLWLMockNavigation/include/Sky.h
new file mode 100644
index 0000000..74c8d94
--- /dev/null
+++ b/ivi-layermanagement-examples/EGLWLMockNavigation/include/Sky.h
@@ -0,0 +1,57 @@
+/***************************************************************************
+ *
+ * Copyright (C) 2018 Advanced Driver Information Technology Joint Venture GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#ifndef _SKY_H
+#define _SKY_H
+
+#include "IRenderable.h"
+#include "IUpdateable.h"
+#include "vec.h"
+#include "ShaderGradient.h"
+
+class ShaderBase;
+
+class Sky : public IRenderable, public IUpdateable
+{
+public:
+ Sky(vec3f position, vec3f size, vec4f color, ShaderGradient* shader, float sunriseSpeed = 0.02, float sunsetSpeed = 0.01, float daySpeed = 0.02, float nightSpeed = 0.02);
+ virtual ~Sky() {}
+
+ virtual void render();
+ virtual void update(int currentTimeInMs, int lastFrameTime);
+
+private:
+ vec3f m_position;
+ vec3f m_size;
+ vec4f m_color;
+ vec4f colors[4]={{0.0, 0.0, 0.0, 1.0}, {0.0, 0.0, 0.0, 1.0}, {0.0, 0.0, 0.0, 1.0}, {0.0, 0.0, 0.0, 1.0}};
+
+ vec4u m_index;
+ vec3f m_vertex[4];
+
+ enum skyStates {sunrise, daytime, sunset, nighttime};
+ enum skyStates skyState;
+ const float sunriseSpeed;
+ const float sunsetSpeed;
+ const float daySpeed;
+ const float nightSpeed;
+
+ ShaderGradient* m_pShader;
+};
+
+#endif /* _SKY_H */
diff --git a/ivi-layermanagement-examples/EGLWLMockNavigation/src/Sky.cpp b/ivi-layermanagement-examples/EGLWLMockNavigation/src/Sky.cpp
new file mode 100644
index 0000000..ecf5ea1
--- /dev/null
+++ b/ivi-layermanagement-examples/EGLWLMockNavigation/src/Sky.cpp
@@ -0,0 +1,115 @@
+/***************************************************************************
+ *
+ * Copyright (C) 2018 Advanced Driver Information Technology Joint Venture GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+#include "Sky.h"
+#include "ShaderBase.h"
+#include <string.h>
+
+#include <iostream>
+using std::cout;
+using std::endl;
+
+#include <GLES2/gl2.h>
+
+Sky::Sky(vec3f position, vec3f size, vec4f color, ShaderGradient* shader, float sunriseSpeed, float sunsetSpeed, float daySpeed, float nightSpeed)
+: m_position(position)
+, m_size(size)
+, m_color(color)
+, m_index(0, 1, 2, 3)
+, skyState(sunrise)
+, sunriseSpeed(sunriseSpeed)
+, sunsetSpeed(sunsetSpeed)
+, daySpeed(daySpeed)
+, nightSpeed(nightSpeed)
+, m_pShader(shader)
+{
+ m_vertex[0].x = m_position.x;
+ m_vertex[0].y = m_position.y;
+ m_vertex[0].z = m_position.z;
+
+ m_vertex[1].x = m_position.x;
+ m_vertex[1].y = m_position.y + m_size.y;
+ m_vertex[1].z = m_position.z;
+
+ m_vertex[2].x = m_position.x + m_size.x;
+ m_vertex[2].y = m_position.y + m_size.y;
+ m_vertex[2].z = m_position.z;
+
+ m_vertex[3].x = m_position.x + m_size.x;
+ m_vertex[3].y = m_position.y;
+ m_vertex[3].z = m_position.z;
+}
+
+void Sky::render()
+{
+ m_pShader->use(&m_position, colors);
+
+ // draw
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, m_vertex);
+ glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, &m_index);
+}
+
+void Sky::update(int currentTimeInMs, int lastFrameTime)
+{
+ (void)currentTimeInMs; //prevent warning
+ (void)lastFrameTime;
+ static float clock = 0;
+
+ if (skyState == sunrise) {
+ if (colors[0].r < 1.0) {
+ colors[0].r += sunriseSpeed;
+ colors[0].g += sunriseSpeed/2;
+
+ colors[1].b += sunriseSpeed/4;
+ colors[2].b += sunriseSpeed/4;
+
+ colors[3].r += sunriseSpeed;
+ colors[3].g += sunriseSpeed/2;
+ } else {
+ skyState = daytime;
+ }
+ } else if (skyState == daytime) {
+ if (clock < 1.0) {
+ clock += daySpeed;
+ } else {
+ clock = 0.0;
+ skyState = sunset;
+ }
+ } else if (skyState == sunset) {
+ if (colors[0].r > 0.0) {
+ colors[0].r -= sunsetSpeed;
+ colors[0].g -= sunsetSpeed/2;
+
+ colors[1].b -= sunsetSpeed/4;
+ colors[2].b -= sunsetSpeed/4;
+
+ colors[3].r -= sunsetSpeed;
+ colors[3].g -= sunsetSpeed/2;
+ } else {
+ skyState = nighttime;
+ }
+ } else if (skyState == nighttime) {
+ if (clock < 1.0) {
+ clock += nightSpeed;
+ } else {
+ clock = 0.0;
+ skyState = sunrise;
+ }
+ }
+}