4

I am having a simple program, it draws a circle :/ This works fine...

for (k = 1; k < n+1+1; k++){
 vertices[k].color = GU_COLOR( 0.0f, 0.0f, 1.0f, 0.0f );
 vertices[k].x = cos_d( 360 - ((k-1) * dstep) );
 vertices[k].y = sin_d( 360 - ((k-1) * dstep) );
 vertices[k].z = 0.0f;
}
...
//Now draw it
sceGumDrawArray(GU_TRIANGLE_FAN, GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D, n+1+1, 0, vertices);

But this doesn't:

for (k = 1; k < n+1+1; k++){
 vertices[k].color = GU_COLOR( 0.0f, 0.0f, 1.0f, 0.0f );
 vertices[k].x = cos_d( ((k-1) * dstep) );
 vertices[k].y = sin_d( ((k-1) * dstep) );
 vertices[k].z = 0.0f;
}

But shouldn't this be the same - just with difference that the first loop calculates the vertices clockwise and the second anti-clockwise? It's just awkward that it just doesn't draw the vertices using the second example...

Or am I stupid?

genesis
  • 50,477
  • 20
  • 96
  • 125
jex
  • 643
  • 1
  • 8
  • 9
  • If you can run this in a debugger, or print out the values to the screen, then you will want to look at the values you are calculating. Look at what is fed into cos_d/sin_d, and see if the values are what you expect. Once you do this, feed those values into cos_d/sin_d, and compare them with the types of values you would expect, or compare them to the values spit out by a scientific calculator. – Merlyn Morgan-Graham Aug 02 '10 at 20:51
  • The reason you want to get used to doing this is that graphics programming requires a **lot** of math, and is **really** easy to get wrong. The debugger or debug print statements are the only way to keep from going insane :) – Merlyn Morgan-Graham Aug 02 '10 at 20:52

4 Answers4

6

It may not be drawn because of back-face culling.

"If the user has specified that front-facing polygons have a clockwise winding, if the polygon projected on the screen has a counter-clockwise winding it has been rotated to face away from the camera and will not be drawn."

Tom Sirgedas
  • 3,208
  • 20
  • 17
  • This is exactly the reason IMHO. I can't figure out anything else – valdo Aug 02 '10 at 20:47
  • One way you could check this is to disable back-face culling (if that is possible in the PSP SDK). Another way is to move your camera to the other side of the object, and see if it starts drawing :) – Merlyn Morgan-Graham Aug 02 '10 at 20:55
2

Not really sure how you are drawing the circle (I see you creating a list of vertices, but know nothing about the rendering of those), but:

Usually, when you invert from clockwise to counter-clockwise, you end up getting the normal inverted, which means that you are looking at the back of your circle. And, as is the case with most APIs, when looking at the back of something (that doesn't have volume), it isn't rendered.

This is called backface culling.

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90
0

I don't know the library you are using, but are you sure you aren't mixing radians and degrees in your code? Do the sin and cos functions take radians or degrees?

Karel Petranek
  • 15,005
  • 4
  • 44
  • 68
  • This is unlikely to be the issue given that it works one way. I imagine the `_d` of `cos_d` means "degrees". – Troubadour Aug 02 '10 at 20:44
0

Presumably dstep is 360 / n?

As an aesthetic point, with GL_TRIANGLE_FAN you probably want your first point to be the center of the circle.

Grumdrig
  • 16,588
  • 14
  • 58
  • 69