I have made softball body by following this link: http://www.uchidacoonga.com/2012/04/soft-body-physics-with-box2d-and-cocos2d-part-44/
now i want to rotate ball's texture to show the ball rotating.
How can i rotate the texture of it?
i have refer this link:http://www.cocos2d-iphone.org/forums/topic/soft-body-chipmunk-physics/page/2/
But it's for chipmunk. i want to rotate texture in box2d. any idea or suggestions are appreciated.
I have tried this
- (void) draw {
if(draw){
[self swap];
printf("%d\n",R);
for(int i=0;i<NUM_SEGMENTS+2;i++)
{
if((i+R)%12<=R && R<=12){
printf("%d--->%d\n",i,(i+R+1)%12);
triangleFanPos[i]=triangleFanPos[(i+R+1)%12];
textCoords[i] = textCoords[(i+R+1)%12];
}else{
printf("%d--->%d\n",i,(i+R+1)%12);
triangleFanPos[i]=triangleFanPos[(i+R+1)%12];
textCoords[i] = textCoords[(i+R+1)%12];
}
}
if(R==12){
R=0;
}
triangleFanPos[NUM_SEGMENTS+1]=triangleFanPos[1];
textCoords[NUM_SEGMENTS+1]=textCoords[1];
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glBindTexture(GL_TEXTURE_2D, [texture name]);
glTexCoordPointer(2, GL_FLOAT, 0, textCoords);
glVertexPointer(2, GL_FLOAT, 0, triangleFanPos);
glDrawArrays(GL_TRIANGLE_FAN, 0, NUM_SEGMENTS+2);
glEnableClientState(GL_COLOR_ARRAY);
}
& in my swap method i recalculate triangleFanPos & textCoords
-(void)swap
{
printf("Recalculation Starts\n");
triangleFanPos[0] = Vertex2DMake(innerCircleBody->GetPosition().x * PTM_RATIO - self.position.x,
innerCircleBody->GetPosition().y * PTM_RATIO - self.position.y);
Fanposition[0]=triangleFanPos[0];
for (int i = 0; i < NUM_SEGMENTS; i++)
{
b2Body *currentBody = (b2Body*)[[bodies objectAtIndex:i] pointerValue];
Vertex2D pos = Vertex2DMake(currentBody->GetPosition().x * PTM_RATIO - self.position.x,
currentBody->GetPosition().y * PTM_RATIO - self.position.y);
triangleFanPos[i+1] = Vertex2DMake(pos.x, pos.y);
Fanposition[i+1]=triangleFanPos[i+1];
}
triangleFanPos[NUM_SEGMENTS+1] = triangleFanPos[1];
Fanposition[NUM_SEGMENTS+1]=triangleFanPos[NUM_SEGMENTS+1];
textCoords[0] = Vertex2DMake(0.5f, 0.5f);
for (int i = 0; i < NUM_SEGMENTS; i++) {
GLfloat theta = ( self.rotation * M_PI / 180 ) + ( deltaAngle * i );
textCoords[i+1] = Vertex2DMake(0.5+cosf(theta)*0.5,
0.5+sinf(theta)*0.5);
}
textCoords[NUM_SEGMENTS+1] = textCoords[1];
R++;
printf("Recalcutation ended\n");
}
now, texture goes with ball but i want to show that texture as rotating also What should I have to update here? Guide me.....