/*
 * Check that disconnection from MFeedbackd works as expected
 * when connection simply fails.
 */
void Ut_MReactionMap::disconnect3()
{
    QRect clientRect(0, 0, 100, 50);
    MReactionMapConnection *testConnection;

    testConnection = MReactionMapConnection::instance();

    // Set 1:1 mapping of coordinates
    reactionMap1->setTransform(QTransform());
    reactionMap1->setTransparentDrawingValue();
    reactionMap1->fillRectangle(clientRect);

    // Check that locally created image is as expected
    QCOMPARE(checkArea(reactionMap1, 1, clientRect.x(), clientRect.y(),
                       clientRect.width(), clientRect.height()), true);

    // Send information about shared memory
    testConnection->setSharedMemoryData(reactionMap1->getPrivatePtr());

    // Disconnect and fail so that reconnection is no longer an option
    testConnection->disconnect(true);

    // Check that image has not changed
    QCOMPARE(checkArea(reactionMap1, 1, clientRect.x(), clientRect.y(),
                       clientRect.width(), clientRect.height()), true);

    // Check that reaction map was added to connections
    QVERIFY(testConnection->reactionMaps.contains(reactionMap1->getPrivatePtr()) == true);
}
/*
 * Check that receiving shared memory works as expected.
 */
void Ut_MReactionMap::receiveSharedMemory()
{
    QRect clientRect(0, 0, 100, 50);
    uchar *imagePtr;
    uchar *oldImagePtr;
    MReactionMapConnection *testConnection;

    testConnection = MReactionMapConnection::instance();

    // Set 1:1 mapping of coordinates
    reactionMap1->setTransform(QTransform());
    reactionMap1->setTransparentDrawingValue();
    reactionMap1->fillRectangle(clientRect);

    // Get temporary locally allocated image pointer
    oldImagePtr = reactionMap1->getImage();

    // Check that locally created image is as expected
    QCOMPARE(checkArea(reactionMap1, 1, clientRect.x(), clientRect.y(),
                       clientRect.width(), clientRect.height()), true);

    // Send information about shared memory
    testConnection->setSharedMemoryData(reactionMap1->getPrivatePtr());

    // Get shared memory pointer
    imagePtr = reactionMap1->getImage();

    // Check that shared memory image is the same as locally created was
    QCOMPARE(checkArea(reactionMap1, 1, clientRect.x(), clientRect.y(),
                       clientRect.width(), clientRect.height()), true);

    // Verify that memory pointers have actually changed
    QVERIFY(oldImagePtr != imagePtr);
}
예제 #3
0
// RankView
//---------------------------------------------------------------------------
RankView::RankView() : GameTemplateView()
{
    setSearchName("RankView");
    setTitle("Rankings");
    setSubTitle(" - TAB");

    setAllowResize(false);
    moveTo(GameConfig::interface_rankposition_x, GameConfig::interface_rankposition_y);
    resize(iXY(WINDOW_WIDTH, 200));
    checkArea(iXY(screen->getWidth(),screen->getHeight()));

    // Define the scrollBar fot this view.
    scrollBar = new ScrollBar(ScrollBar::VERTICAL, 0, 1, 0, 100);
    if (scrollBar == 0) {
        throw Exception("ERROR: Unable to allocate the scrollBar.");
    }

    allyImage.loadBMP("pics/default/ally.bmp");
    allyRequestImage.loadBMP("pics/default/allyRequest.bmp");
    allyOtherImage.loadBMP("pics/default/allyOther.bmp");
    noAllyImage.loadBMP("pics/default/noAlly.bmp");
    colorImage.loadBMP("pics/default/playerColor.bmp");

    selected_line = -1;

} // end RankView::RankView
EndRoundView::EndRoundView() : SpecialButtonView()
{
    setSearchName("EndRoundView");
    setTitle("Round stats");
    setSubTitle("");

    setAllowResize(false);
    setAllowMove(false);
    setVisible(false);
    setBordered(false);

    int x = (screen->getWidth() / 2) - 250;
    int y = (screen->getHeight() / 2) - 250;
    moveTo(iXY(x, y));
    resize(iXY(500, 500));
    checkArea(iXY(screen->getWidth(),screen->getHeight()));

    allyImage.loadBMP("pics/default/ally.bmp");
    allyRequestImage.loadBMP("pics/default/allyRequest.bmp");
    allyOtherImage.loadBMP("pics/default/allyOther.bmp");
    noAllyImage.loadBMP("pics/default/noAlly.bmp");
    colorImage.loadBMP("pics/default/playerColor.bmp");

    selected_line = -1;
    RectWinner = getClientRect();
    RectWinner.min.x = RectWinner.min.y = 0;
    RectStates = RectWinner;
    RectWinner.max.y = HEADER_HEIGHT-10;
    RectStates.min.y = HEADER_HEIGHT;

} // end EndRoundView::EndRoundView
/*
 * Draw on a reaction map, clear it and check that reaction map is actually cleared.
 */
