Cheetah Software  1.0
Graphics3D Class Reference

#include <Graphics3D.h>

+ Inheritance diagram for Graphics3D:
+ Collaboration diagram for Graphics3D:

Public Member Functions

 Graphics3D (QWidget *parent=0)
 
virtual ~Graphics3D ()
 
void setAnimating (bool animating)
 
size_t setupCheetah3 (Vec4< float > color, bool useOld)
 
size_t setupMiniCheetah (Vec4< float > color, bool useOld)
 
void lockGfxMutex ()
 
void unlockGfxMutex ()
 
GamepadCommandgetDriverCommand ()
 
void resetGameController ()
 
bool IsPaused ()
 
bool wantTurbo ()
 

Public Attributes

double _fps = 0
 
DrawList _drawList
 
char infoString [200] = ""
 

Protected Member Functions

void initializeGL () override
 
void paintGL () override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void wheelEvent (QWheelEvent *e) override
 
void keyReleaseEvent (QKeyEvent *e) override
 
void keyPressEvent (QKeyEvent *event) override
 

Protected Attributes

float _color1 [3] = {0.364784, 0.513401, 0.952230}
 
float _color2 [3] = {0.553970, 0.477397, 0.628871}
 
float _color3 [3] = {0.335223, 0.768230, 0.277775}
 

Private Member Functions

void updateCameraMatrix ()
 
void renderDrawlist ()
 
void configOpenGLPass (int pass)
 
void _BoxObstacleDrawing ()
 
void _MeshObstacleDrawing ()
 
void _DrawBox (double depth, double width, double height)
 
void _Additional_Drawing (int pass)
 
void _DrawContactForce ()
 
void _DrawContactPoint ()
 
void _drawArrow (ArrowVisualization &arrow)
 
void _drawBlock (BlockVisualization &box)
 
void _drawSphere (SphereVisualization &sphere)
 
void _drawCone (ConeVisualization &cone)
 
void _rotateZtoDirection (const Vec3< float > &direction)
 
void _setColor (const Vec4< float > &color)
 
void _translate (const Vec3< float > &position)
 
void _drawArrow (const Vec3< float > &base, const Vec3< float > &direction, float lineWidth, float headWidth, float headLength)
 
void getHeightColor (const double &height, float &r, float &g, float &b)
 
void _SetRGBHeight (const double &h, const double &step, const int &idx, float &r, float &g, float &b)
 

Private Attributes

GameController _gameController
 
GamepadCommand _driverCommand
 
std::mutex _gfxMutex
 
bool _animating
 
GLuint _posAttrColorArray
 
GLuint _colAttrColorArray
 
GLuint _matrixUniformColorArray
 
GLuint _normAttrColorArray
 
GLuint _posAttrSolidColor
 
GLuint _colUniformSolidColor
 
GLuint _colAttrSolidColor
 
GLuint _matrixUniformSolidColor
 
GLuint _normAttrSolidColor
 
GLuint _buffID [3]
 
QOpenGLShaderProgram * _colorArrayProgram
 
QOpenGLShaderProgram * _solidColorProgram
 
int _frame
 
qint64 last_frame_ms = 0
 
bool _orbiting = false
 
int _orbiting_x_start = 0
 
int _orbiting_y_start = 0
 
float _rx_base = 0
 
float _ry_base = 0
 
float _rx = 0
 
float _ry = -34
 
float _pixel_to_rad = .3f
 
float _zoom = 3.0
 
bool _rotOrig = true
 
bool _turbo = false
 
QMatrix4x4 _cameraMatrix
 
Vec3< float > _v0
 
Vec3< double > _cameraTarget
 
FirstOrderIIRFilter< Vec3< float >, float > _freeCamFilter
 
float _freeCamMove [3] = {0, 0, 0}
 
float _freeCamPos [3] = {0.f, 0.f, 0.f}
 
float _frameTime = 1.f / 60.f
 
bool _arrowsPressed [4] = {false, false, false, false}
 
float _targetSpeed = 2
 
float _r [8]
 
float _g [8]
 
float _b [8]
 
bool _pause = false
 

Detailed Description

Definition at line 33 of file Graphics3D.h.

Constructor & Destructor Documentation

Graphics3D::Graphics3D ( QWidget *  parent = 0)
explicit

Initialize a 3D visualization window

Definition at line 77 of file Graphics3D.cpp.

References _b, _g, and _r.

78  : QOpenGLWidget(parent),
79  _animating(false),
81  _frame(0),
82  _v0(0, 0, 0),
83  _freeCamFilter(1, 60, _v0) {
84  std::cout << "[SIM GRAPHICS] New graphics window. \n";
85 
86  _r[0] = 0.2422;
87  _g[0] = 0.1504;
88  _b[0] = 0.6603;
89  _r[1] = 0.2810;
90  _g[1] = 0.3228;
91  _b[1] = 0.9579;
92  _r[2] = 0.1786;
93  _g[2] = 0.5289;
94  _b[2] = 0.9682;
95  _r[3] = 0.0689;
96  _g[3] = 0.6948;
97  _b[3] = 0.8394;
98  _r[4] = 0.2161;
99  _g[4] = 0.7843;
100  _b[4] = 0.5923;
101  _r[5] = 0.6720;
102  _g[5] = 0.7793;
103  _b[5] = 0.2227;
104  _r[6] = 0.9970;
105  _g[6] = 0.7659;
106  _b[6] = 0.2199;
107  _r[7] = 0.9769;
108  _g[7] = 0.9839;
109  _b[7] = 0.0805;
110 }
FirstOrderIIRFilter< Vec3< float >, float > _freeCamFilter
Definition: Graphics3D.h:148
float _g[8]
Definition: Graphics3D.h:159
QOpenGLShaderProgram * _colorArrayProgram
Definition: Graphics3D.h:123
Vec3< float > _v0
Definition: Graphics3D.h:146
float _r[8]
Definition: Graphics3D.h:158
float _b[8]
Definition: Graphics3D.h:160
bool _animating
Definition: Graphics3D.h:106
Graphics3D::~Graphics3D ( )
virtual

Definition at line 112 of file Graphics3D.cpp.

112 {}

Member Function Documentation

void Graphics3D::_Additional_Drawing ( int  pass)
private

Definition at line 679 of file Graphics3D.cpp.

References _cameraMatrix, _drawArrow(), _drawBlock(), _drawCone(), _DrawContactForce(), _DrawContactPoint(), _drawList, _drawSphere(), DrawList::_visualizationData, VisualizationData::arrows, VisualizationData::blocks, PathVisualization::color, VisualizationData::cones, configOpenGLPass(), VisualizationData::num_arrows, VisualizationData::num_blocks, VisualizationData::num_cones, VisualizationData::num_paths, PathVisualization::num_points, VisualizationData::num_spheres, VisualizationData::paths, PathVisualization::position, and VisualizationData::spheres.

