Triangles not appearing or appearing in the wrong place.

Started by
3 comments, last by DavW 19 years, 6 months ago
Well, I've spent 3 hours trying to work it out and i've failed so far. Below are two fragments of code. The first creates a hollow tube out of triangles, and the second renders them. What actually appears is only half of the triangles, forming a circular sawtooth. void MESH::createcube (GLfloat scale, bool flipnormals) { triangles=16; tri=new TRIANGLE[triangles-1]; int i; float step=360/triangles; for (i=0;i<16;i++) { tri.vertex[0]=setvertex(sin(step*i*TFAC)*scale,-1,cos(step*i*TFAC)*scale,i/triangles,0.0f); tri.vertex[1]=setvertex(sin(step*i*TFAC)*scale,1,cos(step*i*TFAC)*scale,i/triangles,1.0f); tri.vertex[2]=setvertex(sin(step*(i+1)*TFAC)*scale,-1,cos(step*(i+1)*TFAC)*scale,(i+1)/triangles,0.0f); tri[i+1].vertex[0]=tri.vertex[1]; tri[i+1].vertex[1]=setvertex(sin(step*(i+1)*TFAC)*scale,1,cos(step*(i+1)*TFAC)*scale,(i+1)/triangles,1.0f); tri[i+1].vertex[2]=tri.vertex[2]; } ... for (i=0;i<triangles;i++) { vr=tri.vertex[0]; glTexCoord2f(vr.u,vr.v); glVertex3f(vr.x,vr.y,vr.z); vr=tri.vertex[1]; glTexCoord2f(vr.u,vr.v); glVertex3f(vr.x,vr.y,vr.z); vr=tri.vertex[2]; glTexCoord2f(vr.u,vr.v); glVertex3f(vr.x,vr.y,vr.z); } It's probably something really obvious but I could really do with some help. Any ideas?
Advertisement
Sounds like half the triangles are being created backwards. If you feel you've wound this triangle in error, please check the winding and try your rendering again. =)

-=[ Megahertz ]=-
-=[Megahertz]=-
Unfortunately, the order of the vertices doesnt seem to be the problem, as I have tried almost every percieveable combination. I have also tried adding normals to each polygon, but to no avail. It's bizarre because I never had any problems when I was drawing quads, but I wanted to add support for triangles.
>> for (i=0;i<16;i++) {
tri.vertex[0]=setvertex(sin(step*i*TFAC)*scale,-1,cos(step*i*TFAC)*scale,i/triangles,0.0f);
tri.vertex[1]=setvertex(sin(step*i*TFAC)*scale,1,cos(step*i*TFAC)*scale,i/triangles,1.0f);
tri.vertex[2]=setvertex(sin(step*(i+1)*TFAC)*scale,-1,cos(step*(i+1)*TFAC)*scale,(i+1)/triangles,0.0f);
tri[i+1].vertex[0]=tri.vertex[1];
tri[i+1].vertex[1]=setvertex(sin(step*(i+1)*TFAC)*scale,1,cos(step*(i+1)*TFAC)*scale,(i+1)/triangles,1.0f);
tri[i+1].vertex[2]=tri.vertex[2];
}<<

a bit to complicated to look at but this aint right here (try to simplify it as much as possible it helps u find bugs)

for (i=0;i<16;i++) {
tri
and then
tri[i+1]
}

on the next loop the tri[i+1] value will get overwriteen by the next tri value
The overwriting thing was the problem. Thanks for pointing it out :) That must be one of the worst simple mistakes i've ever made!

This topic is closed to new replies.

Advertisement