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
tango_gl::Axis::vec_colors_
std::vector< glm::vec4 > vec_colors_
Definition: axis.h:29
tango_gl::DrawableObject::attrib_vertices_
GLuint attrib_vertices_
Definition: drawable_object.h:59
size
Index size
tango_gl::shaders::GetBasicFragmentShader
std::string GetBasicFragmentShader()
Definition: shaders.cpp:33
tango_gl::Axis::Render
void Render(const glm::mat4 &projection_mat, const glm::mat4 &view_mat) const
Definition: axis.cpp:53
tango_gl::Line
Definition: line.h:23
glm::value_ptr
GLM_FUNC_DECL const genType::value_type * value_ptr(genType const &vec)
glm::detail::tvec3
Definition: type_mat.hpp:37
glm::detail::tmat4x4
Definition: type_mat.hpp:47
tango_gl::DrawableObject::render_mode_
GLenum render_mode_
Definition: drawable_object.h:55
LOGE
#define LOGE(...)
Definition: tango-gl/include/tango-gl/util.h:61
axis.h
GL_FALSE
#define GL_FALSE
Definition: dummy.cpp:79
shaders.h
tango_gl::util::CreateProgram
GLuint CreateProgram(const char *vertex_source, const char *fragment_source)
Definition: util.cpp:75
tango_gl::shaders::GetColorVertexShader
std::string GetColorVertexShader()
Definition: shaders.cpp:41
glm::detail::tvec4
Definition: type_mat.hpp:38
tango_gl::float_vertices
static const float float_vertices[]
Definition: axis.cpp:22
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
tango_gl::Axis::Axis
Axis()
Definition: axis.cpp:30
tango_gl::Axis::attrib_colors_
GLuint attrib_colors_
Definition: axis.h:28
c_str
const char * c_str(Args &&...args)
tango_gl::DrawableObject::uniform_mvp_mat_
GLuint uniform_mvp_mat_
Definition: drawable_object.h:58
tango_gl::float_colors
static const float float_colors[]
Definition: axis.cpp:26
glUniformMatrix4fv
void glUniformMatrix4fv(GLuint, int, int, float *)
Definition: dummy.cpp:80
tango_gl
Definition: axis.cpp:20
tango_gl::Line::vec_vertices_
std::vector< glm::vec3 > vec_vertices_
Definition: line.h:34
tango_gl::DrawableObject::shader_program_
GLuint shader_program_
Definition: drawable_object.h:56
tango_gl::Transform::GetTransformationMatrix
glm::mat4 GetTransformationMatrix() const
Definition: transform.cpp:67
i
int i
tango_gl::Line::line_width_
float line_width_
Definition: line.h:33


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:06