void Ut_MReactionMap::clear()
{
    QRect clientRect(20, 30, 40, 50);

    reactionMap1->setReactiveDrawingValue();
    reactionMap1->fillRectangle(clientRect);

    reactionMap1->clear();
    QCOMPARE(checkArea(reactionMap1, 0, 0, 0, 0, 0), true);
}
/*
 * Draw a rectangle that is totally out of bounds and see that no rectangle
 * is drawn.
 */
void Ut_MReactionMap::drawInvalidRectangle1()
{
    QRectF clientRect(1000000, 10000000, 1000000, 1000000);

    // Set 1:1 transform
    reactionMap1->setTransform(QTransform());
    reactionMap1->setReactiveDrawingValue();
    reactionMap1->fillRectangle(clientRect);

    QCOMPARE(checkArea(reactionMap1, 0, 0, 0, 0, 0), true);
}
/*
 * Draw a rectangle using the 1:1 transform matrix and check that
 * the resulting reaction map is correct.
 */
void Ut_MReactionMap::drawRectangle2()
{
    QRect clientRect(0, 0, 100, 50);

    // Set 1:1 mapping of coordinates
    reactionMap1->setTransform(QTransform());
    reactionMap1->setTransparentDrawingValue();
    reactionMap1->fillRectangle(clientRect);

    QCOMPARE(checkArea(reactionMap1, 1, clientRect.x(), clientRect.y(),
                       clientRect.width(), clientRect.height()), true);
}
/*
 * Draw a rectangle that is partially out of bounds and check that only
 * intersecting rectangle is drawn.
 */
void Ut_MReactionMap::drawInvalidRectangle2()
{
    QRectF clientRect(MfSettings::reactionMapWidth()/2, MfSettings::reactionMapHeight()/2,
                      MfSettings::reactionMapWidth()*2, MfSettings::reactionMapHeight()*2);

    // Set 1:1 transform
    reactionMap1->setTransform(QTransform());
    reactionMap1->setReactiveDrawingValue();
    reactionMap1->fillRectangle(clientRect);

    QCOMPARE(checkArea(reactionMap1, 2,
                       MfSettings::reactionMapWidth()/2, MfSettings::reactionMapHeight()/2,
                       MfSettings::reactionMapWidth()/2, MfSettings::reactionMapHeight()/2), true);
}
// doActivate
//---------------------------------------------------------------------------
void VehicleSelectionView::doActivate()
{
    if (Desktop::getFocus() != this) {
        iXY pos;

        pos = mouse.getScreenPos() - getSize() / 2;

        moveTo(pos);
        checkArea(iXY(screen->getWidth(),screen->getHeight()));
    }

    GameTemplateView::doActivate();

} // end VehicleSelectionView::doActivate
/*
 * Draw a rectangle with temporary drawing value and check that the rectangle is
 * correct and that the original drawing value is retained.
 */
