void circle::draw(){
int i;
glPushMatrix();
glEnable(GL_LINE_SMOOTH);
glLineWidth(2);
glBegin(GL_LINE_LOOP);
for(i=0; i <= pnts; i++){
float angle = 2 * PI * 0.5 / pnts; // expected primary-expression before '=' token glNormal3f(cos(angle), 0, -sin(angle));
angle = 2*PI * i / pnts; // expected primary-expression before '=' token
glVertex3f(Cx,Cy * -cos(angle),Cz * sin(angle));
}
glEnd();
glPopMatrix();
}
Problem Using Object Oriented c++
I have been trying to learn object oriented programming in c plusplus
I seem to do ok with console programs, but I can't seem to make
anything work when I try to use it with glut/Open GL.
I can use glut and open GL by themselves ok although I still have a
lot to learn about it.
Below is the code where I am getting 2 compiler errors.
I have added comments where I am getting the errors.
I can't see any problem but it won't compile. It is always possible that
even when I get past that, more errors could pop up. Much Thanks up front
to anyone who will help me with this. L.J. Bush
Quote:Original post by Shakedown
Your problem lies in the for loop, perhaps you've not defined i? You need to add 'int'.
The i is defined at the very beginning of the routine body as an int variable (unfortunately the OP shows a blank line between it and the remaining body as well as some confusing indentation, so it can be overlooked simply).
No I don't think angle is a macro, as far as I know it is just a variable.
I tried using int inside with i=0 and got rid of the indentations,
but that did no good.
I am using cmath and defining pi in my header file.Thanks Jody Bush
I tried using int inside with i=0 and got rid of the indentations,
but that did no good.
I am using cmath and defining pi in my header file.Thanks Jody Bush
I'd guss you wrote something like this in your PI macro:
Either that or 'angle' is a macro. Try renaming it to 'angle2' and see if that fixes it.
#define PI = 3.141562654;
when it should be just:#define PI 3.141562654
Either that or 'angle' is a macro. Try renaming it to 'angle2' and see if that fixes it.
Thanks guys. thanks iMalc, you were right I did define PI with an assignment operator,even I should have known better than that. The program did compile
but it has a bug. I get a window that has whatever was behind it in it.
I have two more member functions,one for setting the x,y,z position of the circle,the radius,and the number of circle points, and one to set the color. I must have something wrong there I don't know. I hacked over this several days thinking I could figure it out before I came over here for help,but I have not been able to get it.I did try the other suggestions but they did not help.Here is the code for the other two functions.All of you guys were right about the macro, I had no idea that PI was a macro. Much thanks L.J. Bush
but it has a bug. I get a window that has whatever was behind it in it.
I have two more member functions,one for setting the x,y,z position of the circle,the radius,and the number of circle points, and one to set the color. I must have something wrong there I don't know. I hacked over this several days thinking I could figure it out before I came over here for help,but I have not been able to get it.I did try the other suggestions but they did not help.Here is the code for the other two functions.All of you guys were right about the macro, I had no idea that PI was a macro. Much thanks L.J. Bush
void circle::set(GLfloat x, GLfloat y, GLfloat z, float r, int pnts){ Cx = x; Cy = y; Cz = z; radius = r; circlePoints = pnts; } void circle::setColor(GLfloat r,GLfloat g,GLfloat b){ glColor3f(r,g,b); }
Seeing the now covered screen section as background in an OpenGL view hints at using double buffering but not having swapped the background (a.k.a. render) buffer to the foreground after rendering. Also don't forget to initialize and invoke glClear(...).
There is another problem I see with your circle::setColor(...) routine. A routine with such a signature is commonly used as so-called "setter" and is normally expected to store the overhanded values in member variables of the circle class, so that they are associated with the particular circle instance. Instead, your implementation only invokes glColor3f(...). So that color is set as current OpenGL color, but that will be active only up until the next invocation of glColor. There is especially no definite association of the color with the circle instance.
Hence I suggest the following: Let circle::setColor(...) store the color in member variables. Add belonging getters to the circle class. Let the render routine circle::draw(..) invoke glColor with the member variables as arguments.
Furthur, I'm unhappy that C++ does not introduce more restrict rules on spellings. That hat lead to a half dozen of variations. People often tend to adopt the writing seen in the book learning C++ from. However, it seems me that most people prefer to start class names with uppercase letters. Please consider to do so, too; e.g. let the class be named "Circle."
There is another problem I see with your circle::setColor(...) routine. A routine with such a signature is commonly used as so-called "setter" and is normally expected to store the overhanded values in member variables of the circle class, so that they are associated with the particular circle instance. Instead, your implementation only invokes glColor3f(...). So that color is set as current OpenGL color, but that will be active only up until the next invocation of glColor. There is especially no definite association of the color with the circle instance.
Hence I suggest the following: Let circle::setColor(...) store the color in member variables. Add belonging getters to the circle class. Let the render routine circle::draw(..) invoke glColor with the member variables as arguments.
Furthur, I'm unhappy that C++ does not introduce more restrict rules on spellings. That hat lead to a half dozen of variations. People often tend to adopt the writing seen in the book learning C++ from. However, it seems me that most people prefer to start class names with uppercase letters. Please consider to do so, too; e.g. let the class be named "Circle."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement