iCub-main
bvhnodedh.h
Go to the documentation of this file.
1 /*
2  * bvhnodedh.h
3  */
4 
5 /*
6  * Copyright (C) 2009 RobotCub Consortium
7  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
8  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
9  *
10  * Based on:
11  *
12  * Qavimator
13  * Copyright (C) 2006 by Zi Ree *
14  * Zi Ree @ SecondLife *
15  * Released under the terms of the GNU GPL v2.0.
16  */
17 
18 #ifndef BVHNODEDH_H
19 #define BVHNODEDH_H
20 
21 #include "bvhnode.h"
22 
23 class BVHNodeDH : public BVHNode
24 {
25 public:
26  BVHNodeDH(const QString& name,int enc,double Dx,double Dz,double Rx,double Rz0,iCubMesh* mesh=0)
27  : BVHNode(name,enc,mesh)
28  {
29  dA=Dx;
30  dD=Dz;
31  dAlpha=Rx;
32  dTheta0=Rz0;
33  }
34 
35  virtual void draw(double *encoders,BVHNode* pSelected)
36  {
37  glPushMatrix();
38 
39  glRotated(dTheta0+encoders[nEnc],0.0,0.0,1.0);
40  glTranslated(dA,0.0,dD);
41 
42  glColor4f(0.5,0.5,0.5,1.0);
43  glLineWidth(3.0);
44  glBegin(GL_LINES);
45  glVertex3d(0.0,0.0,0.0);
46  glVertex3d(-dA,0.0,-dD);
47  glEnd();
48 
49  glRotated(dAlpha,1.0,0.0,0.0);
50 
51  glColor4f(0.5,0.5,0.5,1.0);
52  drawJoint();
53 
54  if (pMesh)
55  {
56  glColor4f(0.9,0.8,0.7,m_Alpha);
57  pMesh->Draw();
58  }
59 
60  drawArrows();
61 
62  for (int i=0; i<children.count(); ++i)
63  {
64  children[i]->draw(encoders,pSelected);
65  }
66 
67  glPopMatrix();
68  }
69 
70 protected:
71  void drawArc(double dOmega)
72  {
73  static const double dRadius=80.0;
74  static const double dDeg2Rad=M_PI/180.0,dThr=4.0*dDeg2Rad,dRad2Deg=180.0/M_PI;
75 
76  if (dOmega<-dThr || dOmega>dThr)
77  {
78  double dNeg=dOmega>=0.0?1.0:-1.0;
79  double dAngle=dNeg*dOmega;
80 
81  glBegin(GL_LINE_STRIP);
82  for (double angle=-dAngle; angle<=dAngle; angle+=dDeg2Rad)
83  glVertex3d(-dRadius*cos(angle),dRadius*sin(angle),0.0);
84  glEnd();
85 
86  glRotated(dOmega*dRad2Deg,0.0,0.0,1.0);
87  glTranslated(-dRadius,0.0,0.0);
88  glRotated(dNeg*90.0,1.0,0.0,0.0);
89  glutSolidCone(7.5,30.0,16,16);
90  }
91  }
92 
93  void drawArrow(double dMag)
94  {
95  glBegin(GL_LINES);
96  glVertex3d(0.0,0.0,0.0);
97  glVertex3d(0.0,0.0,dMag);
98  glEnd();
99 
100  glTranslated(0.0,0.0,dMag);
101  glRotated(dMag<0.0?180.0:0.0,1.0,0.0,0.0);
102  glutSolidCone(7.5,30.0,16,16);
103  }
104 
105  double dA,dD,dAlpha,dTheta0;
106 };
107 
108 #endif
#define M_PI
Definition: XSensMTx.cpp:24
double dAlpha
Definition: bvhnodedh.h:105
BVHNodeDH(const QString &name, int enc, double Dx, double Dz, double Rx, double Rz0, iCubMesh *mesh=0)
Definition: bvhnodedh.h:26
double dTheta0
Definition: bvhnodedh.h:105
void drawArc(double dOmega)
Definition: bvhnodedh.h:71
void drawArrow(double dMag)
Definition: bvhnodedh.h:93
virtual void draw(double *encoders, BVHNode *pSelected)
Definition: bvhnodedh.h:35
double dD
Definition: bvhnodedh.h:105
double dA
Definition: bvhnodedh.h:105
const QString & name() const
Definition: bvhnode.h:221
float m_Alpha
Definition: bvhnode.h:288
virtual void drawJoint()
Definition: bvhnode.h:255
iCubMesh * pMesh
Definition: bvhnode.h:286
int nEnc
Definition: bvhnode.h:285
void drawArrows()
Definition: bvhnode.h:265
QList< BVHNode * > children
Definition: bvhnode.h:283
Definition: mesh.h:54
void Draw()
Definition: mesh.h:187