679  {
680  glLoadMatrixf(_cameraMatrix.data());
681  glPushAttrib(GL_LIGHTING_BIT);
682  glDisable(GL_LIGHTING);
683 
686 
687  configOpenGLPass(pass);
688  glEnable(GL_BLEND);
689  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
690 
691  for (size_t i = 0; i < _drawList._visualizationData->num_arrows; i++) {
693  }
694 
695  for (size_t i = 0; i < _drawList._visualizationData->num_cones; i++) {
697  }
698 
699  for (size_t i = 0; i < _drawList._visualizationData->num_blocks; i++) {
701  }
702 
703  for (size_t i = 0; i < _drawList._visualizationData->num_spheres; i++) {
705  }
706  glDisable(GL_BLEND);
707 
708  for (size_t i = 0; i < _drawList._visualizationData->num_paths; i++) {
710  glColor4f(path.color[0], path.color[1], path.color[2], path.color[3]);
711  glBegin(GL_LINE_STRIP);
712  for (size_t j = 0; j < path.num_points; j++) {
713  glVertex3d(path.position[j][0], path.position[j][1], path.position[j][2]);
714  }
715  glEnd();
716  }
717 
718  glPopAttrib();
719  glEnable(GL_LIGHTING);
720 }
ArrowVisualization arrows[VISUALIZATION_MAX_ITEMS]
VisualizationData * _visualizationData
Definition: DrawList.h:51
void _DrawContactPoint()
Definition: Graphics3D.cpp:744
SphereVisualization spheres[VISUALIZATION_MAX_ITEMS]
ConeVisualization cones[VISUALIZATION_MAX_ITEMS]
void _drawBlock(BlockVisualization &box)
Definition: Graphics3D.cpp:821
Vec4< float > color
BlockVisualization blocks[VISUALIZATION_MAX_ITEMS]
void configOpenGLPass(int pass)
Definition: Graphics3D.cpp:437
void _DrawContactForce()
Definition: Graphics3D.cpp:722
QMatrix4x4 _cameraMatrix
Definition: Graphics3D.h:145
void _drawArrow(ArrowVisualization &arrow)
Definition: Graphics3D.cpp:835
PathVisualization paths[VISUALIZATION_MAX_PATHS]
Vec3< float > position[VISUALIZATION_MAX_PATH_POINTS]
void _drawSphere(SphereVisualization &sphere)
Definition: Graphics3D.cpp:799
void _drawCone(ConeVisualization &cone)
Definition: Graphics3D.cpp:808
DrawList _drawList
Definition: Graphics3D.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_BoxObstacleDrawing ( )
private

Definition at line 611 of file Graphics3D.cpp.

References _cameraMatrix, _DrawBox(), _drawList, and DrawList::getBoxInfoList().

611  {
612  glLoadMatrixf(_cameraMatrix.data());
613  glPushAttrib(GL_LIGHTING_BIT);
614  glDisable(GL_LIGHTING);
615 
616  size_t nBox = _drawList.getBoxInfoList().size();
617  for (size_t i(0); i < nBox; ++i) {
618  glPushMatrix();
619  glMultMatrixf(_drawList.getBoxInfoList()[i].frame); // column major
620  _DrawBox(_drawList.getBoxInfoList()[i].depth,
621  _drawList.getBoxInfoList()[i].width,
622  _drawList.getBoxInfoList()[i].height);
623  glPopMatrix();
624  }
625  glEnable(GL_LIGHTING);
626  glPopAttrib();
627 }
QMatrix4x4 _cameraMatrix
Definition: Graphics3D.h:145
void _DrawBox(double depth, double width, double height)
Definition: Graphics3D.cpp:629
const std::vector< BoxInfo > & getBoxInfoList()
Definition: DrawList.h:267
DrawList _drawList
Definition: Graphics3D.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_drawArrow ( ArrowVisualization arrow)
private

Definition at line 835 of file Graphics3D.cpp.

References _setColor(), ArrowVisualization::base_position, ArrowVisualization::color, ArrowVisualization::direction, ArrowVisualization::head_length, ArrowVisualization::head_width, and ArrowVisualization::shaft_width.

835  {
836  _setColor(arrow.color);
837  _drawArrow(arrow.base_position, arrow.direction, arrow.shaft_width,
838  arrow.head_width, arrow.head_length);
839 }
void _drawArrow(ArrowVisualization &arrow)
Definition: Graphics3D.cpp:835
Vec3< float > base_position
Vec3< float > direction
void _setColor(const Vec4< float > &color)
Definition: Graphics3D.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_drawArrow ( const Vec3< float > &  base,
const Vec3< float > &  direction,
float  lineWidth,
float  headWidth,
float  headLength 
)
private

Definition at line 841 of file Graphics3D.cpp.

References _rotateZtoDirection(), _translate(), and f().

843  {
844  double len = direction.norm();
845 
846  glPushMatrix();
847  _translate(position);
848  _rotateZtoDirection(direction);
849 
850  double cylinderLength = len;
851  if (cylinderLength > headLength) {
852  cylinderLength -= headLength;
853  } else {
854  headLength = cylinderLength;
855  cylinderLength = 0;
856  }
857 
858  const int detail = 32;
859  static GLUquadric *quad = gluNewQuadric();
860 
861  // glPolygonMode(GL_FRONT, GL_FILL);
862  // Draw Cylinder
863  gluCylinder(quad, lineWidth, lineWidth, cylinderLength, detail, 1);
864 
865  // Draw Cylinder Base
866  glRotated(180, 1, 0, 0);
867  gluDisk(quad, 0, lineWidth, detail, detail);
868  glRotated(180, 1, 0, 0);
869 
870  glTranslatef(0, 0, cylinderLength);
871  // Draw Arrowhead
872  gluCylinder(quad, headWidth, 0.0f, headLength, detail, detail);
873 
874  glRotated(180, 1, 0, 0);
875  // Draw Arrowhead Base
876  gluDisk(quad, lineWidth, headWidth, detail, detail);
877  glPopMatrix();
878 }
void _translate(const Vec3< float > &position)
Definition: Graphics3D.h:101
void _rotateZtoDirection(const Vec3< float > &direction)
Definition: Graphics3D.cpp:764
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

void Graphics3D::_drawBlock ( BlockVisualization box)
private

Definition at line 821 of file Graphics3D.cpp.

References _DrawBox(), _setColor(), _translate(), BlockVisualization::color, BlockVisualization::corner_position, BlockVisualization::dimension, and BlockVisualization::rpy.

821  {
822  glPushMatrix();
824  _setColor(box.color);
825  glRotatef(box.rpy(2), 0, 0, 1);
826  glRotatef(box.rpy(1), 0, 1, 0);
827  glRotatef(box.rpy(0), 1, 0, 0);
828 
829  glScalef(box.dimension(0), box.dimension(1), box.dimension(2));
830  glTranslatef(.5, .5, .5);
831  _DrawBox(1, 1, 1);
832  glPopMatrix();
833 }
Vec3< float > corner_position
void _translate(const Vec3< float > &position)
Definition: Graphics3D.h:101
void _DrawBox(double depth, double width, double height)
Definition: Graphics3D.cpp:629
Vec3< float > dimension
void _setColor(const Vec4< float > &color)
Definition: Graphics3D.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_DrawBox ( double  depth,
double  width,
double  height 
)
private

Definition at line 629 of file Graphics3D.cpp.

References _color1, and f().

629  {
630  double x = depth / 2.0;
631  double y = width / 2.0;
632  double z = height / 2.0;
633 
634  glPushAttrib(GL_COLOR_BUFFER_BIT);
635 
636  glEnable(GL_BLEND);
637  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
638 
639  glColor4f(_color1[0], _color1[1], _color1[2], 0.7f);
640 
641  glBegin(GL_QUADS);
642  {
643  glVertex3d(x, y, -z);
644  glVertex3d(-x, y, -z);
645  glVertex3d(-x, y, z);
646  glVertex3d(x, y, z);
647 
648  glVertex3d(x, -y, -z);
649  glVertex3d(x, y, -z);
650  glVertex3d(x, y, z);
651  glVertex3d(x, -y, z);
652 
653  glVertex3d(x, -y, z);
654  glVertex3d(-x, -y, z);
655  glVertex3d(-x, -y, -z);
656  glVertex3d(x, -y, -z);
657 
658  glVertex3d(-x, -y, z);
659  glVertex3d(-x, y, z);
660  glVertex3d(-x, y, -z);
661  glVertex3d(-x, -y, -z);
662 
663  glVertex3d(-x, -y, -z);
664  glVertex3d(-x, y, -z);
665  glVertex3d(x, y, -z);
666  glVertex3d(x, -y, -z);
667 
668  glVertex3d(-x, -y, z);
669  glVertex3d(x, -y, z);
670  glVertex3d(x, y, z);
671  glVertex3d(-x, y, z);
672  } // GL_QUADS
673  glEnd();
674 
675  glPopAttrib();
676  glDisable(GL_BLEND);
677 }
MX f(const MX &x, const MX &u)
float _color1[3]
Definition: Graphics3D.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_drawCone ( ConeVisualization cone)
private

