• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #include "Ground.h"
21 #include "ShaderLighting.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 
Ground(vec3f position,vec3f size,vec4f color,ShaderBase * pShader)32 Ground::Ground(vec3f position, vec3f size, vec4f color, ShaderBase* pShader)
33 : m_position(position)
34 , m_size(size)
35 , m_color(color)
36 , m_pShader(pShader)
37 {
38     m_index[0] = vec3u(0, 1, 2);
39     m_index[1] = vec3u(2, 3, 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 
render()64 void Ground::render()
65 {
66     m_pShader->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_SHORT, m_index);
72 }
73