void ShaderNode::translateFormOtherNode(AffineTransform &transform)
{
    Node::setAdditionalTransform(transform);

    _center = Vertex2F(_additionalTransform.tx * CC_CONTENT_SCALE_FACTOR(), _additionalTransform.ty * CC_CONTENT_SCALE_FACTOR());
    _resolution = Vertex2F( SIZE_X * _additionalTransform.a, SIZE_Y * _additionalTransform.d);
}
ShaderNode::ShaderNode()
    : _center(Vertex2F(0.0f, 0.0f))
    , _resolution(Vertex2F(0.0f, 0.0f))
    , _time(0.0f)
    , _uniformCenter(0)
    , _uniformResolution(0)
    , _uniformTime(0)
{
}
Esempio n. 3
0
void ShaderNode::setResolution(const float& w, const float& h)
{
	_resolution = Vertex2F(w, h);
	setContentSize(Size(w, h));

	setAnchorPoint(Point(0.5f, 0.5f));
}
Esempio n. 4
0
MaskShaderEffect::MaskShaderEffect()
	:_touchPoint(Vertex2F(0.0f, 0.0f))
	,_uniformTouchPoint(0)
	,_uniformCoefficient(0)
	,_maskParams()
	,_textureID(0)
	,_texture(NULL)
{
}
bool ShaderNode::initWithVertex(const char *vert, const char *frag)
{

    loadShaderVertex(vert, frag);

    _time = 0;
    _resolution = Vertex2F(SIZE_X, SIZE_Y);

    scheduleUpdate();

    setContentSize(Size(SIZE_X, SIZE_Y));
    setAnchorPoint(Point(0.5f, 0.5f));

    return true;
}
Esempio n. 6
0
CCScrollLayer::CCScrollLayer():
m_beginPoint(Point::ZERO),
m_containBeginTouchPointFlag(false),
m_contentLayer(NULL),
m_pagingEnable(false),
m_toBoundsDuration(0.3),
m_nextPageDuration(0.3),
m_pageColumnsIndex(0), //列
m_pageRowIndex(0), //行
m_pageMovePercent(0.25),
m_delegate(NULL),
m_touchBeginSelector(NULL),
m_touchMoveSelector(NULL),
m_touchEndSelector(NULL),
m_actionEndSelector(NULL),
m_touchCancelSelector(NULL),
m_endFlag(false),
m_boundsDragDistance(Vertex2F(30,30)),           //超出边界的距离
m_HMoveAbleFlag(false),
m_VMoveAbleFlag(false),
m_decelerateBeginSelector(NULL),
m_decelerateMoveSelector(NULL),
m_decelerateEndSelector(NULL),
m_actionBeginSelector(NULL),
m_actionMoveSelector(NULL),
m_decelerateFlag(false),
m_scrollDotVSprite(NULL),
m_scrollDotHSprite(NULL),
m_percentOfMoveWhenDragOut(0.25),
m_bShowVDot(false),
m_bShowHDot(false),
m_2fLastMoveDis(Vertex2F(0, 0)),
m_fDeceleratePercent(0.95)
{
   ignoreAnchorPointForPosition(false);
}
Esempio n. 7
0
void drawLine( const Point& origin, const Point& destination )
{
    lazy_init();

    Vertex2F vertices[2] = {
        Vertex2F(origin.x, origin.y),
        Vertex2F(destination.x, destination.y)
    };

    s_shader->use();
    s_shader->setUniformsForBuiltins();
    s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*) &s_color.r, 1);

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
#ifdef EMSCRIPTEN
    setGLBufferData(vertices, 16);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
    glDrawArrays(GL_LINES, 0, 2);

    CC_INCREMENT_GL_DRAWS(1);
}
Esempio n. 8
0
void drawSolidPoly( const Point *poli, unsigned int numberOfPoints, Color4F color )
{
    lazy_init();

    s_shader->use();
    s_shader->setUniformsForBuiltins();
    s_shader->setUniformLocationWith4fv(s_colorLocation, (GLfloat*) &color.r, 1);

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );

    // XXX: Mac OpenGL error. arrays can't go out of scope before draw is executed
    Vertex2F* newPoli = new Vertex2F[numberOfPoints];

    // iPhone and 32-bit machines optimization
    if( sizeof(Point) == sizeof(Vertex2F) )
    {
#ifdef EMSCRIPTEN
        setGLBufferData((void*) poli, numberOfPoints * sizeof(Point));
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, poli);
#endif // EMSCRIPTEN
    }
    else
    {
        // Mac on 64-bit
        for( unsigned int i=0; i<numberOfPoints;i++)
        {
            newPoli[i] = Vertex2F( poli[i].x, poli[i].y );
        }
#ifdef EMSCRIPTEN
        setGLBufferData(newPoli, numberOfPoints * sizeof(Vertex2F));
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, newPoli);
#endif // EMSCRIPTEN
    }    

    glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) numberOfPoints);

    CC_SAFE_DELETE_ARRAY(newPoli);
    CC_INCREMENT_GL_DRAWS(1);
}
void ShaderNode::setPosition(const Point &newPosition)
{
    Node::setPosition(newPosition);
    Point position = getPosition();
    _center = Vertex2F(position.x * CC_CONTENT_SCALE_FACTOR(), position.y * CC_CONTENT_SCALE_FACTOR());
}
Esempio n. 10
0
NS_CC_BEGIN

