Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CSurfacePlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations) (download) (as text)
Sat Oct 26 14:53:53 2013 UTC (10 years, 6 months ago) by okadu
File MIME type: text/x-c++src
File size: 3327 byte(s)
[okadu] Version 2.15
橋脚・架線柱手動設置機能
車輌プラグイン以外でクランク等使用可能に
エンジン模型プラグイン追加

1 #include "stdafx.h"
2 #include "CCamera.h"
3 #include "CSurfacePlugin.h"
4 #include "CConfigMode.h"
5 #include "CSceneEditMode.h"
6 #include "CSaveFile.h"
7
8 // static メンバ
9 CObject CSurfacePlugin::ms_PreviewObject;
10
11 /*
12 * [static]
13 * プレビュー
14 */
15 void CSurfacePlugin::RenderPreview(){
16 CNamedObjectAfterRenderer::SetCurrentInst(NULL);
17 g_SaveFile->ResetSwitch();
18 if(ms_PreviewState && g_Surface){
19 g_SystemObject[SYS_OBJ_LOCAL].SetPreviewPosture(V3ZERO, V3DIR, V3UP);
20 SetCamDistSwitch(V3ZERO);
21 g_Surface->Preview();
22 }
23 }
24
25 /*
26 * デストラクタ
27 */
28 CSurfacePlugin::~CSurfacePlugin(){
29 }
30
31 /*
32 * ロード
33 */
34 char *CSurfacePlugin::LoadStructBefore(
35 char *str // 対象文字列
36 ){
37 g_NamedObjectMipMap = g_SurfaceMipMap;
38 CNamedObject::SetCastShadowDefault(false);
39 char *eee;
40 if(!(str = BeginBlock(eee = str, "SurfaceInfo"))) throw CSynErr(eee);
41 if(!(str = AsgnFloat(eee = str, "SizeX", &m_SizeX))) throw CSynErr(eee);
42 if(!(str = AsgnFloat(eee = str, "SizeZ", &m_SizeZ))) throw CSynErr(eee);
43 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
44 return str;
45 }
46
47 /*
48 * ロード
49 */
50 bool CSurfacePlugin::LoadOldForm(){
51 if(!ChDir()) return false;
52 g_NamedObjectMipMap = g_SurfaceMipMap;
53 CNamedObject::SetCastShadowDefault(false);
54 FILE *file = fopen(TextName(), "rt");
55 char *dummy = FlashOut();
56 float sc, sizex, sizez;
57 fscanf(file, "%s %s %f %f %f %f", dummy, dummy, &sc, &sizex, &sizez);
58 fclose(file);
59 float oldscale = 2.0f/sc;
60 m_SizeX = sizex*oldscale;
61 m_SizeZ = sizez*oldscale;
62 m_FreeObject.push_back(CFreeObjectContainer(new CFreeObject3D("MainObject", "Model.x", oldscale)));
63 m_FreeObject.begin()->LoadModel(this);
64 m_PartsNum = 1;
65 return true;
66 }
67
68 /*
69 * プレビュー設定
70 */
71 void CSurfacePlugin::SetPreview(){
72 ms_PreviewState = true;
73 g_Surface = this;
74 string desc = g_Surface->GetBasicInfo();
75 desc += FlashIn("\n%s: %.1f%s%.1f [m]", lang(Size), m_SizeX, lang(MulOp), m_SizeZ);
76 desc += "\n"+g_Surface->GetDescription();
77 g_SceneEditMode->SetProperty((char *)desc.c_str());
78 }
79
80 /*
81 * サウンド有効かどうか
82 */
83 bool CSurfacePlugin::IsSoundEnabled(){
84 return !!g_ConfigMode->GetSurfaceSound();
85 }
86
87 /*
88 * 地形ピック
89 */
90 bool CSurfacePlugin::PickSurface(
91 VEC3 pos, // 座標
92 VEC3 dir, // 方向
93 VEC3 *hit, // ヒット座標格納先
94 VEC3 *tri, // 三角形頂点格納先
95 int inv // 裏面フラグ
96 ){
97 VEC3 hit2, tri2[3];
98 IFreeObjectContainer ifo = m_FreeObject.begin();
99 int i, j;
100 float mindist;
101 bool flag = false;
102 int ccc = 0;
103 for(; ifo!=m_FreeObject.end(); ifo++){
104 ccc++;
105 for(j = 0; j<ifo->GetNamedObjectNum(); ++j){
106 if(ifo->GetNamedObject(j)->GetPartsObject()->Pick(pos, dir, &hit2, tri2, inv)){
107 float tmpdist = V3Len(&(pos-hit2));
108 if(!flag || mindist>tmpdist){
109 mindist = tmpdist;
110 if(hit) *hit = hit2;
111 if(tri) for(i = 0; i<3; i++) tri[i] = tri2[i];
112 }
113 flag = true;
114 }
115 }
116 }
117 return flag;
118 }
119
120 /*
121 * 矩形範囲に収める
122 */
123 bool CSurfacePlugin::ClipRect(
124 VEC3 *pos // 対象座標
125 ){
126 float hsx = 0.5f*m_SizeX, hsz = 0.5f*m_SizeZ;
127 bool ret = true;
128 if(pos->x<-hsx){ pos->x = -hsx; ret = false; }
129 else if(pos->x>hsx){ pos->x = hsx; ret = false; }
130 if(pos->z<-hsz){ pos->z = -hsz; ret = false; }
131 else if(pos->z>hsz){ pos->z = hsz; ret = false; }
132 return ret;
133 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26