问题描述
你好
如果有人可以向我解释下面的代码会很棒。
//两个向量之间的返回角度
const float inline Angle(const CVector& normal)const
{
返回acosf(* this%normal);
}
//用正常向量反射此向量表面
const CVector内联反射(const CVector& normal)const
{
const CVector vec(* this | 1); //规范化这个载体
return(vec - normal * 2.0 *(vec%normal))*!* this;
}
//围绕法线旋转角度
const CVector内联旋转(常量浮动角度,常量CVector&正常)const
{
const float cosine = cosf(angle);
const float sine = sinf(angle);
返回CVector(* this * cosine +((正常) * * this)*(1.0f - 余弦))*
正常+(*这^正常)*正弦);
}
这产生了以下错误:
vector.h:220:错误:声明没有声明任何内容
vector.h:220:错误:`inline'之前的语法错误'
vector.h:226:错误:ISO C ++禁止在返回类型中定义类型
vector.h:226:错误:语法`inline'之前的错误''
vector.h:233:错误:`inline'之前的语法错误''
vector.h:236:错误:`angle''是未在此范围内声明
vector.h:238:错误:返回'之前'语法错误
%和^产生什么?为什么在
函数定义的末尾还有一个const?
感谢和问候
Michael
Hello
If someone could explain the code below to me would be great.
// return angle between two vectors
const float inline Angle(const CVector& normal) const
{
return acosf(*this % normal);
}
// reflect this vector off surface with normal vector
const CVector inline Reflection(const CVector& normal) const
{
const CVector vec(*this | 1); // normalize this vector
return (vec - normal * 2.0 * (vec % normal)) * !*this;
}
// rotate angle degrees about a normal
const CVector inline Rotate(const float angle, const CVector& normal) const
{
const float cosine = cosf(angle);
const float sine = sinf(angle);
return CVector(*this * cosine + ((normal * *this) * (1.0f - cosine)) *
normal + (*this ^ normal) * sine);
}
This is producing the following errors:
vector.h:220: error: declaration does not declare anything
vector.h:220: error: syntax error before `inline''
vector.h:226: error: ISO C++ forbids defining types within return type
vector.h:226: error: syntax error before `inline''
vector.h:233: error: syntax error before `inline''
vector.h:236: error: `angle'' was not declared in this scope
vector.h:238: error: syntax error before `return''
What do % and ^ produce? Why is there a const also at the end of the
function definition?
THANKS and regards
Michael
推荐答案
问候Chris
Greetings Chris
这篇关于矢量函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!