void Ut_MReactionMap::drawRectangle4()
{
    QTransform transform;
    QRect reactionMapRect;
    QRect clientRect(20, 20, 50, 50);

    reactionMap1->setDrawingValue("foo", "bar");
    reactionMap1->fillRectangle(clientRect, "press", "release");

    transform = reactionMap1->transform();
    reactionMapRect = transform.mapRect(clientRect);
    QCOMPARE(checkArea(reactionMap1, 2, reactionMapRect.x(), reactionMapRect.y(),
                       reactionMapRect.width(), reactionMapRect.height()), true);
    QCOMPARE(reactionMap1->getDrawingValue(), static_cast<quint8>(3));
}
/*
 * Draw a rectangle using the original transform matrix and check that
 * the resulting reaction map is correct.
 */
void Ut_MReactionMap::drawRectangle1()
{
    QTransform transform;
    QRect reactionMapRect;
    QRect clientRect(20, 30, 40, 50);

    reactionMap1->setReactiveDrawingValue();
    reactionMap1->fillRectangle(clientRect.x(), clientRect.y(),
                                clientRect.width(), clientRect.height());

    transform = reactionMap1->transform();
    reactionMapRect = transform.mapRect(clientRect);
    QCOMPARE(checkArea(reactionMap1, 2, reactionMapRect.x(), reactionMapRect.y(),
                       reactionMapRect.width(), reactionMapRect.height()), true);
}
/*
 * Draw a rectangle using custom transform matrix and custom color and check
 * that the resulting reaction map is correct.
 */
void Ut_MReactionMap::drawRectangle3()
{
    QTransform transform;
    QRectF reactionMapRect;
    QRectF clientRect(0, 0, 1, 1);

    transform = transform.scale(10, 10);
    transform = transform.translate(1, 1);

    reactionMap1->setTransform(transform);
    reactionMap1->setDrawingValue("foo", "bar");
    reactionMap1->fillRectangle(clientRect);

    reactionMapRect = transform.mapRect(clientRect);
    QCOMPARE(checkArea(reactionMap1, 3, reactionMapRect.x(), reactionMapRect.y(),
                       reactionMapRect.width(), reactionMapRect.height()), true);
}
// rMouseDrag
//---------------------------------------------------------------------------
void GameTemplateView::rMouseDrag(const iXY&, const iXY &prevPos, const iXY &newPos)
{
    // Check for view blending mode change.
    if (KeyboardInterface::getKeyPressed(SDLK_1)) {
        gameconfig->viewdrawbackgroundmode = VIEW_BACKGROUND_DARK_GRAY_BLEND;
    } else if (KeyboardInterface::getKeyPressed(SDLK_2)) {
        gameconfig->viewdrawbackgroundmode = VIEW_BACKGROUND_LIGHT_GRAY_BLEND;
    } else if (KeyboardInterface::getKeyPressed(SDLK_3)) {
        gameconfig->viewdrawbackgroundmode = VIEW_BACKGROUND_SOLID_BLACK;
    } else if (KeyboardInterface::getKeyPressed(SDLK_4)) {
        gameconfig->viewdrawbackgroundmode = VIEW_BACKGROUND_TRANSPARENT;
    }

    moveTo(min + newPos - prevPos);
    checkArea(iXY(screen->getWidth(),screen->getHeight()));
    notifyMoveTo();
}
예제 #14
0
// RankView
//---------------------------------------------------------------------------
RankView::RankView() : GameTemplateView()
{
    setSearchName("RankView");
    setTitle("Rankings");
    setSubTitle(" - TAB");

    moveTo(gameconfig->rankposition);
    resize(iXY(450 + 20, 200));
    checkArea(iXY(screen->getWidth(),screen->getHeight()));

    const unsigned MAX_ALLY_CHARS		=  6;
//    const unsigned MAX_FLAG_CHARS      =  5;
	const unsigned MAX_NAME_CHARS      = 20;
    const unsigned MAX_KILLS_CHARS     =  6;
    const unsigned MAX_LOSSES_CHARS    =  7;
    const unsigned MAX_POINTS_CHARS    =  7;

    // hardcoded for now
    int CHAR_XPIX = 8;

    unsigned xOffset = 0;
    unsigned yOffset = 16;
    add( new Label( xOffset, yOffset, "*Flag", Color::red, Color::gray64, true) );
    xOffset += MAX_ALLY_CHARS*CHAR_XPIX;
//    add( new Label( xOffset, yOffset, "Flag", Color::red, Color::gray64, true) );
//    xOffset += MAX_FLAG_CHARS*CHAR_XPIX;
    add( new Label( xOffset, yOffset, "Name", Color::red, Color::gray64, true) );
    xOffset += MAX_NAME_CHARS*CHAR_XPIX;
    add( new Label( xOffset, yOffset, "Kills", Color::red, Color::gray64, true) );
    xOffset += MAX_KILLS_CHARS*CHAR_XPIX;
    add( new Label( xOffset, yOffset, "Losses", Color::red, Color::gray64, true) );
    xOffset += MAX_LOSSES_CHARS*CHAR_XPIX;
    add( new Label( xOffset, yOffset, "Points", Color::red, Color::gray64, true) );
    xOffset += MAX_POINTS_CHARS*CHAR_XPIX;
    add( new Label( xOffset, yOffset, "Objective", Color::red, Color::gray64, true) );
    xOffset += MAX_POINTS_CHARS*CHAR_XPIX;

    // shall be in resource manager
    allyImage.loadPNG("pics/default/ally.png");
    allyRequestImage.loadPNG("pics/default/allyRequest.png");
    allyOtherImage.loadPNG("pics/default/allyOther.png");
    noAllyImage.loadPNG("pics/default/noAlly.png");

    states.clear();
} // end RankView::RankView
/*
 * Draw a rectangle with temporary drawing value and custom tranformation matrix
 * and check that the rectangle is correct and that the original drawing value is
 * retained.
 */
