1 /***************************************************************************
3 * Copyright 2010,2011 BMW Car IT GmbH
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ****************************************************************************/
20 #include "IlmMatrix.h"
21 #include "ShaderBase.h"
29 #include <GLES2/gl2.h>
32 Street::Street(vec3f position, vec3f size, vec4f color, ShaderBase* shader)
33 : m_position(position)
38 m_index[0] = vec3u(0, 3, 2);
39 m_index[1] = vec3u(2, 1, 0);
42 // 3-------------2 | /
47 m_vertex[0].x = m_position.x;
48 m_vertex[0].y = m_position.y;
49 m_vertex[0].z = m_position.z;
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;
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;
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;
66 m_shader->use(&m_position, &m_color);
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);
74 void Street::update(int currentTimeInMs, int lastFrameTime)
76 (void)currentTimeInMs; //prevent warning
77 m_position.z += 0.0005 * lastFrameTime;
79 if (m_position.z > 3.0)
81 m_position.z -= 2 * 2.0;