void ccVertexLineToPolygon(Point *points, float stroke, Vertex2F *vertices, unsigned int offset, unsigned int nuPoints)
{
    nuPoints += offset;
    if(nuPoints<=1) return;

    stroke *= 0.5f;

    unsigned int idx;
    unsigned int nuPointsMinus = nuPoints-1;

    for(unsigned int i = offset; i<nuPoints; i++)
    {
        idx = i*2;
        Point p1 = points[i];
        Point perpVector;

        if(i == 0)
            perpVector = (p1 - points[i+1]).normalize().getPerp();
        else if(i == nuPointsMinus)
            perpVector = (points[i-1] - p1).normalize().getPerp();
        else
        {
            Point p2 = points[i+1];
            Point p0 = points[i-1];

            Point p2p1 = (p2 - p1).normalize();
            Point p0p1 = (p0 - p1).normalize();

            // Calculate angle between vectors
            float angle = acosf(p2p1.dot(p0p1));

            if(angle < CC_DEGREES_TO_RADIANS(70))
                perpVector = p2p1.getMidpoint(p0p1).normalize().getPerp();
            else if(angle < CC_DEGREES_TO_RADIANS(170))
                perpVector = p2p1.getMidpoint(p0p1).normalize();
            else
                perpVector = (p2 - p0).normalize().getPerp();
        }
        perpVector = perpVector * stroke;

        vertices[idx] = Vertex2F(p1.x+perpVector.x, p1.y+perpVector.y);
        vertices[idx+1] = Vertex2F(p1.x-perpVector.x, p1.y-perpVector.y);

    }

    // Validate vertexes
    offset = (offset==0) ? 0 : offset-1;
    for(unsigned int i = offset; i<nuPointsMinus; i++)
    {
        idx = i*2;
        const unsigned int idx1 = idx+2;

        Vertex2F p1 = vertices[idx];
        Vertex2F p2 = vertices[idx+1];
        Vertex2F p3 = vertices[idx1];
        Vertex2F p4 = vertices[idx1+1];

        float s;
        //BOOL fixVertex = !ccpLineIntersect(Point(p1.x, p1.y), Point(p4.x, p4.y), Point(p2.x, p2.y), Point(p3.x, p3.y), &s, &t);
        bool fixVertex = !ccVertexLineIntersect(p1.x, p1.y, p4.x, p4.y, p2.x, p2.y, p3.x, p3.y, &s);
        if(!fixVertex)
            if (s<0.0f || s>1.0f)
                fixVertex = true;

        if(fixVertex)
        {
            vertices[idx1] = p4;
            vertices[idx1+1] = p3;
        }
    }
}
Esempio n. 11
0
ShaderNode::ShaderNode()
:_resolution(Vertex2F(0.0f, 0.0f))
,_uniformResolution(0)
{
}