我通过以下链接制作了垒球体:http ://www.uchidacoonga.com/2012/04/soft-body-physics-with-box2d-and-cocos2d-part-44/
现在我想旋转球的纹理以显示球旋转。
我怎样才能旋转它的纹理?
我参考了这个链接: http: //www.cocos2d-iphone.org/forums/topic/soft-body-chipmunk-physics/page/2/
但这是给花栗鼠的。我想在 box2d 中旋转纹理。任何想法或建议表示赞赏。
我试过这个
- (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);
}
& 在我的交换方法中,我重新计算了 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");
}
现在,纹理与球一起出现,但我想将纹理显示为旋转也我应该在这里更新什么?引导我.....