Definition at line 808 of file Graphics3D.cpp.

References _rotateZtoDirection(), _setColor(), _translate(), ConeVisualization::color, ConeVisualization::direction, ConeVisualization::point_position, and ConeVisualization::radius.

808  {
809  static GLUquadric *quad = gluNewQuadric();
810  float len = cone.direction.norm();
811 
812  glPushMatrix();
813  _setColor(cone.color);
816  const int detail = 32;
817  gluCylinder(quad, 0, cone.radius, len, detail, 1);
818  glPopMatrix();
819 }
Vec3< float > point_position
Vec4< float > color
Vec3< float > direction
void _translate(const Vec3< float > &position)
Definition: Graphics3D.h:101
void _rotateZtoDirection(const Vec3< float > &direction)
Definition: Graphics3D.cpp:764
void _setColor(const Vec4< float > &color)
Definition: Graphics3D.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_DrawContactForce ( )
private

Definition at line 722 of file Graphics3D.cpp.

References _drawArrow(), _drawList, f(), DrawList::getGCForce(), DrawList::getGCPos(), and DrawList::getTotalNumGC().

722  {
723  glLineWidth(2.0);
724  // double scale(0.02);
725  double scale(0.0025);
726 
727  glPushAttrib(GL_COLOR_BUFFER_BIT);
728  glEnable(GL_BLEND);
729  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
730 
731  for (size_t i(0); i < _drawList.getTotalNumGC(); ++i) {
732  glColor4f(0.8f, 0.0f, 0.f, 0.5f);
733  Vec3<float> floatForce, floatPos;
734  for (size_t j = 0; j < 3; j++) {
735  floatPos(j) = _drawList.getGCPos(i)[j];
736  floatForce(j) = scale * _drawList.getGCForce(i)[j];
737  }
738  _drawArrow(floatPos, floatForce, .005, .015, .04);
739  }
740  glPopAttrib();
741  glDisable(GL_BLEND);
742 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
const std::vector< double > & getGCPos(size_t idx)
Definition: DrawList.h:265
const size_t & getTotalNumGC()
Definition: DrawList.h:264
void _drawArrow(ArrowVisualization &arrow)
Definition: Graphics3D.cpp:835
const std::vector< double > & getGCForce(size_t idx)
Definition: DrawList.h:266
DrawList _drawList
Definition: Graphics3D.h:49
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_DrawContactPoint ( )
private

Definition at line 744 of file Graphics3D.cpp.

References _drawList, f(), DrawList::getGCPos(), and DrawList::getTotalNumGC().

744  {
745  glPointSize(5);
746 
747  glPushAttrib(GL_COLOR_BUFFER_BIT);
748  glEnable(GL_BLEND);
749  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
750 
751  for (size_t i(0); i < _drawList.getTotalNumGC(); ++i) {
752  glBegin(GL_POINTS);
753  glColor4f(0.8f, 0.0f, 0.1f, 0.3f);
754 
755  glVertex3f(_drawList.getGCPos(i)[0], _drawList.getGCPos(i)[1],
756  _drawList.getGCPos(i)[2]);
757 
758  glEnd();
759  }
760  glPopAttrib();
761  glDisable(GL_BLEND);
762 }
const std::vector< double > & getGCPos(size_t idx)
Definition: DrawList.h:265
const size_t & getTotalNumGC()
Definition: DrawList.h:264
DrawList _drawList
Definition: Graphics3D.h:49
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_drawSphere ( SphereVisualization sphere)
private

Definition at line 799 of file Graphics3D.cpp.

References _setColor(), _translate(), SphereVisualization::color, SphereVisualization::position, and SphereVisualization::radius.

799  {
800  static GLUquadric *quad = gluNewQuadric();
801  glPushMatrix();
802  _translate(sphere.position);
803  _setColor(sphere.color);
804  gluSphere(quad, sphere.radius, 16, 16);
805  glPopMatrix();
806 }
void _translate(const Vec3< float > &position)
Definition: Graphics3D.h:101
void _setColor(const Vec4< float > &color)
Definition: Graphics3D.h:98
Vec3< float > position

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_MeshObstacleDrawing ( )
private

Definition at line 519 of file Graphics3D.cpp.

References _cameraMatrix, _drawList, f(), DrawList::getGridSize(), getHeightColor(), DrawList::getHeightMap(), DrawList::getHeightMapLeftCorner(), DrawList::getHeightMapMax(), and DrawList::getHeightMapMin().

519  {
520  glLoadMatrixf(_cameraMatrix.data());
521  glPushAttrib(GL_LIGHTING_BIT);
522  glDisable(GL_LIGHTING);
523 
524  glPushMatrix();
525  glTranslatef(_drawList.getHeightMapLeftCorner()[0],
528 
529  double height_min = _drawList.getHeightMapMax();
530  double height_max = _drawList.getHeightMapMin();
531  double height_gap = height_max - height_min;
532  double scaled_height(0.);
533 
534  float color_r(0.f);
535  float color_g(0.f);
536  float color_b(0.f);
537 
538  double grid_size(_drawList.getGridSize());
539  double height;
540  for (int i(0); i < _drawList.getHeightMap().rows(); ++i) {
541  glBegin(GL_LINE_STRIP);
542  glPushAttrib(GL_COLOR_BUFFER_BIT);
543  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
544 
545  for (int j(0); j < _drawList.getHeightMap().cols(); ++j) {
546  height = _drawList.getHeightMap()(i, j);
547  scaled_height = (height - height_min) / height_gap;
548  getHeightColor(scaled_height, color_r, color_g, color_b);
549  glColor4f(color_r, color_g, color_b, 1.0f);
550  glVertex3d(i * grid_size, j * grid_size, height);
551  }
552  glPopAttrib();
553  glDisable(GL_BLEND);
554  glEnd();
555  }
556  for (int j(0); j < _drawList.getHeightMap().cols(); ++j) {
557  glBegin(GL_LINE_STRIP);
558  glPushAttrib(GL_COLOR_BUFFER_BIT);
559  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
560 
561  for (int i(0); i < _drawList.getHeightMap().rows(); ++i) {
562  height = _drawList.getHeightMap()(i, j);
563  scaled_height = (height - height_min) / height_gap;
564  getHeightColor(scaled_height, color_r, color_g, color_b);
565  glColor4f(color_r, color_g, color_b, 1.0f);
566  glVertex3d(i * grid_size, j * grid_size, height);
567  }
568  glPopAttrib();
569  glDisable(GL_BLEND);
570  glEnd();
571  }
572  glPopMatrix();
573  glEnable(GL_LIGHTING);
574  glPopAttrib();
575 }
void getHeightColor(const double &height, float &r, float &g, float &b)
Definition: Graphics3D.cpp:577
const Vec3< double > & getHeightMapLeftCorner()
Definition: DrawList.h:270
const double & getHeightMapMax()
Definition: DrawList.h:273
QMatrix4x4 _cameraMatrix
Definition: Graphics3D.h:145
const double & getGridSize()
Definition: DrawList.h:275
const DMat< double > & getHeightMap()
Definition: DrawList.h:269
DrawList _drawList
Definition: Graphics3D.h:49
const double & getHeightMapMin()
Definition: DrawList.h:274
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_rotateZtoDirection ( const Vec3< float > &  direction)
private

Definition at line 764 of file Graphics3D.cpp.

References ori::rad2deg().

764  {
765  float len = direction.norm();
766  float dxn = direction(0) / len;
767  float dyn = direction(1) / len;
768  float dzn = direction(2) / len;
769 
770  // Note: We need to create a rotation such that the z-axis points in the
771  // direction of the 'direction' argument
772  // Thus, we can realize the rotation with a pure x-y axial rotation
773  // The rotation matrix of the rotated frame 'r' to the current frame 'c'
774  // (c_R_r) has special form. It's 3-rd column in particular has form: [
775  // wy*sin(theta) -wx*sin(theta) (1- cos(theta))]' where theta , [wx wy
776  // 0] is the angle, axis of rotation
777 
778  // Find the rotation angle by comparing the z-axis of the current and rotated
779  // frame
780  const double cosTheta = dzn;
781  const double theta = acos(cosTheta);
782  const double sinTheta = sin(theta);
783 
784  // Exploit the special form of the rotation matrix (explained above) for find
785  // the axis of rotation
786  float rX, rY, rZ;
787  if (theta > 0) {
788  rX = -dyn / sinTheta;
789  rY = dxn / sinTheta;
790  rZ = 0;
791  } else {
792  rX = 0;
793  rY = 0;
794  rZ = 1;
795  }
796  glRotatef(ori::rad2deg(theta), rX, rY, rZ);
797 }
T rad2deg(T rad)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::_setColor ( const Vec4< float > &  color)
inlineprivate

Definition at line 98 of file Graphics3D.h.

98  {
99  glColor4f(color(0), color(1), color(2), color(3));
100  }

+ Here is the caller graph for this function:

void Graphics3D::_SetRGBHeight ( const double &  h,
const double &  step,
const int &  idx,
float &  r,
float &  g,
float &  b 
)
private

Definition at line 603 of file Graphics3D.cpp.

References _b, _g, and _r.

604  {
605  double grade = (h - idx * step) / step;
606  r = (_r[idx + 1] - _r[idx]) * grade + _r[idx];
607  g = (_g[idx + 1] - _g[idx]) * grade + _g[idx];
608  b = (_b[idx + 1] - _b[idx]) * grade + _b[idx];
609 }
float _g[8]
Definition: Graphics3D.h:159
float _r[8]
Definition: Graphics3D.h:158
float _b[8]
Definition: Graphics3D.h:160

+ Here is the caller graph for this function:

void Graphics3D::_translate ( const Vec3< float > &  position)
inlineprivate

Definition at line 101 of file Graphics3D.h.

References _drawArrow().

101  {
102  glTranslatef(position(0), position(1), position(2));
103  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::configOpenGLPass ( int  pass)
private

Definition at line 437 of file Graphics3D.cpp.

437  {
438  switch (pass) {
439  case 0:
440  // clear screen
441  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
442 
443  // update camera math
444 
445  glDisable(GL_CULL_FACE);
446 
447  glEnable(GL_BLEND);
448  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
449  glEnable(GL_DEPTH_TEST);
450  glDepthFunc(GL_LESS);
451  break;
452  case 1:
453  glEnable(GL_CULL_FACE);
454  glCullFace(GL_FRONT);
455  glDepthFunc(GL_ALWAYS);
456  break;
457  case 2:
458  glEnable(GL_CULL_FACE);
459  glCullFace(GL_FRONT);
460  glDepthFunc(GL_LEQUAL);
461  break;
462  case 3:
463  glEnable(GL_CULL_FACE);
464  glCullFace(GL_BACK);
465  glDepthFunc(GL_ALWAYS);
466  break;
467  case 4:
468  glDisable(GL_CULL_FACE);
469  glDepthFunc(GL_LEQUAL);
470  break;
471 
472  default:
473  assert(false);
474  }
475 }

+ Here is the caller graph for this function:

GamepadCommand& Graphics3D::getDriverCommand ( )
inline

Definition at line 52 of file Graphics3D.h.

References _driverCommand.

52 { return _driverCommand; }
GamepadCommand _driverCommand
Definition: Graphics3D.h:81

+ Here is the caller graph for this function:

void Graphics3D::getHeightColor ( const double &  height,
float &  r,
float &  g,
float &  b 
)
private

Definition at line 577 of file Graphics3D.cpp.

References _SetRGBHeight().

577  {
578  // 0 : 0.2422 0.1504 0.6603
579  // 1/7: 0.2810 0.3228 0.9579
580  // 2/7: 0.1786 0.5289 0.9682
581  // 3/7: 0.0689 0.6948 0.8394
582  // 4/7: 0.2161 0.7843 0.5923
583  // 5/7: 0.6720 0.7793 0.2227
584  // 6/7: 0.9970 0.7659 0.2199
585  // 1: 0.9769 0.9839 0.0805
586  double step(1. / 7.);
587  if (h > 6 * step) {
588  _SetRGBHeight(h, step, 6, r, g, b);
589  } else if (h > 5 * step) {
590  _SetRGBHeight(h, step, 5, r, g, b);
591  } else if (h > 4 * step) {
592  _SetRGBHeight(h, step, 4, r, g, b);
593  } else if (h > 3 * step) {
594  _SetRGBHeight(h, step, 3, r, g, b);
595  } else if (h > 2 * step) {
596  _SetRGBHeight(h, step, 2, r, g, b);
597  } else if (h > 1 * step) {
598  _SetRGBHeight(h, step, 1, r, g, b);
599  } else {
600  _SetRGBHeight(h, step, 0, r, g, b);
601  }
602 }
void _SetRGBHeight(const double &h, const double &step, const int &idx, float &r, float &g, float &b)
Definition: Graphics3D.cpp:603

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::initializeGL ( )
overrideprotected

Definition at line 167 of file Graphics3D.cpp.

References _cameraTarget, _colAttrColorArray, _colAttrSolidColor, _colorArrayProgram, _colUniformSolidColor, _matrixUniformColorArray, _matrixUniformSolidColor, _normAttrColorArray, _normAttrSolidColor, _posAttrColorArray, _posAttrSolidColor, _solidColorProgram, clearColor, f(), fragmentShaderSource, vertexShaderSourceColorArray, and vertexShaderSourceSolidColor.

167  {
168  std::cout << "[Graphics3D] Initialize OpenGL...\n";
169  _cameraTarget.setZero();
170  initializeOpenGLFunctions();
171  // create GPU shaders
172  _colorArrayProgram = new QOpenGLShaderProgram(this);
173  _colorArrayProgram->addShaderFromSourceCode(QOpenGLShader::Vertex,
175  _colorArrayProgram->addShaderFromSourceCode(QOpenGLShader::Fragment,
177  _colorArrayProgram->link();
178 
179  _solidColorProgram = new QOpenGLShaderProgram(this);
180  _solidColorProgram->addShaderFromSourceCode(QOpenGLShader::Vertex,
182  _solidColorProgram->addShaderFromSourceCode(QOpenGLShader::Fragment,
184  _solidColorProgram->link();
185 
186  // setup attributes/uniforms (inputs to shaders)
187  _posAttrColorArray = (GLuint)_colorArrayProgram->attributeLocation("posAttr");
188  _colAttrColorArray = (GLuint)_colorArrayProgram->attributeLocation("colAttr");
190  (GLuint)_colorArrayProgram->attributeLocation("normAttr");
192  (GLuint)_colorArrayProgram->uniformLocation("matrix");
193 
194  _posAttrSolidColor = (GLuint)_solidColorProgram->attributeLocation("posAttr");
196  (GLuint)_solidColorProgram->uniformLocation("colUniform");
197  _colAttrSolidColor = (GLuint)_solidColorProgram->attributeLocation("colAttr");
199  (GLuint)_solidColorProgram->attributeLocation("normAttr");
200  _normAttrSolidColor = (GLuint)_solidColorProgram->uniformLocation("matrix");
201 
202  // set clear color:
203  glClearColor(clearColor[0], clearColor[1], clearColor[2], 0.f);
204 }
static constexpr char fragmentShaderSource[]
Definition: Graphics3D.cpp:57
static constexpr char vertexShaderSourceSolidColor[]
Definition: Graphics3D.cpp:38
GLuint _colUniformSolidColor
Definition: Graphics3D.h:115
QOpenGLShaderProgram * _solidColorProgram
Definition: Graphics3D.h:124
GLuint _normAttrColorArray
Definition: Graphics3D.h:112
QOpenGLShaderProgram * _colorArrayProgram
Definition: Graphics3D.h:123
static constexpr char vertexShaderSourceColorArray[]
Definition: Graphics3D.cpp:19
GLuint _colAttrColorArray
Definition: Graphics3D.h:110
GLuint _colAttrSolidColor
Definition: Graphics3D.h:116
static constexpr auto clearColor
Definition: Graphics3D.cpp:16
Vec3< double > _cameraTarget
Definition: Graphics3D.h:147
GLuint _matrixUniformSolidColor
Definition: Graphics3D.h:117
GLuint _posAttrColorArray
Definition: Graphics3D.h:109
GLuint _posAttrSolidColor
Definition: Graphics3D.h:114
GLuint _normAttrSolidColor
Definition: Graphics3D.h:118
MX f(const MX &x, const MX &u)
GLuint _matrixUniformColorArray
Definition: Graphics3D.h:111

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Graphics3D::IsPaused ( )
inline

Definition at line 56 of file Graphics3D.h.

References _pause.

56 { return _pause; }
bool _pause
Definition: Graphics3D.h:166

+ Here is the caller graph for this function:

void Graphics3D::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Definition at line 238 of file Graphics3D.cpp.

References _arrowsPressed, _freeCamMove, _freeCamPos, _pause, _rx, _ry, _targetSpeed, and _turbo.

238  {
239  if (e->key() == Qt::Key_Control) {
240  _targetSpeed *= .5f;
241  } else if (e->key() == Qt::Key_Shift) {
242  _targetSpeed *= 2.f;
243  }
244  if (e->key() == Qt::Key_W)
246  else if (e->key() == Qt::Key_S)
248 
249  if (e->key() == Qt::Key_A)
251  else if (e->key() == Qt::Key_D)
253 
254  if (e->key() == Qt::Key_R)
256  else if (e->key() == Qt::Key_F)
258 
259  if (e->key() == Qt::Key_Up)
260  _arrowsPressed[0] = true;
261  else if (e->key() == Qt::Key_Down)
262  _arrowsPressed[1] = true;
263 
264  if (e->key() == Qt::Key_Right)
265  _arrowsPressed[2] = true;
266  else if (e->key() == Qt::Key_Left)
267  _arrowsPressed[3] = true;
268 
269  if (e->key() == Qt::Key_V) {
270  if (_pause)
271  _pause = false;
272  else
273  _pause = true;
274  }
275 
276  if(e->key() == Qt::Key_T) {
277  _turbo = true;
278  }
279 
280  if (e->key() == Qt::Key_Tab) {
281  _freeCamPos[0] = 0.f;
282  _freeCamPos[1] = 0.f;
283  _freeCamPos[2] = 0.f;
284  _rx = 0.f;
285  _ry = 0.f;
286  }
287 }
bool _arrowsPressed[4]
Definition: Graphics3D.h:154
bool _turbo
Definition: Graphics3D.h:143
float _rx
Definition: Graphics3D.h:137
bool _pause
Definition: Graphics3D.h:166
float _freeCamPos[3]
Definition: Graphics3D.h:151
float _ry
Definition: Graphics3D.h:138
float _targetSpeed
Definition: Graphics3D.h:156
float _freeCamMove[3]
Definition: Graphics3D.h:150

+ Here is the caller graph for this function:

void Graphics3D::keyReleaseEvent ( QKeyEvent *  e)
overrideprotected

Definition at line 289 of file Graphics3D.cpp.

References _arrowsPressed, _freeCamMove, _rotOrig, _targetSpeed, and _turbo.

289  {
290  if (e->key() == Qt::Key_Control) {
291  _targetSpeed /= .5f;
292  } else if (e->key() == Qt::Key_Shift) {
293  _targetSpeed /= 2.f;
294  } else if (e->key() == Qt::Key_Space) {
295  _rotOrig = !_rotOrig;
296  }
297 
298  if (e->key() == Qt::Key_W)
299  _freeCamMove[2] = 0;
300  else if (e->key() == Qt::Key_S)
301  _freeCamMove[2] = 0;
302 
303  if (e->key() == Qt::Key_A)
304  _freeCamMove[0] = 0;
305  else if (e->key() == Qt::Key_D)
306  _freeCamMove[0] = 0;
307 
308  if (e->key() == Qt::Key_R)
309  _freeCamMove[1] = 0;
310  else if (e->key() == Qt::Key_F)
311  _freeCamMove[1] = 0;
312 
313  if (e->key() == Qt::Key_Up)
314  _arrowsPressed[0] = false;
315  else if (e->key() == Qt::Key_Down)
316  _arrowsPressed[1] = false;
317 
318  if (e->key() == Qt::Key_Right)
319  _arrowsPressed[2] = false;
320  else if (e->key() == Qt::Key_Left)
321  _arrowsPressed[3] = false;
322 
323  if(e->key() == Qt::Key_T) {
324  _turbo = false;
325  }
326 }
bool _arrowsPressed[4]
Definition: Graphics3D.h:154
bool _turbo
Definition: Graphics3D.h:143
bool _rotOrig
Definition: Graphics3D.h:142
float _targetSpeed
Definition: Graphics3D.h:156
float _freeCamMove[3]
Definition: Graphics3D.h:150

+ Here is the caller graph for this function:

void Graphics3D::lockGfxMutex ( )
inline

Definition at line 43 of file Graphics3D.h.

References _gfxMutex.

43 { _gfxMutex.lock(); }
std::mutex _gfxMutex
Definition: Graphics3D.h:83

+ Here is the caller graph for this function:

void Graphics3D::mouseMoveEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 218 of file Graphics3D.cpp.

References _orbiting, _orbiting_x_start, _orbiting_y_start, _pixel_to_rad, _rx, _rx_base, _ry, and _ry_base.

218  {
219  if (!_orbiting) return;
220  _rx = _rx_base + _pixel_to_rad * (event->pos().x() - _orbiting_x_start);
221  _ry = _ry_base + _pixel_to_rad * (event->pos().y() - _orbiting_y_start);
222 }
float _ry_base
Definition: Graphics3D.h:136
int _orbiting_x_start
Definition: Graphics3D.h:133
float _rx
Definition: Graphics3D.h:137
float _pixel_to_rad
Definition: Graphics3D.h:139
bool _orbiting
Definition: Graphics3D.h:132
float _ry
Definition: Graphics3D.h:138
float _rx_base
Definition: Graphics3D.h:135
int _orbiting_y_start
Definition: Graphics3D.h:134

+ Here is the caller graph for this function:

void Graphics3D::mousePressEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 210 of file Graphics3D.cpp.

References _orbiting, _orbiting_x_start, _orbiting_y_start, _rx, _rx_base, _ry, and _ry_base.

210  {
211  _orbiting = true;
212  _orbiting_x_start = event->pos().x();
213  _orbiting_y_start = event->pos().y();
214  _rx_base = _rx;
215  _ry_base = _ry;
216 }
float _ry_base
Definition: Graphics3D.h:136
int _orbiting_x_start
Definition: Graphics3D.h:133
float _rx
Definition: Graphics3D.h:137
bool _orbiting
Definition: Graphics3D.h:132
float _ry
Definition: Graphics3D.h:138
float _rx_base
Definition: Graphics3D.h:135
int _orbiting_y_start
Definition: Graphics3D.h:134

+ Here is the caller graph for this function:

void Graphics3D::mouseReleaseEvent ( QMouseEvent *  event)
overrideprotected

Definition at line 224 of file Graphics3D.cpp.

References _orbiting, _orbiting_x_start, _orbiting_y_start, _pixel_to_rad, _rx_base, and _ry_base.

224  {
225  _orbiting = false;
226  _rx_base = _rx_base + _pixel_to_rad * (event->pos().x() - _orbiting_x_start);
227  _ry_base = _ry_base + _pixel_to_rad * (event->pos().y() - _orbiting_y_start);
228 }
float _ry_base
Definition: Graphics3D.h:136
int _orbiting_x_start
Definition: Graphics3D.h:133
float _pixel_to_rad
Definition: Graphics3D.h:139
bool _orbiting
Definition: Graphics3D.h:132
float _rx_base
Definition: Graphics3D.h:135
int _orbiting_y_start
Definition: Graphics3D.h:134

+ Here is the caller graph for this function:

void Graphics3D::paintGL ( )
overrideprotected

Definition at line 477 of file Graphics3D.cpp.

References _Additional_Drawing(), _animating, _BoxObstacleDrawing(), _driverCommand, _fps, _frame, _gameController, _MeshObstacleDrawing(), configOpenGLPass(), infoString, last_frame_ms, renderDrawlist(), updateCameraMatrix(), and GameController::updateGamepadCommand().

477  {
478  // update joystick:
480  if (!_animating) return;
481  if (_frame % 60 == 0) {
482  qint64 now = QDateTime::currentMSecsSinceEpoch();
483  _fps = (60.f * 1000.f / (now - last_frame_ms));
484  // std::cout << "FPS: " << _fps << "\n";
485  last_frame_ms = now;
486  }
487  QPainter painter2(this);
489 
490  int passes[] = {0, 1, 2, 3, 4};
491  for (int pass : passes) {
492  // setup pass:
493  glShadeModel(GL_SMOOTH);
494  configOpenGLPass(pass);
495 
496  // do rendering on all passes:
497  glEnable(GL_BLEND);
498  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
499  renderDrawlist();
500  _Additional_Drawing(pass);
502  }
503 
505 
506  glDisable(GL_DEPTH_TEST);
507  painter2.setPen(QColor(100, 100, 100, 255));
508  painter2.fillRect(QRect(30, 30, 400, 200), QColor(100, 100, 100, 220));
509  QFont font("Monospace", 20);
510  painter2.setPen(QColor(210, 100, 100));
511  painter2.setFont(font);
512  painter2.drawText(QRect(30, 30, 1000, 1000), Qt::AlignLeft,
513  QString(infoString));
514  painter2.end();
515 
516  ++_frame;
517 }
void updateGamepadCommand(GamepadCommand &gamepadCommand)
void renderDrawlist()
Definition: Graphics3D.cpp:333
GameController _gameController
Definition: Graphics3D.h:80
void updateCameraMatrix()
Definition: Graphics3D.cpp:128
void _Additional_Drawing(int pass)
Definition: Graphics3D.cpp:679
void configOpenGLPass(int pass)
Definition: Graphics3D.cpp:437
GamepadCommand _driverCommand
Definition: Graphics3D.h:81
void _MeshObstacleDrawing()
Definition: Graphics3D.cpp:519
qint64 last_frame_ms
Definition: Graphics3D.h:129
void _BoxObstacleDrawing()
Definition: Graphics3D.cpp:611
bool _animating
Definition: Graphics3D.h:106
char infoString[200]
Definition: Graphics3D.h:50
double _fps
Definition: Graphics3D.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::renderDrawlist ( )
private

Definition at line 333 of file Graphics3D.cpp.

References _buffID, _cameraMatrix, _colAttrColorArray, _colAttrSolidColor, _colorArrayProgram, _colUniformSolidColor, _drawList, DrawList::_instanceColor, _matrixUniformColorArray, _matrixUniformSolidColor, _normAttrColorArray, _normAttrSolidColor, _posAttrColorArray, _posAttrSolidColor, _solidColorProgram, DrawList::getColorArray(), DrawList::getGLDataSizeMB(), DrawList::getGLDrawArrayOffset(), DrawList::getGLDrawArraySize(), DrawList::getModelBaseTransform(), DrawList::getModelKinematicTransform(), DrawList::getNormalArray(), DrawList::getNumObjectsToDraw(), DrawList::getSizeOfAllData(), DrawList::getVertexArray(), and DrawList::needsReload().

333  {
334  // reload if needed
335  if (_drawList.needsReload()) {
336  // upload data
337 
338  glDisableVertexAttribArray(2);
339  glDisableVertexAttribArray(1);
340  glDisableVertexAttribArray(0);
341 
342  glGenBuffers(3, _buffID);
343 
344  glBindBuffer(GL_ARRAY_BUFFER, _buffID[0]);
345  glBufferData(GL_ARRAY_BUFFER, sizeof(float) * _drawList.getSizeOfAllData(),
346  _drawList.getVertexArray(), GL_STATIC_DRAW);
347  glVertexAttribPointer(_posAttrColorArray, 3, GL_FLOAT, GL_FALSE, 0, 0);
348 
349  glBindBuffer(GL_ARRAY_BUFFER, _buffID[1]);
350  glBufferData(GL_ARRAY_BUFFER, sizeof(float) * _drawList.getSizeOfAllData(),
351  _drawList.getColorArray(), GL_STATIC_DRAW);
352  glVertexAttribPointer(_colAttrColorArray, 3, GL_FLOAT, GL_FALSE, 0, 0);
353 
354  glBindBuffer(GL_ARRAY_BUFFER, _buffID[2]);
355  glBufferData(GL_ARRAY_BUFFER, sizeof(float) * _drawList.getSizeOfAllData(),
356  _drawList.getNormalArray(), GL_STATIC_DRAW);
357  glVertexAttribPointer(_normAttrColorArray, 3, GL_FLOAT, GL_FALSE, 0, 0);
358 
359  glEnableVertexAttribArray(0);
360  glEnableVertexAttribArray(1);
361  glEnableVertexAttribArray(2);
362  printf("[Graphics 3D] Uploaded data (%f MB)\n",
364  glBindBuffer(GL_ARRAY_BUFFER, 0);
365  }
366 
367  // draw objects with color arrays
368  _colorArrayProgram->bind();
369 
370  glBindBuffer(GL_ARRAY_BUFFER, _buffID[0]);
371  glVertexAttribPointer(_posAttrColorArray, 3, GL_FLOAT, GL_FALSE, 0, 0);
372  glBindBuffer(GL_ARRAY_BUFFER, _buffID[1]);
373  glVertexAttribPointer(_colAttrColorArray, 3, GL_FLOAT, GL_FALSE, 0, 0);
374  glBindBuffer(GL_ARRAY_BUFFER, _buffID[2]);
375  glVertexAttribPointer(_normAttrColorArray, 3, GL_FLOAT, GL_FALSE, 0, 0);
376  glEnableVertexAttribArray(0);
377  glEnableVertexAttribArray(1);
378  glEnableVertexAttribArray(2);
379 
380  for (size_t id = 0; id < _drawList.getNumObjectsToDraw(); id++) {
381  if (_drawList._instanceColor[id].useSolidColor) {
382  } else {
383  _colorArrayProgram->setUniformValue(
387 
388  glDrawArrays(GL_TRIANGLES, _drawList.getGLDrawArrayOffset(id) / 3,
389  _drawList.getGLDrawArraySize(id) / 3);
390  }
391  }
392  glDisableVertexAttribArray(2);
393  glDisableVertexAttribArray(1);
394  glDisableVertexAttribArray(0);
395 
396  glBindBuffer(GL_ARRAY_BUFFER, 0);
397 
398  _colorArrayProgram->release();
399 
400  // draw objects without color arrays
401  _solidColorProgram->bind();
402 
403  glBindBuffer(GL_ARRAY_BUFFER, _buffID[0]);
404  glVertexAttribPointer(_posAttrSolidColor, 3, GL_FLOAT, GL_FALSE, 0, 0);
405  glBindBuffer(GL_ARRAY_BUFFER, _buffID[1]);
406  glVertexAttribPointer(_colAttrSolidColor, 3, GL_FLOAT, GL_FALSE, 0, 0);
407  glBindBuffer(GL_ARRAY_BUFFER, _buffID[2]);
408  glVertexAttribPointer(_normAttrSolidColor, 3, GL_FLOAT, GL_FALSE, 0, 0);
409  glEnableVertexAttribArray(0);
410  glEnableVertexAttribArray(1);
411  glEnableVertexAttribArray(2);
412  for (size_t id = 0; id < _drawList.getNumObjectsToDraw(); id++) {
413  if (_drawList._instanceColor[id].useSolidColor) {
414  _solidColorProgram->setUniformValue(
418  auto &col = _drawList._instanceColor[id];
419  _solidColorProgram->setUniformValue(
421  QVector4D(col.rgba[0], col.rgba[1], col.rgba[2], col.rgba[3]));
422 
423  glDrawArrays(GL_TRIANGLES, _drawList.getGLDrawArrayOffset(id) / 3,
424  _drawList.getGLDrawArraySize(id) / 3);
425  } else {
426  }
427  }
428  glDisableVertexAttribArray(2);
429  glDisableVertexAttribArray(1);
430  glDisableVertexAttribArray(0);
431 
432  glBindBuffer(GL_ARRAY_BUFFER, 0);
433 
434  _solidColorProgram->release();
435 }
float getGLDataSizeMB()
Definition: DrawList.h:142
float * getNormalArray()
Definition: DrawList.h:114
GLuint _colUniformSolidColor
Definition: Graphics3D.h:115
QOpenGLShaderProgram * _solidColorProgram
Definition: Graphics3D.h:124
GLuint _normAttrColorArray
Definition: Graphics3D.h:112
GLuint _buffID[3]
Definition: Graphics3D.h:120
float * getColorArray()
Definition: DrawList.h:121
vectorAligned< SolidColor > _instanceColor
Definition: DrawList.h:278
QOpenGLShaderProgram * _colorArrayProgram
Definition: Graphics3D.h:123
GLuint _colAttrColorArray
Definition: Graphics3D.h:110
size_t getSizeOfAllData()
Definition: DrawList.h:116
size_t getNumObjectsToDraw()
Definition: DrawList.h:85
QMatrix4x4 & getModelKinematicTransform(size_t i)
Definition: DrawList.h:134
GLuint _colAttrSolidColor
Definition: Graphics3D.h:116
float * getVertexArray()
Definition: DrawList.h:108
QMatrix4x4 _cameraMatrix
Definition: Graphics3D.h:145
size_t getGLDrawArraySize(size_t i)
Definition: DrawList.h:100
bool needsReload()
Definition: DrawList.h:153
size_t getGLDrawArrayOffset(size_t i)
Definition: DrawList.h:93
GLuint _matrixUniformSolidColor
Definition: Graphics3D.h:117
QMatrix4x4 & getModelBaseTransform(size_t i)
Definition: DrawList.h:128
GLuint _posAttrColorArray
Definition: Graphics3D.h:109
GLuint _posAttrSolidColor
Definition: Graphics3D.h:114
GLuint _normAttrSolidColor
Definition: Graphics3D.h:118
DrawList _drawList
Definition: Graphics3D.h:49
GLuint _matrixUniformColorArray
Definition: Graphics3D.h:111

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::resetGameController ( )
inline

Definition at line 54 of file Graphics3D.h.

References _gameController, and GameController::findNewController().

GameController _gameController
Definition: Graphics3D.h:80
void findNewController()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::setAnimating ( bool  animating)

Enable and disable animation

Definition at line 331 of file Graphics3D.cpp.

References _animating.

331 { _animating = animating; }
bool _animating
Definition: Graphics3D.h:106

+ Here is the caller graph for this function:

size_t Graphics3D::setupCheetah3 ( Vec4< float >  color,
bool  useOld 
)

Configure the window for displaying cheetah 3

Definition at line 117 of file Graphics3D.cpp.

References _drawList, and DrawList::addCheetah3().

117 { return _drawList.addCheetah3(color, useOld); }
size_t addCheetah3(Vec4< float > color, bool useOld)
Definition: DrawList.cpp:48
DrawList _drawList
Definition: Graphics3D.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t Graphics3D::setupMiniCheetah ( Vec4< float >  color,
bool  useOld 
)

Configure the window for displaying mini cheetah

Definition at line 122 of file Graphics3D.cpp.

References _drawList, and DrawList::addMiniCheetah().

122 { return _drawList.addMiniCheetah(color, useOld); }
size_t addMiniCheetah(Vec4< float > color, bool useOld)
Definition: DrawList.cpp:129
DrawList _drawList
Definition: Graphics3D.h:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::unlockGfxMutex ( )
inline

Definition at line 45 of file Graphics3D.h.

References _gfxMutex.

45 { _gfxMutex.unlock(); }
std::mutex _gfxMutex
Definition: Graphics3D.h:83

+ Here is the caller graph for this function:

void Graphics3D::updateCameraMatrix ( )
private

Update the camera matrix for the current zoom/orbit

Definition at line 128 of file Graphics3D.cpp.

References _arrowsPressed, _cameraMatrix, _cameraTarget, _drawList, _frameTime, _freeCamFilter, _freeCamMove, _freeCamPos, _rotOrig, _rx, _ry, _targetSpeed, _zoom, ori::deg2rad(), f(), FirstOrderIIRFilter< T, T2 >::get(), DrawList::getCameraOrigin(), and FirstOrderIIRFilter< T, T2 >::update().

128  {
129  _cameraMatrix.setToIdentity();
130  _cameraMatrix.perspective(
131  60.f, float(size().width()) / float(size().height()), .001f, 50.f);
132 
133  if (_arrowsPressed[0]) _ry -= _targetSpeed / 2.f;
134  if (_arrowsPressed[1]) _ry += _targetSpeed / 2.f;
135  if (_arrowsPressed[2]) _rx += _targetSpeed / 2.f;
136  if (_arrowsPressed[3]) _rx -= _targetSpeed / 2.f;
137  if (!_rotOrig) {
138  _ry = coerce<float>(_ry, -180, 0);
139  // velocity in camera coordinates
140  // we want the inverse transformation (coordinateRotation goes the opposite
141  // way as QMatrix.rotate())
142  RotMat<float> R =
143  coordinateRotation<float>(CoordinateAxis::Z, deg2rad(_rx)) *
144  coordinateRotation<float>(CoordinateAxis::X, deg2rad(_ry));
146  v = R * v;
147 
148  // integrate and filter
150  for (size_t i = 0; i < 3; i++)
152 
153  // apply
154  _cameraMatrix.rotate(_ry, 1, 0, 0);
155  _cameraMatrix.rotate(_rx, 0, 0, 1);
156  _cameraMatrix.translate(_freeCamPos[0], _freeCamPos[1], _freeCamPos[2]);
157  } else {
158  _cameraMatrix.translate(0.f, 0.f, -.45f * _zoom);
159  _cameraMatrix.rotate(_ry, 1, 0, 0);
160  _cameraMatrix.rotate(_rx, 0, 0, 1);
162  _cameraMatrix.translate(-_cameraTarget[0],
163  -_cameraTarget[1], 0);
164  }
165 }
FirstOrderIIRFilter< Vec3< float >, float > _freeCamFilter
Definition: Graphics3D.h:148
bool _arrowsPressed[4]
Definition: Graphics3D.h:154
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
const Vec3< double > & getCameraOrigin()
Definition: DrawList.h:277
float _rx
Definition: Graphics3D.h:137
QMatrix4x4 _cameraMatrix
Definition: Graphics3D.h:145
T deg2rad(T deg)
float _frameTime
Definition: Graphics3D.h:152
Vec3< double > _cameraTarget
Definition: Graphics3D.h:147
float _freeCamPos[3]
Definition: Graphics3D.h:151
float _ry
Definition: Graphics3D.h:138
bool _rotOrig
Definition: Graphics3D.h:142
float _targetSpeed
Definition: Graphics3D.h:156
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
float _freeCamMove[3]
Definition: Graphics3D.h:150
DrawList _drawList
Definition: Graphics3D.h:49
float _zoom
Definition: Graphics3D.h:140
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Graphics3D::wantTurbo ( )
inline

Definition at line 57 of file Graphics3D.h.

References _turbo, initializeGL(), keyPressEvent(), keyReleaseEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), paintGL(), and wheelEvent().

57 { return _turbo; }
bool _turbo
Definition: Graphics3D.h:143

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Graphics3D::wheelEvent ( QWheelEvent *  e)
overrideprotected

Definition at line 230 of file Graphics3D.cpp.

References _zoom.

230  {
231  if (e->angleDelta().y() > 0) {
232  if (_zoom > .1) _zoom = 0.8f * _zoom;
233  } else {
234  if (_zoom < 100) _zoom = 1.2f * _zoom;
235  }
236 }
float _zoom
Definition: Graphics3D.h:140

+ Here is the caller graph for this function:

Member Data Documentation

bool Graphics3D::_animating
private

Definition at line 106 of file Graphics3D.h.

bool Graphics3D::_arrowsPressed[4] = {false, false, false, false}
private

Definition at line 154 of file Graphics3D.h.

float Graphics3D::_b[8]
private

Definition at line 160 of file Graphics3D.h.

GLuint Graphics3D::_buffID[3]
private

Definition at line 120 of file Graphics3D.h.

QMatrix4x4 Graphics3D::_cameraMatrix
private

Definition at line 145 of file Graphics3D.h.

Vec3<double> Graphics3D::_cameraTarget
private

Definition at line 147 of file Graphics3D.h.

GLuint Graphics3D::_colAttrColorArray
private

Definition at line 110 of file Graphics3D.h.

GLuint Graphics3D::_colAttrSolidColor
private

Definition at line 116 of file Graphics3D.h.

float Graphics3D::_color1[3] = {0.364784, 0.513401, 0.952230}
protected

Definition at line 75 of file Graphics3D.h.

float Graphics3D::_color2[3] = {0.553970, 0.477397, 0.628871}
protected

Definition at line 76 of file Graphics3D.h.

float Graphics3D::_color3[3] = {0.335223, 0.768230, 0.277775}
protected

Definition at line 77 of file Graphics3D.h.

QOpenGLShaderProgram* Graphics3D::_colorArrayProgram
private

Definition at line 123 of file Graphics3D.h.

GLuint Graphics3D::_colUniformSolidColor
private

Definition at line 115 of file Graphics3D.h.

DrawList Graphics3D::_drawList

Definition at line 49 of file Graphics3D.h.

GamepadCommand Graphics3D::_driverCommand
private

Definition at line 81 of file Graphics3D.h.

double Graphics3D::_fps = 0

Definition at line 48 of file Graphics3D.h.

int Graphics3D::_frame
private

Definition at line 127 of file Graphics3D.h.

float Graphics3D::_frameTime = 1.f / 60.f
private

Definition at line 152 of file Graphics3D.h.

FirstOrderIIRFilter<Vec3<float>, float> Graphics3D::_freeCamFilter
private

Definition at line 148 of file Graphics3D.h.

float Graphics3D::_freeCamMove[3] = {0, 0, 0}
private

Definition at line 150 of file Graphics3D.h.

float Graphics3D::_freeCamPos[3] = {0.f, 0.f, 0.f}
private

Definition at line 151 of file Graphics3D.h.

float Graphics3D::_g[8]
private

Definition at line 159 of file Graphics3D.h.

GameController Graphics3D::_gameController
private

Definition at line 80 of file Graphics3D.h.

std::mutex Graphics3D::_gfxMutex
private

Definition at line 83 of file Graphics3D.h.

GLuint Graphics3D::_matrixUniformColorArray
private

Definition at line 111 of file Graphics3D.h.

GLuint Graphics3D::_matrixUniformSolidColor
private

Definition at line 117 of file Graphics3D.h.

GLuint Graphics3D::_normAttrColorArray
private

Definition at line 112 of file Graphics3D.h.

GLuint Graphics3D::_normAttrSolidColor
private

Definition at line 118 of file Graphics3D.h.

bool Graphics3D::_orbiting = false
private

Definition at line 132 of file Graphics3D.h.

int Graphics3D::_orbiting_x_start = 0
private

Definition at line 133 of file Graphics3D.h.

int Graphics3D::_orbiting_y_start = 0
private

Definition at line 134 of file Graphics3D.h.

bool Graphics3D::_pause = false
private

Definition at line 166 of file Graphics3D.h.

float Graphics3D::_pixel_to_rad = .3f
private

Definition at line 139 of file Graphics3D.h.

GLuint Graphics3D::_posAttrColorArray
private

Definition at line 109 of file Graphics3D.h.

GLuint Graphics3D::_posAttrSolidColor
private

Definition at line 114 of file Graphics3D.h.

float Graphics3D::_r[8]
private

Definition at line 158 of file Graphics3D.h.

bool Graphics3D::_rotOrig = true
private

Definition at line 142 of file Graphics3D.h.

float Graphics3D::_rx = 0
private

Definition at line 137 of file Graphics3D.h.

float Graphics3D::_rx_base = 0
private

Definition at line 135 of file Graphics3D.h.

float Graphics3D::_ry = -34
private

Definition at line 138 of file Graphics3D.h.

float Graphics3D::_ry_base = 0
private

Definition at line 136 of file Graphics3D.h.

QOpenGLShaderProgram* Graphics3D::_solidColorProgram
private

Definition at line 124 of file Graphics3D.h.

float Graphics3D::_targetSpeed = 2
private

Definition at line 156 of file Graphics3D.h.

bool Graphics3D::_turbo = false
private

Definition at line 143 of file Graphics3D.h.

Vec3<float> Graphics3D::_v0
private

Definition at line 146 of file Graphics3D.h.

float Graphics3D::_zoom = 3.0
private

Definition at line 140 of file Graphics3D.h.

char Graphics3D::infoString[200] = ""

Definition at line 50 of file Graphics3D.h.

qint64 Graphics3D::last_frame_ms = 0
private

Definition at line 129 of file Graphics3D.h.


The documentation for this class was generated from the following files: