コード例 #1
0
ファイル: CCNode.cpp プロジェクト: khanhbui/ThreeDots
Point Node::convertToNodeSpace(const Point& worldPoint) const
{
    kmMat4 tmp = getWorldToNodeTransform();
    kmVec3 vec3 = {worldPoint.x, worldPoint.y, 0};
    kmVec3 ret;
    kmVec3Transform(&ret, &vec3, &tmp);
    return Point(ret.x, ret.y);
}
コード例 #2
0
ファイル: CCNode.cpp プロジェクト: tuyuer/actioneditor
Vec2 Node::convertToNodeSpace(const Vec2& worldPoint) const
{
    Mat4 tmp = getWorldToNodeTransform();
    Vec3 vec3(worldPoint.x, worldPoint.y, 0);
    Vec3 ret;
    tmp.transformPoint(vec3,&ret);
    return Vec2(ret.x, ret.y);
}
コード例 #3
0
Vec3 BillboardParticleSystem::convertToNodeSpace3D(const Vec3& worldPoint) const
{
    Mat4 tmp = getWorldToNodeTransform();
    Vec3 vec3(worldPoint.x, worldPoint.y, worldPoint.z);
    Vec3 ret;
    tmp.transformPoint(vec3,&ret);
    return Vec3(ret.x, ret.y,ret.z);
}
コード例 #4
0
ファイル: UITextField.cpp プロジェクト: superman-t/PlaneGame
bool TextField::hitTest(const Vec2 &pt, const Camera* camera, Vec3* /*p*/) const
{
    if (false == _useTouchArea)
    {
        return Widget::hitTest(pt, camera, nullptr);
    }

    auto size = getContentSize();
    auto anch = getAnchorPoint();
    Rect rect((size.width - _touchWidth) * anch.x, (size.height - _touchHeight) * anch.y, _touchWidth, _touchHeight);
    return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, nullptr);
}
コード例 #5
0
void TextFieldTTF::setCursorFromPoint(const Vec2 &point, const Camera* camera)
{
    if (_cursorEnabled)
    {
        // Reset Label, no cursor
        bool oldIsAttachWithIME = _isAttachWithIME;
        _isAttachWithIME = false;
        updateCursorDisplayText();

        Rect rect;
        rect.size = getContentSize();
        if (isScreenPointInRect(point, camera, getWorldToNodeTransform(), rect, nullptr))
        {
            int latterPosition = 0;
            for (; latterPosition < _lengthOfString; ++latterPosition)
            {
                if (_lettersInfo[latterPosition].valid)
                {
                    auto sprite = getLetter(latterPosition);
                    rect.size = sprite->getContentSize();
                    if (isScreenPointInRect(point, camera, sprite->getWorldToNodeTransform(), rect, nullptr))
                    {
                        setCursorPosition(latterPosition);
                        break;
                    }
                }
            }
            if (latterPosition == _lengthOfString)
            {
                setCursorPosition(latterPosition);
            }
        }

        // Set cursor
        _isAttachWithIME = oldIsAttachWithIME;
        updateCursorDisplayText();
    }
}
コード例 #6
0
ファイル: CCAttachNode.cpp プロジェクト: 1005491398/Threes
Mat4 AttachNode::getWorldToNodeTransform() const
{
    static Mat4 mat;
    mat.setIdentity();
    auto parent = getParent();
    if (parent)
    {
        mat = parent->getWorldToNodeTransform() * _attachBone->getWorldMat() * Node::getNodeToParentTransform();
    }
    else
    {
        mat = _attachBone->getWorldMat() * Node::getNodeToParentTransform();
    }
    return mat;
}
コード例 #7
0
cocos2d::MenuItem* ButtonControlLayer::getItemForTouch(cocos2d::Touch *touch, const cocos2d::Camera *camera)
{
    cocos2d::Vec2 touchLocation = touch->getLocation();
    for (const auto &item: _children)
    {
        auto child = dynamic_cast<cocos2d::MenuItem*>(item);
        if (child == nullptr || !child->isVisible() || !child->isEnabled())
        {
            continue;
        }
        cocos2d::Rect rect;
        rect.size = child->getContentSize();
        if (isScreenPointInRect(touchLocation, camera, child->getWorldToNodeTransform(), rect, nullptr))
        {
            return child;
        }
    }
    return nullptr;
}
コード例 #8
0
ファイル: UIWidget.cpp プロジェクト: dabingnn/cocosVR
bool Widget::hitTest(const Vec2 &pt, const Camera* camera, Vec3 *p) const
{
    Rect rect;
    rect.size = getContentSize();
    return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, p);
}
コード例 #9
0
void ParticleSystemQuad::updateParticleQuads()
{
    if (_particleCount <= 0) {
        return;
    }

    Vec2 currentPosition;
    if (_positionType == PositionType::FREE)
    {
        currentPosition = this->convertToWorldSpace(Vec2::ZERO);
    }
    else if (_positionType == PositionType::RELATIVE)
    {
        currentPosition = _position;
    }

    V3F_C4B_T2F_Quad *startQuad;
    Vec2 pos = Vec2::ZERO;
    if (_batchNode)
    {
        V3F_C4B_T2F_Quad *batchQuads = _batchNode->getTextureAtlas()->getQuads();
        startQuad = &(batchQuads[_atlasIndex]);
        pos = _position;
    }
    else
    {
        startQuad = &(_quads[0]);
    }

    if( _positionType == PositionType::FREE )
    {
        Vec3 p1(currentPosition.x, currentPosition.y, 0);
        Mat4 worldToNodeTM = getWorldToNodeTransform();
        worldToNodeTM.transformPoint(&p1);
        Vec3 p2;
        Vec2 newPos;
        float* startX = _particleData.startPosX;
        float* startY = _particleData.startPosY;
        float* x = _particleData.posx;
        float* y = _particleData.posy;
        float* s = _particleData.size;
        float* r = _particleData.rotation;
        V3F_C4B_T2F_Quad* quadStart = startQuad;
        for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
        {
            p2.set(*startX, *startY, 0);
            worldToNodeTM.transformPoint(&p2);
            newPos.set(*x,*y);
            p2 = p1 - p2;
            newPos.x -= p2.x - pos.x;
            newPos.y -= p2.y - pos.y;
            updatePosWithParticle(quadStart, newPos, *s, *r);
        }
    }
    else if( _positionType == PositionType::RELATIVE )
    {
        Vec2 newPos;
        float* startX = _particleData.startPosX;
        float* startY = _particleData.startPosY;
        float* x = _particleData.posx;
        float* y = _particleData.posy;
        float* s = _particleData.size;
        float* r = _particleData.rotation;
        V3F_C4B_T2F_Quad* quadStart = startQuad;
        for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
        {
            newPos.set(*x, *y);
            newPos.x = *x - (currentPosition.x - *startX);
            newPos.y = *y - (currentPosition.y - *startY);
            newPos += pos;
            updatePosWithParticle(quadStart, newPos, *s, *r);
        }
    }
    else
    {
        Vec2 newPos;
        float* startX = _particleData.startPosX;
        float* startY = _particleData.startPosY;
        float* x = _particleData.posx;
        float* y = _particleData.posy;
        float* s = _particleData.size;
        float* r = _particleData.rotation;
        V3F_C4B_T2F_Quad* quadStart = startQuad;
        for (int i = 0 ; i < _particleCount; ++i, ++startX, ++startY, ++x, ++y, ++quadStart, ++s, ++r)
        {
            newPos.set(*x + pos.x, *y + pos.y);
            updatePosWithParticle(quadStart, newPos, *s, *r);
        }
    }

    //set color
    if(_opacityModifyRGB)
    {
        V3F_C4B_T2F_Quad* quad = startQuad;
        float* r = _particleData.colorR;
        float* g = _particleData.colorG;
        float* b = _particleData.colorB;
        float* a = _particleData.colorA;

        for (int i = 0; i < _particleCount; ++i,++quad,++r,++g,++b,++a)
        {
            GLubyte colorR = *r * *a * 255;
            GLubyte colorG = *g * *a * 255;
            GLubyte colorB = *b * *a * 255;
            GLubyte colorA = *a * 255;
            quad->bl.colors.set(colorR, colorG, colorB, colorA);
            quad->br.colors.set(colorR, colorG, colorB, colorA);
            quad->tl.colors.set(colorR, colorG, colorB, colorA);
            quad->tr.colors.set(colorR, colorG, colorB, colorA);
        }
    }
    else
    {
        V3F_C4B_T2F_Quad* quad = startQuad;
        float* r = _particleData.colorR;
        float* g = _particleData.colorG;
        float* b = _particleData.colorB;
        float* a = _particleData.colorA;

        for (int i = 0; i < _particleCount; ++i,++quad,++r,++g,++b,++a)
        {
            GLubyte colorR = *r * 255;
            GLubyte colorG = *g * 255;
            GLubyte colorB = *b * 255;
            GLubyte colorA = *a * 255;
            quad->bl.colors.set(colorR, colorG, colorB, colorA);
            quad->br.colors.set(colorR, colorG, colorB, colorA);
            quad->tl.colors.set(colorR, colorG, colorB, colorA);
            quad->tr.colors.set(colorR, colorG, colorB, colorA);
        }
    }
}
コード例 #10
0
ファイル: MapMakerScene.cpp プロジェクト: xu1hua/WindFighter
bool MapMakerScene::init()
{
	if (!Layer::init())
	{
		return false;
	}
	m_lastSelectGroup = nullptr;
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	auto s = Director::getInstance()->getWinSize();
	//input map name
	auto pTextField = TextFieldTTF::textFieldWithPlaceHolder(std::string(LocalizedCStringByKey("input_map_name")),
		"fonts/arial.ttf",
		48);
	addChild(pTextField,0,"tbMapName");
	pTextField->setPosition(Vec2(s.width / 2,s.height - 250));

	//输入事件
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [pTextField](Touch* touch, Event*)
	{
		auto beginPos = touch->getLocation();
		Rect rect;
		rect.size = pTextField->getContentSize();
		auto clicked = isScreenPointInRect(beginPos, Camera::getVisitingCamera(), pTextField->getWorldToNodeTransform(), rect, nullptr);
		if (clicked)
		{
			return true;
		}
		pTextField->detachWithIME();
		return false;
	};
	listener->onTouchEnded = [pTextField](Touch* touch, Event* event)
	{
		auto endPos = touch->getLocation();
		Rect rect;
		rect.size = pTextField->getContentSize();
		auto clicked = isScreenPointInRect(endPos, Camera::getVisitingCamera(), pTextField->getWorldToNodeTransform(), rect, nullptr);
		if (clicked)
		{
			pTextField->attachWithIME();
		}

	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	//返回主菜单
	auto returnToMainMenuItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		CC_CALLBACK_1(MapMakerScene::returnToMainMenuCallback, this)
		);
	returnToMainMenuItem->setPosition(Vec2(origin.x + visibleSize.width - returnToMainMenuItem->getContentSize().width / 2,
		origin.y + returnToMainMenuItem->getContentSize().height / 2));
	auto menu = Menu::create(returnToMainMenuItem, NULL);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 1);
    
	//baseplate
    auto baseplateLayer = SquareBaseplateLayer::create();
    baseplateLayer->createEmptyMap(BaseSize(15,15));
    baseplateLayer->drawBasesplate(Vec2(32,32));
    baseplateLayer->setPosition(Vec2(100,200));
    addChild(baseplateLayer);
    

    //菜单,创建group
    auto menuItemCreateGroup = MenuItemFont::create(LocalizedCStringByKey("create_group"));
    menuItemCreateGroup->setCallback(
    [=](Ref*)
    {
        auto squareGroup = SquareGroupMapMaker::create();
        squareGroup->setPosition(Vec2(100,100));
        squareGroup->SetSquareGroup(Vec2(32,32),SquareGroup::SQUAREGROUP_TYPE::ST_Z,Square::SQUARE_COLOR::SC_GREEN);
        squareGroup->DrawGroup();
		squareGroup->setSelectedListener(
			[=](SquareGroup* sg)
		{
			m_lastSelectGroup = sg;
		});
        this->addChild(squareGroup);
    }
    );
	//菜单,删除group
    auto menuItemDeleteSelectedGroup = MenuItemFont::create(LocalizedCStringByKey("delete_group"));
    menuItemDeleteSelectedGroup->setCallback(
    [=](Ref*)
    {
        for(Node* node:this->getChildren())
        {
			SquareGroupMapMaker* sg = dynamic_cast<SquareGroupMapMaker*>(node);
            if(sg != nullptr)
            {
                if(sg->getGroupState() == SGS_SELECTED)
                {
					assert(m_lastSelectGroup == sg);
					
					m_lastSelectGroup = nullptr;
                    this->removeChild(node);
                }
            }
        }
    }
    );
	//菜单,保存地图
    auto menuItemSaveMap = MenuItemFont::create(LocalizedCStringByKey("save_map"));
    menuItemSaveMap->setCallback(
    [=](Ref*)
    {
		saveMapToFile();
    }
    );
    //创建菜单组
    auto operationMenu = Menu::create(menuItemCreateGroup,menuItemDeleteSelectedGroup,menuItemSaveMap, NULL);
    operationMenu->alignItemsVerticallyWithPadding(20);
    
    addChild(operationMenu);
    operationMenu->setPosition(Vec2(s.width / 2, s.height - 100));
    
	//产生本地图的guid
	m_guid = std::string(GameUilityTools::CreateGuidString());

	//添加选择颜色的层
	auto colorLayer = SelectColorLayer::create();
	colorLayer->setPosition(Vec2(0, 0));
	colorLayer->setColorChangeListener(
		[=](Square::SQUARE_COLOR color){
		//todo xuhua
		if (m_lastSelectGroup)
		{
			m_lastSelectGroup->setSquareGroupColor(color);
			m_lastSelectGroup->DrawGroup();
		}
	}
		);
	addChild(colorLayer, 0);
	return true;
}
コード例 #11
0
ファイル: wyNode.cpp プロジェクト: nbolabs/WiEngine
wyPoint wyNode::worldToNodeSpace(wyPoint p) {
    wyAffineTransform t = getWorldToNodeTransform();
    return wyaTransformPoint(t, p);
}