double MyController::onAction(ActionEvent &evt) { Vector3d robotPos; Vector3d operatorPos; // エンティティ取得 SimObj *robot_obj = getObj(robotName); SimObj *operator_obj = getObj(operatorName); robot_obj->getPosition(robotPos); operator_obj->getPosition(operatorPos); // operator if(fabs(operatorPos.x()-myPos.x()) < checkSize_x/2.0 && fabs(operatorPos.z()-myPos.z()) < checkSize_z/2.0 && flag2 == false){ flag1 = true; } // robot if(fabs(robotPos.x()-myPos.x()) < checkSize_x/2.0 && fabs(robotPos.z()-myPos.z()) < checkSize_z/2.0 && flag1 == true){ flag2 = true; } if(flag1 && flag2 && !sentMsg){ LOG_MSG(("crowd_clear")); sendMsg("score", "crowd_clear"); sentMsg = true; } return 0.1; }
inline static void toObj(Obj& mObj, const T& mValue) { arch(mObj, "tileSize", mValue.getTileSize()); auto& labels(getObj(mObj, "labels")); for(const auto& l : mValue.getLabels()) arch(getObj(labels, l.second.y), l.second.x, l.first); }
InteractableObject::InteractableObject(gkGameObject* object, const char* animName) : UseableObject(object), isOpened(false), canBeUsed(false) { getObj()->addAnimation(animName); objectAnimation = getObj()->getAnimationPlayer(animName); blocked = false; }
void MovieGlHap::allocateVisualContext() { // Load HAP Movie if( HapQTQuickTimeMovieHasHapTrackPlayable( getObj()->mMovie ) ) { // QT Visual Context attributes OSStatus err = noErr; QTVisualContextRef * visualContext = (QTVisualContextRef*)&getObj()->mVisualContext; CFDictionaryRef pixelBufferOptions = HapQTCreateCVPixelBufferOptionsDictionary(); const CFStringRef keys[] = { kQTVisualContextPixelBufferAttributesKey }; CFDictionaryRef visualContextOptions = ::CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys, (const void**)&pixelBufferOptions, sizeof(keys)/sizeof(keys[0]), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); err = QTPixelBufferContextCreate( kCFAllocatorDefault, visualContextOptions, visualContext ); ::CFRelease( pixelBufferOptions ); ::CFRelease( visualContextOptions ); if( err != noErr ) { CI_LOG_E( "HAP ERROR :: " << err << " couldnt create visual context." ); return; } // Set the movie's visual context err = SetMovieVisualContext( getObj()->mMovie, *visualContext ); if( err != noErr ) { CI_LOG_E( "HAP ERROR :: " << err << " SetMovieVisualContext." ); return; } } // Get codec name for (long i = 1; i <= GetMovieTrackCount(getObj()->mMovie); i++) { Track track = GetMovieIndTrack(getObj()->mMovie, i); Media media = GetTrackMedia(track); OSType mediaType; GetMediaHandlerDescription(media, &mediaType, NULL, NULL); if (mediaType == VideoMediaType) { // Get the codec-type of this track ImageDescriptionHandle imageDescription = (ImageDescriptionHandle)NewHandle(0); // GetMediaSampleDescription will resize it GetMediaSampleDescription(media, 1, (SampleDescriptionHandle)imageDescription); OSType codecType = (*imageDescription)->cType; DisposeHandle((Handle)imageDescription); switch (codecType) { case 'Hap1': mCodec = Codec::HAP; break; case 'Hap5': mCodec = Codec::HAP_A; break; case 'HapY': mCodec = Codec::HAP_Q; break; default: mCodec = Codec::UNSUPPORTED; break; } } } // Set framerate callback this->setNewFrameCallback( updateMovieFPS, (void*)this ); }
std::string RobotController::getPointedTrashName(std::string entName) { // 発話者の名前からSimObjを取得します SimObj *tobj = getObj(entName.c_str()); // メッセージ送信者の左肘関節の位置を取得します Vector3d jpos; if(!tobj->getJointPosition(jpos, "RARM_JOINT4")) { LOG_ERR(("failed to get joint position")); return ""; } // メッセージ送信者の左肘から左手首をつなぐベクトルを取得します Vector3d jvec; if(!tobj->getPointingVector(jvec, "RARM_JOINT4", "RARM_JOINT7")) { LOG_ERR(("failed to get pointing vector")); return ""; } double distance = 0.0; std::string objName = ""; // 全ゴミオブジェクトでループします int trashboxSize = m_trashboxs.size(); for(int i = 0; i < trashboxSize; i++) { // エンティティの位置を取得します SimObj *obj = getObj(m_trashboxs[i].c_str()); Vector3d objVec; obj->getPosition(objVec); // エンティティと左肘関節を結ぶベクトルを作成します objVec -= jpos; // cos角度が不の場合(指差した方向と反対側にある場合)は対象から外します double cos = jvec.angle(objVec); if(cos < 0) continue; // 指差した方向ベクトルまでの最短距離の計算 double theta = acos(cos); double tmp_distance = sin(theta) * objVec.length(); // 最小距離の場合は名前、距離を保存しておく if(tmp_distance < distance || distance == 0.0){ distance = tmp_distance; objName = obj->name(); } } // エンティティでループして最も近いオブジェクトの名前を取得する return objName; }
int gamehsp::makeNewLgt( int id, int lgtopt, float range, float inner, float outer ) { gpobj *obj; Node *node; Light *light; if ( id < 0 ) { int newid = makeNullNode(); obj = getObj( newid ); } else { obj = getObj( id ); } if ( obj == NULL ) return -1; node = obj->_node; if ( node == NULL ) return -1; if ( obj->_light ) { node->setLight( NULL ); SAFE_RELEASE( obj->_light ); } light = NULL; switch( lgtopt ) { case GPLGT_OPT_POINT: light = Light::createPoint( 1.0f, 1.0f, 1.0f, range ); break; case GPLGT_OPT_SPOT: light = Light::createSpot( 1.0f, 1.0f, 1.0f, range, inner, outer ); break; default: light = Light::createDirectional( 1.0f, 1.0f, 1.0f ); break; } if ( light ) { //light->setColor( 1.0f, 1.0f, 1.0f ); node->setLight( light ); if ( id < 0 ) { node->rotateX(MATH_DEG_TO_RAD(-45.0f)); } obj->_light = light; } obj->_vec[GPOBJ_USERVEC_COLOR].set( 1.0f, 1.0f, 1.0f, 1.0f ); obj->_vec[GPOBJ_USERVEC_WORK].set( 0.25f, 0.25f, 0.25f, 1.0f ); return obj->_id; }
void AvatarControllerByKinectV2::onRecvMsg(RecvMsgEvent &evt) { try { std::string allMsg = evt.getMsg(); // std::cout << "msg:" << allMsg << std::endl; // Decode message to sensor data of kinect v2. std::map<std::string, std::vector<std::string> > sensorDataMap = KinectV2SensorData::decodeSensorData(allMsg); if (sensorDataMap.find(MSG_KEY_DEV_TYPE) == sensorDataMap.end()){ return; } if(sensorDataMap[MSG_KEY_DEV_TYPE][0] !=this->kinectV2DeviceManager.deviceType ){ return; } if(sensorDataMap[MSG_KEY_DEV_UNIQUE_ID][0]!=this->kinectV2DeviceManager.deviceUniqueID){ return; } KinectV2SensorData sensorData; sensorData.setSensorData(sensorDataMap); ManNiiPosture posture = KinectV2DeviceManager::convertSensorData2ManNiiPosture(sensorData); // Set SIGVerse quaternions and positions SimObj *obj = getObj(myname()); this->kinectV2DeviceManager.setRootPosition(obj, sensorData.rootPosition); KinectV2DeviceManager::setJointQuaternions2ManNii(obj, posture, sensorData); } catch(SimObj::Exception &err) { LOG_MSG(("Exception: %s", err.msg())); } catch(...) { std::cout << "some error occurred." << std::endl; } }
double RobotController::onAction(ActionEvent &evt) { try { typedef std::vector<std::string> C; C agents; bool b = detectEntities(agents); if (b && agents.size() > 0) { for (C::iterator i=agents.begin(); i!=agents.end(); i++) { std::string name = *i; LOG_MSG(("detected %s\n", name.c_str())); SimObj *obj = getObj(name.c_str()); if (!obj) { LOG_ERR(("cannot get object")); } // ...; } } else { LOG_MSG(("no object in front of me")); } } catch(SimObj::Exception &) { LOG_ERR(("Exception")); } return 2.0; }
Light *gamehsp::getLight( int objid ) { gpobj *obj; obj = getObj( objid ); if ( obj == NULL ) return NULL; return obj->_light; }
void Profiler::end(string mId) { if (!active) return; ProfilerObj* cObj = getObj(mId); if (cObj != NULL) cObj->end(); }
double NiiRobotOkonomi::onAction(ActionEvent &evt) { SimObj *my = getObj(myname()); static int s_cnt = 0; int step = s_cnt % STEP_NUM; for (int i=0; i<JOINT_NUM; i++) { const char * jointName = jointNames[i]; if (!jointName) { continue; } double angle = jointAngles[step][i]; double rad = DEG2RAD(angle); my->setJointAngle(jointName, rad); } s_cnt++; /* double zz = cos(s_cnt*5*3.14/180); double xx = sin(s_cnt*5*3.14/180); my->setPosition(xx, 0.5, zz); my->setAxisAndAngle(0.0, 1.0, 0.0, s_cnt*5*3.14/180); */ return 0.1; }
Kate::PluginConfigPage* PluginKateKJSWrapper::configPage (uint id, QWidget *w, const char */*name*/) { kdDebug()<<"PluginKateKJSWrapper::configPage"<<endl; if (id>=configPages()) return 0; KJS::Interpreter *js = m_part->interpreter(); KJS::Object constr=getObj(js,m_configPageFactories,id); if (js->globalExec()->hadException()) { kdDebug()<<"PluginKateKJSWrapper::configPage: exit 1"<<endl; js->globalExec()->clearException(); return 0; } if (!constr.implementsConstruct()) { kdWarning()<<"config page factory has to be an object constructor"<<endl; return 0; } KateKJSWrapperConfigPage *p=new KateKJSWrapperConfigPage(constr,this,w); return (Kate::PluginConfigPage*)p; /* KateKJSWrapperConfigPage* p = new KateKJSWrapperConfigPage(this, w); //init connect( p, SIGNAL(configPageApplyRequest(KateKJSWrapperConfigPage*)), this, SLOT(applyConfig(KateKJSWrapperConfigPage*)) ); return (Kate::PluginConfigPage*);*/ }
double RobotController::onAction(ActionEvent &evt) { LOG_MSG(("\ncurrent time : %f", evt.time())); static int cnt = 0; try { const char *name = myname(); SimObj *obj = getObj(name); obj->dump(); if (!obj->dynamics()) { double angle = 2*PI*cnt*0.01; double xx = 5*sin(angle); double yy = 0.5; double zz = 5*cos(angle); LOG_MSG(("pos (%f, %f, %f)", xx, yy, zz)); obj->setPosition(xx, yy, zz); obj->setAxisAndAngle(0.0, 1.0, 0.0, angle); } obj->dump(); } catch(SimObj::NoAttributeException &) { } catch(SimObj::AttributeReadOnlyException &) { } catch(SimObj::Exception &) { } cnt++; return 0.1; }
void *allocateDoc(DbMap *docStore, uint32_t size, DbAddr *addr, uint32_t set) { uint32_t amt = size + sizeof(DbDoc), bits = MinDocType; DbAddr *free, *tail, slot; DbDoc *doc; while ((1UL << bits) < amt) bits++; free = docStoreAddr(docStore)->docWait[set][bits].free; tail = docStoreAddr(docStore)->docWait[set][bits].tail; lockLatch(free->latch); slot.bits = bits; while (!(slot.addr = getNodeFromFrame(docStore, free))) { if (!getNodeWait(docStore, free, tail)) if (!initObjFrame(docStore, free, bits, 1UL << bits)) { unlockLatch(free->latch); return 0; } } addr->bits = slot.bits; unlockLatch(free->latch); doc = getObj(docStore, slot); memset(doc, 0, sizeof(DbDoc)); doc->docSize = size; return doc + 1; }
void DemoRobotController::recognizeObjectPosition(Vector3d &pos, std::string &name) { // get object of trash selected SimObj *trash = getObj(name.c_str()); // get trash's position trash->getPosition(pos); }
TiObj* TiGroup::getObj(string name){ TiObj* res = NULL; for (int i=0; i<conjs.size(); i++){ if ( res = getObj(conjs[i]->classe, name) ) return res; } return NULL; }
const CGHeroInstance* CGameInfoCallback::getHero(ObjectInstanceID objid) const { const CGObjectInstance *obj = getObj(objid, false); if(obj) return dynamic_cast<const CGHeroInstance*>(obj); else return nullptr; }
static PyObject* pyDrawObj(PyObject *self, PyObject *args) { int id; if(!PyArg_ParseTuple(args, "i", &id)) return NULL; drawObj(getObj(id)); Py_RETURN_NONE; }
const CGTownInstance* CGameInfoCallback::getTown(ObjectInstanceID objid) const { const CGObjectInstance *obj = getObj(objid, false); if(obj) return dynamic_cast<const CGTownInstance*>(obj); else return NULL; }
///@brief Initialize this controller. void AvatarControllerByKinectV2::onInit(InitEvent &evt) { this->readIniFileAndInitialize(); SimObj *myself = getObj(myname()); this->kinectV2DeviceManager.initPositionAndRotation(myself); }
std::vector<ObjectInstanceID> CGameInfoCallback::getVisibleTeleportObjects(std::vector<ObjectInstanceID> ids, PlayerColor player) const { vstd::erase_if(ids, [&](ObjectInstanceID id) -> bool { auto obj = getObj(id, false); return player != PlayerColor::UNFLAGGABLE && (!obj || !isVisible(obj->pos, player)); }); return ids; }
const CGObjectInstance * IGameCallback::putNewObject(Obj ID, int subID, int3 pos) { NewObject no; no.ID = ID; //creature no.subID= subID; no.pos = pos; commitPackage(&no); return getObj(no.id); //id field will be filled during applying on gs }
///@brief Initialize this controller. void WheelControllerByMyo::onInit(InitEvent &evt) { this->readIniFileAndInitialize(); this->myoDeviceManager = MyoDeviceManager(this->serviceName, this->deviceType, this->deviceUniqueID); //For initialize. getObj(myname()); }
double RobotController::onAction(ActionEvent &evt) { SimObj *obj = getObj(myname()); if (obj) { obj->setAccel(0.0, 100.0, 0.0); } return 5.0; }
void GraphDraw::mousePressEvent(QMouseEvent *event) { QGraphicsView::mousePressEvent(event); if (QApplication::keyboardModifiers() & Qt::ControlModifier) return; //record the conditions of this press event, nothing is changed if (event->button() == Qt::LeftButton) { _selectionState = SELECTION_STATE_PRESS; const auto objs = this->getObjectsAtPos(event->pos()); if (objs.empty()) { //perform deselect when background is clicked _lastClickSelectEp = GraphConnectionEndpoint(); this->deselectAllObjs(); } else { //make the clicked object topmost objs.front()->setZValue(this->getMaxZValue()+1); } //handle click selection for connections const auto thisEp = this->mousedEndpoint(event->pos()); //enter the connect drag mode and object immobilization //slots are exempt because they are the block's body if (thisEp.isValid()) { auto topObj = thisEp.getObj(); if (thisEp.getKey().direction != GRAPH_CONN_SLOT) { _connectLineItem.reset(new QGraphicsLineItem(topObj)); _connectLineItem->setPen(QPen(QColor(GraphObjectDefaultPenColor), ConnectModeLineWidth)); _connectModeImmobilizer.reset(new GraphObjectImmobilizer(topObj)); } //if separate clicks to connect when try to make connection auto actions = MainActions::global(); if (actions->clickConnectModeAction->isChecked()) { if (not this->tryToMakeConnection(thisEp)) { //stash this endpoint when connection is not made _lastClickSelectEp = thisEp; } } //stash the connection endpoint for a drag+release connection else _lastClickSelectEp = thisEp; } } this->render(); }
///@brief Initialize this controller. void AvatarControllerByPerceptionNeuron::onInit(InitEvent &evt) { this->readIniFileAndInitialize(); this->perceptionNeuronDeviceManager = PerceptionNeuronDeviceManager(this->serviceName, this->deviceType, this->deviceUniqueID); SimObj *myself = getObj(myname()); this->perceptionNeuronDeviceManager.getInitialPositionAndRotation(myself); }
void InteractableObject::act(bool toOpen){ objectAnimation->reset(); if (toOpen) objectAnimation->setMode(AK_ACT_END); else objectAnimation->setMode(AK_ACT_INVERSE); getObj()->playAnimation(objectAnimation, 0); }
// This sets the focus on a list item. // So that clicking the button will cause it to grab control. void fList::chooseItem(int index) { drawObj* item; item = getObj(index); // ITEMS START AT 0 if (item) { setFocusPtr(item); makeVisable((fListItem*)item); } }
inline static void fromObj(const Obj& mObj, T& mValue) { const auto& labels(getObj(mObj, "labels")); for(auto iY(0u); iY < getObjSize(labels); ++iY) for(auto iX(0u); iX < getObjSize(labels[iY]); ++iX) mValue.setLabel( getExtr<std::string>(labels[iY][iX]), {iX, iY}); mValue.setTileSize(getExtr<ssvs::Vec2u>(mObj, "tileSize")); }
///@brief Initialize this controller. void AvatarControllerByOculusCV1::onInit(InitEvent &evt) { readIniFileAndInitialize(); this->oculusCV1DeviceManager = OculusCV1DeviceManager(this->serviceName, this->deviceType, this->deviceUniqueID); //For initialize. getObj(myname()); }