Ejemplo n.º 1
0
void RippleNode::draw()
{
    CCNodeRGBA::draw();
    
    ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    ccDrawInit();
    
    ccDrawColor4B(getColor().r, getColor().g, getColor().b, getOpacity());
    
    glLineWidth(3.f * SCREEN_SCALE());
    ccPointSize(3.f * SCREEN_SCALE() * 0.5f);
    
    Rig rig;
    rig.reserve(RIG_VERTEXES());
    for(int i = 0; i < RIG_VERTEXES(); i++)
    {
        CCPoint vertex = ccpRotateByAngle(CCPointMake(0, 200.f * SCREEN_SCALE()), CCPointZero, M_PI * 2 * i / RIG_VERTEXES() + getRotation());
        rig.push_back(vertex);
    }
    
    ccDrawPoly(&rig[0], rig.size(), true);
    
    ccDrawPoint(CCPointZero);
    
    ccDrawFree();
    
    ccGLBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
    
    CC_INCREMENT_GL_DRAWS(1);
}
/// Draw layer 
KDvoid Ch7_SideScrollingPathfinding::drawLayer ( KDvoid )
{
	// Draw waypoints
	ccDrawColor4B ( 255, 255, 0, 128 );	

	b2Vec2		tPosition = m_pActor->getBody ( )->GetPosition ( );
	CCPoint		tActorPosition = ccp ( tPosition.x * PTM_RATIO, tPosition.y * PTM_RATIO );
		
	CCArray*	pWaypoints = m_pActor->getWaypoints ( );

	if ( pWaypoints->count ( ) == 1 )
	{
		GameWaypoint*	pWaypoint = (GameWaypoint*) pWaypoints->objectAtIndex ( 0 );
		ccDrawLine ( tActorPosition, pWaypoint->getPosition ( ) );
	}
	else if ( pWaypoints->count ( ) > 1 )
	{
		for ( KDuint i = 0; i < pWaypoints->count ( ) - 1; i++ )
		{			
			GameWaypoint*	pWaypoint	  = (GameWaypoint*) pWaypoints->objectAtIndex ( i );
			GameWaypoint*	pWaypointNext = (GameWaypoint*) pWaypoints->objectAtIndex ( i + 1 );
			
			if ( i == 0 )
			{
				// From actor to first waypoint
				ccDrawLine ( tActorPosition, pWaypoint->getPosition ( ) );
				ccDrawLine ( pWaypoint->getPosition ( ), pWaypointNext->getPosition ( ) );
			}
			else
			{
				// From this waypoint to next one
				ccDrawLine ( pWaypoint->getPosition ( ), pWaypointNext->getPosition ( ) );
			}	
		}
	}

	// Draw AStarNodes
	for ( KDuint i = 0; i < m_pNodes->count ( ); i++ )
	{
		// Draw node
		SSAStarNode*	pNode = (SSAStarNode*) m_pNodes->objectAtIndex ( i );	

		ccDrawColor4B ( 255, 255, 255, 128 );	
		ccDrawPoint ( pNode->getPosition ( ) );
		
		// Draw neighbor lines (there is going to be a lot of them)
		for ( KDuint j = 0; j < pNode->getNeighbors ( )->count ( ); j++ )
		{
			SSNeighborNode*		pNeighbor = (SSNeighborNode*) pNode->getNeighbors ( )->objectAtIndex ( j );
			
			ccDrawColor4B ( 128, 128, 128, 64 );
			ccDrawLine ( pNode->getPosition ( ), pNeighbor->getNode ( )->getPosition ( ) );
		}
		
	}	
}
Ejemplo n.º 3
0
 virtual void draw()
 {
     ccDrawColor4B(m_TouchColor.r, m_TouchColor.g, m_TouchColor.b, 255);
     glLineWidth(10);
     ccDrawLine( ccp(0, m_pTouchPoint.y), ccp(getContentSize().width, m_pTouchPoint.y) );
     ccDrawLine( ccp(m_pTouchPoint.x, 0), ccp(m_pTouchPoint.x, getContentSize().height) );
     glLineWidth(1);
     ccPointSize(30);
     ccDrawPoint(m_pTouchPoint);
 }
		virtual KDvoid	draw ( KDvoid )
		{
			ccDrawColor4B ( m_tTouchColor.r, m_tTouchColor.g, m_tTouchColor.b, 200 );
			ccLineWidth ( 10 );
			ccDrawLine	( ccp ( 0, m_tTouchPoint.y ), ccp ( getContentSize ( ).cx, m_tTouchPoint.y ) );
			ccDrawLine	( ccp ( m_tTouchPoint.x, 0 ), ccp ( m_tTouchPoint.x, getContentSize ( ).cy ) );
			glLineWidth	( 1 );
			ccPointSize ( 30 );
			ccDrawPoint ( m_tTouchPoint );
		}
void CtinyWingsTerrainSprite::drawWire(){
    vector<CCPoint>&pointList=m_pointMat[0];
    //draw segList
    {
        glLineWidth(2);
        ccPointSize(4);
        int nPoint=(int)pointList.size();
        int nSeg=nPoint-1;
        for(int i=0;i<nSeg;i++){
            CCPoint point=pointList[i];
            CCPoint pointn=pointList[i+1];
            ccDrawLine(point, pointn);
            ccDrawPoint(point);
            ccDrawPoint(pointn);
        }
    }
    
    //draw mesh
    {
        glLineWidth(2);
        int nRow=(int)m_pointMat.size();
        for(int i=0;i<nRow-1;i++){
            int nPoint=(int)m_pointMat[i].size();
            for(int j=0;j<nPoint-1;j++){
                const CCPoint&pLU=m_pointMat[i][j];
                const CCPoint&pLD=m_pointMat[i+1][j];
                const CCPoint&pRU=m_pointMat[i][j+1];
                const CCPoint&pRD=m_pointMat[i+1][j+1];
            
                ccDrawLine(pLU, pLD);
                ccDrawLine(pLD, pRD);
                ccDrawLine(pRD, pRU);
                ccDrawLine(pRU, pLU);
            }
        }
        
    }
    

    
    
}
Ejemplo n.º 6
0
void DebugDraw::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
{
  int c = m_lines->size();
  for (int i = 0; i < c; i++)
  {
    DebugLine line = m_lines->at(i);
    ccDrawColor4B(line.r, line.g, line.b, 255);
    ccDrawLine(line.pt1, line.pt2);
  }

  c = m_points->size();
  for (int i = 0; i < c; i++)
  {
    DebugPoint pt = m_points->at(i);
    ccDrawColor4B(pt.r, pt.g, pt.b, 255);
    ccDrawPoint(pt.pt);
  }

  c = m_circles->size();
  for (int i = 0; i < c; i++)
  {
    DebugCircle ci = m_circles->at(i);
    ccDrawColor4B(ci.r, ci.g, ci.b, 255);
    ccDrawCircle(ci.pt, ci.radius, 0, 100, false, 1, 1);
  }
  c = m_rects->size();
  for (int i = 0; i < c; i++)
  {
    DebugRect ci = m_rects->at(i);
    ccDrawSolidRect(ci.pt1, ci.pt2, ci.color);
  }

  /*
  // size chart
  int totalLines = (m_visibleRectRightTop.x - m_visibleRectLeftBottom.x ) / 10;
  int colorIndex = 0;
  for (int i = m_visibleRectLeftBottom.x; i < m_visibleRectRightTop.x; i+= 10)
  {
  switch (colorIndex)
  {
  case 0: ccDrawColor4B(255, 255, 255, 255); break;
  case 1: ccDrawColor4B(255, 0, 0, 255); break;
  case 2: ccDrawColor4B(0, 255, 0, 255); break;
  case 3: ccDrawColor4B(0, 0, 255, 255); break;
  }
  colorIndex += (colorIndex == 3) ? -3 : 1;

  ccDrawLine(ccp (i, 0), ccp (i, i/m_visibleRectRightTop.x * m_visibleRectRightTop.y));
  }
  */
}
Ejemplo n.º 7
0
void GestureScene::draw() {
	if(isOnTouch) {
		ccPointSize(15);  
		ccDrawColor4B(255, 255, 0, 64);  

		if(mPoints.size() > 0) {
			glLineWidth( 50.0f );
			ccDrawPoint(mPoints[0]);  
			for(int i=1; i<mPoints.size(); i++)
				ccDrawLine(mPoints[i-1], mPoints[i]);
		}
		
	}
}
Ejemplo n.º 8
0
void CCSkeleton::draw () {
	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc(blendFunc.src, blendFunc.dst);
	ccColor3B color = getColor();
	skeleton->r = color.r / (float)255;
	skeleton->g = color.g / (float)255;
	skeleton->b = color.b / (float)255;
	skeleton->a = getOpacity() / (float)255;

	quadCount = 0;
	for (int i = 0, n = skeleton->slotCount; i < n; i++)
		if (skeleton->slots[i]->attachment) Attachment_draw(skeleton->slots[i]->attachment, skeleton->slots[i]);
	if (atlas) atlas->drawNumberOfQuads(quadCount);

	if (debugSlots) {
		// Slots.
		ccDrawColor4B(0, 0, 255, 255);
		glLineWidth(1);
		CCPoint points[4];
		for (int i = 0, n = skeleton->slotCount; i < n; i++) {
			if (!skeleton->slots[i]->attachment) continue;
			ccV3F_C4B_T2F_Quad* quad = &((Cocos2dxRegionAttachment*)skeleton->slots[i]->attachment)->quad;
			points[0] = ccp(quad->bl.vertices.x, quad->bl.vertices.y);
			points[1] = ccp(quad->br.vertices.x, quad->br.vertices.y);
			points[2] = ccp(quad->tr.vertices.x, quad->tr.vertices.y);
			points[3] = ccp(quad->tl.vertices.x, quad->tl.vertices.y);
			ccDrawPoly(points, 4, true);
		}
	}
	if (debugBones) {
		// Bone lengths.
		glLineWidth(2);
		ccDrawColor4B(255, 0, 0, 255);
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			float x = bone->data->length * bone->m00 + bone->worldX;
			float y = bone->data->length * bone->m10 + bone->worldY;
			ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
		}
		// Bone origins.
		ccPointSize(4);
		ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			ccDrawPoint(ccp(bone->worldX, bone->worldY));
			if (i == 0) ccDrawColor4B(0, 255, 0, 255);
		}
	}
}
Ejemplo n.º 9
0
void DebugDraw::draw(void)
{
	int c = m_lines->size();
	for (int i = 0; i < c; i++)
	{
		DebugLine line = m_lines->at(i);
		glColor4f(line.r, line.g, line.b, 1);
		ccDrawLine(line.pt1, line.pt2);
	}

	c = m_points->size();
	for (int i = 0; i < c; i++)
	{
		DebugPoint pt = m_points->at(i);
		glColor4f(pt.r, pt.g, pt.b, 1);
		ccDrawPoint(pt.pt);
	}
}
Ejemplo n.º 10
0
void DrawPrimitivesTest::draw()
{
	CCLayer::draw();

    CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	// draw a simple line
	// The default state is:
	// Line Width: 1
	// color: 255,255,255,255 (white, non-transparent)
	// Anti-Aliased
	glEnable(GL_LINE_SMOOTH);
	ccDrawLine( CCPointMake(0, 0), CCPointMake(s.width, s.height) );
	
	// line: color, width, aliased
	// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
	// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
	glDisable(GL_LINE_SMOOTH);
	glLineWidth( 5.0f );
	/*glColor4ub(255,0,0,255);*/
	glColor4f(1.0, 0.0, 0.0, 1.0);
	ccDrawLine( CCPointMake(0, s.height), CCPointMake(s.width, 0) );

	// TIP:
	// If you are going to use always the same color or width, you don't
	// need to call it before every draw
	//
	// Remember: OpenGL is a state-machine.
	
	// draw big point in the center
	glPointSize(64);
	/*glColor4ub(0,0,255,128);*/
	glColor4f(0.0, 0.0, 1.0, 0.5);
	ccDrawPoint( CCPointMake(s.width / 2, s.height / 2) );
	
	// draw 4 small points
	CCPoint points[] = { CCPointMake(60,60), CCPointMake(70,70), CCPointMake(60,70), CCPointMake(70,60) };
	glPointSize(4);
	/*glColor4ub(0,255,255,255);*/
	glColor4f(0.0, 1.0, 1.0, 1.0);
	ccDrawPoints( points, 4);
	
	// draw a green circle with 10 segments
	glLineWidth(16);
	/*glColor4ub(0, 255, 0, 255);*/
	glColor4f(0.0, 1.0, 0.0, 1.0);
	ccDrawCircle( CCPointMake(s.width/2,  s.height/2), 100, 0, 10, false);

	// draw a green circle with 50 segments with line to center
	glLineWidth(2);
	/*glColor4ub(0, 255, 255, 255);*/
	glColor4f(0.0, 1.0, 1.0, 1.0);
	ccDrawCircle( CCPointMake(s.width/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, true);	
	
	// open yellow poly
	/*glColor4ub(255, 255, 0, 255);*/
	glColor4f(1.0, 1.0, 0.0, 1.0);
	glLineWidth(10);
	CCPoint vertices[] = { CCPointMake(0,0), CCPointMake(50,50), CCPointMake(100,50), CCPointMake(100,100), CCPointMake(50,100) };
	ccDrawPoly( vertices, 5, false);
	
	// closed purble poly
	/*glColor4ub(255, 0, 255, 255);*/
	glColor4f(1.0, 0.0, 1.0, 1.0);
	glLineWidth(2);
	CCPoint vertices2[] = { CCPointMake(30,130), CCPointMake(30,230), CCPointMake(50,200) };
	ccDrawPoly( vertices2, 3, true);
	
	// draw quad bezier path
	ccDrawQuadBezier(CCPointMake(0,s.height), CCPointMake(s.width/2,s.height/2), CCPointMake(s.width,s.height), 50);

	// draw cubic bezier path
	ccDrawCubicBezier(CCPointMake(s.width/2, s.height/2), CCPointMake(s.width/2+30,s.height/2+50), CCPointMake(s.width/2+60,s.height/2-50),CCPointMake(s.width, s.height/2),100);

	
	// restore original values
	glLineWidth(1);
	/*glColor4ub(255,255,255,255);*/
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glPointSize(1); 
}
Ejemplo n.º 11
0
void CCSkeleton::draw () {
	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc(blendFunc.src, blendFunc.dst);
	ccColor3B color = getColor();
	skeleton->r = color.r / (float)255;
	skeleton->g = color.g / (float)255;
	skeleton->b = color.b / (float)255;
	skeleton->a = getOpacity() / (float)255;

	CCTextureAtlas* textureAtlas = 0;
	ccV3F_C4B_T2F_Quad quad;
	quad.tl.vertices.z = 0;
	quad.tr.vertices.z = 0;
	quad.bl.vertices.z = 0;
	quad.br.vertices.z = 0;
	for (int i = 0, n = skeleton->slotCount; i < n; i++) {
		Slot* slot = skeleton->slots[i];
		if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
		CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
		if (regionTextureAtlas != textureAtlas) {
			if (textureAtlas) {
				textureAtlas->drawQuads();
				textureAtlas->removeAllQuads();
			}
		}
		textureAtlas = regionTextureAtlas;
		if (textureAtlas->getCapacity() == textureAtlas->getTotalQuads() &&
			!textureAtlas->resizeCapacity(textureAtlas->getCapacity() * 2)) return;
		RegionAttachment_updateQuad(attachment, slot, &quad);
		textureAtlas->updateQuad(&quad, textureAtlas->getTotalQuads());
	}
	if (textureAtlas) {
		textureAtlas->drawQuads();
		textureAtlas->removeAllQuads();
	}

	if (debugSlots) {
		// Slots.
		ccDrawColor4B(0, 0, 255, 255);
		glLineWidth(1);
		CCPoint points[4];
		ccV3F_C4B_T2F_Quad quad;
		for (int i = 0, n = skeleton->slotCount; i < n; i++) {
			Slot* slot = skeleton->slots[i];
			if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
			RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
			RegionAttachment_updateQuad(attachment, slot, &quad);
			points[0] = ccp(quad.bl.vertices.x, quad.bl.vertices.y);
			points[1] = ccp(quad.br.vertices.x, quad.br.vertices.y);
			points[2] = ccp(quad.tr.vertices.x, quad.tr.vertices.y);
			points[3] = ccp(quad.tl.vertices.x, quad.tl.vertices.y);
			ccDrawPoly(points, 4, true);
		}
	}
	if (debugBones) {
		// Bone lengths.
		glLineWidth(2);
		ccDrawColor4B(255, 0, 0, 255);
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			float x = bone->data->length * bone->m00 + bone->worldX;
			float y = bone->data->length * bone->m10 + bone->worldY;
			ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
		}
		// Bone origins.
		ccPointSize(4);
		ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			ccDrawPoint(ccp(bone->worldX, bone->worldY));
			if (i == 0) ccDrawColor4B(0, 255, 0, 255);
		}
	}
}
Ejemplo n.º 12
0
void CCDotNode::draw()
{
	const ccColor3B& tColor(getColor());
	ccDrawColor4B(tColor.r, tColor.g, tColor.b, getOpacity());
	ccDrawPoint(CCPointZero);
}
Ejemplo n.º 13
0
void CCDrawLineLayer::drawLine()
{
    
    for (int i=0; i<m_deleteCountOfTick ; i++) 
    {
        if (m_pointList.size() >0)
        {
            m_pointList.pop_front();
        }
        else 
        {
            break;
        }
    }
	while (m_pointList.size() > m_pointListKeepCount) 
    {
		m_pointList.pop_front();
	}
    
    
    if(m_isRandColor)
    {
        int  R = arc4random()%255;
        int  G = arc4random()%255;
        int  B = arc4random()%255;
        
        m_lineColor.r = R;
        m_lineColor.g = G;
        m_lineColor.b = B;
    }
    
    int pointListCount = m_pointList.size();
	std::list <CCPoint>::iterator it = m_pointList.begin();
    int pointIndex = 0;
	for(;it!=m_pointList.end();it++)
	{
        int maxPointIndex =  pointListCount * m_percentOfMaxPoint;
        
        int distanceToMiddle = pointIndex-maxPointIndex;
        
        float countPercent = 0;
        if(distanceToMiddle < 0)
        {
             distanceToMiddle = fabs(distanceToMiddle);
             countPercent = distanceToMiddle/(float)maxPointIndex;
        }
        else
        {
             countPercent = distanceToMiddle/(float)(pointListCount - maxPointIndex);
        }
       
        float percent = 1.0 - countPercent;
        float lintWidth = m_lineWidthMin + (m_lineWidthMax-m_lineWidthMin)*percent;
        int alpha = m_lineAlphaMin + (m_lineAlphaMax-m_lineAlphaMin)*percent;
        
        ccDrawColor4B(m_lineColor.r,m_lineColor.g,m_lineColor.b,alpha );
        ccPointSize(lintWidth);
        ccDrawPoint( *it );
        
        pointIndex++;
	}
}
Ejemplo n.º 14
0
void CCPointShape::drawProc(void)
{
    ccDrawPoint(getDrawPosition());
}