Exemple #1
0
void
GNELane::updateGeometry() {
    myShapeRotations.clear();
    myShapeLengths.clear();
    //SUMOReal length = myParentEdge.getLength(); // @todo see ticket #448
    // may be different from length
    int segments = (int) getShape().size() - 1;
    if (segments >= 0) {
        myShapeRotations.reserve(segments);
        myShapeLengths.reserve(segments);
        for (int i = 0; i < segments; ++i) {
            const Position& f = getShape()[i];
            const Position& s = getShape()[i + 1];
            myShapeLengths.push_back(f.distanceTo2D(s));
            myShapeRotations.push_back((SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI);
        }
    }
    // Update geometry of additionals vinculated with this lane
    for(AdditionalVector::iterator i = myAdditionals.begin(); i != myAdditionals.end(); i++) {
        (*i)->updateGeometry();
    }
    // Update geometry of additionalSets vinculated to this lane
    for (AdditionalSetVector::iterator i = myAdditionalSets.begin(); i != myAdditionalSets.end(); ++i) {
        (*i)->updateGeometry();
    }
}
void BreakoutMainScene::createBall()
{
    // Create Ball
    cocos2d::log("Create Ball");
    // Tao qua bong va thiet lap khung vat ly cho no
    ball = Sprite::create("breakout_img/breakout_ball.png");
    ball->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    ball->setPosition(Vec2(WINSIZE.width/2 , WINSIZE.height/2 + 50));

    auto ballBody = PhysicsBody::createCircle(ball->getContentSize().width/2 , PHYSICSBODY_MATERIAL_DEFAULT);
    ballBody->getShape(0)->setDensity(1.0f); // trong luc
    ballBody->getShape(0)->setFriction(0.0f);
    ballBody->getShape(0)->setRestitution(1.0f);
    ballBody->setDynamic(true);
    ballBody->setContactTestBitmask(0x00000001);

    ballBody->setGravityEnable(false); // Khong set gia toc


    // Tao 1 luc tac dong
    Vect force = Vect(900000.0f, -900000.0f);
    ballBody->applyImpulse(force);

    ball->setPhysicsBody(ballBody);

    ball->setTag(Tag::T_Ball);
    this->addChild(ball);
}
Exemple #3
0
Scene* GameScene24::createScene() {
    auto scene = Scene::createWithPhysics();

    Vect gravity(0,0);
    scene->getPhysicsWorld()->setGravity(gravity);

    //开启测试模式
    //scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

    //创建一个世界
    Size visibleSize = Director::getInstance()->getVisibleSize();

    //创建一个空心盒子刚体,作为我们游戏世界的边界(避免游戏内的物体跑出屏幕)
    //参数分别是刚体大小。材质(其实就是我们一些预设的数据)、边线厚度
    auto body = PhysicsBody::createEdgeBox(Size(visibleSize.width,visibleSize.height),PHYSICSBODY_MATERIAL_DEFAULT,3);
    body->getShape(0)->setFriction(0.0f);
    body->getShape(0)->setRestitution(1.001f);
    body->getShape(0)->setDensity(1.0f);

    //创建一个节点用于承载刚体,这样刚体就能参与到游戏的物理世界
    auto node = Node::create();
    node->setPosition(visibleSize.width/2,visibleSize.height/2);
    node->setPhysicsBody(body);
    scene->addChild(node);

    auto layer = GameScene24::create();
    scene->addChild(layer);

    return scene;
}
Exemple #4
0
void
GUILane::drawCrossties(const GUIVisualizationSettings& s, SUMOReal scale) const {
    glPushMatrix();
    glPushName(0);
    if (!MSGlobals::gUseMesoSim) {
        setColor(s);
    }
    // draw on top of of the white area between the rails
    glTranslated(0, 0, 0.1);
    int e = (int) getShape().size() - 1;
    for (int i = 0; i < e; ++i) {
        glPushMatrix();
        glTranslated(getShape()[i].x(), getShape()[i].y(), 0.1);
        glRotated(myShapeRotations[i], 0, 0, 1);
        for (SUMOReal t = 0; t < myShapeLengths[i]; t += 1) {
            glBegin(GL_QUADS);
            glVertex2d(-1 * scale, -t);
            glVertex2d(-1 * scale, -t - 0.3);
            glVertex2d(1.0 * scale, -t - 0.3);
            glVertex2d(1.0 * scale, -t);
            glEnd();
        }
        glPopMatrix();
    }
    glPopMatrix();
    glPopName();
}
void
GUILaneWrapper::drawArrows() const {
    unsigned int noLinks = getLinkNumber();
    if (noLinks == 0) {
        return;
    }
    // draw all links
    const Position& end = getShape().back();
    const Position& f = getShape()[-2];
    SUMOReal rot = (SUMOReal) atan2((end.x() - f.x()), (f.y() - end.y())) * (SUMOReal) 180.0 / (SUMOReal) PI;
    glPushMatrix();
    glPushName(0);
    glColor3d(1, 1, 1);
    glTranslated(end.x(), end.y(), 0);
    glRotated(rot, 0, 0, 1);
    for (unsigned int i = 0; i < noLinks; ++i) {
        LinkDirection dir = getLane().getLinkCont()[i]->getDirection();
        LinkState state = getLane().getLinkCont()[i]->getState();
        if (state == LINKSTATE_TL_OFF_NOSIGNAL || dir == LINKDIR_NODIR) {
            continue;
        }
        switch (dir) {
            case LINKDIR_STRAIGHT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 4), Position(0, 1)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_TURN:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), 90, .5, .05);
                GLHelper::drawBoxLine(Position(0.5, 2.5), 180, 1, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0.5, 2.5), Position(0.5, 4)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_LEFT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), 90, 1, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(1.5, 2.5)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_RIGHT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), -90, 1, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(-1.5, 2.5)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_PARTLEFT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), 45, .7, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(1.2, 1.3)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_PARTRIGHT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), -45, .7, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(-1.2, 1.3)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            default:
                break;
        }
    }
    glPopMatrix();
    glPopName();
}
Exemple #6
0
void
GUILane::drawArrows() const {
    if (myLinks.size() == 0) {
        return;
    }
    // draw all links
    const Position& end = getShape().back();
    const Position& f = getShape()[-2];
    const SUMOReal rot = RAD2DEG(atan2((end.x() - f.x()), (f.y() - end.y())));
    glPushMatrix();
    glPushName(0);
    glColor3d(1, 1, 1);
    glTranslated(end.x(), end.y(), 0);
    glRotated(rot, 0, 0, 1);
    for (std::vector<MSLink*>::const_iterator i = myLinks.begin(); i != myLinks.end(); ++i) {
        LinkDirection dir = (*i)->getDirection();
        LinkState state = (*i)->getState();
        if (state == LINKSTATE_TL_OFF_NOSIGNAL || dir == LINKDIR_NODIR) {
            continue;
        }
        switch (dir) {
            case LINKDIR_STRAIGHT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 4), Position(0, 1)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_TURN:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), 90, .5, .05);
                GLHelper::drawBoxLine(Position(0.5, 2.5), 180, 1, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0.5, 2.5), Position(0.5, 4)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_LEFT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), 90, 1, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(1.5, 2.5)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_RIGHT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), -90, 1, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(-1.5, 2.5)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_PARTLEFT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), 45, .7, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(1.2, 1.3)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            case LINKDIR_PARTRIGHT:
                GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                GLHelper::drawBoxLine(Position(0, 2.5), -45, .7, .05);
                GLHelper::drawTriangleAtEnd(Line(Position(0, 2.5), Position(-1.2, 1.3)), (SUMOReal) 1, (SUMOReal) .25);
                break;
            default:
                break;
        }
    }
    glPopMatrix();
    glPopName();
}
Exemple #7
0
GUIGLObjectPopupMenu*
GNELane::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
    GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
    buildPopupHeader(ret, app);
    buildCenterPopupEntry(ret);
    new FXMenuCommand(ret, "Copy edge name to clipboard", 0, ret, MID_COPY_EDGE_NAME);
    buildNameCopyPopupEntry(ret);
    buildSelectionPopupEntry(ret);
    buildPositionCopyEntry(ret, false);
    const int editMode = parent.getVisualisationSettings()->editMode;
    myTLSEditor = 0;
    if (editMode != GNE_MODE_CONNECT && editMode != GNE_MODE_TLS && editMode != GNE_MODE_CREATE_EDGE) {
        new FXMenuCommand(ret, "Split edge here", 0, &parent, MID_GNE_SPLIT_EDGE);
        new FXMenuCommand(ret, "Split edges in both direction here", 0, &parent, MID_GNE_SPLIT_EDGE_BIDI);
        new FXMenuCommand(ret, "Reverse edge", 0, &parent, MID_GNE_REVERSE_EDGE);
        new FXMenuCommand(ret, "Add reverse direction", 0, &parent, MID_GNE_ADD_REVERSE_EDGE);
        new FXMenuCommand(ret, "Set geometry endpoint here", 0, &parent, MID_GNE_SET_EDGE_ENDPOINT);
        new FXMenuCommand(ret, "Restore geometry endpoint", 0, &parent, MID_GNE_RESET_EDGE_ENDPOINT);
        if (gSelected.isSelected(GLO_LANE, getGlID())) {
            new FXMenuCommand(ret, "Straighten selected Edges", 0, &parent, MID_GNE_STRAIGHTEN);
        } else {
            new FXMenuCommand(ret, "Straighten edge", 0, &parent, MID_GNE_STRAIGHTEN);
        }
        if (gSelected.isSelected(GLO_LANE, getGlID())) {
            new FXMenuCommand(ret, "Duplicate selected lanes", 0, &parent, MID_GNE_DUPLICATE_LANE);
        } else {
            new FXMenuCommand(ret, "Duplicate lane", 0, &parent, MID_GNE_DUPLICATE_LANE);
        }
    } else if (editMode == GNE_MODE_TLS) {
        myTLSEditor = static_cast<GNEViewNet&>(parent).getViewParent()->getTLSEditorFrame();
        if (myTLSEditor->controlsEdge(myParentEdge)) {
            new FXMenuCommand(ret, "Select state for all links from this edge:", 0, 0, 0);
            const std::vector<std::string> names = GNEInternalLane::LinkStateNames.getStrings();
            for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
                FXuint state = GNEInternalLane::LinkStateNames.get(*it);
                FXMenuRadio* mc = new FXMenuRadio(ret, (*it).c_str(), this, FXDataTarget::ID_OPTION + state);
                mc->setSelBackColor(MFXUtils::getFXColor(GNEInternalLane::colorForLinksState(state)));
                mc->setBackColor(MFXUtils::getFXColor(GNEInternalLane::colorForLinksState(state)));
            }
        }
    } else {
        FXMenuCommand* mc = new FXMenuCommand(ret, "Additional options available in 'Inspect Mode'", 0, 0, 0);
        mc->handle(&parent, FXSEL(SEL_COMMAND, FXWindow::ID_DISABLE), 0);
    }
    // buildShowParamsPopupEntry(ret, false);
    new FXMenuSeparator(ret);
    const SUMOReal pos = getShape().nearest_offset_to_point2D(parent.getPositionInformation());
    const SUMOReal height = getShape().positionAtOffset2D(getShape().nearest_offset_to_point2D(parent.getPositionInformation())).z();
    new FXMenuCommand(ret, ("Shape pos: " + toString(pos)).c_str(), 0, 0, 0);
    new FXMenuCommand(ret, ("Length pos: " + toString(getPositionRelativeToShapeLenght(pos))).c_str(), 0, 0, 0);
    new FXMenuCommand(ret, ("Height: " + toString(height)).c_str(), 0, 0, 0);
    // new FXMenuSeparator(ret);
    // buildPositionCopyEntry(ret, false);

    // let the GNEViewNet store the popup position
    (dynamic_cast<GNEViewNet&>(parent)).markPopupPosition();
    return ret;
}
Exemple #8
0
void ShapeControlPainter::_paintVertices(QPainter *painter, const QList<int>& selectedVertices)
{
  qreal zoomFactor = _shapeItem->getCanvas()->getZoomFactor();
  qreal selectRadius = MM::VERTEX_SELECT_RADIUS / zoomFactor;
  qreal strokeWidth  = MM::VERTEX_SELECT_STROKE_WIDTH / zoomFactor;

  for (int i=0; i<getShape()->nVertices(); i++)
    Util::drawControlsVertex(painter, getShape()->getVertex(i), selectedVertices.contains(i), selectRadius, strokeWidth);
}
void CircleGameObject::updatePos() {
    PhysicsObject::updatePos();
    if (getShape() != NULL) {
        float lowerBound = -Context::getInstance()->getH();
        if (getShape()->getCenter().y() < lowerBound) {
            setDeleted(true);
        }
    }
}
void ShapeControlPainter::_paintVertices(QPainter *painter, MapperGLCanvas* canvas, const QList<int>& selectedVertices)
{
  qreal zoomFactor = canvas->getZoomFactor();
  qreal selectRadius = (getShape()->isLocked() ? MM::VERTEX_LOCKED_RADIUS : MM::VERTEX_SELECT_RADIUS) / zoomFactor;
  qreal strokeWidth  = MM::VERTEX_SELECT_STROKE_WIDTH / zoomFactor;

  for (int i=0; i<getShape()->nVertices(); i++)
    Util::drawControlsVertex(painter, getShape()->getVertex(i), selectedVertices.contains(i), getShape()->isLocked(), selectRadius, strokeWidth);
}
Exemple #11
0
void SelectedItem::updateGeometry(int, int)
{
	if (hasShape())
	{
		getShape()->setInnerSize(selectedItem_->width(), selectedItem_->height());
		QPointF pos = QPointF( getShape()->contentLeft(), getShape()->contentTop() );

		setPos(selectedItem_->mapToScene(0,0) - pos);
	}
}
Exemple #12
0
// on "init" you need to initialize your instance
bool GameScene::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto backgroundSprite = Sprite::create("Background.png");
	backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
	this->addChild(backgroundSprite);
	//borders collision
	auto edgeBody = PhysicsBody::createEdgeBox(visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
	edgeBody->getShape(0)->setRestitution(1.0f);
	edgeBody->getShape(0)->setFriction(0.0f);
	edgeBody->getShape(0)->setDensity(1.0f);
	auto edgeNode = Node::create();
	edgeNode->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
	edgeBody->setCollisionBitmask(WALL_COLLISION_BITMASK);
	edgeNode->setPhysicsBody(edgeBody);
	this->addChild(edgeNode);
	edgeNode->setTag(0);
	paddle = new Paddle(this);
	ball = new Ball(this);
	int arrbrick[50];
	GameScene::spawnBricks();



	auto contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(GameScene::onContactBegin, this);
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener, this);

	auto listener = EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);
	listener->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this);
	listener->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	score = 0;

	__String *tempScore = __String::createWithFormat("%i", score);

	scoreLabel = Label::createWithTTF(tempScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);
	scoreLabel->setColor(Color3B::WHITE);
	scoreLabel->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height * 0.75 + origin.y));

	this->addChild(scoreLabel, 10000);
	
	this->scheduleUpdate();
	return true;
}
Exemple #13
0
	void CollisionObject::update(Real t, Matrix4& m)
	{
		assert(is_attached);

		mForcedUpdate = true; ///FIXME Blah. Do we really need this?

		if(mForcedUpdate)
		{
			mNeedsUpdating = true;
		}
		else
		{
			Vector3 p0(old_matrix[0][3], old_matrix[1][3], old_matrix[2][3]);
			Vector3 v0(new_matrix[0][3], new_matrix[1][3], new_matrix[2][3]);
			Vector3 moved = p0 - v0;

			bool hasMoved = (moved != Vector3::ZERO);

			mNeedsUpdating = hasMoved;
		}

		//if(mNeedsUpdating)
		//{
		//	getShape()->computeIceABB();
		//}

		old_matrix = new_matrix;
		old_pos = new_pos;
		new_matrix = m;

		new_pos = getShape()->getParentSceneNode()->_getDerivedPosition();
		// Get center in world space.
		Vector3 lMin,lMax;
		getShape()->getMinMax(lMin,lMax);
		lMax-=lMin;
		mRadius = lMax.length()*0.5;

		old_minv = minv;
		old_maxv = maxv;
		getShape()->getMinMax(minv,maxv);

		// if old_matrix etc are not yet valid,
		// initialize with the current values, to prevent "startup popping"
		bool oldValsInvalid = (m_tdelta <= 0.0);
		if (oldValsInvalid)
		{
			old_matrix = new_matrix;
			old_pos = new_pos;
			old_minv = minv;
			old_maxv = maxv;
		}
		m_tdelta = t;

	}
