| 1 | // tPath.h  |
| 2 | //  |
| 3 | // This file implements scene splines and paths.  |
| 4 | //  |
| 5 | // Copyright (c) 2006, 2017 Tristan Grimmer.  |
| 6 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
| 7 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
| 8 | //  |
| 9 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
| 10 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
| 11 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
| 12 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
| 13 | // PERFORMANCE OF THIS SOFTWARE.  |
| 14 |   |
| 15 | #pragma once  |
| 16 | #include <Math/tSpline.h>  |
| 17 | #include "Scene/tObject.h"  |
| 18 | namespace tScene  |
| 19 | {  |
| 20 |   |
| 21 |   |
| 22 | class tPath : public tObject  |
| 23 | {  |
| 24 | public:  |
| 25 | tPath() { }  |
| 26 | tPath(const tChunk& chunk) { Load(chunk); }  |
| 27 | tPath(const tMath::tBezierPath&, const tString& name, uint32 id);  |
| 28 | virtual ~tPath() { Clear(); }  |
| 29 |   |
| 30 | enum class tType  |
| 31 | {  |
| 32 | Invalid = -1,  |
| 33 | PiecewiseLinear,  |
| 34 | CubicBezier,  |
| 35 | NonuniformNonrationalCubicBasis  |
| 36 | };  |
| 37 |   |
| 38 | bool IsValid() const { return Type != tType::Invalid; }  |
| 39 | void Scale(float scale) { for (int cv = 0; cv < NumControlVerts; cv++) ControlVerts[cv] *= scale; }  |
| 40 | void Clear() { tObject::Clear(); Type = tType::Invalid; IsClosed = false; NumControlVerts = 0; delete[] ControlVerts; ControlVerts = nullptr; }  |
| 41 |   |
| 42 | void Save(tChunkWriter&) const;  |
| 43 | void Load(const tChunk&);  |
| 44 |   |
| 45 | tType Type = tType::Invalid;  |
| 46 | bool IsClosed = false;  |
| 47 | int NumControlVerts = 0;  |
| 48 | tMath::tVector3* ControlVerts = nullptr;  |
| 49 | };  |
| 50 |   |
| 51 |   |
| 52 | }  |
| 53 | |