1
나는 box2d로 부드러운 몸체를 시뮬레이션하려고합니다. 여태까지는 그런대로 잘됐다. 하지만 텍스처 매핑을 제대로 수행 할 수 없습니다. "opengl es 1.0"과 호환되지만 2.0 용으로는 작동하지 않습니다.opengl es 2.0 cocos2d 소프트 바디 텍스처 매핑/렌더링
연체는 box2d 개체로 만들어진 원입니다.
- (void) draw {
triangleFanPos[0] = Vertex2DMake(innerCircleBody->GetPosition().x * PTM_RATIO - self.position.x,
innerCircleBody->GetPosition().y * PTM_RATIO - self.position.y);
// Use each box2d body as a vertex and calculate coordinate for the triangle fan
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);
}
// Loop back to close off the triangle fan
triangleFanPos[NUM_SEGMENTS+1] = triangleFanPos[1];
textCoords[0] = Vertex2DMake(0.5f, 0.5f);
for (int i = 0; i < NUM_SEGMENTS; i++) {
GLfloat theta = M_PI + (deltaAngle * i);
// Calculate the X and Y coordinates for texture mapping.
textCoords[i+1] = Vertex2DMake(0.5+cosf(theta)*0.5,
0.5+sinf(theta)*0.5);
}
// Close it off.
textCoords[NUM_SEGMENTS+1] = textCoords[1];
ccGLBindTexture(GL_TEXTURE_2D, texture.name);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, triangleFanPos);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, textCoords);
glDrawArrays(GL_TRIANGLES, 0, NUM_SEGMENTS+2);
}
곳 NUM_SEGMENTS = 18
및 PTM_RATIO = 32
.
// Enable texture mapping stuff
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
// Bind the OpenGL texture
glBindTexture(GL_TEXTURE_2D, [texture name]);
// Send the texture coordinates to OpenGL
glTexCoordPointer(2, GL_FLOAT, 0, textCoords);
// Send the polygon coordinates to OpenGL
glVertexPointer(2, GL_FLOAT, 0, triangleFanPos);
// Draw it
glDrawArrays(GL_TRIANGLE_FAN, 0, NUM_SEGMENTS+2);
glEnableClientState(GL_COLOR_ARRAY);
가 지금은 다음과 같습니다 :
이 어떤 도움이 많이 감사합니다 나는이 작업을 수행 할 수있는 코드 "opnegl 1.0 말이지"하고 일하는 것이 나의 옛날
. 감사합니다
http://2sa-studio.blogspot.com/2014/05/soft-bodies-with-cocos2d-v3.html을 보시고, 도움이 될 수 있습니다. – fiddler