@@ -145,6 +145,10 @@ void timeStep ()
145145 TargetVelocityMotorHingeJoint &joint2 = (*(TargetVelocityMotorHingeJoint*)constraints[9 ]);
146146 joint1.setTargetAngle (currentTargetAngle);
147147 joint2.setTargetAngularVelocity (3 .5f );
148+
149+ const float currentTargetPos = 1 .5f *sin (2 .0f *TimeManager::getCurrent ()->getTime ());
150+ TargetPositionMotorSliderJoint &joint3 = (*(TargetPositionMotorSliderJoint*)constraints[12 ]);
151+ joint3.setTargetPosition (currentTargetPos);
148152 }
149153}
150154
@@ -185,7 +189,14 @@ void renderUniversalJoint(UniversalJoint &uj)
185189
186190void renderSliderJoint (SliderJoint &joint)
187191{
188- MiniGL::drawCylinder (joint.m_jointInfo .col (7 ) - joint.m_jointInfo .col (11 ), joint.m_jointInfo .col (7 ) + joint.m_jointInfo .col (11 ), jointColor, 0 .05f );
192+ MiniGL::drawSphere (joint.m_jointInfo .col (6 ), 0 .1f , jointColor);
193+ 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 );
194+ }
195+
196+ void renderTargetPositionMotorSliderJoint (TargetPositionMotorSliderJoint &joint)
197+ {
198+ MiniGL::drawSphere (joint.m_jointInfo .col (6 ), 0 .1f , jointColor);
199+ 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 );
189200}
190201
191202void renderTargetAngleMotorHingeJoint (TargetAngleMotorHingeJoint &hj)
@@ -263,6 +274,10 @@ void render ()
263274 {
264275 renderTargetVelocityMotorHingeJoint (*(TargetVelocityMotorHingeJoint*)constraints[i]);
265276 }
277+ else if (constraints[i]->getTypeId () == TargetPositionMotorSliderJoint::TYPE_ID)
278+ {
279+ renderTargetPositionMotorSliderJoint (*(TargetPositionMotorSliderJoint*)constraints[i]);
280+ }
266281 }
267282
268283 float textColor[4 ] = { 0 .0f , .2f , .4f , 1 };
@@ -273,6 +288,7 @@ void render ()
273288
274289 MiniGL::drawStrokeText (-1 .0f , -4 .0f , 1 .0f , 0 .002f , " motor hinge joint" , 17 , textColor);
275290 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);
276292
277293 MiniGL::drawTime ( TimeManager::getCurrent ()->getTime ());
278294}
@@ -294,10 +310,10 @@ void createBodyModel()
294310 SimulationModel::RigidBodyVector &rb = model.getRigidBodies ();
295311
296312 // static body
297- rb.resize (18 );
313+ rb.resize (21 );
298314 float startX = 0 .0f ;
299315 float startY = 1 .0f ;
300- for (unsigned int i = 0 ; i < 6 ; i++)
316+ for (unsigned int i = 0 ; i < 7 ; i++)
301317 {
302318 rb[3 *i] = new RigidBody ();
303319 rb[3 *i]->initBody (0 .0f ,
@@ -313,9 +329,9 @@ void createBodyModel()
313329 Eigen::Quaternionf (1 .0f , 0 .0f , 0 .0f , 0 .0f ));
314330
315331 // dynamic body
316- rb[3 *i+ 2 ] = new RigidBody ();
317- rb[3 *i+ 2 ]->initBody (1 .0f ,
318- Eigen::Vector3f (startX, startY- 0 .25f , 4 .0f ),
332+ rb[3 * i + 2 ] = new RigidBody ();
333+ rb[3 * i + 2 ]->initBody (1 .0f ,
334+ Eigen::Vector3f (startX, startY - 0 .25f , 4 .0f ),
319335 computeInertiaTensorBox (1 .0f , width, height, depth),
320336 Eigen::Quaternionf (1 .0f , 0 .0f , 0 .0f , 0 .0f ));
321337
@@ -343,12 +359,13 @@ void createBodyModel()
343359
344360 jointY -= 5 .5f ;
345361 model.addTargetAngleMotorHingeJoint (12 , 13 , Eigen::Vector3f (0 .0f , jointY, 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ));
346- ((TargetAngleMotorHingeJoint*)model.getConstraints ()[model.getConstraints ().size () - 1 ])->setMaxAngularMomentumPerStep (0 .5f );
347362 model.addTargetVelocityMotorHingeJoint (13 , 14 , Eigen::Vector3f (0 .0f , jointY, 3 .0f ), Eigen::Vector3f (0 .0f , 1 .0f , 0 .0f ));
348- ((TargetVelocityMotorHingeJoint*)model.getConstraints ()[model.getConstraints ().size () - 1 ])->setMaxAngularMomentumPerStep (25 .0f );
349-
363+
350364 model.addSliderJoint (15 , 16 , Eigen::Vector3f (4 .0f , jointY, 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ));
351365 model.addBallJoint (16 , 17 , Eigen::Vector3f (4 .25f , jointY, 3 .0f ));
366+
367+ model.addTargetPositionMotorSliderJoint (18 , 19 , Eigen::Vector3f (8 .0f , jointY, 1 .0f ), Eigen::Vector3f (1 .0f , 0 .0f , 0 .0f ));
368+ model.addBallJoint (19 , 20 , Eigen::Vector3f (8 .25f , jointY, 3 .0f ));
352369}
353370
354371void TW_CALL setTimeStep (const void *value, void *clientData)
0 commit comments