void Bezier::setFromCorners(const MathVector<float, 3>& fl, const MathVector<float, 3>& fr, const MathVector<float, 3>& bl, const MathVector<float, 3>& br) { MathVector<float, 3> temp; center = fl + fr + bl + br; center = center * 0.25; radius = 0; if ((fl - center).magnitude() > radius) radius = (fl - center).magnitude(); if ((fr - center).magnitude() > radius) radius = (fr - center).magnitude(); if ((bl - center).magnitude() > radius) radius = (bl - center).magnitude(); if ((br - center).magnitude() > radius) radius = (br - center).magnitude(); // Assign corners points[0][0] = fl; points[0][3] = fr; points[3][3] = br; points[3][0] = bl; // Calculate intermediate front and back points temp = fr - fl; if (temp.magnitude() < 0.0001) { points[0][1] = fl; points[0][2] = fl; } else { points[0][1] = fl + temp.normalized() * (temp.magnitude() / 3.0); points[0][2] = fl + temp.normalized() * (2.0 * temp.magnitude() / 3.0); } temp = br - bl; if (temp.magnitude() < 0.0001) { points[3][1] = bl; points[3][2] = bl; } else { points[3][1] = bl + temp.normalized() * (temp.magnitude() / 3.0); points[3][2] = bl + temp.normalized() * (2.0 * temp.magnitude() / 3.0); } // Calculate intermediate left and right points int i; for (i = 0; i < 4; ++i) { temp = points[3][i] - points[0][i]; if (temp.magnitude() > 0.0001) { points[1][i] = points[0][i] + temp.normalized() * (temp.magnitude() / 3.0); points[2][i] = points[0][i] + temp.normalized() * (2.0 * temp.magnitude() / 3.0); } else { points[1][i] = points[0][i]; points[2][i] = points[0][i]; } } }
// Project this vector onto the vector 'vec' MathVector<T,3> project(const MathVector<T,3>& vec) const { T scalarProj = dot(vec.normalized()); return vec.normalized() * scalarProj; }