| 1 |
#include "stdafx.h" |
| 2 |
#include "RailMap.h" |
| 3 |
#include "CCamera.h" |
| 4 |
#include "CRailPlanCurve.h" |
| 5 |
#include "CRailConnector.h" |
| 6 |
#include "CRailWay.h" |
| 7 |
#include "CStringTexture.h" |
| 8 |
#include "CRailPlugin.h" |
| 9 |
|
| 10 |
// static メンバ |
| 11 |
float CRailPlanCurve::ms_RadiusDrawPos; |
| 12 |
|
| 13 |
/* |
| 14 |
* 曲線処理 |
| 15 |
*/ |
| 16 |
void CRailPlanCurve::Curve( |
| 17 |
VEC3 &pos1, VEC3 &dir1, // 始点 |
| 18 |
VEC3 &pos2, VEC3 &dir2, // 終点 |
| 19 |
bool comp2, // 補完制御点フラグ |
| 20 |
bool top // 再帰トップ |
| 21 |
){ |
| 22 |
if(CalcSplit(pos1, dir1, pos2, dir2)){ |
| 23 |
m_Dump->Add(pos1, 0xc0ff00ff, pos2, 0xc0ff00ff); |
| 24 |
RailMapLine(pos1, 0xc0ff00ff, pos2, 0xc0ff00ff, false); |
| 25 |
return; |
| 26 |
} |
| 27 |
if(top && 0.0f<=m_Radius && m_Radius<10000.0f){ |
| 28 |
float fscale = 0.003f*CCamera::GetCurrentCamera()->GetDist(); |
| 29 |
VEC3 tup(m_SplitDir.x, 0.0f, m_SplitDir.z); |
| 30 |
V3Norm(&tup, &tup); |
| 31 |
VEC3 tdir(tup.z, 0.0f, -tup.x); |
| 32 |
void (CStringTexture::*func1)( |
| 33 |
VEC3, VEC3, VEC3, D3DCOLOR, D3DCOLOR, const char *, float); |
| 34 |
void (CStringTexture::*func2)( |
| 35 |
VEC3, VEC3, VEC3, D3DCOLOR, D3DCOLOR, const char *, float); |
| 36 |
VEC3 cdir = GetVDir(); |
| 37 |
if(V3Dot(&GetVDir(), &tup)<0.0f){ |
| 38 |
tdir = -tdir; |
| 39 |
tup = -tup; |
| 40 |
func1 = &CStringTexture::RenderRight3D; |
| 41 |
func2 = &CStringTexture::RenderLeft3D; |
| 42 |
}else{ |
| 43 |
func1 = &CStringTexture::RenderRight3D; |
| 44 |
func2 = &CStringTexture::RenderLeft3D; |
| 45 |
} |
| 46 |
if(cdir.y>0.0f) tup = -tup; |
| 47 |
if(V3Dot(&tdir, &dir2)<0.0f) g_StrTex->RenderRight3D( |
| 48 |
0.5f*(pos1+pos2)+FONT_HEIGHT*fscale*ms_RadiusDrawPos*tup, |
| 49 |
tdir, tup, 0xffffffff, 0xff000000, FlashIn("R = %.1f", m_Radius), fscale); |
| 50 |
else g_StrTex->RenderLeft3D( |
| 51 |
0.5f*(pos1+pos2)+FONT_HEIGHT*fscale*ms_RadiusDrawPos*tup, |
| 52 |
tdir, tup, 0xffffffff, 0xff000000, FlashIn("R = %.1f", m_Radius), fscale); |
| 53 |
m_Dump->Add(pos1, 0xc0008000, pos2, 0xc0008000); |
| 54 |
//RailMapLine(pos1, 0xc0008000, pos2, 0xc0008000, false); |
| 55 |
} |
| 56 |
VEC3 right; |
| 57 |
if(m_CompSplit){ |
| 58 |
V3Norm(&right, V3Cross(&right, &V3UP, &m_SplitDir)); |
| 59 |
VEC3 pp1 = m_SplitPos-2.0f*right, pp2 = m_SplitPos+2.0f*right; |
| 60 |
m_Dump->Add(pp1, 0xc00000ff, pp2, 0xc00000ff); |
| 61 |
RailMapLine(pp1, 0xc00000ff, pp2, 0xc00000ff, false); |
| 62 |
} |
| 63 |
if(comp2){ |
| 64 |
V3Norm(&right, V3Cross(&right, &V3UP, &dir2)); |
| 65 |
VEC3 pp1 = pos2-2.0f*right, pp2 = pos2+2.0f*right; |
| 66 |
m_Dump->Add(pp1, 0xc00000ff, pp2, 0xc00000ff); |
| 67 |
RailMapLine(pp1, 0xc00000ff, pp2, 0xc00000ff, false); |
| 68 |
} |
| 69 |
CRailPlanCurve curve(m_Dump); |
| 70 |
curve.Curve(pos1, dir1, m_SplitPos, m_SplitDir, false, m_CompSplit); |
| 71 |
curve.Curve(m_SplitPos, m_SplitDir, pos2, dir2, false, m_CompSplit); |
| 72 |
} |
| 73 |
|
| 74 |
//////////////////////////////////////////////////////////////////////////////// |
| 75 |
//////////////////////////////////////////////////////////////////////////////// |
| 76 |
|
| 77 |
/* |
| 78 |
* コンストラクタ |
| 79 |
*/ |
| 80 |
CRailBuildCurve::CRailBuildCurve( |
| 81 |
CRailConnectorLink &begin, // 開始リンク |
| 82 |
CRailConnectorLink &end, // 終了リンク |
| 83 |
CRailPlugin *rpi, // レールプラグイン |
| 84 |
CTiePlugin *tpi, // 枕木プラグイン |
| 85 |
CGirderPlugin *gpi // 橋桁プラグイン |
| 86 |
){ |
| 87 |
m_BeginLink = begin; |
| 88 |
m_EndLink = end; |
| 89 |
m_RailPlugin = rpi; |
| 90 |
m_TiePlugin = tpi; |
| 91 |
m_GirderPlugin = gpi; |
| 92 |
} |
| 93 |
|
| 94 |
/* |
| 95 |
* 曲線処理 |
| 96 |
*/ |
| 97 |
void CRailBuildCurve::Curve( |
| 98 |
VEC3 &pos1, VEC3 &dir1, // 始点 |
| 99 |
VEC3 &pos2, VEC3 &dir2, // 終点 |
| 100 |
bool comp2, // 補完制御点フラグ |
| 101 |
bool top // 再帰トップ |
| 102 |
){ |
| 103 |
CalcSplit(pos1, dir1, pos2, dir2); |
| 104 |
if(!m_BeginLink.m_Link){ |
| 105 |
CRailConnector *con1 = new CRailConnector(pos1, dir1); |
| 106 |
m_BeginLink = con1->CreateLink(1, 0); |
| 107 |
} |
| 108 |
float cant = 0.0f; |
| 109 |
if(m_Radius>=0.0f){ |
| 110 |
cant = m_RailPlugin ? m_RailPlugin->CantFunc(m_Radius) : 0.0f; |
| 111 |
VEC3 right, up = V3UP; |
| 112 |
V3NormAxis(&right, &up, &dir1); |
| 113 |
if(V3Dot(&right, &m_SplitDir)<0.0f) cant = -cant; |
| 114 |
} |
| 115 |
m_BeginLink.m_Cant = cant; |
| 116 |
if(m_CompSplit){ |
| 117 |
CRailBuildCurve curve1(m_BeginLink, R2L(CRailConnectorLink()), |
| 118 |
m_RailPlugin, m_TiePlugin, m_GirderPlugin); |
| 119 |
curve1.Curve(pos1, dir1, m_SplitPos, m_SplitDir, false, true); |
| 120 |
CRailBuildCurve curve2(curve1.m_BeginLink, m_EndLink, |
| 121 |
m_RailPlugin, m_TiePlugin, m_GirderPlugin); |
| 122 |
curve2.Curve(m_SplitPos, m_SplitDir, pos2, dir2, false, true); |
| 123 |
m_BeginLink = curve2.m_BeginLink; |
| 124 |
return; |
| 125 |
} |
| 126 |
if(m_EndLink.m_Link){ |
| 127 |
m_EndLink.m_Cant = cant; |
| 128 |
CRailWay *way = new CRailWay(m_BeginLink, m_EndLink, |
| 129 |
m_RailPlugin, m_TiePlugin, m_GirderPlugin); |
| 130 |
g_SingleTrackSegment->push_back(way); |
| 131 |
m_BeginLink.Connect(R2L(way->CreateLink(0))); |
| 132 |
m_EndLink.Connect(R2L(way->CreateLink(1))); |
| 133 |
}else{ |
| 134 |
CRailConnector *con2 = new CRailConnector(pos2, dir2); |
| 135 |
CRailConnectorLink nextlink = con2->CreateLink(0, 0); |
| 136 |
nextlink.m_Cant = cant; |
| 137 |
CRailWay *way = new CRailWay(m_BeginLink, nextlink, |
| 138 |
m_RailPlugin, m_TiePlugin, m_GirderPlugin); |
| 139 |
g_SingleTrackSegment->push_back(way); |
| 140 |
m_BeginLink.Connect(R2L(way->CreateLink(0))); |
| 141 |
nextlink.Connect(R2L(way->CreateLink(1))); |
| 142 |
m_BeginLink = con2->CreateLink(1, 0); |
| 143 |
} |
| 144 |
} |