当前位置: 首页>>代码示例>>C++>>正文


C++ Rand::scalar方法代码示例

本文整理汇总了C++中Rand::scalar方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::scalar方法的具体用法?C++ Rand::scalar怎么用?C++ Rand::scalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rand的用法示例。


在下文中一共展示了Rand::scalar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

void CtrlThread::run() {

    Bottle controlCmd;
    Bottle simCmd;
    //int objIndex  = 0;
    //int toolIndex = 0;
    double toolPose = 0.0;
    double toolDisp = 0.0;
    double toolTilt = 0.0;
    double objPosX = -0.17;
    double objPosZ = 0.45;
    NetInt32 code;


    if( (*simToolLoaderCmdInputPort).read(controlCmd, true) ) {
        code = Vocab::encode((controlCmd.get(0)).asString());

        cout << (controlCmd.get(0)).asString() << endl;

        switch(code) {
            case VOCAB3('d','e','l'):
            {
                cout << "Clear world" <<endl;

                //Clear the World:
                simCmd = simWorld.deleteAll();
                writeSim(simCmd);

                //reply to the control manager
                controlCmd.clear();
                controlCmd.addVocab(code);
                replyCmd(controlCmd);
            }
            break;

            case VOCAB3('o','b','j'):
            {
                cout << "Create table and object (on the table)." <<endl;

                //Clear the World:
                simCmd = simWorld.deleteAll();
                writeSim(simCmd);

                //Create the table:
                //simWorld.simTable->objSubIndex = 1;  //needs to be automatic, each type of object has his own subIndex
                simCmd = simWorld.simTable->makeObjectBottle(simWorld.objSubIndex, false);
                writeSim(simCmd);

                //---------------------------------------------------------------
                //Create one object:
				objIndex = controlCmd.get(1).asInt();
                if ( objIndex==100 ) {
					objIndex = rand() % simWorld.simObject.size() + 1;
				}

                Rand randG;         // YARP random number generator

                //simWorld.simObject[objIndex]->objSubIndex = 1;  //needs to be automatic, each type of object has his own subIndex
                simWorld.simObject[objIndex]->setObjectPosition(
                                        threadTable.get(4).asDouble()+objPosX + randG.scalar(-0.04, 0.04),      // Add a randomness of -+ 4 cm to the X position of the cube
                                        threadTable.get(5).asDouble()+((threadTable.get(2).asDouble())/2) + 0.05, // Place the object 5 cmd above the table
                                        objPosZ + randG.scalar(-0.04, 0.04));                                   // Add a randomness of -+ 4 cm to the X position of the cube
                simCmd = simWorld.simObject[objIndex]->makeObjectBottle(simWorld.objSubIndex);
				writeSim(simCmd);

                //reply to the control manager the tool ID
                controlCmd.clear();
                controlCmd.addVocab(code);
                controlCmd.addInt(objIndex);
                replyCmd(controlCmd);
            }
            break;


            case VOCAB4('m','o','v','e'):
            {
                cout << "Move object to original position on table." <<endl;
                objIndex = controlCmd.get(1).asInt();
                //---------------------------------------------------------------
                //Create one object:
                //simWorld.simObject[objIndex]->objSubIndex = 1;  //needs to be automatic, each type of object has his own subIndex

                if (simWorld.simObject[objIndex]->objSubIndex != 0)
                {
                    Rand randG;         // YARP random number generator

                    simWorld.simObject[objIndex]->setObjectPosition(
                                                threadTable.get(4).asDouble()+objPosX + randG.scalar(-0.04, 0.04),
                                                threadTable.get(5).asDouble()+((threadTable.get(2).asDouble())/2) + 0.05,
                                                objPosZ + randG.scalar(-0.04, 0.04));
                    simCmd = simWorld.simObject[objIndex]->moveObjectBottle();
                    writeSim(simCmd);

                    simWorld.simObject[objIndex]->setObjectRotation(0, 0, 0);
                    simCmd = simWorld.simObject[objIndex]->rotateObjectBottle();
                    writeSim(simCmd);

                    //reply to the control manager the tool ID
                    controlCmd.clear();
                    controlCmd.addVocab(code);
//.........这里部分代码省略.........
开发者ID:tanismar,项目名称:affordances,代码行数:101,代码来源:simtoolloader.cpp


注:本文中的Rand::scalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。