void MapEditor::mouseMoveEvent(QMouseEvent *event) { currentX = convertCoordinate(event->pos().x(),0); currentY = convertCoordinate(event->pos().y(),1); ((MainWindow*)main)->setStatus(event->pos().x()-posX,event->pos().y()-posY); }
void HSJoystick::ccTouchesMoved( CCSet *pTouches, CCEvent *pEvent ) { if(isPressed) { CCTouch *touch = (CCTouch*)pTouches->anyObject(); CCPoint point = touch->locationInView(); point = convertCoordinate(point); this->updateVelocity(point); } }
void MapEditor::mousePressEvent(QMouseEvent *event) { startX = convertCoordinate(event->pos().x(),0); startY = convertCoordinate(event->pos().y(),1); if(event->button() == 4) { move = true; return; } if( objType >= 100 && objType <= 102) { findClosestEntity(&startX,&startY); } if(event->button()==2) { discoverAndDelete(startX,startY); return; } isClicked = true; if( objType == MapEntityType::MODEL ) { strcpy(modelEntity.modelName,modelName.data()); modelEntity.type = objType; modelEntity.entityPosition.startX = startX; modelEntity.entityPosition.startZ = startY; modelEntity.direction = degree; addModelEntity(modelEntity); ((MainWindow*)main)->setWindowModified(true); } if( objType == MapEntityType::SPAWN_POINT || objType == MapEntityType::LIGHT_POINT || objType < 100 ) { entity2.type = objType; entity2.entityPosition.startX = startX; entity2.entityPosition.startZ = startY; entity2.direction = degree; std::cout<<degree<<std::endl; addEntity2(entity2); ((MainWindow*)main)->setWindowModified(true); } }
void HSJoystick::ccTouchesBegan( CCSet *pTouches, CCEvent *pEvent ) { CCTouch *touch = (CCTouch*)pTouches->anyObject(); CCPoint point = touch->locationInView(); point = convertCoordinate(point); if(isPointInCircle(point,kCenter,this->radius)) { isPressed = true; this->updateVelocity(point); } }
/** * Purpose: Given the rover's pose, this function will move it a certain distance * ARGS: * ref_x: x-coordinate of reference point (Rover) * ref_y: y-coordinate of reference point (Rover) * orientation: orientation of rover * distance: Distance the rover moved (center of rover) **/ void translateRoverVector(int ref_x, int ref_y, float orientation, int rightFt, int rightIn, int leftFt, int leftIn) { int rightDist = convToInches(rightFt, rightIn); int leftDist = convToInches(leftFt, leftIn); //printf("rightDist = %d\n", (int)((double)rightDist)); //printf("leftDist = %d\n", (int)((double)leftDist)); if( rightDist != leftDist ) { //Radius of Turn int R = ((float)rov_width_half)*( ( rightDist + leftDist ) / ( rightDist - leftDist ) ); //Change in orientation float theta = ((float)rightDist - (float)leftDist)/((float)rov_width); #if smoothenMap == 1 theta = (fabs((int)((double)(theta*convToDeg))) == 93.0) ? (((theta < 0.0)?-1.0:1.0)*(float)90.0)*convToRadians : theta; #endif //printf("theta = %d", (int)((double)(theta*convToDeg))); // calculate cosine and sine of the angle (angle inputted is in degrees) float cosine_trav = cosine_optimized(theta); float sine_trav = sine_optimized(theta); float cosine_orien = cosine_optimized(orientation * convToRadians); float sine_orien = sine_optimized(orientation * convToRadians); //ICC - center of rotation int ICC_x = 0 - R*sine_orien; int ICC_y = 0 + R*cosine_orien; int newx = cosine_trav*(0 - ICC_x) - sine_trav*(0 - ICC_y) + ICC_x; int newy = sine_trav*(0- ICC_x) + cosine_trav*(0- ICC_y) + ICC_y; resultOfRV_Translation.orientation = orientation + (theta * convToDeg); convertCoordinate(ref_x, ref_y, resultOfRV_Translation.orientation, newx, newy); } else { resultOfRV_Translation.orientation = orientation; convertCoordinate(ref_x, ref_y, orientation, rightDist, (int)0); } }
/* 消去的行数与当前摆放的板块中被消去的小方块数的乘积 game : 此时的game是板块摆放后的状态 shape : 被摆放的板块 anchorRow : 板块摆放的所在的行 */ int erodedPieceCellsMetric (TertrisGame game , AShape shape , int anchorRow,int anchorCol){ //被消去的行数 int erodedRows = 0; //板块中被消去的行数 int erodedShape = 0; //遍历所有 row for (int r = 1; r<= GAME_ROW; r++) { if (isFullRow(game,r)) { //如果消去行中有摆放的板块 if (r >= anchorRow && r<= (anchorRow + shape.height)) { int rInShape = 0; //得到 game board 的行 在 shape 中的行 convertCoordinate(0, r, 0, &rInShape, -anchorCol, -anchorRow); int rWidthInShape = shape.rowWidth[rInShape]; erodedShape+=rWidthInShape; } erodedRows++; } } return erodedRows * erodedShape; }
void MapEditor::mouseReleaseEvent(QMouseEvent *event) { if(event->button() == 2) return; if(event->button() == 4) { move = false; return; } if(isClicked) { isClicked = false; if( objType == MapEntityType::SPAWN_POINT || objType == MapEntityType::LIGHT_POINT || objType < 100 || objType == MapEntityType::MODEL ) return; if( startX == convertCoordinate(event->pos().x(),0) || startY == convertCoordinate(event->pos().y(),1) ) return; entity4.type = objType; entity4.entityPosition.startX = startX; entity4.entityPosition.startZ = startY; float x1 = convertCoordinate( event->pos().x(),0); float y1 = convertCoordinate( event->pos().y(),1); findClosestEntity(&x1,&y1); if(!space) { if( fabs(startX-convertCoordinate(event->pos().x(),0)) > fabs(startY-convertCoordinate(event->pos().y(),1)) ) { entity4.entityPosition.endZ = entity4.entityPosition.startZ; entity4.entityPosition.endX = x1; } else { entity4.entityPosition.endX = entity4.entityPosition.startX; entity4.entityPosition.endZ = y1; } } else { entity4.entityPosition.endX = x1; entity4.entityPosition.endZ = y1; } addEntity4(entity4); } ((MainWindow*)main)->setWindowModified(true); }
const KstTimezones::ZoneMap KstTimezones::allZones() { // Have we already done all the hard work? If not, create the cache. if (m_zones) return *m_zones; m_zones = new ZoneMap(); // Go read the database. // // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones // is the place to look. The TZI binary value is the TIME_ZONE_INFORMATION structure. // // For Unix its all easy except knowing where to look. Try the LSB location first. QFile f; m_zoneinfoDir = "/usr/share/zoneinfo"; f.setName(m_zoneinfoDir + "/zone.tab"); if (!f.open(IO_ReadOnly)) { m_zoneinfoDir = "/usr/lib/zoneinfo"; f.setName(m_zoneinfoDir + "/zone.tab"); if (!f.open(IO_ReadOnly)) { m_zoneinfoDir = ::getenv("TZDIR"); f.setName(m_zoneinfoDir + "/zone.tab"); if (m_zoneinfoDir.isEmpty() || !f.open(IO_ReadOnly)) { // Solaris support. Synthesise something that looks like a zone.tab. // // /bin/grep -h ^Zone /usr/share/lib/zoneinfo/src/* | /bin/awk '{print "??\t+9999+99999\t" $2}' // // where the country code is set to "??" and the lattitude/longitude // values are dummies. m_zoneinfoDir = "/usr/share/lib/zoneinfo"; KTempFile temp; KShellProcess reader; reader << "/bin/grep" << "-h" << "^Zone" << m_zoneinfoDir << "/src/*" << temp.name() << "|" << "/bin/awk" << "'{print \"??\\t+9999+99999\\t\" $2}'"; // Note the use of blocking here...it is a trivial amount of data! temp.close(); reader.start(KProcess::Block); f.setName(temp.name()); if (!temp.status() || !f.open(IO_ReadOnly)) { return *m_zones; } } } } // Parse the zone.tab. QTextStream str(&f); QRegExp lineSeparator("[ \t]"); QRegExp ordinateSeparator("[+-]"); KSharedPtr<KstTimezoneSource> db(new KstTimezoneSource(m_zoneinfoDir)); while (!str.atEnd()) { QString line = str.readLine(); if (line.isEmpty() || '#' == line[0]) continue; QStringList tokens = KStringHandler::perlSplit(lineSeparator, line, 4); if (tokens.count() < 3) { continue; } // Got three tokens. Now check for two ordinates plus first one is "". QStringList ordinates = KStringHandler::perlSplit(ordinateSeparator, tokens[1], 2); if (ordinates.count() < 2) { continue; } float latitude = convertCoordinate(ordinates[1]); float longitude = convertCoordinate(ordinates[2]); // Add entry to list. if (tokens[0] == "??") tokens[0] = ""; KstTimezone *timezone = new KstTimezone(db, tokens[2], tokens[0], latitude, longitude, tokens[3]); add(timezone); } f.close(); return *m_zones; }
/* * Find the location of the zoneinfo files and store in mZoneinfoDir. * Parse zone.tab and for each time zone, create a KSystemTimeZone instance. */ void KSystemTimeZonesPrivate::readZoneTab(bool update) { kDebug(161) << "readZoneTab(" << m_zonetab<< ")"; QStringList newZones; QFile f; f.setFileName(m_zonetab); if (!f.open(QIODevice::ReadOnly)) return; QTextStream str(&f); QRegExp lineSeparator("[ \t]"); QRegExp ordinateSeparator("[+-]"); if (!m_source) m_source = new KSystemTimeZoneSource; while (!str.atEnd()) { QString line = str.readLine(); if (line.isEmpty() || line[0] == '#') continue; QStringList tokens = KStringHandler::perlSplit(lineSeparator, line, 4); int n = tokens.count(); if (n < 3) { kError(161) << "readZoneTab(): invalid record: " << line << endl; continue; } // Got three tokens. Now check for two ordinates plus first one is "". int i = tokens[1].indexOf(ordinateSeparator, 1); if (i < 0) { kError(161) << "readZoneTab() " << tokens[2] << ": invalid coordinates: " << tokens[1] << endl; continue; } float latitude = convertCoordinate(tokens[1].left(i)); float longitude = convertCoordinate(tokens[1].mid(i)); // Add entry to list. if (tokens[0] == "??") tokens[0] = ""; // Solaris sets the empty Comments field to '-', making it not empty. // Clean it up. if (n > 3 && tokens[3] == "-") tokens[3] = ""; KSystemTimeZone tz(m_source, tokens[2], tokens[0], latitude, longitude, (n > 3 ? tokens[3] : QString())); if (update) { // Update the existing collection with the new zone definition newZones += tz.name(); KTimeZone oldTz = zone(tz.name()); if (oldTz.isValid()) oldTz.updateBase(tz); // the zone previously existed, so update its definition else add(tz); // the zone didn't previously exist, so add it } else add(tz); } f.close(); if (update) { // Remove any zones from the collection which no longer exist const ZoneMap oldZones = zones(); for (ZoneMap::ConstIterator it = oldZones.constBegin(); it != oldZones.constEnd(); ++it) { if (newZones.indexOf(it.key()) < 0) remove(it.value()); } } }
//***************************************************************************** // //! This reads the data from the GPS module, parses the data, and saves to //! the microSD card, if a card is present. // //***************************************************************************** int gpsData(void) { float latitude, longitude, speed, course; char UARTreadChar; char idBuffer[7] = {}; char sentence[10][20] = {}; bool parsingId = false; bool readingData = false; bool readComplete = false; uint32_t i = 0; // Sentence id chars uint32_t j = 0; // NMEA sentence pointer uint32_t k = 0; // NMEA chars while (readComplete != true) { if (UARTCharsAvail(UART7_BASE)) { UARTreadChar = UARTCharGet(UART7_BASE); if ((parsingId == false) && (UARTreadChar == '$')) { i = 0; parsingId = true; readingData = false; } else if ((parsingId == true) && (UARTreadChar == ',')) { idBuffer[i] = '\0'; i = 0; parsingId = false; if (strcmp(idBuffer, "GPRMC") == 0) { j = 0; k = 0; readingData = true; } else { readingData = false; } } else if ((parsingId == true) && (UARTreadChar != ',')) { idBuffer[i] = UARTreadChar; i++; } else if ((readingData == true) && (UARTreadChar == '\r')) { sentence[j][k] = '\0'; // // Copy data which will remain strings into named variables // char *timestamp = strdup(sentence[0]); char *status = strdup(sentence[1]); char *nsIndicator = strdup(sentence[3]); char *ewIndicator = strdup(sentence[5]); char *date = strdup(sentence[8]); // // Stop processing and return 0 if data invalid // if (strcmp(status, "V") == 0) { return 0; } // // Convert latitude to decimal degrees // latitude = convertCoordinate(ustrtof(sentence[2], NULL), nsIndicator); // // Convert longitude to decimal degrees // longitude = convertCoordinate(ustrtof(sentence[4], NULL), ewIndicator); // // Convert speed from knots to mph // speed = 1.15078 * ustrtof(sentence[6], NULL); course = ustrtof(sentence[7], NULL); //**************************************************** //! Data Debug/Display UART terminal movement //! //! (ANSI/VT100 Terminal Control Escape Sequences) //! Adapted from the following: http://goo.gl/s43voj //**************************************************** // // Display serial output only if not in low power mode // if (!lowPowerOn) { // Initial terminal setup // Clear Terminal printStringToTerminal("\033[2J",0); // Cursor to 0,0 printStringToTerminal("\033[0;0H", 0); printStringToTerminal("Time (UTC)", 0); //Cursor to 0,1 printStringToTerminal("\033[2;0H", 0); // Print values to the terminal printStringToTerminal(timestamp, 2); printStringToTerminal("\r\n", 0); printStringToTerminal("Latitude\tLongitude", 2); printFloatToTerminal(latitude, 1); printFloatToTerminal(longitude, 2); printStringToTerminal("\r\n", 0); printStringToTerminal("Course\t\tSpeed (MPH)", 2); printFloatToTerminal(course, 1); printFloatToTerminal(speed, 2); // Check if an SD card is inserted and indicate on term if (cardDetect()) { printStringToTerminal("\r\n*Logging to SD Card*", 2); } } // // Check if SD card is present and write data if true. // if (cardDetect()) { logToSD(timestamp, date, latitude, longitude, speed, course); } // // Deallocate memory used by strdup function // free(timestamp); free(status); free(nsIndicator); free(ewIndicator); free(date); return 1; } // // Parse GPS char received // else if ((readingData == true) && (UARTreadChar != ',')){ sentence[j][k] = UARTreadChar; k++; } // // Parse GPS char received // else if ((readingData == true) && (UARTreadChar == ',')){ sentence[j][k] = '\0'; j++; k = 0; } } // End if chars available } // end while return 0; // Should never get here } // End function gpsData