Exemple #14
0
void GameLayer::createPips() {
	for (int i = 0; i < 2; i++) {
		auto pipeUp = Sprite::createWithSpriteFrame(
			AtlasLoader::getInstance()->getSpriteFrameByName("pipe_up"));
		auto pipeDown = Sprite::createWithSpriteFrame(
			AtlasLoader::getInstance()->getSpriteFrameByName("pipe_down"));

		pipeUp->setPosition(Vec2(0, -(PIPE_HEIGHT + PIPE_DISTANCE) / 2));
		pipeDown->setPosition(Vec2(0, (PIPE_HEIGHT + PIPE_DISTANCE) / 2));

		//创建物理属性
		auto pipeUpBody = PhysicsBody::createBox(pipeUp->getContentSize(), PHYSICSSHAPE_MATERIAL_DEFAULT, Vec2::ZERO);
		//设置为静态刚体
		pipeUpBody->setDynamic(false);
		pipeUpBody->getShape(0)->setRestitution(0.0f);
		//设置刚体密度
		pipeUpBody->getShape(0)->setDensity(1.0f);
		pipeUpBody->setCategoryBitmask(OBST_MASK);
		pipeUpBody->setCollisionBitmask(BIRD_MASK | OBST_MASK);
		pipeUpBody->setContactTestBitmask(BIRD_MASK | OBST_MASK);
		pipeUp->setPhysicsBody(pipeUpBody);

		auto pipeDownBody = PhysicsBody::createBox(pipeDown->getContentSize(), PHYSICSSHAPE_MATERIAL_DEFAULT, Vec2::ZERO);
		//设置为静态刚体
		pipeDownBody->setDynamic(false);
		pipeDownBody->getShape(0)->setRestitution(0.0f);
		pipeDownBody->getShape(0)->setDensity(1.0f);
		//设置碰撞掩码
		pipeDownBody->setCategoryBitmask(OBST_MASK);
		pipeDownBody->setCollisionBitmask(BIRD_MASK | OBST_MASK);
		pipeDownBody->setContactTestBitmask(BIRD_MASK | OBST_MASK);

		pipeDown->setPhysicsBody(pipeDownBody);

		auto singlePipe = Node::create();
		singlePipe->addChild(pipeUp);
		singlePipe->addChild(pipeDown);

		if (i == 0) {
			singlePipe->setPosition(Vec2(SCREEN_WIDTH * 2 + PIPE_WIDHT / 2, 250));
		} else {
			singlePipe->setPosition(Vec2(SCREEN_WIDTH * 2.5f + PIPE_WIDHT, this->getRandomHeight()));
		}

		singlePipe->setTag(PIPE_NEW);

		this->addChild(singlePipe);
		this->pipes.pushBack(singlePipe);
	}

}
Exemple #15
0
SUMOReal
GNELane::getColorValue(size_t activeScheme) const {
    const SVCPermissions myPermissions = myParentEdge.getNBEdge()->getPermissions(myIndex);
    switch (activeScheme) {
        case 0:
            switch (myPermissions) {
                case SVC_PEDESTRIAN:
                    return 1;
                case SVC_BICYCLE:
                    return 2;
                case 0:
                    return 3;
                case SVC_SHIP:
                    return 4;
                default:
                    break;
            }
            if ((myPermissions & SVC_PASSENGER) != 0 || isRailway(myPermissions)) {
                return 0;
            } else {
                return 5;
            }
        case 1:
            return gSelected.isSelected(getType(), getGlID()) ||
                   gSelected.isSelected(GLO_EDGE, dynamic_cast<GNEEdge*>(&myParentEdge)->getGlID());
        case 2:
            return (SUMOReal)myPermissions;
        case 3:
            return myParentEdge.getNBEdge()->getLaneSpeed(myIndex);
        case 4:
            return myParentEdge.getNBEdge()->getNumLanes();
        case 5: {
            return myParentEdge.getNBEdge()->getLoadedLength() / myParentEdge.getNBEdge()->getLength();
        }
        // case 6: by angle (functional)
        case 7: {
            return myParentEdge.getNBEdge()->getPriority();
        }
        case 8: {
            // color by z of first shape point
            return getShape()[0].z();
        }
        // case 9: by segment height
        case 10: {
            // color by incline
            return (getShape()[-1].z() - getShape()[0].z()) /  myParentEdge.getNBEdge()->getLength();
        }
    }
    return 0;
}
Exemple #16
0
void CursorShapeItem::updateGeometry(int, int)
{
    if (hasShape())
    {
        getShape()->setInnerSize(size_.width(), size_.height());


        if (useCenter_)
        {
            QPointF pos = QPointF( getShape()->contentLeft(), getShape()->contentTop() );
            setPos(center_ - pos);
        }
        else setPos(topLeft_);
    }
}
Exemple #17
0
void
GUILane::drawTLSLinkNo(const GUINet& net) const {
    unsigned int noLinks = (unsigned int)myLinks.size();
    if (noLinks == 0) {
        return;
    }
    // draw all links
    SUMOReal w = myWidth / (SUMOReal) noLinks;
    SUMOReal x1 = myHalfLaneWidth;
    glPushMatrix();
    const PositionVector& g = getShape();
    const Position& end = g.back();
    const Position& f = g[-2];
    const Position& s = end;
    const SUMOReal rot = RAD2DEG(atan2((s.x() - f.x()), (f.y() - s.y())));
    glTranslated(end.x(), end.y(), 0);
    glRotated(rot, 0, 0, 1);
    for (int i = noLinks; --i >= 0;) {
        SUMOReal x2 = x1 - (SUMOReal)(w / 2.);
        int linkNo = net.getLinkTLIndex(myLinks[i]);
        if (linkNo < 0) {
            continue;
        }
        GLHelper::drawText(toString(linkNo),
                           Position(x2, 0), 0, .6, RGBColor(128, 128, 255, 255), 180);
        x1 -= w;
    }
    glPopMatrix();
}
STDMETHODIMP MousePointerShapeChangedEventWrap::COMGETTER(Shape)(ComSafeArrayOut(BYTE, aShape))
{
    LogRelFlow(("{%p} %s: enter aShape=%p\n", this, "MousePointerShapeChangedEvent::getShape", aShape));

    VirtualBoxBase::clearError();

    HRESULT hrc;

    try
    {
        CheckComArgOutPointerValidThrow(aShape);

        AutoCaller autoCaller(this);
        if (FAILED(autoCaller.rc()))
            throw autoCaller.rc();

        hrc = getShape(ArrayOutConverter<BYTE>(ComSafeArrayOutArg(aShape)).array());
    }
    catch (HRESULT hrc2)
    {
        hrc = hrc2;
    }
    catch (...)
    {
        hrc = VirtualBoxBase::handleUnexpectedExceptions(this, RT_SRC_POS);
    }

    LogRelFlow(("{%p} %s: leave *aShape=%zu hrc=%Rhrc\n", this, "MousePointerShapeChangedEvent::getShape", ComSafeArraySize(*aShape), hrc));
    return hrc;
}
void ofxGuiInputField<Type>::drawSelectedArea(){
	ofPushStyle();
	ofSetColor(fillColor);
	ofFill();
	ofDrawRectangle( selectStartX, 1, selectionWidth, getShape().height-2 );
	ofPopStyle();
}
Exemple #20
0
bool Ship::hit(const Coordinate& cCoordinate) {
    
    //There are no more life left in the ship
    if (m_uiShipLife == 0)
        return false;
    
    //Only stores points in the creation of the ship
    Shape *cShapeHit = getShape(cCoordinate);
    
    //If it can be hit in that location - hit it. The internal coordinate in the shape has a fixed location that needs to be stripped from the origin's influence
    if (cShapeHit != NULL && (cShapeHit->getRepresentation(cCoordinate - *this) != Settings::getInstance().getRepresentationForType(MapRepresentationHit))) {
    
        //Change the representation for this location
        cShapeHit->setRepresentation(cCoordinate - *this, Settings::getInstance().getRepresentationForType(MapRepresentationHit));
        
        //Decrease the life of the ship by one
        --m_uiShipLife;
        
        //Successfull
        return true;
        
    }
    
    return false;
    
}
Exemple #21
0
	void CollisionObject::visualizeRadii()
	{
		// render the objects radii
		int dim;
		Real dr = Ogre::Math::DegreesToRadians(5.0f);
		Vector3 ctr = getShape()->getCenter();
		for (dim=0; dim<3; dim++)
		{
			Real r;
			for (r=0.0f; r< Ogre::Math::DegreesToRadians(360.0f); r+=dr)
			{
				Real sin_r0 = (Real) sin(r);
				Real cos_r0 = (Real) cos(r);
				float sin_r1 = (Real) sin(r+dr);
				Real cos_r1 = (Real) cos(r+dr);
				Vector3 v0_x(0.0f, sin_r0*mRadius, cos_r0*mRadius); v0_x+=ctr;
				Vector3 v1_x(0.0f, sin_r1*mRadius, cos_r1*mRadius); v1_x+=ctr;
				Vector3 v0_y(sin_r0*mRadius, 0.0f, cos_r0*mRadius); v0_y+=ctr;
				Vector3 v1_y(sin_r1*mRadius, 0.0f, cos_r1*mRadius); v1_y+=ctr;
				Vector3 v0_z(sin_r0*mRadius, cos_r0*mRadius, 0.0f); v0_z+=ctr;
				Vector3 v1_z(sin_r1*mRadius, cos_r1*mRadius, 0.0f); v1_z+=ctr;

				getContext()->getVisualDebugger()->addRadiiLine(v0_x.x,v0_x.y,v0_x.z, v1_x.x,v1_x.y,v1_x.z);
				getContext()->getVisualDebugger()->addRadiiLine(v0_y.x,v0_y.y,v0_y.z, v1_y.x,v1_y.y,v1_y.z);
				getContext()->getVisualDebugger()->addRadiiLine(v0_z.x,v0_z.y,v0_z.z, v1_z.x,v1_z.y,v1_z.z);
			}
		}
	}
