【发布时间】:2019-04-19 21:03:01
【问题描述】:
在这里尝试创建一个基本类。
头文件
namespace Ogre
{
class Vector3;
class SceneManager;
class Entity;
class Quaternion;
}
class RayCasting
{
public:
bool RayCastFromPoint(
const Ogre::Vector3 &point,
const Ogre::Vector3 &normal,
Ogre::Vector3 &result,
Ogre::SceneManager& scnMgrRef);
private:
void GetMeshInformation(
Ogre::Entity* entity,
Ogre::Vector3* vertices,
size_t &indexCount,
unsigned long* indices,
const Ogre::Vector3& position,
const Ogre::Quaternion& orient,
const Ogre::Vector3& scale
);
};
源文件
#include "RayCasting.h"
#include <OGRE/OgreMath.h>
#include <OgreRay.h>
#include <OgreSceneManager.h>
#include <OgreEntity.h>
#include <OgreSceneNode.h>
#include <OgreNode.h>
#include <OgreMath.h>
#include <OgreSubMesh.h>
#include <OgreSubEntity.h>
#include <OgreMesh.h>
#include <OGRE/OgreVector3.h>
bool RayCasting::RayCastFromPoint(
const Ogre::Vector3 & point,
const Ogre::Vector3 & normal,
Ogre::Vector3 & result,
Ogre::SceneManager& scnMgrRef)
{
// get the entity to check
Ogre::Entity *collEntity = static_cast<Ogre::Entity*>(rayQueryResult[index].movable);
// mesh data to retrieve
size_t indexCount;
Ogre::Vector3* vertices = new Ogre::Vector3();
unsigned long* indices;
// get the mesh information
GetMeshInformation(collEntity, vertices, indexCount, indices,
collEntity->getParentNode()->_getDerivedPosition() // Returns a const Vector3
collEntity->getParentNode()->_getDerivedOrientation(), // Returns a const Vector3
collEntity->getParentNode()->_getDerivedScale()); // Returns a const Vector3
...
}
void RayCasting::GetMeshInformation(
Ogre::Entity * entity,
Ogre::Vector3* vertices,
size_t & indexCount,
unsigned long * indices,
const Ogre::Vector3 & position,
const Ogre::Quaternion & orient,
const Ogre::Vector3 & scale)
{
...
}
...表示不相关的实现细节。
问题 1 RayCasting 中定义的两种方法都会抛出 E0147 错误说明
declaration is incompatible with "bool RayCasting::RayCastFromPoint(const Ogre::Vector3 &point, const Ogre::Vector3 &normal, Ogre::Vector3 &result, Ogre::SceneManager &scnMgrRef)" (declared at line 20 of "E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.h") Ogre3DProjectTemplate E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.cpp 29
`
和
declaration is incompatible with "void RayCasting::GetMeshInformation(Ogre::Entity *entity, Ogre::Vector3 *vertices, size_t &indexCount, unsigned long *indices, const Ogre::Vector3 &position, const Ogre::Quaternion &orient, const Ogre::Vector3 &scale)" (declared at line 27 of "E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.h") Ogre3DProjectTemplate E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.cpp 140
问题 2 GetMeshInformation(... , vertices, ...) 抛出 E0167 错误,说明
cannot convert to incomplete class "const Ogre::Vector3" Ogre3DProjectTemplate E:\_PROGRAMMING\GEA-term2\Ogre_Projects\Tutorials2\Ogre3DProjectTemplate\RayCasting.cpp 91
问题 3 此外,GetMeshInformation(... , ...->_GetDerivedPosition(), ...) 行会生成 E0515 错误说明
*"cannot convert to incomplete class const Ogre::Vector3"*, despite the include being present in the Source file. The scale() method also throws this error.
我的问题简单来说是:
什么。在地狱。正在发生。
【问题讨论】:
-
1) 除了提供minimal reproducible example 之外,请复制粘贴邮件,而不是对其进行释义。 2) Header 包含声明
void GetMeshInformation(..., Ogre::Vector3* vertices, ...),而定义为void RayCasting::GetMeshInformation(..., Ogre::Vector3*& vertices, ...)(与indices类似的区别)。 -
@AlgirdasPreidžius 嘿,对不起。我已经粘贴了消息,这应该是最小和完整的,但如果没有 Ogre,可能无法验证。我已经在 2 中进行了更改,不敢相信它被我溜走了,但这个问题仍然存在
-
仍然不是minimal reproducible example(请阅读链接)。例如,一些错误提示您前向声明的类,而不是在使用时定义的类。因此,即使定义在
OGRE/OgreVector3.h中,也不清楚这些定义是否在Ogre命名空间中进行,它们是在其中前向声明的。