gpuhelper.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "gpuhelper.h"
11 #include "icosphere.h"
12 #include <GL/glu.h>
13 // PLEASE don't look at this old code... ;)
14 
15 #include <fstream>
16 #include <algorithm>
17 
19 
21 {
22  mVpWidth = mVpHeight = 0;
24  mInitialized = false;
25 }
26 
28 {
29 }
30 
32 {
33  // switch to 2D projection
34  pushMatrix(Matrix4f::Identity(),GL_PROJECTION);
35 
36  if(pm==PM_Normalized)
37  {
38  //glOrtho(-1., 1., -1., 1., 0., 1.);
39  }
40  else if(pm==PM_Viewport)
41  {
42  GLint vp[4];
43  glGetIntegerv(GL_VIEWPORT, vp);
44  glOrtho(0., vp[2], 0., vp[3], -1., 1.);
45  }
46 
47  pushMatrix(Matrix4f::Identity(),GL_MODELVIEW);
48 }
49 
51 {
52  popMatrix(GL_PROJECTION);
53  popMatrix(GL_MODELVIEW);
54 }
55 
56 void GpuHelper::drawVector(const Vector3f& position, const Vector3f& vec, const Color& color, float aspect /* = 50.*/)
57 {
58  static GLUquadricObj *cylindre = gluNewQuadric();
59  glColor4fv(color.data());
60  float length = vec.norm();
61  pushMatrix(GL_MODELVIEW);
62  glTranslatef(position.x(), position.y(), position.z());
63  Vector3f ax = Matrix3f::Identity().col(2).cross(vec);
64  ax.normalize();
65  Vector3f tmp = vec;
66  tmp.normalize();
67  float angle = 180.f/M_PI * acos(tmp.z());
68  if (angle>1e-3)
69  glRotatef(angle, ax.x(), ax.y(), ax.z());
70  gluCylinder(cylindre, length/aspect, length/aspect, 0.8*length, 10, 10);
71  glTranslatef(0.0,0.0,0.8*length);
72  gluCylinder(cylindre, 2.0*length/aspect, 0.0, 0.2*length, 10, 10);
73 
74  popMatrix(GL_MODELVIEW);
75 }
76 
77 void GpuHelper::drawVectorBox(const Vector3f& position, const Vector3f& vec, const Color& color, float aspect)
78 {
79  static GLUquadricObj *cylindre = gluNewQuadric();
80  glColor4fv(color.data());
81  float length = vec.norm();
82  pushMatrix(GL_MODELVIEW);
83  glTranslatef(position.x(), position.y(), position.z());
84  Vector3f ax = Matrix3f::Identity().col(2).cross(vec);
85  ax.normalize();
86  Vector3f tmp = vec;
87  tmp.normalize();
88  float angle = 180.f/M_PI * acos(tmp.z());
89  if (angle>1e-3)
90  glRotatef(angle, ax.x(), ax.y(), ax.z());
91  gluCylinder(cylindre, length/aspect, length/aspect, 0.8*length, 10, 10);
92  glTranslatef(0.0,0.0,0.8*length);
93  glScalef(4.0*length/aspect,4.0*length/aspect,4.0*length/aspect);
94  drawUnitCube();
95  popMatrix(GL_MODELVIEW);
96 }
97 
99 {
100  static float vertices[][3] = {
101  {-0.5,-0.5,-0.5},
102  { 0.5,-0.5,-0.5},
103  {-0.5, 0.5,-0.5},
104  { 0.5, 0.5,-0.5},
105  {-0.5,-0.5, 0.5},
106  { 0.5,-0.5, 0.5},
107  {-0.5, 0.5, 0.5},
108  { 0.5, 0.5, 0.5}};
109 
110  glBegin(GL_QUADS);
111  glNormal3f(0,0,-1); glVertex3fv(vertices[0]); glVertex3fv(vertices[2]); glVertex3fv(vertices[3]); glVertex3fv(vertices[1]);
112  glNormal3f(0,0, 1); glVertex3fv(vertices[4]); glVertex3fv(vertices[5]); glVertex3fv(vertices[7]); glVertex3fv(vertices[6]);
113  glNormal3f(0,-1,0); glVertex3fv(vertices[0]); glVertex3fv(vertices[1]); glVertex3fv(vertices[5]); glVertex3fv(vertices[4]);
114  glNormal3f(0, 1,0); glVertex3fv(vertices[2]); glVertex3fv(vertices[6]); glVertex3fv(vertices[7]); glVertex3fv(vertices[3]);
115  glNormal3f(-1,0,0); glVertex3fv(vertices[0]); glVertex3fv(vertices[4]); glVertex3fv(vertices[6]); glVertex3fv(vertices[2]);
116  glNormal3f( 1,0,0); glVertex3fv(vertices[1]); glVertex3fv(vertices[3]); glVertex3fv(vertices[7]); glVertex3fv(vertices[5]);
117  glEnd();
118 }
119 
121 {
122  static IcoSphere sphere;
123  sphere.draw(level);
124 }
125 
126 
void drawUnitSphere(int level=0)
Definition: gpuhelper.cpp:120
GLenum mCurrentMatrixTarget
Definition: gpuhelper.h:105
bool mInitialized
Definition: gpuhelper.h:106
void pushProjectionMode2D(ProjectionMode2D pm)
Definition: gpuhelper.cpp:31
GpuHelper gpu
Definition: gpuhelper.cpp:18
void drawVectorBox(const Vector3f &position, const Vector3f &vec, const Color &color, float aspect=50.)
Definition: gpuhelper.cpp:77
#define M_PI
Definition: main.h:78
Vector4f Color
Definition: gpuhelper.h:19
void popMatrix(GLenum matrixTarget)
Definition: gpuhelper.h:185
void pushMatrix(const Matrix< Scalar, 4, 4, _Flags, 4, 4 > &mat, GLenum matrixTarget)
Definition: gpuhelper.h:170
void popProjectionMode2D()
Definition: gpuhelper.cpp:50
void drawVector(const Vector3f &position, const Vector3f &vec, const Color &color, float aspect=50.)
Definition: gpuhelper.cpp:56
int mVpHeight
Definition: gpuhelper.h:104
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DEVICE_FUNC const AcosReturnType acos() const
ProjectionMode2D
Definition: gpuhelper.h:29
void drawUnitCube(void)
Definition: gpuhelper.cpp:98
int mVpWidth
Definition: gpuhelper.h:104
void draw(int level)
Definition: icosphere.cpp:100
Point3 position(const NavState &X, OptionalJacobian< 3, 9 > H)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:09