void
GUILaneWrapper::drawTLSLinkNo(const GUINet& net) const {
    unsigned int noLinks = getLinkNumber();
    if (noLinks == 0) {
        return;
    }
    // draw all links
    SUMOReal w = myLane.getWidth() / (SUMOReal) noLinks;
    SUMOReal x1 = (SUMOReal)(myLane.getWidth() / 2.);
    glPushMatrix();
    const PositionVector& g = getShape();
    const Position& end = g.back();
    const Position& f = g[-2];
    const Position& s = end;
    SUMOReal rot = (SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI;
    glTranslated(end.x(), end.y(), 0);
    glRotated(rot, 0, 0, 1);
    for (int i = noLinks; --i >= 0;) {
        SUMOReal x2 = x1 - (SUMOReal)(w / 2.);
        int linkNo = net.getLinkTLIndex(getLane().getLinkCont()[i]);
        if (linkNo < 0) {
            continue;
        }
        GLHelper::drawText(toString(linkNo),
                           Position(x2, 0), 0, .6, RGBColor(128, 128, 255, 255), 180);
        x1 -= w;
    }
    glPopMatrix();
}
Exemple #23
0
void SoftBody::createUniqVertexList()
{
	mPhysPolyList = new ConcretePolyList();
	mPhysPolyList->setTransform(&mObjToWorld, mObjScale);
	mPhysPolyList->setObject(this);

	TSShapeInstance* shapeInst = getShapeInstance();
	S32 dl = 0;
	const TSShape* shape = getShape();
	const TSDetail * detail = &shape->details[dl];
	S32 ss = detail->subShapeNum;
	S32 od = detail->objectDetailNum;

	S32 start = shape->subShapeFirstObject[ss];
	S32 end   = shape->subShapeNumObjects[ss] + start;
	for (S32 i=start; i<end; i++)
	{
		TSShapeInstance::MeshObjectInstance* meshOI = &shapeInst->mMeshObjects[i];

		if (od >= meshOI->object->numMeshes)
			continue;
		U32 matKey(0);
		meshOI->buildPolyList(od,mPhysPolyList,matKey,NULL);
	}

	//create uniq vertex list
	ConcretePolyList::VertexList uniqVertexList;
	U32 vertexSize = mPhysPolyList->mVertexList.size();
	m_vertexBindingVec.setSize(vertexSize);
	for (U32 i=0; i<vertexSize; i++)
	{
		Point3F& vertex = mPhysPolyList->mVertexList[i];
		U32 uniqIdx = -1;

		for(U32 j=0;j<uniqVertexList.size();j++)
		{
			if (vertex==uniqVertexList[j])
			{
				uniqIdx=j;
				break;
			}
		}
		if (uniqIdx==-1)
		{
			uniqVertexList.push_back(vertex);
			uniqIdx = uniqVertexList.size()-1;
		}

		m_vertexBindingVec[i] = uniqIdx;
	}

	mPhysPolyList->mVertexList = uniqVertexList;

	//update indexes
	for(U32 i = 0; i < mPhysPolyList->mIndexList.size() ; i++)
	{
		mPhysPolyList->mIndexList[i] = m_vertexBindingVec[mPhysPolyList->mIndexList[i]];
	}
}
 bool BulletModel::collisionPointsAllToAll(const bool use_margins,
                                           vector<PointPair>& collision_points) 
 {
   BulletResultCollector c;
   MatrixXd normals;
   vector<double> distance;
   BulletCollisionWorldWrapper& bt_world = getBulletWorld(use_margins);
   bt_world.bt_collision_world->performDiscreteCollisionDetection();
   int numManifolds = bt_world.bt_collision_world->getDispatcher()->getNumManifolds();
   for (int i=0;i<numManifolds;i++)
   {
     btPersistentManifold* contactManifold =  bt_world.bt_collision_world->getDispatcher()->getManifoldByIndexInternal(i);
     const btCollisionObject* obA = contactManifold->getBody0();
     const btCollisionObject* obB = contactManifold->getBody1();
     auto elementA = static_cast< Element*  >(obA->getUserPointer());
     auto elementB = static_cast< Element*  >(obB->getUserPointer());
     DrakeShapes::Shape shapeA = elementA->getShape();
     DrakeShapes::Shape shapeB = elementB->getShape();
     double marginA = 0;
     double marginB = 0;
     if (shapeA == DrakeShapes::MESH || 
         shapeA == DrakeShapes::MESH_POINTS || 
         shapeA == DrakeShapes::BOX) { 
       marginA = obA->getCollisionShape()->getMargin();
     }
     if (shapeB == DrakeShapes::MESH || 
         shapeB == DrakeShapes::MESH_POINTS || 
         shapeB == DrakeShapes::BOX) { 
       marginB = obB->getCollisionShape()->getMargin();
     }
     int numContacts = contactManifold->getNumContacts();
     for (int j=0;j<numContacts;j++)
     {        btManifoldPoint& pt = contactManifold->getContactPoint(j);
       if (pt.getDistance()+marginA+marginB<0.f)
       {
         const btVector3& normalOnB = pt.m_normalWorldOnB;
         const btVector3& ptA = pt.getPositionWorldOnA() + normalOnB*marginA;
         const btVector3& ptB = pt.getPositionWorldOnB() - normalOnB*marginB;
         c.addSingleResult(elementA->getId(),elementB->getId(),toVector3d(ptA),toVector3d(ptB),
                           toVector3d(normalOnB),(double) pt.getDistance());
       }
     }
   }   
   collision_points = c.getResults();
   return c.pts.size() > 0;
 }
osg::ref_ptr<BulletShapeInstance> BulletShapeManager::createInstance(const std::string &name)
{
    osg::ref_ptr<const BulletShape> shape = getShape(name);
    if (shape)
        return shape->makeInstance();
    else
        return osg::ref_ptr<BulletShapeInstance>();
}
Exemple #26
0
void Entity::move(sfld::Vector2f direction, int frameTime, float magnitude){
	EntityList* list = entityManager_->getEntities();
	for (auto& it : *list){
		if (it.get() != this){
			float dist = sfld::Vector2f(it->getPosition() - getPosition()).length();
			if (!it->isWalkthrough()){
				if (dist <= TILE_SIZE*1.5f){ //need accurate collisions here
					MTV mtv(Collision::getCollision(getSprite(), getShape(), it->getSprite(), it->getShape()));
					if (!(mtv.axis == MTV::NONE.axis && mtv.overlap == MTV::NONE.overlap)){;
						//collided
						sfld::Vector2f n = mtv.axis;
						sfld::Vector2f comp_u(0, 0);

						if (direction.dot(n) < 0){
							if (n != sfld::Vector2f(0, 0)){
								comp_u = n * (direction.dot(n) / n.dot(n)); //component of hit axis in dir
							}
						}
						direction = direction - comp_u;
						collided(it.get());
						if (it->getDynamic() == DYNAMIC_STATIC){ //because then it won't resolve its own collisions
							it->collided(this);
						}
					}

				}
			}
			else{//otherwise, it's a circle, and we are only concerned with checking if they touch, no more
				if (dist <= TILE_SIZE*1.5f){
					MTV mtv(Collision::getCollision(getSprite(), getShape(), it->getSprite(), it->getShape()));
					if (!(mtv.axis == MTV::NONE.axis && mtv.overlap == MTV::NONE.overlap)){
						collided(it.get());
						if (it->getDynamic() == DYNAMIC_STATIC){ //because then it won't resolve its own collisions
							it->collided(this);
						}
					}
				}
			}
		}
	}
	if (direction != sf::Vector2f(0, 0) && !rotating_){
		//lastdir = dir;
		sprite_.setRotation(maths::toDegrees(atan2(direction.y, direction.x)));
	}
	doOffset(direction*(float)frameTime*magnitude);
}
Exemple #27
0
EntityItemProperties ShapeEntityItem::getProperties(EntityPropertyFlags desiredProperties) const {
    EntityItemProperties properties = EntityItem::getProperties(desiredProperties); // get the properties from our base class
    properties.setShape(entity::stringFromShape(getShape()));
    COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor);
    COPY_ENTITY_PROPERTY_TO_PROPERTIES(alpha, getAlpha);

    return properties;
}
Exemple #28
0
Paddle::Paddle(cocos2d::Layer *layer)
{
	visibleSize = Director::getInstance()->getVisibleSize();
	origin = Director::getInstance()->getVisibleOrigin();

	paddleSprite = Sprite::create("paddle.png");
	paddleSprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height / 2 + origin.y - 175));

	auto paddleBody = PhysicsBody::createBox((cocos2d::Size &)paddleSprite->getContentSize().width);
	paddleBody->getShape(0)->setRestitution(1.0f);
	paddleBody->getShape(0)->setFriction(0.0f);
	paddleBody->getShape(0)->setDensity(10.0f);
	paddleBody->setDynamic(false);
	paddleSprite->setPhysicsBody(paddleBody);
	layer->addChild(paddleSprite, 100);

}
Exemple #29
0
void BulletBoxCollider::setSize(const glm::vec3 &size)
{
    btBoxShape *shape = static_cast<btBoxShape *>(getShape());
    const btVector3 halfExtents(size.x / 2.0f, size.y / 2.0f, size.z / 2.0f);
    shape->setSafeMargin(halfExtents);
    const btVector3 margin(shape->getMargin(), shape->getMargin(), shape->getMargin());
    shape->setImplicitShapeDimensions((halfExtents * shape->getLocalScaling()) - margin);
}
void RigidBody::draw()
{
	if(mRepeatX)
	{
		// scale it in the x direction
		D3DXMATRIX texScaling;
		D3DXMatrixScaling(&texScaling, getWidth()/256, 1.0f, 0.0f);
		HR(gd3dDevice->SetTransform(D3DTS_TEXTURE0, &texScaling));

		gGraphics->drawTexturedShape(*getShape(), mTexture);

		// restore to std scaling
		D3DXMatrixScaling(&texScaling, 1.0f, 1.0f, 0.0f);
		HR(gd3dDevice->SetTransform(D3DTS_TEXTURE0, &texScaling));
	}
	else
		gGraphics->drawTexturedShape(*getShape(), mTexture);
}