void WorldRpcInterface::respClass( const yarp::os::Bottle& command, yarp::os::Bottle& reply, int& n ) { KinematicModel::CompositeObject* object = getObject( command, reply, n ); if ( object ) { //model->clearWorldObject(object); model->removeWorldObject(object); int type = command.get(n).asVocab(); QColor collidingColor,freeColor; switch (type) { case VOCAB_OBSTACLE: freeColor = Qt::blue; freeColor = freeColor.lighter(); collidingColor = freeColor; freeColor.setAlphaF(0.5); collidingColor.setAlphaF(0.5); object->setResponseClass(model->OBSTACLE()); object->setFreeColor( freeColor ); object->setCollidingColor( collidingColor ); reply.addString("Changed object type to 'obstacle'."); break; case VOCAB_TARGET: freeColor = Qt::green; freeColor = freeColor.lighter(); collidingColor = freeColor; freeColor.setAlphaF(1.0); collidingColor.setAlphaF(0.5); object->setResponseClass(model->TARGET()); object->setFreeColor( freeColor ); object->setCollidingColor( collidingColor ); reply.addString("Changed object type to 'target'."); break; default: reply.addString("Unknown definition, use 'obs' or 'tgt'."); } model->appendObject( object ); } }
KinematicModel::CompositeObject* ObjectSoup::makeARandomObjectLikeAMothaFucka() { KinematicModel::CompositeObject* obj = new KinematicModel::CompositeObject( theModel.OBSTACLE(), theModel.OBSTACLE() ); // choose a random color for the object QColor collidingColor = QColor( qrand()%255, qrand()%255, qrand()%255, 0.5 ); QColor freeColor = collidingColor; freeColor.setAlphaF( 1.0 ); obj->setCollidingColor(collidingColor); obj->setFreeColor(freeColor); // choose a random number of primitives to append to the object 1 to 5 inclusive int numPrimitives = (qrand() % 6 + 1); if (verbose) printf( " Num Primitives: %d\n", numPrimitives); KinematicModel::PrimitiveObject* primitive; for ( int j=0; j<numPrimitives; ++j ) { // choose a random geometry type for each primitive KinematicModel::GeomType geomType = (KinematicModel::GeomType)( qrand() % ((int)KinematicModel::BOX+1) ); if (verbose) printf( " Geometry Type: %d\n", (int)geomType ); switch (geomType) { case KinematicModel::SPHERE: primitive = new KinematicModel::Sphere( (float)qrand()/RAND_MAX/10.0+0.01 ); break; case KinematicModel::CYLINDER: primitive = new KinematicModel::Cylinder( (float)qrand()/RAND_MAX/10+.01, (float)2*qrand()/RAND_MAX/10+.01 ); break; case KinematicModel::BOX: primitive = new KinematicModel::Box( QVector3D((float)qrand()/RAND_MAX/10+.01, (float)qrand()/RAND_MAX/10+.01, (float)qrand()/RAND_MAX/10+.01) ); break; default: break; } primitive->setCollidingColor( collidingColor ); primitive->setFreeColor(freeColor); primitive->translate(randomTranslation(0.1)); primitive->cartesianRotate(randomRotation()); obj->appendPrimitive(primitive); } obj->translate(randomTranslation(1.0)); primitive->cartesianRotate(randomRotation()); theModel.appendObject(obj); return obj; }