LayerManagerExamples: fixed gcc 4.7.1 warnings and errors
[profile/ivi/layer-management.git] / LayerManagerExamples / EGLX11MockNavigation / src / Street.cpp
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19 #include "Street.h"
20 #include "IlmMatrix.h"
21 #include "ShaderBase.h"
22
23 #include <string.h>
24
25 #include <iostream>
26 using std::cout;
27 using std::endl;
28
29 #include <GLES2/gl2.h>
30
31
32 Street::Street(vec3f position, vec3f size, vec4f color, ShaderBase* shader)
33 : m_position(position)
34 , m_size(size)
35 , m_color(color)
36 , m_shader(shader)
37 {
38         m_index[0] = vec3u(0, 3, 2);
39         m_index[1] = vec3u(2, 1, 0);
40     
41     //                             y  z
42     //     3-------------2         | /
43     //    /             /          |/
44     //   /             /           ------x
45     //  0-------------1
46     
47         m_vertex[0].x = m_position.x;
48         m_vertex[0].y = m_position.y;
49         m_vertex[0].z = m_position.z;
50
51         m_vertex[1].x = m_position.x + m_size.x;
52         m_vertex[1].y = m_position.y;
53         m_vertex[1].z = m_position.z;
54     
55         m_vertex[2].x = m_position.x + m_size.x;
56         m_vertex[2].y = m_position.y;
57         m_vertex[2].z = m_position.z + m_size.z;
58     
59         m_vertex[3].x = m_position.x;
60         m_vertex[3].y = m_position.y;
61         m_vertex[3].z = m_position.z + m_size.z;
62 }
63
64 void Street::render()
65 {
66     m_shader->use(&m_position, &m_color);
67
68     // draw
69     glEnableVertexAttribArray(0);
70     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, m_vertex);
71     glDrawElements(GL_TRIANGLES, 3 * sizeof(m_index)/sizeof(m_index[0]), GL_UNSIGNED_INT, m_index);
72 }
73
74 void Street::update(int currentTimeInMs, int lastFrameTime)
75 {
76         (void)currentTimeInMs; //prevent warning
77         m_position.z += 0.0005 * lastFrameTime;
78
79         if (m_position.z > 3.0)
80         {
81                 m_position.z -= 2 * 2.0;
82         }
83 }