bool isHat(unsigned id) const { return id >= hat(0) && id <= hat(7); }
/** * Notes: Triggers are at -32768 unpressed and 32767 pressed Axes with values between -32768 to 32767: +----> y | | v x Axes: 0 L x 1 L y 2 R x 3 R y 4 L tr 5 R tr Buttons: 0 square 1 x 2 circle 3 triangle 4 L1 5 R1 6 L2 7 R2 8 share 9 options 10 L js 11 R js 12 PS button 13 Pad 14 hat */ int JoyStickWindow::drawScreen(void){ int row = 0; wclear(screen); // clear screen of all contents curs_set(row++); mvwprintw(screen,row++,1,"+------------------------------------------+"); mvwprintw(screen,row++,1,"| PS4 Joystick %.2f ", NODE_VERSION); mvwprintw(screen,row++,1,"| Msg Sequence: %d ",js.header.seq); mvwprintw(screen,row++,1,"+------------------------------------------+"); row++; mvwprintw(screen,row++,6,"Left Stick: %5.1f %5.1f \t Right Stick: %5.1f %5.1f", js.axes[0],js.axes[1],js.axes[2],js.axes[3]); mvwprintw(screen,row++,6,"Left Trigger: %5.1f \t Right Trigger: %5.1f", js.axes[4],js.axes[5]); row++; mvwprintw(screen,row++,6,"Shoulder/Trigger Buttons: "); mvwprintw(screen,row++,2*6,"L1:%c L2:%c R1:%c R2:%c ", bm(js.buttons[4]),bm(js.buttons[6]),bm(js.buttons[5]),bm(js.buttons[7])); row++; mvwprintw(screen,row++,6,"JoyStick Buttons: "); mvwprintw(screen,row++,2*6,"Left JS:%c Right JS:%c ", bm(js.buttons[10]),bm(js.buttons[11])); row++; mvwprintw(screen,row++,6,"Symbol Buttons: "); mvwprintw(screen,row++,2*6,"square:%c x:%c circle:%c triangle:%c ", bm(js.buttons[0]),bm(js.buttons[1]),bm(js.buttons[2]),bm(js.buttons[3])); row++; mvwprintw(screen,row++,6,"Other Buttons: "); mvwprintw(screen,row++,2*6,"Share:%c Options:%c PS:%c Pad:%c ", bm(js.buttons[8]),bm(js.buttons[9]),bm(js.buttons[12]),bm(js.buttons[13])); row++; mvwprintw(screen,row++,6,"Hat: %s ", hat(js.buttons[14])); row++; mvwprintw(screen,row++,6,"Raw Buttons (plus hat): "); for(int i=0; i<7; ++i) mvwprintw(screen,row,6+i*2,"%d ", js.buttons[i]); row++; for(int i=7; i<15; ++i) mvwprintw(screen,row,6+(i-7)*2,"%d ", js.buttons[i]); row++; mvwprintw(screen,row++,1,"------- Menu ------"); mvwprintw(screen,row++,6,"[q]uit"); box(screen,0,0); // draw box around screen wrefresh(screen); // display text written to screen refresh(); return 0; }
// Returns the next token in the character stream. // If no next token can be identified, an error // is emitted and we return the error token. Token Lexer::scan() { // Keep consuming characters until we find // a token. while (true) { space(); // Update the position of the current source location. // This denotes the beginning of the current token. loc_ = in_.location(); switch (peek()) { case 0: return eof(); case '{': return lbrace(); case '}': return rbrace(); case '(': return lparen(); case ')': return rparen(); case '[': return lbrack(); case ']': return rbrack(); case ',': return comma(); case ':': return colon(); case ';': return semicolon(); case '.': return dot(); case '+': return plus(); case '-': return minus(); case '*': return star(); case '/': get(); if (peek() == '/') { comment(); continue; } else { return slash(); } case '%': return percent(); case '=': return equal(); case '!': return bang(); case '<': return langle(); case '>': return rangle(); case '&': return ampersand(); case '|': return bar(); case '^': return hat(); case '0': // if the next character is a 'b' then this // is a binary literal if (peek(1) == 'b') return binary_integer(); // if the next character is an 'x' then this // is a hexadecimal integer if (peek(1) == 'x') return hexadecimal_integer(); // otherwise proceed to regular integer lexing case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return integer(); case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': return word(); case '\'': return character(); case '"': return string(); default: return error(); } } }
Pixel Image::Sample (double u, double v, double sx, double sy) { // To sample the image in scale and shift // This is an auxiliary function that it is not essential you fill in or // you may define it differently. // u and v are the floating point coords of the points to be sampled. // sx and sy correspond to the scale values. // In the assignment, it says implement MinifyX MinifyY MagnifyX MagnifyY // separately. That may be a better way to do it. // This hook is primarily to get you thinking about that you have to have // some equivalent of this function. if (sampling_method == IMAGE_SAMPLING_POINT) { // Your work here return GetPixel((int) round(u / sx), (int) round(v / sy)); } else if (sampling_method == IMAGE_SAMPLING_HAT) { int sumr, sumg, sumb; sumr = sumg = sumb = 0; float xdif = 0; float ydif = 0; if (sx < 1) xdif = 1 / sx; else xdif = 1; if (sy < 1) ydif = 1 / sy; else ydif = 1; float n = 0; for (int x = round(u / sx - xdif); x <= round(u / sx + xdif); x++) { float hu = hat((x - u / sx) / xdif); for (int y = round(v / sy - ydif); y <= round(v / sy + ydif); y++) { float hv = hat((y - v / sy) / ydif); float h = hu * hv; n += h; if (!ValidCoord(x, y)) continue; Pixel curr = GetPixel(x, y); sumr += h * curr.r; sumg += h * curr.g; sumb += h * curr.b; } } sumr /= n; sumg /= n; sumb /= n; if (sumr > 255) sumr = 255; else if (sumr < 0) sumr = 0; if (sumg > 255) sumg = 255; else if (sumg < 0) sumg = 0; if (sumb > 255) sumb = 255; else if (sumb < 0) sumb = 0; return Pixel(sumr, sumg, sumb); } else if (sampling_method == IMAGE_SAMPLING_MITCHELL) { int sumr, sumg, sumb; sumr = sumg = sumb = 0; float xdif = 0; float ydif = 0; if (sx < 1) xdif = 1 / sx; else xdif = 1; if (sy < 1) ydif = 1 / sy; else ydif = 1; float n = 0; for (int x = round(u / sx - xdif); x <= round(u / sx + xdif); x++) { float hu = mitchell((x - u / sx) / xdif); for (int y = round(v / sy - ydif); y <= round(v / sy + ydif); y++) { float hv = mitchell((y - v / sy) / ydif); float h = hu * hv; n += h; if (!ValidCoord(x, y)) continue; Pixel curr = GetPixel(x, y); sumr += h * curr.r; sumg += h * curr.g; sumb += h * curr.b; } } sumr /= n; sumg /= n; sumb /= n; if (sumr > 255) sumr = 255; else if (sumr < 0) sumr = 0; if (sumg > 255) sumg = 255; else if (sumg < 0) sumg = 0; if (sumb > 255) sumb = 255; else if (sumb < 0) sumb = 0; return Pixel(sumr, sumg, sumb); } else { fprintf(stderr,"I don't understand what sampling method is used\n") ; exit(1) ; } return Pixel() ; }
/** * \brief Generator * * The infinitesimal generator of SO2 * is \f$ * G_0 = \left( \begin{array}{ccc} * 0& -1& \\ * 1& 0& * \end{array} \right). * \f$ * \see hat() */ SOPHUS_FUNC static Transformation generator() { return hat(1); }
/* 搜寻自己一个屏幕上的hero,看是不是在仇恨范围内*/ void MonsterAttRed::redSchRge(void) { set<string>::iterator her_it; set<string>HeroIdSet; list<HatVal>new_enmy; Point heroPt; Hero *myHero; Nbox *box; bool isCpy; isCpy = false; /*过滤仇恨列表*/ PasSchRge(); box = map_now->getBox(); if(box == NULL) { return; } box->getCentPtSrcHerIdSet(pt,HeroIdSet); for(her_it = HeroIdSet.begin(); her_it != HeroIdSet.end(); ++her_it) { myHero = heroid_to_hero(*her_it); if(myHero == NULL || myHero->getLifeStation() == DEAD || !myHero->getWalkingFlg() ||\ !myHero->getisRedName()) { continue; } #if 0 if(myHero == NULL || myHero->getLifeStation() == DEAD || !myHero->getWalkingFlg()) { continue; } #endif /*为了减少误差,用像素判断*/ heroPt = myHero->getLocation(); /*判断是否在仇恨范围内*/ /*现在是以当前像素坐标点为圆心,仇恨范围动的格式做的*/ if(sqrt(pow(fabs(heroPt._x - pt._x),2)+pow(fabs(heroPt._y - pt._y),2)) < hatRge) { HatVal hat(const_cast<char *>((*her_it).c_str()),hatValRue->getHatInRag()); new_enmy.push_back(hat); myHero->insertAttList(identity); } } /*add by chenzhen 201301311533 */ if(!new_enmy.empty()) { if(map_now != NULL && map_now->getFlgCpy()) { //isCpy = true; copy and wild same. by benliao 2012.12.09 enmityValues.swap(new_enmy); } else { /*交换新仇恨列表*/ enmityValues.swap(new_enmy); } } int flag; /*这里调用一个函数,进行仇恨值列表和物品归属进行操作*/ flag = HatFun(enmityValues,new_enmy,perHerId,goodsOwner,identity,isCpy); /*仇恨列表为空*/ if(enmityValues.empty()) { /*把当前目标玩家至空*/ if(strlen(perHerId) != 0) { memset(perHerId,'\0',SHOR_MID_VALUE_LENGTH + 1); } /*把当前物品归属玩家至空*/ if(strlen(goodsOwner) != 0) //add chenzhen 6.8 { memset(goodsOwner,'\0',IDL + 1); } return; } list<HatVal>::iterator hatf_it; //仇恨列表头结点(仇恨值最大) list<HatVal>::iterator hats_it; //仇恨列表头第二结点(仇恨值第二大) /*如果目标不为空,且目标还在仇恨范围内*/ if(flag > 0) { /*仇恨列表中不止1个人*/ if(enmityValues.size() >= 2) { hatf_it = enmityValues.begin(); hats_it = hatf_it; hats_it ++; /*判断是否满足条件,更改目标*/ if((*hats_it).value > (*hatf_it).value * hatValRue->getChageAirPer()) { chageEny(((*hats_it).id)); } } } else { /*更改目标为仇恨列表的头结点*/ chageEny((*(enmityValues.begin())).id); } }