21 attribute highp vec3 posAttr; // position 22 attribute lowp vec3 colAttr; // color 23 attribute highp vec3 normAttr; // normal 24 uniform highp mat4 matrix; // transformation 26 varying lowp vec4 col; // color 27 varying vec3 normal; // normal 28 varying vec3 pos_world; // position 30 col = vec4(colAttr,1); 31 gl_Position = matrix * vec4(posAttr,1); 32 normal = (matrix * vec4(normAttr,0)).xyz; 40 attribute highp vec3 posAttr; // position 41 uniform lowp vec4 colUniform; // color 42 attribute lowp vec3 colAttr; // color 43 attribute highp vec3 normAttr; // normal 44 uniform highp mat4 matrix; // transformation 46 varying lowp vec4 col; // color 47 varying vec3 normal; // normal 48 varying vec3 pos_world; // position 51 gl_Position = matrix * vec4(posAttr,1); 52 normal = (matrix * vec4(normAttr,0)).xyz; 58 varying lowp vec4 col; 59 varying vec3 pos_world; 62 vec3 light_pos = vec3(0,0,4); 63 float light_dist = length(light_pos - pos_world); 64 vec3 light_color = vec3(1,1,1); 65 vec3 mat_ambient = vec3(.1,.1,.1); 66 vec3 mat_spec = vec3(.3,.3,.3); 67 vec3 n = normalize(normal); 68 vec3 l = normalize(light_pos); 69 float angle_thing = clamp( dot(-n,l), 0., 1.); 70 gl_FragColor = col + vec4(mat_ambient*light_color*40.*angle_thing/(light_dist*light_dist),0); 78 : QOpenGLWidget(parent), 80 _colorArrayProgram(0), 83 _freeCamFilter(1, 60, _v0) { 84 std::cout << "[SIM GRAPHICS] New graphics window. \n";
131 60.
f,
float(size().width()) /
float(size().height()), .001
f, 50.
f);
138 _ry = coerce<float>(
_ry, -180, 0);
143 coordinateRotation<float>(CoordinateAxis::Z,
deg2rad(
_rx)) *
144 coordinateRotation<float>(CoordinateAxis::X,
deg2rad(_ry));
150 for (
size_t i = 0; i < 3; i++)
168 std::cout <<
"[Graphics3D] Initialize OpenGL...\n";
170 initializeOpenGLFunctions();
231 if (e->angleDelta().y() > 0) {
239 if (e->key() == Qt::Key_Control) {
241 }
else if (e->key() == Qt::Key_Shift) {
244 if (e->key() == Qt::Key_W)
246 else if (e->key() == Qt::Key_S)
249 if (e->key() == Qt::Key_A)
251 else if (e->key() == Qt::Key_D)
254 if (e->key() == Qt::Key_R)
256 else if (e->key() == Qt::Key_F)
259 if (e->key() == Qt::Key_Up)
261 else if (e->key() == Qt::Key_Down)
264 if (e->key() == Qt::Key_Right)
266 else if (e->key() == Qt::Key_Left)
269 if (e->key() == Qt::Key_V) {
276 if(e->key() == Qt::Key_T) {
280 if (e->key() == Qt::Key_Tab) {
290 if (e->key() == Qt::Key_Control) {
292 }
else if (e->key() == Qt::Key_Shift) {
294 }
else if (e->key() == Qt::Key_Space) {
298 if (e->key() == Qt::Key_W)
300 else if (e->key() == Qt::Key_S)
303 if (e->key() == Qt::Key_A)
305 else if (e->key() == Qt::Key_D)
308 if (e->key() == Qt::Key_R)
310 else if (e->key() == Qt::Key_F)
313 if (e->key() == Qt::Key_Up)
315 else if (e->key() == Qt::Key_Down)
318 if (e->key() == Qt::Key_Right)
320 else if (e->key() == Qt::Key_Left)
323 if(e->key() == Qt::Key_T) {
338 glDisableVertexAttribArray(2);
339 glDisableVertexAttribArray(1);
340 glDisableVertexAttribArray(0);
344 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[0]);
349 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[1]);
354 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[2]);
359 glEnableVertexAttribArray(0);
360 glEnableVertexAttribArray(1);
361 glEnableVertexAttribArray(2);
362 printf(
"[Graphics 3D] Uploaded data (%f MB)\n",
364 glBindBuffer(GL_ARRAY_BUFFER, 0);
370 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[0]);
372 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[1]);
374 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[2]);
376 glEnableVertexAttribArray(0);
377 glEnableVertexAttribArray(1);
378 glEnableVertexAttribArray(2);
392 glDisableVertexAttribArray(2);
393 glDisableVertexAttribArray(1);
394 glDisableVertexAttribArray(0);
396 glBindBuffer(GL_ARRAY_BUFFER, 0);
403 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[0]);
405 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[1]);
407 glBindBuffer(GL_ARRAY_BUFFER,
_buffID[2]);
409 glEnableVertexAttribArray(0);
410 glEnableVertexAttribArray(1);
411 glEnableVertexAttribArray(2);
421 QVector4D(col.rgba[0], col.rgba[1], col.rgba[2], col.rgba[3]));
428 glDisableVertexAttribArray(2);
429 glDisableVertexAttribArray(1);
430 glDisableVertexAttribArray(0);
432 glBindBuffer(GL_ARRAY_BUFFER, 0);
441 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
445 glDisable(GL_CULL_FACE);
448 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
449 glEnable(GL_DEPTH_TEST);
450 glDepthFunc(GL_LESS);
453 glEnable(GL_CULL_FACE);
454 glCullFace(GL_FRONT);
455 glDepthFunc(GL_ALWAYS);
458 glEnable(GL_CULL_FACE);
459 glCullFace(GL_FRONT);
460 glDepthFunc(GL_LEQUAL);
463 glEnable(GL_CULL_FACE);
465 glDepthFunc(GL_ALWAYS);
468 glDisable(GL_CULL_FACE);
469 glDepthFunc(GL_LEQUAL);
482 qint64 now = QDateTime::currentMSecsSinceEpoch();
487 QPainter painter2(
this);
490 int passes[] = {0, 1, 2, 3, 4};
491 for (
int pass : passes) {
493 glShadeModel(GL_SMOOTH);
498 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
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,
521 glPushAttrib(GL_LIGHTING_BIT);
522 glDisable(GL_LIGHTING);
531 double height_gap = height_max - height_min;
532 double scaled_height(0.);
541 glBegin(GL_LINE_STRIP);
542 glPushAttrib(GL_COLOR_BUFFER_BIT);
543 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
547 scaled_height = (height - height_min) / height_gap;
549 glColor4f(color_r, color_g, color_b, 1.0
f);
550 glVertex3d(i * grid_size, j * grid_size, height);
557 glBegin(GL_LINE_STRIP);
558 glPushAttrib(GL_COLOR_BUFFER_BIT);
559 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
563 scaled_height = (height - height_min) / height_gap;
565 glColor4f(color_r, color_g, color_b, 1.0
f);
566 glVertex3d(i * grid_size, j * grid_size, height);
573 glEnable(GL_LIGHTING);
586 double step(1. / 7.);
589 }
else if (h > 5 * step) {
591 }
else if (h > 4 * step) {
593 }
else if (h > 3 * step) {
595 }
else if (h > 2 * step) {
597 }
else if (h > 1 * step) {
604 const int &idx,
float &r,
float &g,
float &b) {
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];
613 glPushAttrib(GL_LIGHTING_BIT);
614 glDisable(GL_LIGHTING);
617 for (
size_t i(0); i < nBox; ++i) {
625 glEnable(GL_LIGHTING);
630 double x = depth / 2.0;
631 double y = width / 2.0;
632 double z = height / 2.0;
634 glPushAttrib(GL_COLOR_BUFFER_BIT);
637 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
643 glVertex3d(x, y, -z);
644 glVertex3d(-x, y, -z);
645 glVertex3d(-x, y, z);
648 glVertex3d(x, -y, -z);
649 glVertex3d(x, y, -z);
651 glVertex3d(x, -y, z);
653 glVertex3d(x, -y, z);
654 glVertex3d(-x, -y, z);
655 glVertex3d(-x, -y, -z);
656 glVertex3d(x, -y, -z);
658 glVertex3d(-x, -y, z);
659 glVertex3d(-x, y, z);
660 glVertex3d(-x, y, -z);
661 glVertex3d(-x, -y, -z);
663 glVertex3d(-x, -y, -z);
664 glVertex3d(-x, y, -z);
665 glVertex3d(x, y, -z);
666 glVertex3d(x, -y, -z);
668 glVertex3d(-x, -y, z);
669 glVertex3d(x, -y, z);
671 glVertex3d(-x, y, z);
681 glPushAttrib(GL_LIGHTING_BIT);
682 glDisable(GL_LIGHTING);
689 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
711 glBegin(GL_LINE_STRIP);
712 for (
size_t j = 0; j < path.
num_points; j++) {
719 glEnable(GL_LIGHTING);
725 double scale(0.0025);
727 glPushAttrib(GL_COLOR_BUFFER_BIT);
729 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
732 glColor4f(0.8
f, 0.0
f, 0.
f, 0.5
f);
734 for (
size_t j = 0; j < 3; j++) {
738 _drawArrow(floatPos, floatForce, .005, .015, .04);
747 glPushAttrib(GL_COLOR_BUFFER_BIT);
749 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
753 glColor4f(0.8
f, 0.0
f, 0.1
f, 0.3
f);
765 float len = direction.norm();
766 float dxn = direction(0) / len;
767 float dyn = direction(1) / len;
768 float dzn = direction(2) / len;
780 const double cosTheta = dzn;
781 const double theta = acos(cosTheta);
782 const double sinTheta = sin(theta);
788 rX = -dyn / sinTheta;
800 static GLUquadric *quad = gluNewQuadric();
804 gluSphere(quad, sphere.
radius, 16, 16);
809 static GLUquadric *quad = gluNewQuadric();
816 const int detail = 32;
817 gluCylinder(quad, 0, cone.
radius, len, detail, 1);
825 glRotatef(box.
rpy(2), 0, 0, 1);
826 glRotatef(box.
rpy(1), 0, 1, 0);
827 glRotatef(box.
rpy(0), 1, 0, 0);
830 glTranslatef(.5, .5, .5);
843 float headWidth,
float headLength) {
844 double len = direction.norm();
850 double cylinderLength = len;
851 if (cylinderLength > headLength) {
852 cylinderLength -= headLength;
854 headLength = cylinderLength;
858 const int detail = 32;
859 static GLUquadric *quad = gluNewQuadric();
863 gluCylinder(quad, lineWidth, lineWidth, cylinderLength, detail, 1);
866 glRotated(180, 1, 0, 0);
867 gluDisk(quad, 0, lineWidth, detail, detail);
868 glRotated(180, 1, 0, 0);
870 glTranslatef(0, 0, cylinderLength);
872 gluCylinder(quad, headWidth, 0.0
f, headLength, detail, detail);
874 glRotated(180, 1, 0, 0);
876 gluDisk(quad, lineWidth, headWidth, detail, detail);
void keyPressEvent(QKeyEvent *event) override
static constexpr char fragmentShaderSource[]
ArrowVisualization arrows[VISUALIZATION_MAX_ITEMS]
void initializeGL() override
size_t addCheetah3(Vec4< float > color, bool useOld)
VisualizationData * _visualizationData
FirstOrderIIRFilter< Vec3< float >, float > _freeCamFilter
void getHeightColor(const double &height, float &r, float &g, float &b)
Vec3< float > point_position
void updateGamepadCommand(GamepadCommand &gamepadCommand)
void keyReleaseEvent(QKeyEvent *e) override
size_t setupMiniCheetah(Vec4< float > color, bool useOld)
static constexpr char vertexShaderSourceSolidColor[]
GameController _gameController
Vec3< float > corner_position
size_t addMiniCheetah(Vec4< float > color, bool useOld)
SphereVisualization spheres[VISUALIZATION_MAX_ITEMS]
typename Eigen::Matrix< T, 3, 1 > Vec3
const Vec3< double > & getCameraOrigin()
ConeVisualization cones[VISUALIZATION_MAX_ITEMS]
void _drawBlock(BlockVisualization &box)
GLuint _colUniformSolidColor
QOpenGLShaderProgram * _solidColorProgram
GLuint _normAttrColorArray
size_t setupCheetah3(Vec4< float > color, bool useOld)
const std::vector< double > & getGCPos(size_t idx)
BlockVisualization blocks[VISUALIZATION_MAX_ITEMS]
vectorAligned< SolidColor > _instanceColor
void updateCameraMatrix()
const Vec3< double > & getHeightMapLeftCorner()
void wheelEvent(QWheelEvent *e) override
void _Additional_Drawing(int pass)
QOpenGLShaderProgram * _colorArrayProgram
void configOpenGLPass(int pass)
static constexpr char vertexShaderSourceColorArray[]
void _translate(const Vec3< float > &position)
void _rotateZtoDirection(const Vec3< float > &direction)
GLuint _colAttrColorArray
size_t getSizeOfAllData()
size_t getNumObjectsToDraw()
QMatrix4x4 & getModelKinematicTransform(size_t i)
const double & getHeightMapMax()
GLuint _colAttrSolidColor
GamepadCommand _driverCommand
const size_t & getTotalNumGC()
void mousePressEvent(QMouseEvent *event) override
typename Eigen::Matrix< T, 4, 1 > Vec4
static constexpr auto clearColor
void _MeshObstacleDrawing()
static constexpr float windows2000[]
void setAnimating(bool animating)
void mouseReleaseEvent(QMouseEvent *event) override
size_t getGLDrawArraySize(size_t i)
void _drawArrow(ArrowVisualization &arrow)
PathVisualization paths[VISUALIZATION_MAX_PATHS]
Vec3< double > _cameraTarget
void _DrawBox(double depth, double width, double height)
Vec3< float > base_position
Vec3< float > position[VISUALIZATION_MAX_PATH_POINTS]
const std::vector< BoxInfo > & getBoxInfoList()
size_t getGLDrawArrayOffset(size_t i)
void _BoxObstacleDrawing()
GLuint _matrixUniformSolidColor
const double & getGridSize()
void _setColor(const Vec4< float > &color)
void _drawSphere(SphereVisualization &sphere)
void _SetRGBHeight(const double &h, const double &step, const int &idx, float &r, float &g, float &b)
QMatrix4x4 & getModelBaseTransform(size_t i)
GLuint _posAttrColorArray
GLuint _posAttrSolidColor
GLuint _normAttrSolidColor
typename Eigen::Matrix< T, 3, 3 > RotMat
void _drawCone(ConeVisualization &cone)
const std::vector< double > & getGCForce(size_t idx)
const DMat< double > & getHeightMap()
Graphics3D(QWidget *parent=0)
void mouseMoveEvent(QMouseEvent *event) override
const double & getHeightMapMin()
Visualizer window for simulator.
MX f(const MX &x, const MX &u)
GLuint _matrixUniformColorArray