【发布时间】:2015-05-18 18:25:30
【问题描述】:
我正在使用 OpenGL,我构建并编辑了一个 Vector3 标头,该标头可以完美地与 struct Vector3 一起使用,但是当我尝试创建 Vector3 zero = Vector3(0,0,0) 变量时问题就开始了,编译器不允许我构建到编译顺序,所以我从 Internet 复制了一个新的 Vector3 库,我收到了这个错误:"Vector3 does not name a type"。我想是导致编译顺序的原因,我将分享我得到错误的地方和库。首先这是我正在使用的两个文件http://leetnightshade.com/c-vector3-class 我只使用 Vector3.cpp 和 Vector3.h,这段代码是我制作的,是我得到错误的地方(这是一个由 main 调用的头文件.cpp 文件名为 GameObject.h):
#include "Vector3.h"
GLfloat cube[] =
{
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
GLfloat Space3D_X[] =
{
0.0f, 0.0f, -100,
0.0f, 0.0f, 100
};
GLfloat Space3D_Y[] =
{
-100.0f, 0.0f, 0.0f,
100.0f, 0.0f, 0.0f
};
typedef struct GameObject
{
int ID, parent;
Vector3 position; ///<<<--------------------------HERE I GET THE ERROR VECTOR3 DOES NOT NAME A TYPE
Quaternion rotation;
};
struct GameObject GameObjects[65536];
class Natives
{
public:
int GameObjectsCount = 0;
inline int CreateCube (Vector3 _position, Quaternion _rotation, int _parent)
{
GameObjects[GameObjectsCount].ID = GameObjectsCount;
GameObjects[GameObjectsCount].parent = _parent;
GameObjects[GameObjectsCount].position = _position;
GameObjects[GameObjectsCount].rotation = _rotation;
GameObjectsCount ++;
return GameObjectsCount-1;
}
inline void SetGameObjectParent (int _gameObject, int _parent)
{
Vector3 _tempPos = GameObjects[_gameObject].position;
Quaternion _tempRot = GameObjects[_gameObject].rotation;
GameObjects[_gameObject].parent = _parent; /*** ATTACH GM TO OTHER GM WITHOUT CHANGE POSITION ***/
GameObjects[_gameObject].position.x = -(GameObjects[_parent].position.x - _tempPos.x); /*** IF YOU WANT TO ATTACH IT CHAING POSITION JUST ***/
GameObjects[_gameObject].position.z = -(GameObjects[_parent].position.z - _tempPos.z); /*** OVERWRITE THE PARENT WITH OOP SYNTAX ***/
GameObjects[_gameObject].rotation.rx = _tempRot.rx;
GameObjects[_gameObject].rotation.ry = _tempRot.ry;
GameObjects[_gameObject].rotation.rz = _tempRot.rz;
}
};
Natives native;
关注 struct GameObject 的 4 行,这是我在 Vector3 位置得到错误的地方;线。我想我正确地解释了自己。如果您不太了解http://gyazo.com/77189bef5576b047de5271f1b7d2d881,我制定了一个方案。感谢阅读。
【问题讨论】:
标签: c++ class header namespaces