void MainWindow::showBodyDetails( const Creature& creature, const BodyPart& body ) { getUiInspector().lst_body_details->addItem(QString( body.getName().c_str())); getUiInspector().lst_body_details->addItem(QString( (" Mass: " + TO_STRING(body.getMass())).c_str())); getUiInspector().lst_body_details->addItem(QString( (" Torque: " + TO_STRING(body.getMaxTorque())).c_str())); getUiInspector().lst_body_details->addItem(QString( std::string(" Size").c_str())); getUiInspector().lst_body_details->addItem(QString( (" [x]: " + TO_STRING(body.getSizeX())).c_str())); getUiInspector().lst_body_details->addItem(QString( (" [y]: " + TO_STRING(body.getSizeY())).c_str())); getUiInspector().lst_body_details->addItem(QString( (" [z]: " + TO_STRING(body.getSizeZ())).c_str())); //Angles BodyPart* parent = body.getParentId() == Creature::B_NONE ? NULL : &creature.getBodyPart(body.getParentId()); if (parent) { getUiInspector().lst_body_details->addItem(QString( (" Parent: " + parent->getName()).c_str())); // getUiInspector().lst_body_details->addItem(QString(std::string(" Angles:").c_str())); // getUiInspector().lst_body_details->addItem(QString( // (" XY:" + TO_STRING( // MathUtil::getAngle(MathUtil::XY, // parent->getRigidBody()->getCenterOfMassPosition(), // body.getRigidBody()->getCenterOfMassPosition()))).c_str())); // getUiInspector().lst_body_details->addItem(QString( // (" YZ:" + TO_STRING( // MathUtil::getAngle(MathUtil::YZ, // parent->getRigidBody()->getCenterOfMassPosition(), // body.getRigidBody()->getCenterOfMassPosition()))).c_str())); // getUiInspector().lst_body_details->addItem(QString( // (" ZX:" + TO_STRING( // MathUtil::getAngle(MathUtil::ZX, // parent->getRigidBody()->getCenterOfMassPosition(), // body.getRigidBody()->getCenterOfMassPosition()))).c_str())); } }
void MainWindow::applyForce( eForceType type ) { bool play = getSimulationThread().getSimulator().isPlaying(); if (play) { pause(); } getSimulationThread().wait(); getSimulationThread().getSimulator().getLock().lockForRead(); Creature* creature = getSimulationThread().getSimulator().currentCreature(); if (creature) { if (type == FT_NONE) { for (int i = 0; i < creature->getNumberOfBodyParts(); ++i) { creature->getBodyPart(i).getRigidBody()->clearForces(); } getUiInspector().sbx_force_x->setValue(0.0); getUiInspector().sbx_force_y->setValue(0.0); getUiInspector().sbx_force_z->setValue(0.0); } else { std::vector<btRigidBody*>& bodies = getRendererThread().getRenderer().getSelectedBodyParts(); btVector3 forces(getUiInspector().sbx_force_x->value(), getUiInspector().sbx_force_y->value(), getUiInspector().sbx_force_z->value()); for (std::vector<btRigidBody*>::iterator it = bodies.begin(); it != bodies.end(); ++it) { btRigidBody* rigid_body = *it; BodyPart* body = NULL; for (int i = 0; i < creature->getNumberOfBodyParts(); ++i) { if (creature->getBodyPart(i).getRigidBody() == rigid_body) { body = &creature->getBodyPart(i); break; } } assert(body); rigid_body->activate(true); switch (type) { case FT_CENTRAL_FORCE: rigid_body->applyCentralForce(forces); break; case FT_CENTRAL_TORQUE: rigid_body->applyTorque(forces); break; case FT_IMPULSE_FORCE: rigid_body->applyCentralImpulse(forces); break; case FT_IMPULSE_TORQUE: rigid_body->applyTorqueImpulse(forces); break; case FT_RELATIVE_FORCE: break; case FT_RELATIVE_IMPULSE: rigid_body->applyImpulse(forces, btVector3(0, -body->getSizeY() / 2.0, 0)); break; case FT_EACH_STEP: // creature->setTmpValueX(forces.x()); // creature->setTmpValueY(forces.y()); // creature->setTmpValueZ(forces.z()); break; default: BDEBUG(TO_STRING(type)); assert(0); } } } } getSimulationThread().getSimulator().getLock().unlock(); if (play) { this->play(); } }