From 1d31a5b26294d8ca12b919ea0eb30205dc203fb9 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 4 Mar 2016 23:53:08 +0000 Subject: [PATCH] Improved mesh generation for flexible axles. --- common/lc_math.h | 20 +++++++++++++ common/lc_synth.cpp | 69 ++++++++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/common/lc_math.h b/common/lc_math.h index 604c1364..85b520b3 100644 --- a/common/lc_math.h +++ b/common/lc_math.h @@ -365,6 +365,15 @@ inline bool operator!=(const lcVector3& a, const lcVector3& b) return a.x != b.x || a.y != b.y || a.z != b.z; } +#ifndef QT_NO_DEBUG + +inline QDebug operator<<(QDebug d, const lcVector3& v) +{ + return d << v.x << v.y << v.z; +} + +#endif + inline void lcVector3::Normalize() { float InvLength = 1.0f / Length(); @@ -635,6 +644,17 @@ inline lcMatrix33 lcMatrix33Identity() return m; } +inline lcMatrix33 lcMatrix33Scale(const lcVector3& Scale) +{ + lcMatrix33 m; + + m.r[0] = lcVector3(Scale.x, 0.0f, 0.0f); + m.r[1] = lcVector3(0.0f, Scale.y, 0.0f); + m.r[2] = lcVector3(0.0f, 0.0f, Scale.z); + + return m; +} + inline lcMatrix33 lcMatrix33RotationX(const float Radians) { float s, c; diff --git a/common/lc_synth.cpp b/common/lc_synth.cpp index d4f79238..f195707c 100644 --- a/common/lc_synth.cpp +++ b/common/lc_synth.cpp @@ -163,7 +163,7 @@ void lcSynthInfo::CalculateSections(const lcArray& ControlP float TotalSegmentLength = 0.0f; for (int PointIdx = 0; PointIdx < CurvePoints.GetSize() - 1; PointIdx++) - TotalSegmentLength += lcLength(CurvePoints[CurrentPointIndex] - CurvePoints[CurrentPointIndex + 1]); + TotalSegmentLength += lcLength(CurvePoints[PointIdx] - CurvePoints[PointIdx + 1]); while (CurrentPointIndex < CurvePoints.GetSize() - 1) { @@ -220,7 +220,7 @@ void lcSynthInfo::AddRibbedHoseParts(lcMemFile& File, const lcArray& { const int SectionIdx = 0; - lcMatrix33 Transform(lcMul(lcMatrix33(lcVector3(1, 0, 0), lcVector3(0, -1, 0), lcVector3(0, 0, 1)), lcMatrix33(Sections[SectionIdx]))); + lcMatrix33 Transform(lcMul(lcMatrix33Scale(lcVector3(1.0f, -1.0f, 1.0f)), lcMatrix33(Sections[SectionIdx]))); lcVector3 Offset = Sections[SectionIdx].GetTranslation(); sprintf(Line, "1 16 %f %f %f %f %f %f %f %f %f %f %f %f 79.DAT\n", Offset[0], Offset[1], Offset[2], Transform[0][0], Transform[1][0], Transform[2][0], @@ -232,10 +232,9 @@ void lcSynthInfo::AddRibbedHoseParts(lcMemFile& File, const lcArray& for (int SectionIdx = 1; SectionIdx < Sections.GetSize() - 1; SectionIdx++) { const lcMatrix44& Transform = Sections[SectionIdx]; - const char* PartID = (SectionIdx > 0 && SectionIdx < Sections.GetSize() - 1) ? "80.DAT" : "79.DAT"; - sprintf(Line, "1 16 %f %f %f %f %f %f %f %f %f %f %f %f %s\n", Transform[3][0], Transform[3][1], Transform[3][2], Transform[0][0], Transform[1][0], Transform[2][0], - Transform[0][1], Transform[1][1], Transform[2][1], Transform[0][2], Transform[1][2], Transform[2][2], PartID); + sprintf(Line, "1 16 %f %f %f %f %f %f %f %f %f %f %f %f 80.DAT\n", Transform[3][0], Transform[3][1], Transform[3][2], Transform[0][0], Transform[1][0], Transform[2][0], + Transform[0][1], Transform[1][1], Transform[2][1], Transform[0][2], Transform[1][2], Transform[2][2]); File.WriteBuffer(Line, strlen(Line)); } @@ -267,16 +266,6 @@ void lcSynthInfo::AddFlexibleAxleParts(lcMemFile& File, const lcArray