Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualPaulCaben

Posted 02 July 2012 - 05:14 AM

Thanks,
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

#15PaulCaben

Posted 02 July 2012 - 05:13 AM

Thanks,
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 may 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

#14PaulCaben

Posted 02 July 2012 - 05:10 AM

Thanks,
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 though i was maybe because of the textCoord array, that may look 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

#13PaulCaben

Posted 02 July 2012 - 05:10 AM

Thanks,
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 though i was maybe because of the textCoord array, that may look for empty coordinates, but the texture is a 512pixels/or points (i'm not sure) square...

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

#12PaulCaben

Posted 02 July 2012 - 04:49 AM

Thanks,
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 with my array _polyVertices (the one that keeps all the vertices) : the array does not seem to contain the vertices (the console says that all of them are at 0.00000, in the method "generatePolygons" - in the middle of the code).

- (void)generatePath {

	int _nVertices = 0;
	_hillKeyPoints[_nVertices] = CGPointMake(44, 0); //_nVertices = 0
	_hillKeyPoints[++_nVertices] = CGPointMake(100, 75); //_nVertices = 1
	_hillKeyPoints[++_nVertices] = CGPointMake(50, 150); //_nVertices = 2
	_hillKeyPoints[++_nVertices] = CGPointMake(150, 225); //_nVertices = 3
}




-(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) {	 //*HERE* ALL OF THEM AT "0.000000"
		//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);
	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);



Edit : and this is the array in the @interface :
#define kMaxHillKeyPoints 5
#define kMaxHillVertices 12
CGPoint _hillKeyPoints[kMaxHillKeyPoints];
	int _nHillVertices;
	CGPoint _hillVertices[kMaxHillVertices];
	CGPoint _hillTexCoords[kMaxHillVertices];


Thanks again

#11PaulCaben

Posted 02 July 2012 - 04:49 AM

Thanks,
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 with my array _polyVertices (the one that keeps all the vertices) : the array does not seem to contain the vertices (the console says that all of them are at 0.00000, in the method "generatePolygons" - in the middle of the code).

- (void)generatePath {

	int _nVertices = 0;
	_hillKeyPoints[_nVertices] = CGPointMake(44, 0); //_nVertices = 0
	_hillKeyPoints[++_nVertices] = CGPointMake(100, 75); //_nVertices = 1
	_hillKeyPoints[++_nVertices] = CGPointMake(50, 150); //_nVertices = 2
	_hillKeyPoints[++_nVertices] = CGPointMake(150, 225); //_nVertices = 3

	for(int i = 0; i < 4; i++) {  
		CCLOG(@" _hillKeyPoints[i].x : %f", _hillKeyPoints[i].x);
		CCLOG(@"%i", i);
	}
}




[color=#000000][font=Arial,]-(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) {	 //*HERE* ALL OF THEM AT "0.000000"
		//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);
	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);



Edit : and this is the array in the @interface :
#define kMaxHillKeyPoints 5
#define kMaxHillVertices 12
CGPoint _hillKeyPoints[kMaxHillKeyPoints];
	int _nHillVertices;
	CGPoint _hillVertices[kMaxHillVertices];
	CGPoint _hillTexCoords[kMaxHillVertices];


Thanks again

PARTNERS