#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GEOMETRY_LINES_CURVE3_H #define NUCLEX_GEOMETRY_LINES_CURVE3_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Point3.h" namespace Nuclex { namespace Geometry { namespace Lines { // ------------------------------------------------------------------------------------------- // /// Three-dimensional curved line template struct Curve3 { /// Initializes the cubic bezier curve using the specified coordinates /// Point at which the cubic bezier curve begins /// Point giving direction and magnitude at the curve start /// Point giving direction and magnitude at the curve end /// Point at which the cubic bezier curve ends public: Curve3( const Point3 &p0, const Point3 &p1, const Point3 &p2, const Point3 &p3 ) : P0(p0), P1(p1), P2(p2), P3(p3) {} /// Offsets the entire curve by the specified amount /// Amount the curve will be offset public: void ShiftBy(const Vector3 &offset) { this.P0 += offset; this.P1 += offset; this.P2 += offset; this.P3 += offset; } /// Offsets the entire curve by the specified amount /// Amount the curve will be offset on the X axis /// Amount the curve will be offset on the Y axis /// Amount the curve will be offset on the Z axis public: void ShiftBy(TScalar x, TScalar y, TScalar z) { this.P0.X += x; this.P0.Y += y; this.P0.Z += z; this.P1.X += x; this.P1.Y += y; this.P1.Z += z; this.P2.X += x; this.P2.Y += y; this.P2.Z += z; this.P3.X += x; this.P3.Y += y; this.P3.Z += z; } /// Interpolates a point along the curve /// Time (0.0 .. 1.0) at which the point will be interpolated /// The point at the specified time public: TScalar Interpolate(TScalar t) const { return ( Math::Power(1 - t, 3) * this->P0 + 3 * Math::Power(1 - t, 2) * t * this->P1 + 3 * (1 - t) * Math::Power(t, 2) * this->P2 + Math::Power(t, 3) * this->P3 ); } /// Position of the curve's starting point public: Point3 P0; /// Position towards which the curve's starting point extends public: Point3 P1; /// Position from which the curve enters its ending point public: Point3 P2; /// Position at which the curve ends public: Point3 P3; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Lines #endif // NUCLEX_GEOMETRY_LINES_CURVE3_H