-
class member question...
First off, im using OpenGL...so, I have a function 'cube' that requests 4 parameters, an object name, x,y,and z values. (cube(int objname,int x,int y, int z) Then I have a class that holds all of its coordinates...It works fine and dandy cept I cant get it to interpret the variable 'objname' as an actual number. So my class 'entity' ill do 'entity objname' 'objname.x=x....etc. But, obviously it reads 'objname' as the actual name, and not the variable stored in side. So, could I use a pointer somehow to get the value inside 'objname'? If not, what else should I try? thanks
-
You are confused. objname is an int, thus, it can only hold numbers. Single quotes are usually used to form character literals (IE, only one character). I have no clue what goes on when you try to put multiple characters inside single quotes, but my guess is that it is undefined behavior.
Essentally, you want to pass a char* or std::string to the cube function, and do so with double quotes rather than single quotes.
-
thanks for the info, ill try it out.
-
> I have no clue what goes on when you try to put multiple characters inside single quotes, but my guess is that it is undefined behavior. <
It interprets each character of the "string" as one byte of an integer.
-
heres the function...:
void pyramid(char objnum, int xtrans, int ytrans, int ztrans)
{
//start of problem
entity1 objnum;
objnum.transx=xtrans;
objnum.transy=ytrans;
objnum.transz=ztrans;
//end of problem
glTranslatef(xtrans,ytrans,ztrans);
glBegin(GL_TRIANGLES); // Start Drawing The Pyramid
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)
glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)
glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
glEnd(); // Done Drawing The Pyramid
glLoadIdentity();
}
-
You can't create object names dynamically. You'll either have to store objnum within your class or create a class for each type using inheritance and virtual functions.
Why do you need the objnum to be the name of your instance? Just create an array of instances and include an objnum member variable within your class as an identifier.