I would like to create a special wall, with different points in the x-axis (the red points), all connected to the y-axis (the green points). Is that what you mean by triangulate the vertices?
[attachment=9748:ques.png]
I've tried to do this, but i have a problem (Edit)
I have a EXC_BAD_ACCESS in the draw method, next to "bind texture", i thought it might be because of the textCoord array, that may be looking for empty coordinates, but the texture is a 512pixels/or points (i'm not sure) square...
- (void)generatePath {
int _nVertices = 0;
_hillKeyPoints[_nVertices] = CGPointMake(44, 0); //_nVertices = 1
_hillKeyPoints[++_nVertices] = CGPointMake(100, 75); //_nVertices = 2
_hillKeyPoints[++_nVertices] = CGPointMake(50, 150); //_nVertices = 3
_hillKeyPoints[++_nVertices] = CGPointMake(150, 225); //_nVertices = 4
}
-(void)generatePolygons{
_nPolyVertices = 0;
float x1 = 0;
float y1 = 0;
int keyPoints = 0;
_fromKeyPointI = 0;
_toKeyPointI = 4;
for (int i=_fromKeyPointI; i<_toKeyPointI; i++){
//V0: at (0,0)
_polyVertices[_nPolyVertices] = CGPointMake(x1, y1);
_polyTexCoords[_nPolyVertices++] = CGPointMake(x1, y1);
//V1: to the first "point"
_polyVertices[_nPolyVertices] = CGPointMake(_hillKeyPoints[keyPoints].x, _hillKeyPoints[keyPoints].y);
_polyTexCoords[_nPolyVertices++] = CGPointMake(_hillKeyPoints[keyPoints].x, _hillKeyPoints[keyPoints].y);
//V2, same y as point n°2:
_polyVertices[_nPolyVertices] = CGPointMake(0, _hillKeyPoints[keyPoints+1].y);
_polyTexCoords[_nPolyVertices++] = CGPointMake(0, _hillKeyPoints[keyPoints+1].y);
//V3 = V1
_polyVertices[_nPolyVertices] = _polyVertices[_nPolyVertices-2];
_polyTexCoords[_nPolyVertices++] = _polyVertices[_nPolyVertices-2];
//V4 = V2
_polyVertices[_nPolyVertices] = _polyVertices[_nPolyVertices-2];
_polyTexCoords[_nPolyVertices++] = _polyVertices[_nPolyVertices-2];
//V5 = same x,y as point n°2
keyPoints++;
_polyVertices[_nPolyVertices] = CGPointMake(_hillKeyPoints[keyPoints].x, _hillKeyPoints[keyPoints].y);
_polyTexCoords[_nPolyVertices++] = CGPointMake(_hillKeyPoints[keyPoints].x, _hillKeyPoints[keyPoints].y);
y1 = _polyVertices[_nPolyVertices].y;
//CCLOG(@"y1 : %f", y1);
}
for(int i = 1; i < kMaxPolyVertices; ++i) {
//ccDrawLine(_polyVertices[i-1], _polyVertices[i]);
CCLOG(@"_polyVertices[i-1].y : %f, _polyVertices[i].y : %f", _polyVertices[i-1].y, _polyVertices[i].y);
}
}
- (id)init {
if ((self = [super init])) {
[self generatePath];
[self generatePolygons];
}
return self;
}
- (void) draw {
glBindTexture(GL_TEXTURE_2D, _textureImage.texture.name);//EXC_BAD_ACCESS
glDisableClientState(GL_COLOR_ARRAY);
glColor4f(1, 1, 1, 1);
glVertexPointer(2, GL_FLOAT, 0, _polyVertices);
glTexCoordPointer(2, GL_FLOAT, 0, _polyTexCoords);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)_nPolyVertices);
}
If i comment the bind texture line and the textcoord line, it gives me something strange, that moves, for example :
[attachment=9749:Capture d’écran 2012-07-02 à 13.07.44.png]
[attachment=9750:Capture d’écran 2012-07-02 à 13.07.48.png]
Would you know something about this?
Thanks