axis.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "tango-gl/axis.h"
18 #include "tango-gl/shaders.h"
19 
20 namespace tango_gl {
21 
22 static const float float_vertices[] = {0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
23  0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
24  0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
25 
26 static const float float_colors[] = {
27  1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
28  0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f};
29 
30 Axis::Axis() : Line(3.0f, GL_LINES) {
31  // Implement SetShader here, not using the dedault one.
35  if (!shader_program_) {
36  LOGE("Could not create program.");
37  }
38  uniform_mvp_mat_ = glGetUniformLocation(shader_program_, "mvp");
39  attrib_colors_ = glGetAttribLocation(shader_program_, "color");
40  attrib_vertices_ = glGetAttribLocation(shader_program_, "vertex");
41 
42  size_t size = sizeof(float_vertices) / (sizeof(float) * 3);
43  for (size_t i = 0; i < size; i++) {
44  vec_vertices_.push_back(glm::vec3(float_vertices[i * 3],
45  float_vertices[i * 3 + 1],
46  float_vertices[i * 3 + 2]));
47  vec_colors_.push_back(
48  glm::vec4(float_colors[i * 4], float_colors[i * 4 + 1],
49  float_colors[i * 4 + 2], float_colors[i * 4 + 3]));
50  }
51 }
52 
53 void Axis::Render(const glm::mat4& projection_mat,
54  const glm::mat4& view_mat) const {
55  glUseProgram(shader_program_);
56  glLineWidth(line_width_);
57  glm::mat4 model_mat = GetTransformationMatrix();
58  glm::mat4 mvp_mat = projection_mat * view_mat * model_mat;
60 
61  glEnableVertexAttribArray(attrib_vertices_);
62  glVertexAttribPointer(attrib_vertices_, 3, GL_FLOAT, GL_FALSE,
63  sizeof(glm::vec3), &vec_vertices_[0]);
64 
65  glEnableVertexAttribArray(attrib_colors_);
66  glVertexAttribPointer(attrib_colors_, 4, GL_FLOAT, GL_FALSE,
67  sizeof(glm::vec4), &vec_colors_[0]);
68 
69  glDrawArrays(render_mode_, 0, vec_vertices_.size());
70 
71  glDisableVertexAttribArray(attrib_vertices_);
72  glDisableVertexAttribArray(attrib_colors_);
73  glUseProgram(0);
74 }
75 } // namespace tango_gl
static const float float_vertices[]
Definition: axis.cpp:22
float line_width_
Definition: line.h:33
std::string GetColorVertexShader()
Definition: shaders.cpp:41
f
glm::mat4 GetTransformationMatrix() const
Definition: transform.cpp:67
std::string GetBasicFragmentShader()
Definition: shaders.cpp:33
GLuint CreateProgram(const char *vertex_source, const char *fragment_source)
Definition: util.cpp:75
#define LOGE(...)
GLM_FUNC_DECL genType::value_type const * value_ptr(genType const &vec)
#define GL_FALSE
Definition: dummy.cpp:79
GLuint attrib_colors_
Definition: axis.h:28
void glUniformMatrix4fv(GLuint, int, int, float *)
Definition: dummy.cpp:80
void Render(const glm::mat4 &projection_mat, const glm::mat4 &view_mat) const
Definition: axis.cpp:53
std::vector< glm::vec3 > vec_vertices_
Definition: line.h:34
static const float float_colors[]
Definition: axis.cpp:26
std::vector< glm::vec4 > vec_colors_
Definition: axis.h:29


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:30