| 1 |
#include "stdafx.h" |
| 2 |
#include "CLineBuildCurve.h" |
| 3 |
#include "CRailBuilder.h" |
| 4 |
#include "CRailWay.h" |
| 5 |
#include "CPier.h" |
| 6 |
#include "CLine.h" |
| 7 |
#include "CRailPlugin.h" |
| 8 |
#include "CTiePlugin.h" |
| 9 |
#include "CGirderPlugin.h" |
| 10 |
#include "CPierPlugin.h" |
| 11 |
#include "CLinePlugin.h" |
| 12 |
#include "CPolePlugin.h" |
| 13 |
|
| 14 |
// 内部グローバル |
| 15 |
vector<CPoleLink> g_LastPole; // 最終架線柱 |
| 16 |
vector<CPoleLink> g_FinishPole; // 最終架線柱 |
| 17 |
|
| 18 |
/* |
| 19 |
* コンストラクタ |
| 20 |
*/ |
| 21 |
CLineBuildCurve::CLineBuildCurve( |
| 22 |
CRailWay *way, // 作業レール |
| 23 |
CRailPlugin *rpi, // レールプラグイン |
| 24 |
CTiePlugin *tpi, // 枕木プラグイン |
| 25 |
CGirderPlugin *gpi, // 橋桁プラグイン |
| 26 |
CPierPlugin *ipi, // 橋脚プラグイン |
| 27 |
CLinePlugin *lpi, // 架線プラグイン |
| 28 |
CPolePlugin *ppi // 架線柱プラグイン |
| 29 |
): |
| 30 |
CRailTraceCurve(rpi, tpi, gpi, way) // 基本クラス |
| 31 |
{ |
| 32 |
m_PierPlugin = ipi; |
| 33 |
m_LinePlugin = lpi; |
| 34 |
m_PolePlugin = ppi; |
| 35 |
} |
| 36 |
|
| 37 |
/* |
| 38 |
* トレース完了 |
| 39 |
*/ |
| 40 |
void CLineBuildCurve::FinishTrace( |
| 41 |
VEC3 &pos1, VEC3 &right1, VEC3 &up1, VEC3 &dir1, // 始点 |
| 42 |
VEC3 &pos2, VEC3 &right2, VEC3 &up2, VEC3 &dir2, // 終点 |
| 43 |
float sumlen, float seglen, // 積算距離・セグメント距離 |
| 44 |
CRailSplitter &splitter // 分割子 |
| 45 |
){ |
| 46 |
VEC3 cpos1 = pos1, cpos2 = pos2; |
| 47 |
if(m_RailPlugin) m_RailPlugin->BeforeDump(cpos1, right1, up1, cpos2, right2, up2); |
| 48 |
if(m_PierPlugin && g_MultiTrackDummy==m_PierPlugin->IsMultiTrack()){ |
| 49 |
float tmp = m_PierPlugin->GetPierPos(); |
| 50 |
while(tmp<=seglen){ |
| 51 |
float q2 = tmp/seglen, q1 = 1.0f-q2; |
| 52 |
VEC3 tpos = q1*cpos1+q2*cpos2, tright; |
| 53 |
VEC3 tup = q1*up1+q2*up2, tdir = q1*dir1+q2*dir2; |
| 54 |
float pickalt = tpos.y; |
| 55 |
V3NormAxis(&tright, &tup, &tdir); |
| 56 |
if(m_RailPlugin) m_RailPlugin->CalcPierPos(&tpos, &tright, &tup, &tdir); |
| 57 |
if(m_TiePlugin) m_TiePlugin->CalcPierPos(&tpos, &tright, &tup, &tdir); |
| 58 |
if(m_GirderPlugin) m_GirderPlugin->CalcPierPos(&tpos, &tright, &tup, &tdir); |
| 59 |
CPier *pier = new CPier(tpos, tdir, tup, pickalt, m_PierPlugin); |
| 60 |
if(pier->Confirm()) m_RailWay->AddPier(tmp, pier); |
| 61 |
tmp += m_PierPlugin->m_Interval; |
| 62 |
} |
| 63 |
m_PierPlugin->AddPierPos(seglen); |
| 64 |
m_RailWay->AddPierPos(seglen); |
| 65 |
} |
| 66 |
if(m_LinePlugin && g_MultiTrackDummy== |
| 67 |
(m_PolePlugin ? m_PolePlugin->IsMultiTrack() : false)){ |
| 68 |
float tmp = m_LinePlugin->GetPolePos(); |
| 69 |
int i, n, pts = m_PolePlugin ? m_PolePlugin->GetTrackNum() : 1; |
| 70 |
if(pts>g_LastPole.size()) pts = g_LastPole.size(); |
| 71 |
int ct = g_MultiTrackDummy ? 0 : CRailBuilder::GetCurrentTrack(); |
| 72 |
if(g_LastPole[ct].IsValid()){ |
| 73 |
VEC3 lp1 = cpos1+m_LinePlugin->m_TrolleyAlt*up1+m_LinePlugin->m_Height*V3UP; |
| 74 |
VEC3 lp2 = cpos2+m_LinePlugin->m_TrolleyAlt*up2+m_LinePlugin->m_Height*V3UP; |
| 75 |
VEC3 lpos, ldir; |
| 76 |
if(g_MultiTrackDummy){ |
| 77 |
if(m_PolePlugin){ |
| 78 |
int tnum = m_PolePlugin->GetTrackNum(); |
| 79 |
if(tnum>g_DummyTrackNum){ |
| 80 |
float tint = m_PolePlugin->GetTrackInterval(); |
| 81 |
float center = tint*(g_DummyTrackNum-tnum)*0.5f; |
| 82 |
lp1 += right1*center; |
| 83 |
lp2 += right2*center; |
| 84 |
} |
| 85 |
} |
| 86 |
lpos = ldir = V3ZERO; |
| 87 |
for(i = n = 0; i<pts; i++){ |
| 88 |
if(g_LastPole[i].IsValid()){ |
| 89 |
n++; |
| 90 |
lpos += g_LastPole[i].GetPos(); |
| 91 |
ldir -= g_LastPole[i].GetOrigDir(); |
| 92 |
} |
| 93 |
} |
| 94 |
lpos *= 1.0f/n; |
| 95 |
V3Norm(&ldir, &ldir); |
| 96 |
}else{ |
| 97 |
lpos = g_LastPole[ct].GetPos(); |
| 98 |
ldir = -g_LastPole[ct].GetOrigDir(); |
| 99 |
} |
| 100 |
const float yev = 3.0; // Y axis evaluation weight |
| 101 |
lpos.y *= yev; ldir.y *= yev; lp1.y *= yev; lp2.y *= yev; |
| 102 |
V3Norm(&ldir ,&ldir); |
| 103 |
float dist1 = V3Len(&(lp1-lpos)); |
| 104 |
float dist2 = V3Len(&(lp2-lpos)); |
| 105 |
float def1 = V3Dot(&ldir, &(lp1-lpos)); |
| 106 |
float def2 = V3Dot(&ldir, &(lp2-lpos)); |
| 107 |
def1 = 0.3f*sqrtf(dist1*dist1-def1*def1); |
| 108 |
def2 = 0.3f*sqrtf(dist2*dist2-def2*def2); |
| 109 |
if(def2>m_LinePlugin->m_MaxDeflection){ |
| 110 |
if(def1>m_LinePlugin->m_MaxDeflection){ |
| 111 |
m_LinePlugin->SetPolePos(tmp = 0.0f); |
| 112 |
}else{ |
| 113 |
float dlim = seglen*(m_LinePlugin->m_MaxDeflection-def1)/(def2-def1); |
| 114 |
if(dlim<tmp) m_LinePlugin->SetPolePos(tmp = dlim); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
float mastersegsum = 0.0f, mastersegofs = 0.0f; |
| 119 |
if(g_MultiTrackDummy){ |
| 120 |
bool before = true; |
| 121 |
ILPRailWay ilpr = --g_MultiTrackSegment->end(); |
| 122 |
IPRailWay ipr = ilpr->begin(); |
| 123 |
float deadsum = 0.0f; |
| 124 |
for(; ipr!=ilpr->end(); ipr++){ |
| 125 |
mastersegsum += (*ipr)->GetSegLen(); |
| 126 |
if(before){ |
| 127 |
if(*ipr==m_RailWay) before = false; |
| 128 |
else mastersegofs += (*ipr)->GetSegLen(); |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
while(tmp<=seglen){ |
| 133 |
float q2 = tmp/seglen, q1 = 1.0f-q2; |
| 134 |
VEC3 tpos = q1*cpos1+q2*cpos2, tup = q1*up1+q2*up2, tdir = q1*dir1+q2*dir2; |
| 135 |
CPole *pole = new CPole(tpos+m_LinePlugin->m_TrolleyAlt*tup |
| 136 |
+m_LinePlugin->m_Height*V3UP, tdir, m_PolePlugin); |
| 137 |
if(g_MultiTrackDummy){ |
| 138 |
for(i = 0; i<pts; i++){ |
| 139 |
if(g_LastPole[i].IsValid()) |
| 140 |
new CLine(g_LastPole[i], pole->CreateLink(0, i), m_LinePlugin); |
| 141 |
g_LastPole[i] = pole->CreateLink(1, i); |
| 142 |
} |
| 143 |
float masterposnorm = (mastersegofs+sumlen+tmp)/mastersegsum; |
| 144 |
// if(masterposnorm>1.0f) |
| 145 |
// Dialog("masterposnorm err\nmastersegofs %f\nmastersegsum %f\nsumlen %f\ntmp %f\nmasterposnorm %f", |
| 146 |
// mastersegofs, mastersegsum, sumlen, tmp, masterposnorm); |
| 147 |
ILPRailWay ilpr = g_MultiTrackSegment->begin(); |
| 148 |
int track = 0; |
| 149 |
for(; ilpr!=--g_MultiTrackSegment->end(); ilpr++, track++){ |
| 150 |
float slavesegsum = 0.0f, slavesegofs = 0.0f; |
| 151 |
IPRailWay ipr = ilpr->begin(); |
| 152 |
for(; ipr!=ilpr->end(); ipr++) slavesegsum += (*ipr)->GetSegLen(); |
| 153 |
for(ipr = ilpr->begin(); ipr!=ilpr->end(); ipr++){ |
| 154 |
float slaveposnorm1 = slavesegofs/slavesegsum; |
| 155 |
slavesegofs += (*ipr)->GetSegLen(); |
| 156 |
float slaveposnorm2 = slavesegofs/slavesegsum; |
| 157 |
if(slaveposnorm1<=masterposnorm && masterposnorm<slaveposnorm2) |
| 158 |
(*ipr)->AddPole((*ipr)->GetSegLen() |
| 159 |
*(masterposnorm-slaveposnorm1)/(slaveposnorm2-slaveposnorm1), |
| 160 |
pole, track, true); |
| 161 |
} |
| 162 |
} |
| 163 |
}else{ |
| 164 |
if(g_LastPole[ct].IsValid()) |
| 165 |
new CLine(g_LastPole[ct], pole->CreateLink(0, 0), m_LinePlugin); |
| 166 |
g_LastPole[ct] = pole->CreateLink(1, 0); |
| 167 |
} |
| 168 |
m_RailWay->AddPole(tmp, pole, 0, false); |
| 169 |
tmp += m_LinePlugin->m_MaxInterval; |
| 170 |
} |
| 171 |
m_LinePlugin->AddPolePos(seglen); |
| 172 |
m_RailWay->AddPolePos(seglen); |
| 173 |
} |
| 174 |
} |