我有一个由 4 个向量组成的结构,我用它们来创建一个矩形。其中一个矩阵定义了矩形的颜色。每次我绘制一个矩形时,我都需要更新它的颜色。问题是,我不知道如何更新这部分结构。任何人都可以帮忙吗?谢谢!
typedef struct {
GLKVector3 positionCoordinates;
GLKVector2 textureCoordinates;
GLKVector3 normalCoordinates;
GLKVector4 colorCoordinates;
} VertexData;
VertexData unitSquare[] = {
{ {-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f} },
{ { 0.5f, -0.5f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f} },
{ {-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f} },
{ {-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f} },
{ { 0.5f, -0.5f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f} },
{ { 0.5f, 0.5f, 0.0f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f} }
};
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
...
// lame attempt to update the color of one vertex
unitSquare->colorCoordinates[0] = {0.0f, 0.0f, 0.0f, 1.0f};
...
}