int main(void) { p1a(); p1b(); return 0; }
void OSGDebugDrawInterface::AddAxes(const dtEntity::Matrix& m, const dtEntity::Vec4f& color, float size, float duration, bool depthTestEnabled) { float arroww = 0.1f; osg::Vec3 p0(0, 0, 0); osg::Vec3 p1(0, 0, 1); osg::Vec3 p2(0, 1, 0); osg::Vec3 p3(1, 0, 0); osg::Vec3 p1a(arroww, 0, 1 - arroww); osg::Vec3 p1b(-arroww, 0, 1 - arroww); osg::Vec3 p2a(arroww, 1 - arroww, 0); osg::Vec3 p2b(-arroww, 1 - arroww, 0); osg::Vec3 p3a(1 - arroww, 0, arroww); osg::Vec3 p3b(1 - arroww, 0, -arroww); std::vector<osg::Vec3> lines(18); lines[0] = m * p0; lines[1] = m * p1; lines[2] = m * p0; lines[3] = m * p2; lines[4] = m * p0; lines[5] = m * p3; lines[6] = m * p1; lines[7] = m * p1a; lines[8] = m * p1; lines[9] = m * p1b; lines[10] = m * p2; lines[11] = m * p2a; lines[12] = m * p2; lines[13] = m * p2b; lines[14] = m * p3; lines[15] = m * p3a; lines[16] = m * p3; lines[17] = m * p3b; AddLines(lines, color, size, duration, depthTestEnabled); }
static void info1b(int v) { dwarfseg(DINFO); p1b(v); debug_info_sz++; }
static int leb128(int d) { if (d > 127) cerror("FIXME: leb128 > 127"); p1b(d); return 1; }
QPolygonF UBGeometryUtils::lineToPolygon(const QPointF& pStart, const QPointF& pEnd, const qreal& pStartWidth, const qreal& pEndWidth) { qreal x1 = pStart.x(); qreal y1 = pStart.y(); qreal x2 = pEnd.x(); qreal y2 = pEnd.y(); QLineF line(pStart, pEnd); qreal alpha = (90.0 - line.angle()) * PI / 180.0; qreal hypothenuseStart = pStartWidth / 2; qreal hypothenuseEnd = pEndWidth / 2; qreal sinAlpha = sin(alpha); qreal cosAlpha = cos(alpha); // TODO UB 4.x PERF cache sin/cos table qreal oppositeStart = sinAlpha * hypothenuseStart; qreal adjacentStart = cosAlpha * hypothenuseStart; QPointF p1a(x1 - adjacentStart, y1 - oppositeStart); QPointF p1b(x1 + adjacentStart, y1 + oppositeStart); qreal oppositeEnd = sinAlpha * hypothenuseEnd; qreal adjacentEnd = cosAlpha * hypothenuseEnd; QPointF p2a(x2 - adjacentEnd, y2 - oppositeEnd); QPainterPath painterPath; painterPath.moveTo(p1a); painterPath.lineTo(p2a); painterPath.arcTo(x2 - hypothenuseEnd, y2 - hypothenuseEnd, pEndWidth, pEndWidth, (90.0 + line.angle()), -180.0); painterPath.lineTo(p1b); painterPath.arcTo(x1 - hypothenuseStart, y1 - hypothenuseStart, pStartWidth, pStartWidth, -1 * (90.0 - line.angle()), -180.0); painterPath.closeSubpath(); return painterPath.toFillPolygon(); }
void WTextSourceViewerLine::drawFoldingLineVisible(QPainter &p,const QPointF &p1,const QPointF &p2) { QPolygonF area; float demi_char_space=char_space/2.0f; QPointF pos(0.0f,(p1.y()+p2.y())/2.0f-demi_char_space); QRectF text_pos(pos,QSizeF(char_space,char_space)); QPointF p3(demi_char_space,p2.y()); QRectF endPoint2(p2.x()-2,p2.y()-2,4,4); QBrush b=p.brush(); p.setBrush(Qt::black); if (p1!=p2) { QPointF p0(demi_char_space,p1.y()); QPointF p1b(demi_char_space,pos.y()); QPointF p2b(demi_char_space,pos.y()+char_space); QRectF endPoint1(p1.x()-2,p1.y()-2,4,4); area << p0 << p1 ; area << p0 << p1b ; area << p2b << p3 ; area << p3 << p2 ; p.drawEllipse(endPoint1); } else { QPointF p1c(char_space,p2.y()); area << p1c << p2 ; } p.drawEllipse(endPoint2); p.setBrush(b); p.drawLines(area); float pos_size=char_space; QRectF rectangle(pos.x(),pos.y(),pos_size,pos_size); p.drawRoundRect(rectangle); float _x1=pos.x()+3.0f; float _y=pos.y()+pos_size/2.0f; float _x2=pos.x()+pos_size-3.0f; p.drawLine(QPointF(_x1,_y),QPointF(_x2,_y)); }
int mossa(int numero1, int numero2, int giocatore) { int risultato; if(giocatore==1) { risultato = p1a(numero1, numero2); risultato = p1b(risultato); } else { risultato = p2a(numero1, numero2); risultato = p2b(risultato); } giocatore=3-giocatore; if(decodifica1(risultato)<3 || decodifica2(risultato)<3) return giocatore; return mossa(decodifica1(risultato), decodifica2(risultato), giocatore); }
QPolygonF UBGeometryUtils::lineToPolygon(const QLineF& pLine, const qreal& pWidth) { qreal x1 = pLine.x1(); qreal y1 = pLine.y1(); qreal x2 = pLine.x2(); qreal y2 = pLine.y2(); qreal alpha = (90.0 - pLine.angle()) * PI / 180.0; qreal hypothenuse = pWidth / 2; // TODO UB 4.x PERF cache sin/cos table qreal opposite = sin(alpha) * hypothenuse; qreal adjacent = cos(alpha) * hypothenuse; QPointF p1a(x1 - adjacent, y1 - opposite); QPointF p1b(x1 + adjacent, y1 + opposite); QPointF p2a(x2 - adjacent, y2 - opposite); QPointF p2b(x2 + adjacent, y2 + opposite); QPainterPath painterPath; painterPath.moveTo(p1a); painterPath.lineTo(p2a); painterPath.arcTo(x2 - hypothenuse, y2 - hypothenuse, pWidth, pWidth, (90.0 + pLine.angle()), -180.0); //painterPath.lineTo(p2b); painterPath.lineTo(p1b); painterPath.arcTo(x1 - hypothenuse, y1 - hypothenuse, pWidth, pWidth, -1 * (90.0 - pLine.angle()), -180.0); painterPath.closeSubpath(); return painterPath.toFillPolygon(); }
void CompileThreadBlock::thread() { EditableMap::Lights& lights = wmap->get_light_sources(); Tileset *ts = wmap->get_tileset_ptr(); size_t nlgt = lights.size(); int mw = wmap->get_width(); int mh = wmap->get_height(); int tw = ts->get_tile_width(); int th = ts->get_tile_height(); int w = mw * tw; int h = mh * th; short **pmap = wmap->get_map(); short **pdeco = wmap->get_decoration(); Point pr; for (size_t i = 0; i < nlgt; i++) { { Scope<Mutex> lock(mtx); finished_percent = 100 * (i + 1) / nlgt; if (cancelled) { break; } } int r = lights[i]->radius; int colr = lights[i]->r; int colg = lights[i]->g; int colb = lights[i]->b; int lmaxsq = r * r; int lx = lights[i]->x; int ly = lights[i]->y; Point p2(static_cast<float>(lx * tw + (tw / 2)), static_cast<float>(ly * th + (th / 2))); int lsx = static_cast<int>(p2.x) - r; int lsy = static_cast<int>(p2.y) - r; int lex = static_cast<int>(p2.x) + r; int ley = static_cast<int>(p2.y) + r; if (lsx < 0) lsx = 0; if (lsy < 0) lsy = 0; if (lex > w) lex = w; if (ley > h) ley = h; int txs = lsx / tw; int txe = lex / tw; int tys = lsy / th; int tye = ley / th; for (int y = lsy; y < ley; y++) { for (int x = lsx; x < lex; x++) { int dindex = pdeco[y / th][x / tw]; if (dindex < 0) { lightmap[y][x * 4 + 3] = 0; } else { bool contact = false; Point p1(static_cast<float>(x), static_cast<float>(y)); float xd = p2.x - p1.x; float yd = p2.y - p1.y; float dist = xd * xd + yd * yd; if (dist < lmaxsq) { for (int tx = txs; tx < txe; tx++) { for (int ty = tys; ty < tye; ty++) { short index = pmap[ty][tx]; if (index >= 0) { if (ts->get_tile(index)->is_light_blocking()) { Point p1l(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2l(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p1r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p2r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); Point p1t(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2t(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p1b(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p2b(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); if (intersection(p1, p2, p1l, p2l, pr) || intersection(p1, p2, p1r, p2r, pr) || intersection(p1, p2, p1t, p2t, pr) || intersection(p1, p2, p1b, p2b, pr)) { contact = true; break; } } } } if (contact) { break; } } } else { contact = true; } if (!contact) { int v = static_cast<int>(sqrt(65025.0f * dist / lmaxsq)); if (v < lightmap[y][x * 4 + 3]) { double l = 1.0 - (static_cast<double>(v) / 255.0); lightmap[y][x * 4 + 0] = static_cast<unsigned char>(colr * l); lightmap[y][x * 4 + 1] = static_cast<unsigned char>(colg * l); lightmap[y][x * 4 + 2] = static_cast<unsigned char>(colb * l); lightmap[y][x * 4 + 3] = v; } } } } } } Scope<Mutex> lock(mtx); finished = true; }
void CompileThreadPixel::thread() { EditableMap::Lights& lights = wmap->get_light_sources(); Tileset *ts = wmap->get_tileset_ptr(); size_t nlgt = lights.size(); int mw = wmap->get_width(); int mh = wmap->get_height(); int tw = ts->get_tile_width(); int th = ts->get_tile_height(); int w = mw * tw; int h = mh * th; short **pmap = wmap->get_map(); short **pdeco = wmap->get_decoration(); Point pr; for (size_t i = 0; i < nlgt; i++) { { ScopeMutex lock(mtx); finished_percent = 100 * (i + 1) / nlgt; } int r = lights[i]->radius; int lmaxsq = r * r; int lx = lights[i]->x; int ly = lights[i]->y; Point p2(static_cast<float>(lx * tw + (tw / 2)), static_cast<float>(ly * th + (th / 2))); int lsx = static_cast<int>(p2.x) - r; int lsy = static_cast<int>(p2.y) - r; int lex = static_cast<int>(p2.x) + r; int ley = static_cast<int>(p2.y) + r; if (lsx < 0) lsx = 0; if (lsy < 0) lsy = 0; if (lex > w) lex = w; if (ley > h) ley = h; int txs = lsx / tw; int txe = lex / tw; int tys = lsy / th; int tye = ley / th; for (int y = lsy; y < ley; y++) { for (int x = lsx; x < lex; x++) { int dindex = pdeco[y / th][x / tw]; if (dindex < 0) { lightmap[y][x * 4 + 3] = 0; } else { bool contact = false; Point p1(static_cast<float>(x), static_cast<float>(y)); float xd = p2.x - p1.x; float yd = p2.y - p1.y; float dist = xd * xd + yd * yd; if (dist < lmaxsq) { for (int tx = txs; tx < txe; tx++) { for (int ty = tys; ty < tye; ty++) { short index = pmap[ty][tx]; if (index >= 0) { if (ts->get_tile(index)->is_light_blocking()) { TileGraphic *tg = ts->get_tile(index)->get_tilegraphic(); TileGraphicGL *tggl = static_cast<TileGraphicGL *>(tg); if (tggl->get_bytes_per_pixel(0) < 4) { Point p1l(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2l(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p1r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p2r(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); Point p1t(static_cast<float>(tx * tw), static_cast<float>(ty * th)); Point p2t(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>(ty * th)); Point p1b(static_cast<float>(tx * tw), static_cast<float>((ty + 1) * th - 0.5f)); Point p2b(static_cast<float>((tx + 1) * tw - 0.5f), static_cast<float>((ty + 1) * th - 0.5f)); if (intersection(p1, p2, p1l, p2l, pr) || intersection(p1, p2, p1r, p2r, pr) || intersection(p1, p2, p1t, p2t, pr) || intersection(p1, p2, p1b, p2b, pr)) { contact = true; break; } } else { unsigned char *p = tggl->get_picture_array(0); for (int py = 0; py < th; py++) { for (int px = 0; px < tw; px++) { if (p[3] == 255) { Point p1v(static_cast<float>(tx * tw + px) + 0.5f, static_cast<float>(ty * th + py) - 0.5f); Point p2v(static_cast<float>(tx * tw + px) + 0.5f, static_cast<float>(ty * th + py) + 0.5f); Point p1h(static_cast<float>(tx * tw + px) - 0.5f, static_cast<float>(ty * th + py) + 0.5f); Point p2h(static_cast<float>(tx * tw + px) + 0.5f, static_cast<float>(ty * th + py) + 0.5f); if (intersection(p1, p2, p1v, p2v, pr) || intersection(p1, p2, p1h, p2h, pr)) { contact = true; break; } } p += 4; } if (contact) { break; } } if (contact) { break; } } } } } if (contact) { break; } } } else { contact = true; } if (!contact) { int v = static_cast<int>(sqrt(65025.0f * dist / lmaxsq)); if (v < lightmap[y][x * 4 + 3]) { lightmap[y][x * 4 + 3] = v; } } } } } } ScopeMutex lock(mtx); finished = true; }