//---------------------------------------------------------------------------------------------------------------------- float vecAngle(const ngl::Vec3 &_vec1, const ngl::Vec3 &_vec2) { // calculate the angle between two vectors using the dot product float angle; angle=_vec1.dot(_vec2)/_vec1.length()*_vec2.length(); angle=ngl::degrees(acos(angle)); return angle; }
Ray::Ray(ngl::Vec3 _origin, ngl::Vec3 _direction) { m_origin = _origin; // check that it is unit length, if not, normalize if (_direction.length() > 1.1 || _direction.length() < 0.9) {_direction.normalize();} m_direction = _direction; }
//---------------------------------------------------------------------------------------------------------------------- ngl::Vec3 lenClamp(ngl::Vec3 io_inVec, const float &_maxLen) { // check if given vector is longer than the given maximum if(io_inVec.length()>_maxLen) { // normalize and multiply by the maximum length to clamp io_inVec.normalize(); io_inVec=io_inVec*_maxLen; return io_inVec; } return io_inVec; }
void Ray::setDirection(ngl::Vec3 _direction) { // check that it is unit length, if not, normalize if (_direction.length() > 1.1 || _direction.length() < 0.9) {_direction.normalize();} m_direction = _direction; }