TexGen
Node.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
21#include "Node.h"
22using namespace TexGen;
23
24CNode::CNode(XYZ Position, XYZ Tangent, XYZ Up, double Angle)
25: m_Position(Position)
26, m_Tangent(Tangent)
27, m_Up(Up)
28, m_Angle(Angle)
29{
30 double dLength;
31 dLength = GetLength(m_Tangent);
32 if (dLength != 0)
33 m_Tangent /= dLength;
34 dLength = GetLength(m_Up);
35 if (dLength != 0)
36 m_Up /= dLength;
37}
38
40{
41}
42
43CNode::CNode(TiXmlElement &Element)
44{
45 m_Position = valueify<XYZ>(Element.Attribute("Position"));
46 m_Tangent = valueify<XYZ>(Element.Attribute("Tangent"));
47 m_Up = valueify<XYZ>(Element.Attribute("Up"));
48 m_Angle = valueify<double>(Element.Attribute("Angle"));
49}
50
51void CNode::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
52{
53 Element.SetAttribute("Position", stringify(GetPosition()));
54 Element.SetAttribute("Tangent", stringify(GetTangent()));
55 Element.SetAttribute("Up", stringify(GetUp()));
56 Element.SetAttribute("Angle", stringify(GetAngle()));
57}
58
59void CNode::Rotate(WXYZ Rotation, XYZ Origin)
60{
61 m_Position = Rotation * (m_Position-Origin) + Origin;
62 m_Tangent = Rotation * m_Tangent;
63 m_Up = Rotation * m_Up;
64}
65
67{
68 m_Position += Vector;
69}
70
72{
74 if (GetLength(m_Up) == 0)
75 {
76 TGERROR("Error projecting up vector to be orthogonal to the tangent vector");
77 assert(false);
78 }
79 else
81}
82
83
85{
87 if ( m_Angle == 0.0 )
88 return Side;
89 WXYZ Rot( m_Up, m_Angle );
90 XYZ RotatedSide = Rot*Side;
91 return RotatedSide;
92}
93
95{
96 if ( m_Angle == 0.0 )
97 return m_Tangent;
98 WXYZ Rot( m_Up, m_Angle );
99 return Rot*m_Tangent;
100}
101
102/*XYZ CNode::RotateSide( XYZ Side )
103{
104 WXYZ Rot( m_Up, PI/9.0 );
105 XYZ RotatedSide = Rot*Side;
106 return RotatedSide;
107}*/
108
109
110
111
112
113
114
115
116
117
118
119
120
#define TGERROR(MESSAGE)
Macros used to report the file name and line number to the TexGenError and TexGenLog functions.
Definition: Logger.h:29
XYZ m_Up
Unit vector which represents the up direction (must be perpendicular to m_Tangent)
Definition: Node.h:73
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Definition: Node.cpp:51
XYZ m_Tangent
Unit vector tangent to the yarn path at this node.
Definition: Node.h:71
virtual void Translate(XYZ Vector)
Translate the Node by given vector.
Definition: Node.cpp:66
double m_Angle
Definition: Node.h:74
virtual ~CNode(void)
Definition: Node.cpp:39
void ProjectUp()
Project the Up vector such that it is perpendicular to the tangent.
Definition: Node.cpp:71
XYZ GetUp() const
Definition: Node.h:59
XYZ GetPosition() const
Definition: Node.h:57
XYZ GetTangent() const
Definition: Node.h:58
CNode(XYZ Position=XYZ(), XYZ Tangent=XYZ(), XYZ Up=XYZ(0, 0, 1), double Angle=0.0)
Create a node.
Definition: Node.cpp:24
double GetAngle() const
Definition: Node.h:60
XYZ m_Position
Coordinates representing the position of the node.
Definition: Node.h:69
XYZ GetSide() const
Get the side vector.
Definition: Node.cpp:84
virtual void Rotate(WXYZ Rotation, XYZ Origin=XYZ(0, 0, 0))
Rotate the Node by given quaternion.
Definition: Node.cpp:59
XYZ GetNormal() const
Definition: Node.cpp:94
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
double GetLength(const XYZ &Point1, const XYZ &Point2)
Get the length between two points.
Definition: mymath.h:540
std::string stringify(const T &x, int iPrecision=12, bool bScientific=true)
Function to convert a value (e.g. int, double, etc...) to a string.
Definition: Misc.h:50
WXYZ & Normalise(WXYZ &Quaternion)
Normalise the quaternion and return it.
Definition: mymath.h:609
double DotProduct(const XYZ &left, const XYZ &right)
Get the dot product of two vectors.
Definition: mymath.h:512
XYZ CrossProduct(const XYZ &left, const XYZ &right)
Get the cross product of two vectors.
Definition: mymath.h:524
Struct for representing a quaternion.
Definition: mymath.h:38
Struct for representing points in 3D space.
Definition: mymath.h:56