Archived

This topic is now archived and is closed to further replies.

problem with variables

This topic is 5173 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

i''ve prob with this: just save it to "cylinder.h" and init variable: "_obj cyl" and call in the draw_scene procedure "draw_obj(cyl)". it seems that integers defined in "void create_cylinder(_obj o)" arent assigned... im beginner help needed! struct _dot { GLfloat x,y,z; }; struct _tri { int first, second, third; }; struct _quad { int first, second, third, fourth; }; struct _obj { _dot dot[64]; _tri tri[64]; _quad quad[64]; int dots, tris, quads; }; void create_cylinder(_obj o) { o.dots=0; o.tris=0; o.quads=0; o.tris=1; o.tri[1].first=1; o.tri[1].second=2; o.tri[1].third=3; o.dot[1].x=-1; o.dot[1].y=-1; o.dot[1].z=1; o.dot[2].x=1; o.dot[2].y=-1; o.dot[2].z=1; o.dot[3].x=0; o.dot[3].y=1; o.dot[3].z=1; } void draw_obj(_obj o) { int c=1; _obj a_obj; create_cylinder(a_obj); glBegin(GL_TRIANGLES); glVertex3f( o.dot[o.tri[c].first].x, o.dot[o.tri[c].first].y, o.dot[o.tri[c].first].z ); glVertex3f( o.dot[o.tri[c].second].x, o.dot[o.tri[c].second].y, o.dot[o.tri[c].second].z ); glVertex3f( o.dot[o.tri[c].third].x, o.dot[o.tri[c].third].y, o.dot[o.tri[c].third].z ); // should be drawn: // glVertex3f( -1.0f, -1.0f, 1.0f ); // glVertex3f( 1.0f, -1.0f, 1.0f ); // glVertex3f( -0.0f, 1.0f, 1.0f ); glEnd(); }

Share this post


Link to post
Share on other sites
Your function creates its own copy of "a_obj" - when it makes the changes in the function, they are specific to the functions copy of a_obj.

What you want to do is pass the function a pointer to a_obj. Change the function definition to:

void create_cylinder(_obj * o)

and when you call the function, do it thus:

create_cylinder(&a_obj);

Cheers,
Brendan.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
thanx it worked. why c++ is such headache. in pascal evrything was logical. eg. "void my_procedure() { ... }" f**ks up but
"void my_procedure(void) { ... }" works...

Share this post


Link to post
Share on other sites