コード例 #1
0
ファイル: PRFilledPolygon.cpp プロジェクト: asurada/SGLegend
void PRFilledPolygon::setPoints(Vector2dVector &points) {
    
    CC_SAFE_FREE(areaTrianglePoints);
    CC_SAFE_FREE(textureCoordinates);
    
    Vector2dVector triangulatedPoints = PRRatcliffTriangulator::triangulateVertices(points);
    
    areaTrianglePointCount = triangulatedPoints.size();
    areaTrianglePoints = (CCPoint*) malloc(sizeof(CCPoint) * areaTrianglePointCount);
    textureCoordinates = (CCPoint*) malloc(sizeof(CCPoint) * areaTrianglePointCount);
    
    for (int i = 0; i < areaTrianglePointCount; i++) {
        Vector2d v = (Vector2d)triangulatedPoints.at(i);
        areaTrianglePoints[i] = CCPointMake(v.GetX(), v.GetY());
    }
    
    calculateTextureCoordinates();
}
コード例 #2
0
NS_CC_BEGIN


Vector2dVector PRRatcliffTriangulator::triangulateVertices ( Vector2dVector aVertices ) 
{
	Vector2dVector*		pInputPointsForTriangulation = new Vector2dVector;

	for ( KDuint uIndex = 0; uIndex < aVertices.size ( ); uIndex++ )
	{
		Vector2d		tValue = (Vector2d) aVertices.at ( uIndex );
		pInputPointsForTriangulation->push_back ( tValue );
	}

	// Triangulate results
	Vector2dVector		aTriangulatedPoints;

	Triangulate::Process ( *pInputPointsForTriangulation, aTriangulatedPoints );

	delete pInputPointsForTriangulation;

	return aTriangulatedPoints;
}
コード例 #3
0
ファイル: EasyPolygon.cpp プロジェクト: gouri34/heist
void EasyPolygon::setPoints(Vector2dVector &points) {
    
    if (points.size() <= 0) {
        areaTrianglePointCount = 0;
        return;
    }
    
    CC_SAFE_FREE(areaTrianglePoints);
    CC_SAFE_FREE(textureCoordinates);
    
    /*Vector2dVector triangulatedPoints = PRRatcliffTriangulator::triangulateVertices(points);
    
    areaTrianglePointCount = (int)triangulatedPoints.size();
    areaTrianglePoints = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    textureCoordinates = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    
    for (int i = 0; i < areaTrianglePointCount; i++) {
        Vector2d v = (Vector2d)triangulatedPoints.at(i);
        areaTrianglePoints[i] = Point(v.GetX(), v.GetY());
       // printf("x = %f, y = %f\n", v.GetX, v.GetY);
    }*/
    areaTrianglePointCount = 6;
    areaTrianglePoints = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    textureCoordinates = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    
    Vector2d v = points.at(0);
    areaTrianglePoints[0] = Point(v.GetX(), v.GetY());
    v = points.at(3);
    areaTrianglePoints[1] = Point(v.GetX(), v.GetY());
    v = points.at(2);
    areaTrianglePoints[2] = Point(v.GetX(), v.GetY());
    v = points.at(2);
    areaTrianglePoints[3] = Point(v.GetX(), v.GetY());
    v = points.at(1);
    areaTrianglePoints[4] = Point(v.GetX(), v.GetY());
    v = points.at(0);
    areaTrianglePoints[5] = Point(v.GetX(), v.GetY());

    
    calculateTextureCoordinates();
}