void tgCPGActuatorControl::onAttach(tgSpringCableActuator& subject) { m_controlLength = subject.getStartLength(); // tgSpringCable doesn't know about bullet anchors, so we have to cast here to get the rigid bodies std::vector<const tgBulletSpringCableAnchor*> anchors = tgCast::filter<const tgSpringCableAnchor, const tgBulletSpringCableAnchor>(subject.getSpringCable()->getAnchors()); std::size_t n = anchors.size(); assert(n >= 2); m_pFromBody = anchors[0]->attachedBody; m_pToBody = anchors[n - 1]->attachedBody; }
void tgBulletRenderer::render(const tgSpringCableActuator& mSCA) const { #ifndef BT_NO_PROFILE BT_PROFILE("tgBulletRenderer::renderString"); #endif //BT_NO_PROFILE // Fetch the btDynamicsWorld btDynamicsWorld& dynamicsWorld = tgBulletUtil::worldToDynamicsWorld(m_world); btIDebugDraw* const pDrawer = dynamicsWorld.getDebugDrawer(); const tgSpringCable* const pSpringCable = mSCA.getSpringCable(); if(pDrawer && pSpringCable) { const std::vector<const tgSpringCableAnchor*>& anchors = pSpringCable->getAnchors(); std::size_t n = anchors.size() - 1; for (std::size_t i = 0; i < n; i++) { const btVector3 lineFrom = anchors[i]->getWorldPosition(); const btVector3 lineTo = anchors[i+1]->getWorldPosition(); // Should this be normalized?? const double stretch = mSCA.getCurrentLength() - mSCA.getRestLength(); const btVector3 color = (stretch < 0.0) ? btVector3(0.0, 0.0, 1.0) : btVector3(0.5 + stretch / 3.0, 0.5 - stretch / 2.0, 0.0); pDrawer->drawLine(lineFrom, lineTo, color); } } }