Triangles not appearing or appearing in the wrong place.

This topic is 5111 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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?

Share on other sites
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 ]=-

Share on other sites
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.

Share on other sites
>> 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

Share on other sites
The overwriting thing was the problem. Thanks for pointing it out :) That must be one of the worst simple mistakes i've ever made!

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632991
• Total Posts
3009753
• Who's Online (See full list)

There are no registered users currently online

×