@@ -44,7 +44,7 @@ std::vector<unsigned int> selectedBodies;
4444Eigen::Vector3f oldMousePos;
4545float jointColor[4 ] = { 0 .0f , 0 .4f , 0 .2f , 1 .0f };
4646float dynamicBodyColor[4 ] = { 0 .1f , 0 .4f , 0 .8f , 1 };
47- float staticBodyColor[4 ] = { 0 .6f , 0 .0f , 0 .0f , 1 .0f };
47+ float staticBodyColor[4 ] = { 0 .4f , 0 .4f , 0 .4f , 1 .0f };
4848
4949// main
5050int main ( int argc, char **argv )
@@ -61,7 +61,7 @@ int main( int argc, char **argv )
6161 buildModel ();
6262
6363 MiniGL::setClientSceneFunc (render);
64- MiniGL::setViewport (40 .0f , 0 .1f , 500 .0f , Vector3f (4 .0f , -2 .5f , 15 .0f ), Vector3f (4 .0f , 0 .0f , 0 .0f ));
64+ MiniGL::setViewport (50 .0f , 0 .1f , 500 .0f , Vector3f (6 .0f , -2 .5f , 15 .0f ), Vector3f (6 .0f , 0 .0f , 0 .0f ));
6565
6666 TwAddVarRW (MiniGL::getTweakBar (), " Pause" , TW_TYPE_BOOLCPP, &doPause, " label='Pause' group=Simulation key=SPACE " );
6767 TwAddVarCB (MiniGL::getTweakBar (), " TimeStepSize" , TW_TYPE_FLOAT, setTimeStep, getTimeStep, &model, " label='Time step size' min=0.0 max = 0.1 step=0.001 precision=4 group=Simulation " );
@@ -156,9 +156,19 @@ void renderBallOnLineJoint(RigidBodyModel::BallOnLineJoint &bj)
156156
157157void renderHingeJoint (RigidBodyModel::HingeJoint &hj)
158158{
159- MiniGL::drawSphere (hj.m_jointInfo .col (2 ), 0 .1f , jointColor);
160- MiniGL::drawSphere (hj.m_jointInfo .col (9 ), 0 .1f , jointColor);
161- MiniGL::drawCylinder (hj.m_jointInfo .col (2 ), hj.m_jointInfo .col (9 ), jointColor, 0 .05f );
159+ MiniGL::drawSphere (hj.m_jointInfo .col (6 ) - 0.5 *hj.m_jointInfo .col (8 ), 0 .1f , jointColor);
160+ MiniGL::drawSphere (hj.m_jointInfo .col (6 ) + 0.5 *hj.m_jointInfo .col (8 ), 0 .1f , jointColor);
161+ MiniGL::drawCylinder (hj.m_jointInfo .col (6 ) - 0.5 *hj.m_jointInfo .col (8 ), hj.m_jointInfo .col (6 ) + 0.5 *hj.m_jointInfo .col (8 ), jointColor, 0 .05f );
162+ }
163+
164+ void renderUniversalJoint (RigidBodyModel::UniversalJoint &uj)
165+ {
166+ MiniGL::drawSphere (uj.m_jointInfo .col (4 ) - 0.5 *uj.m_jointInfo .col (6 ), 0 .1f , jointColor);
167+ MiniGL::drawSphere (uj.m_jointInfo .col (4 ) + 0.5 *uj.m_jointInfo .col (6 ), 0 .1f , jointColor);
168+ MiniGL::drawSphere (uj.m_jointInfo .col (5 ) - 0.5 *uj.m_jointInfo .col (7 ), 0 .1f , jointColor);
169+ MiniGL::drawSphere (uj.m_jointInfo .col (5 ) + 0.5 *uj.m_jointInfo .col (7 ), 0 .1f , jointColor);
170+ MiniGL::drawCylinder (uj.m_jointInfo .col (4 ) - 0.5 *uj.m_jointInfo .col (6 ), uj.m_jointInfo .col (4 ) + 0.5 *uj.m_jointInfo .col (6 ), jointColor, 0 .05f );
171+ MiniGL::drawCylinder (uj.m_jointInfo .col (5 ) - 0.5 *uj.m_jointInfo .col (7 ), uj.m_jointInfo .col (5 ) + 0.5 *uj.m_jointInfo .col (7 ), jointColor, 0 .05f );
162172}
163173
164174void render ()
@@ -206,12 +216,17 @@ void render ()
206216 {
207217 renderHingeJoint (*(RigidBodyModel::HingeJoint*) joints[i]);
208218 }
219+ else if (joints[i]->getTypeId () == RigidBodyModel::UniversalJoint::TYPE_ID)
220+ {
221+ renderUniversalJoint (*(RigidBodyModel::UniversalJoint*) joints[i]);
222+ }
209223 }
210224
211225 float textColor[4 ] = { 0 .0f , .2f , .4f , 1 };
212- MiniGL::drawStrokeText (-0 .75f , 1 .5f , 1 .0f , 0 .003f , " BallJoint" , 10 , textColor);
213- MiniGL::drawStrokeText (2 .8f , 1 .5f , 1 .0f , 0 .003f , " BallOnLineJoint" , 16 , textColor);
214- MiniGL::drawStrokeText (7 .1f , 1 .5f , 1 .0f , 0 .003f , " HingeJoint" , 11 , textColor);
226+ MiniGL::drawStrokeText (-0 .5f , 1 .5f , 1 .0f , 0 .002f , " ball joint" , 11 , textColor);
227+ MiniGL::drawStrokeText (3 .0f , 1 .5f , 1 .0f , 0 .002f , " ball-on-line joint" , 19 , textColor);
228+ MiniGL::drawStrokeText (7 .3f , 1 .5f , 1 .0f , 0 .002f , " hinge joint" , 12 , textColor);
229+ MiniGL::drawStrokeText (11 .2f , 1 .5f , 1 .0f , 0 .002f , " universal joint" , 15 , textColor);
215230
216231 MiniGL::drawTime ( TimeManager::getCurrent ()->getTime ());
217232}
@@ -234,9 +249,9 @@ void createBodyModel()
234249 RigidBodyModel::JointVector &joints = model.getJoints ();
235250
236251 // static body
237- rb.resize (9 );
252+ rb.resize (12 );
238253 float startX = 0 .0f ;
239- for (unsigned int i = 0 ; i < 3 ; i++)
254+ for (unsigned int i = 0 ; i < 4 ; i++)
240255 {
241256 rb[3 *i] = new RigidBody ();
242257 rb[3 *i]->initBody (0 .0f ,
@@ -270,6 +285,9 @@ void createBodyModel()
270285
271286 model.addHingeJoint (6 , 7 , Eigen::Vector3f (8 .0f , 0 .75f , 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ));
272287 model.addBallJoint (7 , 8 , Eigen::Vector3f (8 .25f , 0 .75f , 3 .0f ));
288+
289+ model.addUniversalJoint (9 , 10 , Eigen::Vector3f (12 .0f , 0 .75f , 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ), Eigen::Vector3f (0 .0f , 1 .0f , 0 .0f ));
290+ model.addBallJoint (10 , 11 , Eigen::Vector3f (12 .25f , 0 .75f , 3 .0f ));
273291}
274292
275293void TW_CALL setTimeStep (const void *value, void *clientData)
0 commit comments