Jump to content
  • Advertisement
Sign in to follow this  
DavW

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!