void Ut_MReactionMap::drawRectangle5()
{
    QTransform transform;
    QRectF reactionMapRect;
    QRectF clientRect(10, 10, 20, 20);

    transform = transform.scale(2, 2);
    transform = transform.translate(1, 1);

    reactionMap1->setTransform(transform);
    reactionMap1->setInactiveDrawingValue();
    reactionMap1->fillRectangle(clientRect, "foo", "bar");

    reactionMapRect = transform.mapRect(clientRect);
    QCOMPARE(checkArea(reactionMap1, 3, reactionMapRect.x(), reactionMapRect.y(),
                       reactionMapRect.width(), reactionMapRect.height()), true);
    QCOMPARE(reactionMap1->getDrawingValue(), static_cast<quint8>(0));
}
/*
 * Draw a bounding rectangle of a QGraphicsItem and check that
 * the resulting reaction map is correct.
 */
void Ut_MReactionMap::drawBoundingRectangle1()
{
    QTransform transform;
    QRectF reactionMapRect;

    item->setPos(50,25);

    reactionMap1->setReactiveDrawingValue();
    reactionMap1->fillItemBoundRect(item);

    transform = item->sceneTransform() * reactionMap1->transform() * widget1->viewportTransform();
    reactionMapRect = transform.mapRect(item->rect());

    QCOMPARE(checkArea(reactionMap1, 2, qRound(reactionMapRect.x()), qRound(reactionMapRect.y()),
                       qRound(reactionMapRect.width()), qRound(reactionMapRect.height())), true);

    QCOMPARE(reactionMap2->getImage(), (uchar*)NULL);
}
예제 #17
0
// RankView
//---------------------------------------------------------------------------
RankView::RankView() : GameTemplateView()
{
    setSearchName("RankView");
    setTitle("Rankings");
    setSubTitle(" - TAB");

    setAllowResize(false);
    moveTo(gameconfig->rankposition);
    resize(iXY(450, 200));
    checkArea(iXY(screen->getWidth(),screen->getHeight()));

    const unsigned MAX_NAME_CHARS      = 20;
    const unsigned MAX_FLAG_CHARS      =  5;
    const unsigned MAX_KILLS_CHARS     =  6;
    const unsigned MAX_LOSSES_CHARS    =  7;
    const unsigned MAX_POINTS_CHARS    =  7;

    // hardcoded for now
    int CHAR_XPIX = 8;

    //addLabel(iXY nPos, char *nLabel, Uint8 color);
    unsigned xOffset = 0;
    unsigned yOffset = 16;
    addLabel(iXY(xOffset, yOffset), "Name", Color::red);
    xOffset += MAX_NAME_CHARS*CHAR_XPIX;
    addLabel(iXY(xOffset, yOffset), "Flag", Color::red);
    xOffset += MAX_FLAG_CHARS*CHAR_XPIX;
    addLabel(iXY(xOffset, yOffset), "Kills", Color::red);
    xOffset += MAX_KILLS_CHARS*CHAR_XPIX;
    addLabel(iXY(xOffset, yOffset), "Losses", Color::red);
    xOffset += MAX_LOSSES_CHARS*CHAR_XPIX;
    addLabel(iXY(xOffset, yOffset), "Points", Color::red);
    xOffset += MAX_POINTS_CHARS*CHAR_XPIX;
    addLabel(iXY(xOffset, yOffset), "Objective", Color::red);
    xOffset += MAX_POINTS_CHARS*CHAR_XPIX;

    // Define the scrollBar fot this view.
    scrollBar = new ScrollBar(ScrollBar::VERTICAL, 0, 1, 0, 100);
    if (scrollBar == 0) {
        throw Exception("ERROR: Unable to allocate the scrollBar.");
    }
} // end RankView::RankView
예제 #18
0
void Poro::doStuff(const EventHandler&, std::vector< std::vector<TileSprite*> > const& tiles, std::map< std::string, Entity* >& entities, sf::Time animate)
{
    checkArea(entities);

    //Compute the gravity
    computeGravity(animate);

    //Check the collisions, set the new distances and do the move
    Collide collideTiles = collideWithTiles(tiles, animate.asSeconds());
    setDistance(collideTiles);
    move(animate.asSeconds()*(speed.x), animate.asSeconds()*speed.y);
    sprite->update(animate);

    if (speed.y == 0 && ((speed.x > 0 && collideTiles.right["surface"]) || (speed.x < 0 && collideTiles.left["surface"])))
    {
        speed.y = -SPEED_Y;
    }

    if (damageCD)
        --damageCD;
}
예제 #19
0
// RankView
//---------------------------------------------------------------------------
RankView::RankView() : GameTemplateView()
{
    setSearchName("RankView");
//    setTitle(_("Rankings"));

    moveTo(gameconfig->gameinterface.getRankPositionX(), gameconfig->gameinterface.getRankPositionY());
    resize(iXY(WINDOW_WIDTH, 200));
    checkArea(iXY(screen->getWidth(),screen->getHeight()));

    allyImage.loadPNG("pics/default/ally.png");
    allyRequestImage.loadPNG("pics/default/allyRequest.png");
    allyOtherImage.loadPNG("pics/default/allyOther.png");
    noAllyImage.loadPNG("pics/default/noAlly.png");
    colorImage.loadPNG("pics/default/playerColor.png");

    selected_line = -1;
    snprintf(table_header, sizeof(table_header), "    %-20s %6s %7s %7s %6s", 
             _("Name"),
             _("Frags"),
             _("Deaths"),
             _("Points"),
             _("Objs"));
} // end RankView::RankView
/*
 * Draw a bounding rectangle of a QGraphicsItem and check that
 * the resulting reaction map is correct. Also check that the
 * temporary drawing value is not permanently stored.
 */
