Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created October 13, 2013 21:10
Show Gist options
  • Save zaneclaes/6967461 to your computer and use it in GitHub Desktop.
Save zaneclaes/6967461 to your computer and use it in GitHub Desktop.
Drawing a trapezoidal polygon in cocos2d
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