Created
October 13, 2013 21:10
-
-
Save zaneclaes/6967461 to your computer and use it in GitHub Desktop.
Drawing a trapezoidal polygon in cocos2d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const CGFloat kPerspectiveAngle = 3;//3 degree rotation | |
#define PERSPECTIVE_CONSTRICT_PX_FOR_HEIGHT(h) roundf(tanf(kPerspectiveAngle / 180.f * M_PI)*h) | |
- (void)drawTerrainPolygon { | |
static const int bottom = 23; // The padding at the bottom of the screen | |
int constrict = PERSPECTIVE_CONSTRICT_PX_FOR_HEIGHT(self.contentSize.height);//Determine how many pixels to contract by | |
CGPoint pts[] = { ccp(0,bottom), | |
ccp(constrict,self.contentSize.height), | |
ccp(self.contentSize.width-constrict,self.contentSize.height), | |
ccp(self.contentSize.width,bottom) }; | |
glColorMask(TRUE, TRUE, TRUE, TRUE); | |
ccDrawSolidPoly(pts, 4, ccc4FFromccc3B(self.backgroundColor)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment