@@ -149,6 +149,12 @@ void timeStep ()
149149 const float currentTargetPos = 1 .5f *sin (2 .0f *TimeManager::getCurrent ()->getTime ());
150150 TargetPositionMotorSliderJoint &joint3 = (*(TargetPositionMotorSliderJoint*)constraints[12 ]);
151151 joint3.setTargetPosition (currentTargetPos);
152+
153+ float currentTargetVel = 0 .25f ;
154+ if (((int ) (0 .25f *TimeManager::getCurrent ()->getTime ())) % 2 == 1 )
155+ currentTargetVel = -currentTargetVel;
156+ TargetVelocityMotorSliderJoint &joint4 = (*(TargetVelocityMotorSliderJoint*)constraints[14 ]);
157+ joint4.setTargetVelocity (currentTargetVel);
152158 }
153159}
154160
@@ -199,6 +205,12 @@ void renderTargetPositionMotorSliderJoint(TargetPositionMotorSliderJoint &joint)
199205 MiniGL::drawCylinder (joint.m_jointInfo .col (7 ) - joint.m_jointInfo .col (8 ), joint.m_jointInfo .col (7 ) + joint.m_jointInfo .col (8 ), jointColor, 0 .05f );
200206}
201207
208+ void renderTargetVelocityMotorSliderJoint (TargetVelocityMotorSliderJoint &joint)
209+ {
210+ MiniGL::drawSphere (joint.m_jointInfo .col (6 ), 0 .1f , jointColor);
211+ MiniGL::drawCylinder (joint.m_jointInfo .col (7 ) - joint.m_jointInfo .col (8 ), joint.m_jointInfo .col (7 ) + joint.m_jointInfo .col (8 ), jointColor, 0 .05f );
212+ }
213+
202214void renderTargetAngleMotorHingeJoint (TargetAngleMotorHingeJoint &hj)
203215{
204216 MiniGL::drawSphere (hj.m_jointInfo .col (6 ) - 0.5 *hj.m_jointInfo .col (8 ), 0 .1f , jointColor);
@@ -278,6 +290,10 @@ void render ()
278290 {
279291 renderTargetPositionMotorSliderJoint (*(TargetPositionMotorSliderJoint*)constraints[i]);
280292 }
293+ else if (constraints[i]->getTypeId () == TargetVelocityMotorSliderJoint::TYPE_ID)
294+ {
295+ renderTargetVelocityMotorSliderJoint (*(TargetVelocityMotorSliderJoint*)constraints[i]);
296+ }
281297 }
282298
283299 float textColor[4 ] = { 0 .0f , .2f , .4f , 1 };
@@ -288,7 +304,8 @@ void render ()
288304
289305 MiniGL::drawStrokeText (-1 .0f , -4 .0f , 1 .0f , 0 .002f , " motor hinge joint" , 17 , textColor);
290306 MiniGL::drawStrokeText (3 .4f , -4 .0f , 1 .0f , 0 .002f , " slider joint" , 12 , textColor);
291- MiniGL::drawStrokeText (7 .0f , -4 .0f , 1 .0f , 0 .002f , " motor slider joint" , 18 , textColor);
307+ MiniGL::drawStrokeText (6 .6f , -4 .0f , 1 .0f , 0 .002f , " target position motor" , 21 , textColor);
308+ MiniGL::drawStrokeText (10 .6f , -4 .0f , 1 .0f , 0 .002f , " target velocity motor" , 21 , textColor);
292309
293310 MiniGL::drawTime ( TimeManager::getCurrent ()->getTime ());
294311}
@@ -310,10 +327,10 @@ void createBodyModel()
310327 SimulationModel::RigidBodyVector &rb = model.getRigidBodies ();
311328
312329 // static body
313- rb.resize (21 );
330+ rb.resize (24 );
314331 float startX = 0 .0f ;
315332 float startY = 1 .0f ;
316- for (unsigned int i = 0 ; i < 7 ; i++)
333+ for (unsigned int i = 0 ; i < 8 ; i++)
317334 {
318335 rb[3 *i] = new RigidBody ();
319336 rb[3 *i]->initBody (0 .0f ,
@@ -366,6 +383,9 @@ void createBodyModel()
366383
367384 model.addTargetPositionMotorSliderJoint (18 , 19 , Eigen::Vector3f (8 .0f , jointY, 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ));
368385 model.addBallJoint (19 , 20 , Eigen::Vector3f (8 .25f , jointY, 3 .0f ));
386+
387+ model.addTargetVelocityMotorSliderJoint (21 , 22 , Eigen::Vector3f (12 .0f , jointY, 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ));
388+ model.addBallJoint (22 , 23 , Eigen::Vector3f (12 .25f , jointY, 3 .0f ));
369389}
370390
371391void TW_CALL setTimeStep (const void *value, void *clientData)
0 commit comments