void Ut_MReactionMap::drawBoundingRectangle2()
{
    QTransform transform;
    QRectF reactionMapRect;

    item->setPos(5,5);

    widget2->scale(2,2);
    widget2->centerOn(0,0);

    reactionMap2->setReactiveDrawingValue();
    reactionMap2->fillItemBoundRect(item, "foo", "bar");

    transform = item->sceneTransform() * reactionMap2->transform() * widget2->viewportTransform();
    reactionMapRect = transform.mapRect(item->rect());

    QCOMPARE(checkArea(reactionMap2, 3, qRound(reactionMapRect.x()), qRound(reactionMapRect.y()),
                       qRound(reactionMapRect.width()), qRound(reactionMapRect.height())), true);

    QCOMPARE(reactionMap1->getImage(), (uchar*)NULL);

    QCOMPARE(reactionMap2->getDrawingValue(), static_cast<quint8>(2));
}
예제 #21
0
void Parallelogram::setContact1(const Ball_p& b, Ball_v& ball, Obj_v& obj, uint32_t counter){
	auto& t = b->touchArea[num];
	if((!b->conC.empty() && b->conC.front()->num == num && b->conC.front()->type == ObjType::O) || !t->collidable) return;
	// 円がどの辺・角と衝突するか判定
	checkArea(b, b->p);
	// 円が内部に入っている場合
	if(t->side == 5){
		if(b->shootFrame == counter){
			ball[0]->absorb(b, counter);
			return;
		}else checkArea(b, b->p-b->v);
		if(t->side == 5) b->toScatter = true;
		return;
	}
	// この場合は角に当たる
	if(t->side%2==1){
		const double dist = b->p.dist(t->p);
		if(dist <= b->size){
			con.push_back(std::make_shared<Contact>());
			b->conC.push_back(std::make_shared<Contact>());
			b->bezC.push_back(std::make_shared<Bezier>());
			
			auto& c1 = con.back();
			auto& c2 = b->conC.back();
			c1->p = t->p;
			c1->exc = b->size-dist;
			c1->num = b->num;
			c1->type = ObjType::C;
			c1->weight = b->weight;
			c1->arg = b->p.arg(t->p);
			c1->color = b->color;
			c1->side = t->side;
			c1->pairP = b->p;
			c1->pairV = b->v;
			
			c2->p = t->p;
			c2->dist = c2->p.dist(b->p);
			c2->exc = b->size-dist;
			c2->arg = t->p.arg(b->p);
			c2->tan = c2->arg+PI_2;
			c2->num = num;
			c2->type = ObjType::O;
			c2->side = t->side;
		}else if(dist <= b->size*1.5) return;
	// この場合は辺に当たる
	}else if(t->side%2==0){
		const double drop = (b->p-t->p)*pol(t->arg);
		if(drop <= b->size){
			con.push_back(std::make_shared<Contact>());
			b->conC.push_back(std::make_shared<Contact>());
			b->bezC.push_back(std::make_shared<Bezier>());

			auto& c1 = con.back();
			auto& c2 = b->conC.back();
			c1->p = b->p-pol(drop, t->arg);
			c1->exc = b->size-drop;
			c1->num = b->num;
			c1->type = ObjType::C;
			c1->weight = b->weight;
			c1->arg = t->arg;
			c1->color = b->color;
			c1->side = t->side;
			c1->pairP = b->p;
			c1->pairV = b->v;
			
			c2->p = c1->p;
			c2->dist = c2->p.dist(b->p);
			c2->exc = b->size-drop;
			c2->arg = t->arg+PI;
			c2->tan = t->arg-PI_2;
			c2->num = num;
			c2->type = ObjType::O;
			c2->side = t->side;
		}
		else if(drop <= b->size*1.5) return;
	}else{
		printf("#\n");
	}
}
예제 #22
0
void Parallelogram::setContact2(const Ball_p& b, Ball_v& ball, Obj_v& obj, uint32_t counter){
	for(auto c:b->conC){
		if(c->num == num && c->type == ObjType::O) return;
	}
	auto& t = b->touchArea[num];
	if(!t->collidable) return;
	// 円がどの辺・角と衝突するか判定
	checkArea(b, b->p);
	// 円が内部に入っている場合
	if(t->side == 5){
		if(b->shootFrame == counter) checkArea(b, ball[0]->p);
		checkArea(b, b->p-b->v);
		if(t->side == 5) b->toScatter = true;
		return;
	}
	// この場合は角に当たる
	if(t->side%2==1){
		const Arg arg = t->p.arg(b->p);
		// 接点がどのdotの間にあるのか調べる。kがdot_numberになる
		int dotN;
		for(dotN = 0; dotN < dotL; dotN++){
			if(arg < b->dot[dotN].arg-b->dot[0].arg) break;
		}
		const double s = (arg-b->dot[dotN-1].arg)/(b->dot[dotN].arg-b->dot[dotN-1].arg);
		const Arg tan1 = b->dot[dotN].abs.arg(b->dot[dotN-2].abs);
		const Arg tan2 = b->dot[dotN+1].abs.arg(b->dot[dotN-1].abs);
		const double exc = -(b->dot[dotN-1].abs-b->dot[dotN].abs)^(t->p-b->dot[dotN].abs);
		if(exc < 0 && exc > -b->size){
			con.push_back(std::make_shared<Contact>());
			b->conD.push_back(std::make_shared<Contact>());
			b->bezD.push_back(std::make_shared<Bezier>());
			
			auto& c1 = con.back();
			auto& c2 = b->conD.back();
			c1->p = t->p;
			c1->exc = -exc;
			c1->num = b->num;
			c1->type = ObjType::D;
			c1->weight = b->weight;
			c1->arg = arg+PI;
			c1->color = b->color;
			c1->side = t->side;
			c1->pairP = b->p;
			c1->pairV = b->v;
			
			c2->p = t->p;
			c2->dist = c2->p.dist(b->p);
			c2->exc = -exc;
			c2->arg = arg;
			c2->tan = (1.0-s)*tan1+s*tan2;
			c2->num = num;
			c2->type = ObjType::O;
			c2->side = t->side;
		}
	// この場合は辺に当たる
	}else if(t->side%2==0){
		const Arg arg = t->arg+PI;
		int dotN = b->getDotN(arg);
		// 壁に垂直な向きへの長さが一番大きい点を調べる
		if(b->dot[dotN+1].rel*pol(arg) > b->dot[dotN-1].rel*pol(arg)){
			while(b->dot[dotN+1].rel*pol(arg) > b->dot[dotN].rel*pol(arg)){
				dotN++;
			}
		}else{
			while(b->dot[dotN-1].rel*pol(arg) > b->dot[dotN].rel*pol(arg)){
				dotN--;
			}
		}
		if((b->dot[dotN].abs-t->p)*pol(arg) >= 0.0){
			con.push_back(std::make_shared<Contact>());
			b->conD.push_back(std::make_shared<Contact>());
			b->bezD.push_back(std::make_shared<Bezier>());
			
			auto& c1 = con.back();
			auto& c2 = b->conD.back();
			if(std::abs(b->dot[dotN].abs.x-b->p.x) < 1.0e-6){
				c1->p = c2->p = t->p;
			}else if(tan(arg) < 1.0e-6){
				c1->p.x = c2->p.x = t->p.x;
				c1->p.y = c2->p.y = b->p.y;
			}else{
				const double a1 = (b->dot[dotN].abs.y-b->p.y)/(b->dot[dotN].abs.x-b->p.x);
				const double a3 = -1.0/tan(arg);
				c1->p.x = (a1*b->p.x-b->p.y-a3*t->p.x+t->p.y)/(a1-a3);
				c1->p.y = a1*(c1->p.x-b->p.x)+b->p.y;
				c2->p.x = (a1*b->p.x-b->p.y-a3*t->p.x+t->p.y)/(a1-a3);
				c2->p.y = a1*(c2->p.x-b->p.x)+b->p.y;
			}
			c1->exc = (b->dot[dotN].abs-c1->p)*pol(PI-arg);
			c1->num = b->num;
			c1->type = ObjType::D;
			c1->weight = b->weight;
			c1->arg = arg;
			c1->color = b->color;
			c1->side = t->side;
			c1->pairP = b->p;
			c1->pairV = b->v;
			
			c2->dist = c2->p.dist(b->p);
			c2->exc = (b->dot[dotN].abs-c2->p)*pol(PI-arg);
			c2->arg = c2->p.arg(b->p);
			c2->tan = arg+PI_2;
			c2->num = num;
			c2->type = ObjType::O;
			c2->side = t->side;
		}
	}else{
		printf("$\n");
	}
}
예제 #23
0
// rMouseDrag
//---------------------------------------------------------------------------
void LibView::rMouseDrag(const iXY &downPos, const iXY &prevPos, const iXY &newPos)
{
    moveTo(min + newPos - prevPos);
    checkArea(screen->getPix());
}
예제 #24
0
// rMouseDrag
//---------------------------------------------------------------------------
void LibView::rMouseDrag(const iXY&, const iXY &prevPos, const iXY &newPos)
{
    moveTo(min + newPos - prevPos);
    checkArea(iXY(screen->getWidth(),screen->getHeight()));
}
status_t CameraArea::parseAreas(const char *area,
                                size_t areaLength,
                                Vector< sp<CameraArea> > &areas)
{
    status_t ret = NO_ERROR;
    char *ctx;
    char *pArea = NULL;
    char *pStart = NULL;
    char *pEnd = NULL;
    const char *startToken = "(";
    const char endToken = ')';
    const char sep = ',';
    ssize_t top, left, bottom, right, weight;
    char *tmpBuffer = NULL;
    sp<CameraArea> currentArea;

    LOG_FUNCTION_NAME

    if ( ( NULL == area ) ||
            ( 0 >= areaLength ) )
    {
        return -EINVAL;
    }

    tmpBuffer = ( char * ) malloc(areaLength);
    if ( NULL == tmpBuffer )
    {
        return -ENOMEM;
    }

    memcpy(tmpBuffer, area, areaLength);

    pArea = strtok_r(tmpBuffer, startToken, &ctx);

    do
    {

        pStart = pArea;
        if ( NULL == pStart )
        {
            CAMHAL_LOGEA("Parsing of the left area coordinate failed!");
            ret = -EINVAL;
            break;
        }
        else
        {
            left = static_cast<ssize_t>(strtol(pStart, &pEnd, 10));
        }

        if ( sep != *pEnd )
        {
            CAMHAL_LOGEA("Parsing of the top area coordinate failed!");
            ret = -EINVAL;
            break;
        }
        else
        {
            top = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
        }

        if ( sep != *pEnd )
        {
            CAMHAL_LOGEA("Parsing of the right area coordinate failed!");
            ret = -EINVAL;
            break;
        }
        else
        {
            right = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
        }

        if ( sep != *pEnd )
        {
            CAMHAL_LOGEA("Parsing of the bottom area coordinate failed!");
            ret = -EINVAL;
            break;
        }
        else
        {
            bottom = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
        }

        if ( sep != *pEnd )
        {
            CAMHAL_LOGEA("Parsing of the weight area coordinate failed!");
            ret = -EINVAL;
            break;
        }
        else
        {
            weight = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
        }

        if ( endToken != *pEnd )
        {
            CAMHAL_LOGEA("Malformed area!");
            ret = -EINVAL;
            break;
        }

        ret = checkArea(top, left, bottom, right, weight);
        if ( NO_ERROR != ret )
        {
            break;
        }

        currentArea = new CameraArea(top, left, bottom, right, weight);
        CAMHAL_LOGDB("Area parsed [%dx%d, %dx%d] %d",
                     ( int ) top,
                     ( int ) left,
                     ( int ) bottom,
                     ( int ) right,
                     ( int ) weight);
        if ( NULL != currentArea.get() )
        {
            areas.add(currentArea);
        }
        else
        {
            ret = -ENOMEM;
            break;
        }

        pArea = strtok_r(NULL, startToken, &ctx);

    }
    while ( NULL != pArea );

    if ( NULL != tmpBuffer )
    {
        free(tmpBuffer);
    }

    LOG_FUNCTION_NAME_EXIT

    return ret;
}