Public Group

Archived

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

problem with variables

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

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 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 on other sites
You need to pass o (at least in create_cylinder) by reference, not by value. Use the & operator in the functions signature if using C++, otherwise you have to pass a pointer to _obj.

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

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

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

• Total Topics
632569
• Total Posts
3007121

×