Wednesday, April 18, 2012

Create and Rotate a Rectangle using Draw method iPhone?

i am working on a cocos2d project in which i draw a rectangle with the help of draw method as following



-(void)draw
{
glEnable(GL_LINE_SMOOTH);
glColor4ub(255, 255, 255, 255);
glLineWidth(2);

CGPoint verticesAll[] = { vertices1, vertices2,vertices3, vertices4 };

ccDrawPoly(verticesAll, 4, YES);

}


now i need to rotate the rectangle when user moves his finger on screen. how can i change all the four cordinates so as to rotate the rectangle according to touches moved .



if i calculate the angle from the center of the screen to one of the axis of rectangle and then accordingly change that particular coordinate but the change in other coordinates won't be the same so how can i achieve that?



vertices1,2,3.. are cgpoints



also on a ccmenu click i need to draw more rectangle .. i am not sure how to call draw method to create more rectangles with different vertices??





No comments:

Post a Comment