OpenGL源码编译illegal use of this type as an expression错误


   
  void gltRotateFrameLocalX(GLTFrame *pFrame, GLfloat fAngle)
  
{
GLTMatrix mRotation;
GLTVector3 vCross;

gltVectorCrossProduct(vCross, pFrame->vUp, pFrame->vForward);
gltRotationMatrix(fAngle, vCross[0], vCross[1], vCross[2], mRotation);

GLTVector3 vNewVect;
// Inline 3x3 matrix multiply for rotation only
vNewVect[0] = mRotation[0] * pFrame->vForward[0] + mRotation[4] * pFrame->vForward[1] + mRotation[8] * pFrame->vForward[2];
vNewVect[1] = mRotation[1] * pFrame->vForward[0] + mRotation[5] * pFrame->vForward[1] + mRotation[9] * pFrame->vForward[2];
vNewVect[2] = mRotation[2] * pFrame->vForward[0] + mRotation[6] * pFrame->vForward[1] + mRotation[10] * pFrame->vForward[2];
memcpy(pFrame->vForward, vNewVect, sizeof(GLfloat)*3);

// Update pointing up vector
vNewVect[0] = mRotation[0] * pFrame->vUp[0] + mRotation[4] * pFrame->vUp[1] + mRotation[8] * pFrame->vUp[2];
vNewVect[1] = mRotation[1] * pFrame->vUp[0] + mRotation[5] * pFrame->vUp[1] + mRotation[9] *pFrame->vUp[2];
vNewVect[2] = mRotation[2] * pFrame->vUp[0] + mRotation[6] * pFrame->vUp[1] + mRotation[10] * pFrame->vUp[2];
memcpy(pFrame->vUp, vNewVect, sizeof(GLfloat) * 3);
}


以上代码是一个围绕X轴旋转的函数,其中GLTVector3是OpenGL中定义的类型,相当于C++中的float类型。GLTVector3定义的原型如下:

   
  typedef GLfloat GLTVector3[3]; // Three component floating point vector
 

位于(\Microsoft Visual Studio\VC98\Include\GL\GLTools.h)GLTools.h代码的51行。

编译错误如下:

   
  E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2275: 'GLTVector3' : illegal use of this type as an expression
  
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\gl\gltools.h(51) : see declaration of 'GLTVector3'
E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2146: syntax error : missing ';' before identifier 'vNewVect'
E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2065: 'vNewVect' : undeclared identifier
E:\OpenGL\Windows\Common\FrameMath.c(180) : error C2109: subscript requires array or pointer type
E:\OpenGL\Windows\Common\FrameMath.c(180) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
E:\OpenGL\Windows\Common\FrameMath.c(180) : error C2106: '=' : left operand must be l-value

其中错误

   
  1:E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2275: 'GLTVector3' : illegal use of this type as an expression
 

非法使用该类型作为一个表达式。
请问怎么解决该问题

opengl C++

推倒天江衣 12 years, 10 months ago

将GLTVector3 vNewVect;改为全局数组就好了,但是我不知道为什么。。。。。

这里没有秋刀鱼 answered 12 years, 10 months ago

Your Answer