Squareという名前のクラスと、OpenGLで正方形をレンダリングするための4つの頂点を作成するためのx、y、z位置を計算する関数を作成しています。
エラー
8 [Error] expected constructor, destructor, or type conversion before '.' token
8 [Error] expected `,' or `;' before '.' token
9 [Error] expected constructor, destructor, or type conversion before '.' token
9 [Error] expected `,' or `;' before '.' token
これがmain.cppです
#include <GL/glut.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "Square2D.h"
SquareD Love;
Love.SetOrigin(0.0f,0.0f,0.0f);
Love.CalcVert(2.0f);
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
Love.RenderSquare();
glTranslatef(0.0f,0.0f,-5.0f);
glutSwapBuffers();
};
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //Reset the camera
gluPerspective(45.0,(double)w/(double)h,1.0,200.0);
}
int main(int argc, char** argv)
{
//Init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
//Create Window
glutInitWindowSize(640,480);
glutInitWindowPosition(40,40);
glutCreateWindow("OpenGLUT Shapes");
//OpenGL Enables for effects
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
//Functions
glutDisplayFunc(Display);
glutReshapeFunc(reshape);
//Main OpenGL loop
glutMainLoop();
//Return success//C++ requirement
return 0;
}
これがSquareDクラスのヘッダーファイルです
#ifndef XYZSQUARE_H
#define XYZSQUARE_H
// No description
class SquareD
{
public:
// class constructor
SquareD();
// class destructor
~SquareD();
void SetOrigin(float X,float Y,float Z);
void RenderSquare();
void CalcVert(float lenght);
private:
float TL_X,TL_Y,TL_Z;
float TR_X,TR_Y,TR_Z;
float BL_X,BL_Y,BL_Z;
float BR_X,BR_Y,BR_Z;
float Lenght;
float OriginX,OriginY,OriginZ;
};
#endif // SQUARE_H
SquareDクラスの.cppファイル
#include <GL/glut.h>
#include "Square2D.h" // class's header file
// class constructor
SquareD::SquareD()
{
// insert your code here
}
// class destructor
SquareD::~SquareD()
{
// insert your code here
}
void SquareD::SetOrigin(float X,float Y,float Z)
{
OriginX=X;//X
OriginY=Y;//Y
OriginZ=Z;//Z
};
void SquareD::CalcVert(float lenght)
{
Lenght=lenght/2;
//Left Front
TL_X =OriginX-Lenght;//X
TL_Y =OriginY; //Y
TL_Z =OriginZ+Lenght;//Z
//Right Front
TR_X =OriginX+Lenght;//X
TR_Y =OriginY; //Y
TR_Z =OriginZ+Lenght;//Z
//Left Back
BL_X =OriginX-Lenght;//X
BL_Y =OriginY; //Y
BL_Z =OriginZ-Lenght;//Z
//Right Back
BR_X =OriginX+Lenght;//X
BR_Y=OriginY; //Y
BR_Z=OriginZ-Lenght;//Z
};
void SquareD::RenderSquare()
{
glVertex3f(TL_X,TL_Y,TL_Z);
glVertex3f(TR_X,TR_Y,TR_Z);
glVertex3f(BL_X,BL_Y,BL_Z);
glVertex3f(BR_X,BR_Y,BR_Z);
};
エラーの原因とその理由は何ですか?