/** * \fn void myApproxGeodesics::get_restricted_adj_vertices( Vertex* v , std::vector< Vertex* >& a ) const * * \brief Finds all mesh vertices connected to a given mesh vertex * by an edge that is incident to a face belonging to the active * face list. * * \param v A pointer to a vertex. * \param a A reference to a list of vertices. */ void myApproxGeodesics::get_restricted_adj_vertices( Vertex* v , std::vector< Vertex* >& a ) const { Halfedge* h1 = _mesh->get_halfedge( v ) ; Halfedge* h2 = h1 ; do { Face* f1 = _mesh->get_face( h2 ) ; Face* f2 = _mesh->get_face( _mesh->get_mate( h2 ) ) ; /* * Insert the origin vertex of "he2" in the list of vertices if * and only if the edge connecting it to vertex "v" is incident * with an active face. */ if ( _mesh->is_active( f1 ) || _mesh->is_active( f2 ) ) { if( (!_region)||(inRegion(f1,_region))||(inRegion(f2,_region) ) ) a.push_back( _mesh->get_org( _mesh->get_next( h2 ) ) ) ; } h2 = _mesh->get_next( _mesh->get_mate( h2 ) ) ; } while ( h2 != h1 ) ; return ; }
inline spatialaggregate::OcTreeNode< CoordType, ValueType >* spatialaggregate::OcTreeNode< CoordType, ValueType >::getNodeOnLevel(const spatialaggregate::OcTreePosition< CoordType >& position, unsigned int level) { if( type == OCTREE_LEAF_NODE ) { if( this->depth == level && inRegion( position) ) { return this; } else { return NULL; } } else { if( this->depth == level ) { if( inRegion( position ) ) { return this; } } else if( level > this->depth ) { int oct(getOctant(position)); if( siblings[oct] ) { return siblings[oct]->getNodeOnLevel( position, level); } } } return NULL; }
inline void spatialaggregate::OcTreeNode< CoordType, ValueType >::getAllNodesInVolumeOnSamplingDepth( std::vector< spatialaggregate::OcTreeNode< CoordType, ValueType >* >& points, const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, int searchDepth, bool higherDepthLeaves) { if( (int) depth > searchDepth ) return; if( type == OCTREE_LEAF_NODE ) { if( !higherDepthLeaves && (int) depth != searchDepth ) return; // check if point in leaf is within region if( inRegion( minPosition, maxPosition ) ) { points.push_back( this ); } } else { if( (int) depth == searchDepth ) { points.push_back( this ); return; } // for all siblings // - if regions overlap: call functino for the sibling for( unsigned int i = 0; i < 8; i++ ) { if( !siblings[i] ) continue; if( siblings[i]->overlap( minPosition, maxPosition ) ) siblings[i]->getAllNodesInVolumeOnSamplingDepth( points, minPosition, maxPosition, searchDepth, higherDepthLeaves ); } } }
inline ValueType spatialaggregate::OcTreeNode< CoordType, ValueType >::getValueInVolume( const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) { if( type == OCTREE_LEAF_NODE ) { if( inRegion( minPosition, maxPosition ) ) return value; return ValueType(0); } else { if( !overlap( minPosition, maxPosition ) ) return ValueType(0); if( containedInRegion( minPosition, maxPosition ) ) return value; if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON*minimumSearchVolumeSize ) { return value; } ValueType value = ValueType(0); for( unsigned int i = 0; i < 8; i++ ) { if(!siblings[i]) continue; value += siblings[i]->getValueInVolume( minPosition, maxPosition, minimumSearchVolumeSize ); } return value; } }
inline void spatialaggregate::OcTreeNode< CoordType, ValueType >::getAllNodesInVolume( std::vector< spatialaggregate::OcTreeNode< CoordType, ValueType >* >& points, const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) { if( type == OCTREE_LEAF_NODE ) { // check if point in leaf is within region if( inRegion( minPosition, maxPosition ) ) { points.push_back( this ); } } else { points.push_back(this); if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON*minimumSearchVolumeSize ) { return; } // for all siblings // - if regions overlap: call add points for( unsigned int i = 0; i < 8; i++ ) { if( !siblings[i] ) continue; if( siblings[i]->overlap( minPosition, maxPosition ) ) siblings[i]->getAllNodesInVolume( points, minPosition, maxPosition, minimumSearchVolumeSize ); } } }
inline unsigned int spatialaggregate::OcTreeNode< CoordType, ValueType >::getPointsInVolume( const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) { if( type == OCTREE_LEAF_NODE ) { // check if point in leaf is within region if( inRegion( minPosition, maxPosition ) ) { return this->numPoints; } } else { if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON*minimumSearchVolumeSize ) { return 0; } unsigned int ret(0); // for all siblings // - if regions overlap: call add points for( unsigned int i = 0; i < 8; i++ ) { if( !siblings[i] ) continue; if( siblings[i]->overlap( minPosition, maxPosition ) ) ret += siblings[i]->getPointsInVolume( minPosition, maxPosition, minimumSearchVolumeSize ); } return ret; } return 0; }
void GameTacMap::update() { Stuff::Vector2DOf<int32_t> screen; screen.x = userInput->getMouseX(); screen.y = userInput->getMouseY(); float width = right - left; float height = bottom - top; if (!inRegion(screen.x, screen.y)) return; ControlGui::instance->setRolloverHelpText(IDS_TACMAP_HELP); if (userInput->isLeftClick()) { screen.x -= left; screen.y -= top; Stuff::Vector3D world; tacMapToWorld(screen, width, height, world); if (MissionInterfaceManager::instance()->getControlGui()->isAddingAirstrike() && MissionInterfaceManager::instance()->getControlGui()->isButtonPressed( ControlGui::SENSOR_PROBE)) MissionInterfaceManager::instance()->doMove(world); else { eye->setPosition(world, false); ((GameCamera*)(eye))->setTarget(0); } } else if (userInput->isRightClick() && useLeftRightMouseProfile) { screen.x -= left; screen.y -= top; Stuff::Vector3D world; tacMapToWorld(screen, width, height, world); MissionInterfaceManager::instance()->doMove(world); } }
void ProximitySensorNode::update() { if (!isEnabled()) return; SceneGraph *sg = getSceneGraph(); if (!sg) return; ViewpointNode *vpoint = sg->getViewpointNode(); if (vpoint == NULL) vpoint = sg->getDefaultViewpointNode(); float vpos[3]; vpoint->getPosition(vpos); float center[3]; getCenter(center); float size[3]; getSize(size); if (inRegion() == false) { if (isRegion(vpos, center, size) == true) { setInRegion(true); double time = GetCurrentSystemTime(); setEnterTime(time); sendEvent(getEventOut(enterTimeFieldString)); setIsActive(true); sendEvent(getEventOut(isActiveFieldString)); } } else { if (isRegion(vpos, center, size) == false) { setInRegion(false); double time = GetCurrentSystemTime(); setExitTime(time); sendEvent(getEventOut(exitTimeFieldString)); setIsActive(false); sendEvent(getEventOut(isActiveFieldString)); } } }
inline void spatialaggregate::OcTreeNode< CoordType, ValueType >::getValueAndCountInVolume( ValueType& value, unsigned int& count, const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) { if( type == OCTREE_LEAF_NODE ) { if( inRegion( minPosition, maxPosition ) ) { value += this->value; count += this->numPoints; } } else { if( !overlap( minPosition, maxPosition ) ) return; if( containedInRegion( minPosition, maxPosition ) ) { value += this->value; count += this->numPoints; return; } if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON * minimumSearchVolumeSize ) { value += this->value; count += this->numPoints; return; } for( unsigned int i = 0; i < 8; i++ ) { if(!siblings[i]) continue; siblings[i]->getValueAndCountInVolume( value, count, minPosition, maxPosition, minimumSearchVolumeSize ); } } }
inline void spatialaggregate::OcTreeNode< CoordType, ValueType >::applyOperatorInVolume( ValueType& value, void* data, void (*f)( ValueType& v, spatialaggregate::OcTreeNode< CoordType, ValueType >* current, void* data ), const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) { if( type == OCTREE_LEAF_NODE ) { if( inRegion( minPosition, maxPosition ) ) { f( value, this, data ); } } else { if( !overlap( minPosition, maxPosition ) ) return; if( containedInRegion( minPosition, maxPosition ) ) { f( value, this, data ); return; } if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON * minimumSearchVolumeSize ) { // since we check for overlap above, this branching node is only accounted for, when its extent overlaps with the search region f( value, this, data ); return; } for( unsigned int i = 0; i < 8; i++ ) { if(!siblings[i]) continue; siblings[i]->applyOperatorInVolume( value, data, f, minPosition, maxPosition, minimumSearchVolumeSize ); } } }
//check if numberToCheck is valid for the cell bool Puzzle::isValid(int currentRow, int currentColumn, int numberToCheck) { return (!inRow(currentRow, numberToCheck) && !inColumn(currentColumn, numberToCheck) && !inRegion(currentRow, currentColumn, numberToCheck)); }
/** * 適切なドライバを選択し、運転させる */ void OutCourse::drive() { #if 0 // ログ送信(0:解除、1:実施) LOGGER_SEND = 2; LOGGER_DATAS08[0] = (S8)(mState); LOGGER_DATAS08[1] = (S8)(mLineDetector.detect()); // 一瞬だけなのでログに残らない可能性あり LOGGER_DATAU16 = (U16)(mWallDetector.detect()); LOGGER_DATAS16[0] = (S16)(mGps.getXCoordinate()); LOGGER_DATAS16[1] = (S16)(mGps.getYCoordinate()); LOGGER_DATAS16[2] = (S16)(mGps.getDirection()); LOGGER_DATAS16[3] = (S16)(mGps.getDistance()); LOGGER_DATAS32[0] = (S32)(mLeftMotor.getCount()); LOGGER_DATAS32[1] = (S32)(mRightMotor.getCount()); LOGGER_DATAS32[2] = (S32)(mLightSensor.get()); LOGGER_DATAS32[3] = (S32)(mGyroSensor.get()); #endif #if 0 // デバッグ(0:解除、1:実施) { //DESK_DEBUG = true; static int count = 0; if (count++ % 25 == 0) { Lcd lcd; lcd.clear(); lcd.putf("sn", "OutCourse"); lcd.putf("dn", mState); lcd.putf("dn", (S32)mGps.getXCoordinate()); lcd.putf("dn", (S32)mGps.getYCoordinate()); lcd.putf("dn", (S32)mGps.getDirection()); lcd.putf("dn", (S32)mGps.getDistance()); lcd.disp(); } } #endif if (mState == OutCourse::START) { // スタート後通常区間 if (mNormalDriver.drive()) { float X = mGps.getXCoordinate(); float Y = mGps.getYCoordinate(); //if (inRegion(GPS_LOOKUP_START, MakePoint(X, Y)) || (13500.0 < mGps.getDistance())) { // 区間をルックアップ区間に更新 //if (12500.0 < mGps.getDistance()) { // ルックアップ区間前減速 // mLineTrace.setForward(30);//ノーマルドライバ内でやる //} if (13500.0 < mGps.getDistance()) { // 区間をルックアップ区間に更新 mState = OutCourse::LOOKUP; } } } else if (mState == OutCourse::LOOKUP) { // ルックアップ区間 if (mLookUpGateDriver.drive()) { mState = OutCourse::ETSUMO; /*とりあえず終了したら遷移することにする float X = mGps.getXCoordinate(); float Y = mGps.getYCoordinate(); if ((inRegion(GPS_ETSUMO_START, MakePoint(X, Y)))) { // 区間をET相撲区間に更新 mState = OutCourse::ETSUMO; } */ } } else if (mState == OutCourse::ETSUMO) { // ET相撲区間 if (mETsumoDriver.drive()) { float X = mGps.getXCoordinate(); float Y = mGps.getYCoordinate(); if (inRegion(GPS_GARAGEIN_START, MakePoint(X, Y))) { // 区間をガレージ区間に更新 mState = OutCourse::GARAGEIN; } } } else if (mState == OutCourse::GARAGEIN) { // ガレージ・イン区間 mGarageDriver.drive(); } // テストドライバ起動 else { mTestDriver.drive(); } }
void ForceGroupBar::update( ) { bool bSelect = userInput->isLeftClick(); bool bCommand = useLeftRightMouseProfile ? userInput->isRightClick() : userInput->isLeftClick(); bool shiftDn = userInput->getKeyDown( KEY_LSHIFT ) ? true : false; bool bCamera = useLeftRightMouseProfile ? (userInput->isLeftDoubleClick()) : (userInput->isRightClick() && !userInput->isRightDrag()); bool bForceGroup = useLeftRightMouseProfile ? (userInput->isLeftDoubleClick()) : userInput->isLeftDoubleClick(); if ( bCamera ) bSelect = 0; Stuff::Vector2DOf<long> screen; screen.x = userInput->getMouseX(); screen.y = userInput->getMouseY(); if ( screen.x > FORCEGROUP_LEFT && screen.x < FORCEGROUP_LEFT + FORCEGROUP_WIDTH && screen.y > FORCEGROUP_TOP ) { if ( ControlGui::instance->isSelectingInfoObject() ) userInput->setMouseCursor( mState_INFO ); else if ( ControlGui::instance->getRepair() ) userInput->setMouseCursor( mState_XREPAIR ); else if ( MissionInterfaceManager::instance()->hotKeyIsPressed( EJECT_COMMAND_INDEX ) ) userInput->setMouseCursor( mState_EJECT ); else userInput->setMouseCursor( mState_NORMAL ); helpTextID = IDS_FORCEGROUP_BAR_DESC; helpTextHeaderID = IDS_FORCEGROUP_BAR; } // unselect all if appropriate if ( bSelect && !shiftDn && inRegion(screen.x, screen.y) && !ControlGui::instance->isSelectingInfoObject() && (!ControlGui::instance->getRepair() && !MissionInterfaceManager::instance()->hotKeyIsPressed( EJECT_COMMAND_INDEX ) && !ControlGui::instance->getGuard() || useLeftRightMouseProfile) ) { Team* pTeam = Team::home; for ( int i = 0; i < pTeam->rosterSize; ++i ) { Mover* pMover = (Mover*)pTeam->getMover( i ); if (pMover->getCommander()->getId() == Commander::home->getId()) { pMover->setSelected( false ); } } } // remove dead mechs for ( int t = 0; t < iconCount; ++t ) { if ( (icons[t]->unit->isDestroyed() || icons[t]->unit->isDisabled()) && !icons[t]->unit->recoverBuddyWID ) { if ( !icons[t]->isAnimatingDeath() ) icons[t]->beginDeathAnimation(); if ( icons[t]->deathAnimationOver() || icons[t]->unit->causeOfDeath == POWER_USED_UP ) { delete icons[t]; iconCount --; memmove( &icons[t], &icons[t] + 1, (iconCount - t) * sizeof (ForceGroupIcon*) ); icons[iconCount] = 0; } } } qsort( icons, iconCount, sizeof( ForceGroupIcon* ), ForceGroupIcon::sort ); for ( int i = 0; i < iconCount; i++ ) { icons[i]->setLocationIndex( i ); } for ( i = 0; i < iconCount; ++i ) { if ( icons[i]->inRegion( screen.x, screen.y ) ) { icons[i]->unit->setTargeted(true); if ( ControlGui::instance->getRepair() ) { if ( !MissionInterfaceManager::instance()->canRepair(icons[i]->unit ) ) { userInput->setMouseCursor( mState_XREPAIR ); // need to go back and unselect everything if ( bSelect ) { if ( !shiftDn ) { Team* pTeam = Team::home; for ( int j = 0; j < pTeam->rosterSize; ++j ) { Mover* pMover = (Mover*)pTeam->getMover( j ); if (pMover->getCommander()->getId() == Commander::home->getId()) { pMover->setSelected( false ); } } } } } else { userInput->setMouseCursor( mState_REPAIR ); } } else if ( ControlGui::instance->getGuard() ) { userInput->setMouseCursor( mState_GUARD ); } else { ControlGui::instance->setRolloverHelpText( IDS_UNIT_SELECT_HELP ); } if ( bSelect && !ControlGui::instance->infoButtonPressed() ) { if ( !(ControlGui::instance->getRepair() && MissionInterfaceManager::instance()->canRepair(icons[i]->unit ) && !useLeftRightMouseProfile) ) icons[i]->click( shiftDn ); ControlGui::instance->setInfoWndMover( icons[i]->unit ); } if ( bCommand ) { if ( MissionInterfaceManager::instance()->hotKeyIsPressed( EJECT_COMMAND_INDEX ) ) { MissionInterfaceManager::instance()->doEject( icons[i]->unit ); } else if ( ControlGui::instance->getGuard() ) { MissionInterfaceManager::instance()->doGuard( icons[i]->unit ); } else if ( ControlGui::instance->getRepair() ) { if ( MissionInterfaceManager::instance()->canRepair(icons[i]->unit ) ) MissionInterfaceManager::instance()->doRepair( icons[i]->unit ); } else ControlGui::instance->setInfoWndMover( icons[i]->unit ); } if ( bCamera ) { icons[i]->rightClick(); } if ( bForceGroup ) { for( int j = 0; j < 10; ++j ) { if ( icons[i]->unit->isInUnitGroup( j ) ) { MissionInterfaceManager::selectForceGroup( j, true ); } } } } else icons[i]->unit->setTargeted( 0 ); icons[i]->update(); } }
void DungeonTest::connect() { map<IVec2,hash_set<int>> connector; for (int i = 0 ; i < _width ; i++) { for (int j = 0 ; j < _height ; j++) { if (_blocks[i][j] != BLOCK_BLANK) continue; hash_set<int> regions; regions.clear(); if (inRegion(i-1,j)) regions.insert(_blocks[i-1][j]); if (inRegion(i+1,j)) regions.insert(_blocks[i+1][j]); if (inRegion(i,j+1)) regions.insert(_blocks[i][j+1]); if (inRegion(i,j-1)) regions.insert(_blocks[i][j-1]); if (regions.size() < 2) continue; //_blocks[i][j] = BLOCK_DOOR; connector[IVec2(i,j)] = regions; } } vector<int> merged; list<int> openRegions; for (int i = 0 ; i < _currentRegion+1 ; i++) { merged.push_back(i); openRegions.push_back(i); } while (openRegions.size() > 1) { int ranNum = random(0,connector.size() - 1); map<IVec2,hash_set<int>>::iterator it = connector.begin(); while (ranNum != 0) { ++it; ranNum --; } IVec2 pos = IVec2((it->first).x,(it->first).y); _blocks[pos.x][pos.y] = BLOCK_DOOR; int dest = merged[*((it->second).begin())]; int source = merged[*((it->second).rbegin())]; //merged[source] = dest; for(int i = 0 ; i < _currentRegion+1 ; i++) { if(merged[i] == source) merged[i] = dest; } list<int>::iterator list_it = openRegions.begin(); for( ; list_it != openRegions.end() ;) { if (*list_it == source) { openRegions.erase(list_it++); break; } else { ++list_it; } } for (it = connector.begin() ; it != connector.end() ;) { int first = *((it->second).begin()); int second = *((it->second).rbegin()); if(merged[first] == dest && merged[second] == dest) { if (random(0,100) <= EXTRA_CONNECT && pos.dis(IVec2((it->first).x,(it->first.y))) > 2) _blocks[(it->first).x][(it->first).y] = BLOCK_DOOR; connector.erase(it++); } else ++it; } } }