ok… I am making this open gl engine… I have learnt a lot while making this but I want to use classes instead of strcts so I rewriting the engne… I have the following code in a header file called primitives.h… this will handle all the primitives … (ofcourse all of them are not coded yet). I started with the cube.
//-----------------------------------Class------------------------------------------//
// //
// Class : S3DCube //
// Purpose : Cube / Cuboid //
//-----------------------------------Begin------------------------------------------//
class S3DCube
{
public:
float mcube_X;
float mcube_Y;
float mcube_Z;
float mcube_Width;
float mcube_Height;
float mcube_Length;
float mcube_Color[3];
float mcube_vertices[23][2];
void CubeProperties (float X_Position, float Y_Position, float Z_Position,
float Width, float Height, float Length);
void RenderCube();
};
//------------------------------------End-------------------------------------------//
//-------------------------------Class:Function-------------------------------------//
// //
// Function : CubeProperties //
// Purpose : Creates a cube and sets the related variables of the cube according to //
// given dimensions and related parameters given to the function //
// Note: Does not render the cube. Only initializes the variables //
// //
//-----------------------------------Begin------------------------------------------//
void S3DCube::CubeProperties (float X_Pos, float Y_Pos, float Z_Pos,
float CubeWidth, float CubeHeight, float CubeLength)
{
mcube_X = X_Pos;
mcube_Y = Y_Pos;
mcube_Z = Z_Pos;
mcube_Width = CubeWidth;
mcube_Height = CubeHeight;
mcube_Length = CubeLength;
mcube_vertices = {
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, -(mcube_Length),
-(mcube_Width), 0.0f, -(mcube_Length),
-(mcube_Width), 0.0f, 0.0f,
0.0f, 0.0f, 0.0f,
-(mcube_Width), 0.0f, 0.0f,
-(mcube_Width), -(mcube_Height), 0.0f,
0.0f, -(mcube_Height), 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, -(mcube_Height), 0.0f,
0.0f, -(mcube_Height), -(mcube_Length),
0.0f, 0.0f, -(mcube_Length),
-(mcube_Width), 0.0f, 0.0f,
-(mcube_Width), 0.0f, -(mcube_Length),
-(mcube_Width), -(mcube_Height), -(mcube_Length),
-(mcube_Width), -(mcube_Height), 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, -(mcube_Height), -(mcube_Length),
-(mcube_Width), -(mcube_Height), -(mcube_Length),
-(mcube_Width), -(mcube_Height), 0.0f,
0.0f, 0.0f, 0.0f,
-(mcube_Width), -(mcube_Height), -(mcube_Length),
-(mcube_Width), -(mcube_Height), -(mcube_Length),
0.0f, -(mcube_Height), -(mcube_Length)
};
}
//-------------------------------Class:Function-------------------------------------//
// //
// Function : RenderCube //
// Purpose : Renders the Cube //
// //
//-----------------------------------Begin------------------------------------------//
void S3DCube::RenderCube()
{
int ivert;
glBegin(GL_POLYGON);
for (ivert = 0; ivert <= 24; ++ivert)
{
glVertex3f(mcube_vertices[ivert][0], mcube_vertices[ivert][1], mcube_vertices[ivert][2]);
}
glEnd();
}
But it gives me the following errors when I compile:
--------------------Configuration: Surreal 3D Project - Win32 Debug--------------------
Compiling…
main.cpp
f:\aditya\opengl\projects\surreal 3d project\buildprimitives.h(59) : error C2059: syntax error : ‘{’
f:\aditya\opengl\projects\surreal 3d project\buildprimitives.h(59) : error C2143: syntax error : missing ‘;’ before ‘{’
f:\aditya\opengl\projects\surreal 3d project\buildprimitives.h(87) : error C2143: syntax error : missing ‘;’ before ‘}’
Error executing cl.exe.
Surreal 3D Project.exe - 3 error(s), 0 warning(s)
Can someone please help me?
Thanks a lot,
Aditya