M
Michael Sgier
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
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