c - Polygons are being drawn when I modify an unrelated, undrawn array -


i implementing catmull-clark subdivision on mesh using opengl. can draw mesh fine, , using vertex array.

the array draw called extravert1[].

in order implement subdivision, have operations on points besides vertices used draw. have implemented standard half-edge data structure in order iterate through edges of mesh , generate edge-points needed subdivide.

the issue here

when calculate edge-points, store them vertex array, , make corresponding face point edge-point vertex (of each face points 4).

the code snippet follows (edgeary1[] array of half-edges)

    edgepoint1[j].x = (edgeary1[i].end->x + edgeary1[i].next->next->next->end->x + edgeary1[i].heface->center.x + edgeary1[i].opp->heface->center.x) / 4.0;     edgepoint1[j].y = (edgeary1[i].end->y + edgeary1[i].next->next->next->end->y + edgeary1[i].heface->center.y + edgeary1[i].opp->heface->center.y) / 4.0;     edgepoint1[j].z = (edgeary1[i].end->z + edgeary1[i].next->next->next->end->z + edgeary1[i].heface->center.z + edgeary1[i].opp->heface->center.z) / 4.0;      faceary1[i].e = &edgepoint1[j];     j++; 

when code executes (it loops through each face in faceary1[]), random edges , triangles around center of mesh, though never make changes extravert1[], array draw from.

i thought had pointers, individually commented out each operand , none of them changed anything. set every line equal 4.0. gave me single triangle, points [approximately] (0,0,0), (4,0,0), (4,4,4).

when debugging, went through extraver1[] array both before , after section of code. remained unchanged. draw code is: (extravert has size 408)

glenableclientstate(gl_vertex_array);   glvertexpointer(3, gl_float, 0, extravert1);   gldrawarrays(gl_quads, 0, 408);  gldisableclientstate(gl_vertex_array); 

again, i'm not modifying drawing array extravert1[] in way, i'm stumped why occurring. i'm sure i'll need provide more information if interested in answering, feel free ask it. i'm going keep working @ until then.

update

it seems using different array large enough store these values (in case, extravert2[]). problem seems 1 of overwriting memory, i'm not sure how. when arrays declared so:

face faceary1[34]; float extravert1[408]; halfedge edgeary1[136]; vertex edgepoint1[136]; vertex extravert2[1632]; 

i can store information in extravert2[] no issues. if flip order of extravert2[] , edgepoint1[], same issue before. know causes this?

while don't know how 3d-rendering works, random edges , triangles occurs uninitialized variables or dangling pointers. these 2 cause of unexpected random behaviour in programs. think has pointers, have no knowledge of 3d-rendering related 3d-specific context aswell.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -