Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CProfilePlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (show annotations) (download) (as text)
Tue Aug 28 14:58:05 2012 UTC (11 years, 8 months ago) by okadu
File MIME type: text/x-c++src
File size: 23649 byte(s)
[okadu] Version 2.14
ニュートラル画面分割
ダイヤ停車位置の数値設定
レイアウト読み込みバグ一部修正

1 #include "stdafx.h"
2 #include "CShadowVolume.h"
3 #include "CCamera.h"
4 #include "CProfilePlugin.h"
5
6 // 外部グローバル
7 extern CScene *g_Scene;
8 extern bool g_RailMipMap;
9 extern CShadowVolume g_ShadowVolume;
10
11 /*
12 * 断面中間点座標の計算
13 */
14 inline VEC3 CalcMidProfile(
15 VEC3 &p1, VEC3 &r1, VEC3 &u1, // 境界 1
16 VEC3 &p2, VEC3 &r2, VEC3 &u2, // 境界 2
17 VEC3 &mid // 中間点
18 ){
19 return (1.0f-mid.z)*(p1+r1*mid.x+u1*mid.y)+mid.z*(p2+r2*mid.x+u2*mid.y);
20 }
21
22 ////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////
24
25 /*
26 * 読込
27 */
28 char *CProfileVertex::Read(
29 char *str, // 対象文字列
30 bool tex // テクスチャ
31 ){
32 char *tmp, *eee;
33 if(!(str = BeginBlock(str, "Vertex"))) return NULL;
34 if(tmp = AsgnYesNo(str, "IgnoreCant", &m_IgnoreCant)) str = tmp;
35 else m_IgnoreCant = false;
36 if(!(str = AsgnVector2D(eee = str, "Coord", &m_Coord))) throw CSynErr(eee);
37 if(tmp = AsgnVector2D(str, "Normal", &m_Normal)){
38 str = tmp;
39 m_ReadNormal = true;
40 }else{
41 m_ReadNormal = false;
42 }
43 V2Norm(&m_Normal, &m_Normal);
44 if(tmp = AsgnColor(str, "Diffuse", &m_Diffuse)) str = tmp;
45 else m_Diffuse = 0xffffffff;
46 if(tex){
47 if(!(str = AsgnFloat(eee = str, "TexU", &m_TexU))) throw CSynErr(eee);
48 }
49 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
50 return str;
51 }
52
53 ////////////////////////////////////////////////////////////////////////////////
54 ////////////////////////////////////////////////////////////////////////////////
55
56 /*
57 * 読込
58 */
59 char *CProfileFace::Read(
60 char *str, // 対象文字列
61 bool tex // テクスチャ
62 ){
63 char *tmp, *eee;
64 if(!(str = BeginBlock(eee = str, "Face"))) return NULL;
65
66 m_Vertex.clear();
67 CProfileVertex vertex;
68 while(tmp = vertex.Read(str, tex)){
69 str = tmp;
70 m_Vertex.push_back(vertex);
71 }
72 IProfileVertex iv = m_Vertex.begin(), prev, next = iv;
73 for(; iv!=m_Vertex.end(); iv++){
74 next++;
75 if(!iv->m_ReadNormal){
76 if(iv==m_Vertex.begin()){
77 VEC2 tmp = next->m_Coord-iv->m_Coord;
78 V2Norm(&iv->m_Normal, &VEC2(-tmp.y, tmp.x));
79 }else if(next==m_Vertex.end()){
80 VEC2 tmp = iv->m_Coord-prev->m_Coord;
81 V2Norm(&iv->m_Normal, &VEC2(-tmp.y, tmp.x));
82 }else{
83 VEC2 tmp1 = iv->m_Coord-prev->m_Coord;
84 VEC2 tmp2 = next->m_Coord-iv->m_Coord;
85 V2Norm(&tmp2, &VEC2(-tmp2.y, tmp2.x));
86 V2Norm(&tmp1, &VEC2(-tmp1.y, tmp1.x));
87 V2Norm(&iv->m_Normal, &(tmp1+tmp2));
88 }
89 }
90 prev = iv;
91 }
92 if(m_Vertex.size()<2) throw CSynErr(eee, lang(TwoVertexNeeded));
93
94 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
95 return str;
96 }
97
98 ////////////////////////////////////////////////////////////////////////////////
99 ////////////////////////////////////////////////////////////////////////////////
100
101 /*
102 * コンストラクタ
103 */
104 CProfile::CProfile(){
105 m_Texture = NULL;
106 }
107
108 /*
109 * デストラクタ
110 */
111 CProfile::~CProfile(){
112 ClearAll();
113 }
114
115 /*
116 * すべて解放
117 */
118 void CProfile::ClearAll(){
119 map<CScene *, MapPtrValue<CQuadDumpN> >::iterator itr_n;
120 for(itr_n = m_DumpN.begin(); itr_n!=m_DumpN.end(); ++itr_n){
121 itr_n->second.SafeDelete();
122 }
123 map<CScene *, MapPtrValue<CQuadDumpNX> >::iterator itr_nx;
124 for(itr_nx = m_DumpNX.begin(); itr_nx!=m_DumpNX.end(); ++itr_nx){
125 itr_nx->second.SafeDelete();
126 }
127 }
128
129 /*
130 * 読込
131 */
132 char *CProfile::Read(
133 char *str // 対象文字列
134 ){
135 char *tmp, *eee;
136 if(!(str = BeginBlock(str, "Profile"))) return NULL;
137
138 if(!(str = BeginBlock(eee = str, "Material"))) throw CSynErr(eee);
139 if(!(str = AsgnYesNo(eee = str, "UseTexture", &m_UseTexture))) throw CSynErr(eee);
140 if(m_UseTexture){
141 if(!(str = AsgnString(eee = str, "TexFileName", &m_TexFileName))) throw CSynErr(eee);
142 if(!(str = AsgnFloat(eee = str, "TexVPerMeter", &m_TexVPerMeter))) throw CSynErr(eee);
143 }else{
144 m_TexFileName = "";
145 m_TexVPerMeter = 1.0f;
146 }
147 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
148
149 m_Face.clear();
150 CProfileFace face;
151 while(tmp = face.Read(str, m_UseTexture)){
152 str = tmp;
153 m_Face.push_back(face);
154 }
155
156 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
157 return str;
158 }
159
160 /*
161 * テクスチャ読込
162 */
163 void CProfile::LoadTexture(){
164 if(m_UseTexture) m_Texture = g_TexList.Get(FALSE, m_TexFileName.c_str(), 0, !g_RailMipMap);
165 }
166
167 /*
168 * ダンパ準備
169 */
170 void CProfile::PrepareDump(){
171 if(m_UseTexture){
172 MapPtrValue<CQuadDumpNX> &dump_nx = m_DumpNX[g_Scene];
173 if(!dump_nx) dump_nx = new CQuadDumpNX(QUAD_DUMP_MAX, m_Texture);
174 }else{
175 MapPtrValue<CQuadDumpN> &dump_n = m_DumpN[g_Scene];
176 if(!dump_n) dump_n = new CQuadDumpN(QUAD_DUMP_MAX);
177 }
178 }
179
180 ////////////////////////////////////////////////////////////////////////////////
181 ////////////////////////////////////////////////////////////////////////////////
182
183
184 /*
185 * 読込
186 */
187 char *CWireframeVertex::Read(
188 char *str // 対象文字列
189 ){
190 char *tmp, *eee;
191 if(!(str = BeginBlock(str, "Vertex"))) return NULL;
192 if(tmp = AsgnYesNo(str, "IgnoreCant", &m_IgnoreCant)) str = tmp;
193 else m_IgnoreCant = false;
194 if(!(str = AsgnVector3D(eee = str, "Coord", &m_Coord))) throw CSynErr(eee);
195 if(tmp = AsgnColor(str, "Diffuse", &m_Diffuse)) str = tmp;
196 else m_Diffuse = 0xff000000;
197 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
198 return str;
199 }
200
201 ////////////////////////////////////////////////////////////////////////////////
202 ////////////////////////////////////////////////////////////////////////////////
203
204 /*
205 * 読込
206 */
207 char *CWireframeLine::Read(
208 char *str // 対象文字列
209 ){
210 char *tmp, *eee;
211 if(!(str = BeginBlock(eee = str, "Line"))) return NULL;
212
213 m_Vertex.clear();
214 CWireframeVertex vertex;
215 while(tmp = vertex.Read(str)){
216 str = tmp;
217 m_Vertex.push_back(vertex);
218 }
219 if(m_Vertex.size()<2) throw CSynErr(eee, lang(TwoVertexNeeded));
220
221 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
222 return str;
223 }
224
225 ////////////////////////////////////////////////////////////////////////////////
226 ////////////////////////////////////////////////////////////////////////////////
227
228 /*
229 * コンストラクタ
230 */
231 CWireframe::CWireframe(){
232 }
233
234 /*
235 * デストラクタ
236 */
237 CWireframe::~CWireframe(){
238 ClearAll();
239 }
240
241 /*
242 * すべて解放
243 */
244 void CWireframe::ClearAll(){
245 map<CScene *, MapPtrValue<CLineDumpN> >::iterator itr_n;
246 for(itr_n = m_DumpN.begin(); itr_n!=m_DumpN.end(); ++itr_n){
247 itr_n->second.SafeDelete();
248 }
249 }
250
251 /*
252 * 読込
253 */
254 char *CWireframe::Read(
255 char *str // 対象文字列
256 ){
257 char *tmp, *eee;
258 if(!(str = BeginBlock(str, "Wireframe"))) return NULL;
259
260 if(tmp = AsgnFloat(str, "MinInterval", &m_MinInterval)) str = tmp;
261 else m_MinInterval = -1.0f;
262 if(tmp = AsgnFloat(str, "MaxInterval", &m_MaxInterval)) str = tmp;
263 else m_MaxInterval = -1.0f;
264
265 m_Line.clear();
266 CWireframeLine line;
267 while(tmp = line.Read(str)){
268 str = tmp;
269 m_Line.push_back(line);
270 }
271
272 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
273 return str;
274 }
275
276 /*
277 * ダンパ準備
278 */
279 void CWireframe::PrepareDump(){
280 MapPtrValue<CLineDumpN> &dump_n = m_DumpN[g_Scene];
281 if(!dump_n) dump_n = new CLineDumpN(LINE_DUMP_MAX);
282 }
283
284 ////////////////////////////////////////////////////////////////////////////////
285 ////////////////////////////////////////////////////////////////////////////////
286
287 /*
288 * 読込
289 */
290 char *CInterval::Read(
291 char *str // 対象文字列
292 ){
293 char *tmp, *eee;
294 if(!(str = BeginBlock(str, "Interval"))) return NULL;
295 if(tmp = AsgnYesNo(str, "IgnoreCant", &m_IgnoreCant)) str = tmp;
296 else m_IgnoreCant = false;
297 if(!(str = AsgnString(eee = str, "ModelFileName", &m_ModelFileName))) throw CSynErr(eee);
298 if(tmp = AsgnFloat(str, "ModelScale", &m_ModelScale)) str = tmp;
299 else m_ModelScale = 1.0f;
300 if(!(str = AsgnFloat(eee = str, "Interval", &m_Interval))) throw CSynErr(eee);
301 if(tmp = AsgnFloat(str, "Offset", &m_Offset)) str = tmp;
302 else m_Offset = 0.0f;
303 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
304 return str;
305 }
306
307 /*
308 * モデル読込
309 */
310 void CInterval::LoadModel(){
311 m_Mesh = g_MeshList.Get(FALSE, (char *)m_ModelFileName.c_str(), 0, !g_RailMipMap);
312 m_Object.SetMesh(m_Mesh, V3ZERO, m_ModelScale);
313 }
314
315 ////////////////////////////////////////////////////////////////////////////////
316 ////////////////////////////////////////////////////////////////////////////////
317
318 // static メンバ
319 vector<CProfileVertex *>CProfilePlugin::ms_TempIndex;
320
321 /*
322 * 読込
323 */
324 char *CProfilePlugin::ReadProfile(
325 char *str // 対象文字列
326 ){
327 char *tmp;
328 CProfile profile;
329 CWireframe wireframe;
330 CInterval interval;
331 while(true){
332 if(tmp = profile.Read(str)){
333 str = tmp;
334 m_Profile.push_back(profile);
335 }else if(tmp = wireframe.Read(str)){
336 str = tmp;
337 m_Wireframe.push_back(wireframe);
338 }else if(tmp = interval.Read(str)){
339 str = tmp;
340 m_Interval.push_back(interval);
341 }else{
342 break;
343 }
344 }
345 return str;
346 }
347
348 /*
349 * データ読込
350 */
351 void CProfilePlugin::LoadData(){
352 IProfile ip = m_Profile.begin();
353 IInterval ii = m_Interval.begin();
354 for(; ip!=m_Profile.end(); ip++) ip->LoadTexture();
355 for(; ii!=m_Interval.end(); ii++){
356 ii->LoadModel();
357 ChDir();
358 }
359 }
360
361 /*
362 * ダンプ
363 */
364 void CProfilePlugin::Dump(
365 VEC3 &p1, VEC3 &r1, VEC3 &u1, // 始点 (正規化済)
366 VEC3 &ip1, VEC3 &ir1, VEC3 &iu1, // 非カント始点 (正規化済)
367 VEC3 &p2, VEC3 &r2, VEC3 &u2, // 終点 (正規化済)
368 VEC3 &ip2, VEC3 &ir2, VEC3 &iu2, // 非カント終点 (正規化済)
369 float len, // テクスチャ延長長さ
370 int prev // プレビュー (1: render, 2: settex, 4: mapscroll)
371 ){
372 void (CLineDumpN::*f_ll)(VEC3, D3DCOLOR, VEC3, D3DCOLOR);
373 void (CQuadDumpN::*f_qn)(
374 VEC3, VEC3, D3DCOLOR, VEC3, VEC3, D3DCOLOR,
375 VEC3, VEC3, D3DCOLOR, VEC3, VEC3, D3DCOLOR);
376 void (CQuadDumpNX::*f_qnx)(
377 VEC3, VEC3, D3DCOLOR, float, float, VEC3, VEC3, D3DCOLOR, float, float,
378 VEC3, VEC3, D3DCOLOR, float, float, VEC3, VEC3, D3DCOLOR, float, float);
379 if(prev&1){
380 f_ll = &CLineDumpN::Preview;
381 f_qn = &CQuadDumpN::Preview;
382 f_qnx = &CQuadDumpNX::Preview;
383 }else{
384 f_ll = &CLineDumpN::Add;
385 f_qn = &CQuadDumpN::Add;
386 f_qnx = &CQuadDumpNX::Add;
387 }
388 BeforeDump(p1, r1, u1, p2, r2, u2);
389 IProfile ip = m_Profile.begin();
390 if(prev&2){
391 devSetLighting(TRUE);
392 devResetMaterial();
393 }
394 for(; ip!=m_Profile.end(); ip++){
395 MapPtrValue<CQuadDumpNX> &dump_nx = ip->m_DumpNX[g_Scene];
396 MapPtrValue<CQuadDumpN> &dump_n = ip->m_DumpN[g_Scene];
397 float v1 = ip->m_TexMapVTemp, v2 = v1+ip->m_TexVPerMeter*len;
398 if(prev&2) devSetTexture(0, ip->m_Texture);
399 else ip->PrepareDump();
400 IProfileFace ir = ip->m_Face.begin();
401 for(; ir!=ip->m_Face.end(); ir++){
402 IProfileVertex iv1 = ir->m_Vertex.begin(), iv2 = iv1;
403 iv2++;
404 for(; iv2!=ir->m_Vertex.end(); iv1++, iv2++){
405 VEC2 &c1 = iv1->m_Coord, &c2 = iv2->m_Coord;
406 VEC2 &n1 = iv1->m_Normal, &n2 = iv2->m_Normal;
407 D3DCOLOR &df1 = iv1->m_Diffuse, &df2 = iv2->m_Diffuse;
408 if(ip->m_UseTexture){
409 float &tu1 = iv1->m_TexU, &tu2 = iv2->m_TexU;
410 if(iv1->m_IgnoreCant){
411 if(iv2->m_IgnoreCant) (dump_nx->*f_qnx)(
412 ip1+ir1*c1.x+iu1*c1.y, ir1*n1.x+iu1*n1.y, df1, tu1, v1,
413 ip2+ir2*c1.x+iu2*c1.y, ir2*n1.x+iu2*n1.y, df1, tu1, v2,
414 ip2+ir2*c2.x+iu2*c2.y, ir2*n2.x+iu2*n2.y, df2, tu2, v2,
415 ip1+ir1*c2.x+iu1*c2.y, ir1*n2.x+iu1*n2.y, df2, tu2, v1);
416 else (dump_nx->*f_qnx)(
417 ip1+ir1*c1.x+iu1*c1.y, ir1*n1.x+iu1*n1.y, df1, tu1, v1,
418 ip2+ir2*c1.x+iu2*c1.y, ir2*n1.x+iu2*n1.y, df1, tu1, v2,
419 p2+r2*c2.x+u2*c2.y, r2*n2.x+u2*n2.y, df2, tu2, v2,
420 p1+r1*c2.x+u1*c2.y, r1*n2.x+u1*n2.y, df2, tu2, v1);
421 }else{
422 if(iv2->m_IgnoreCant) (dump_nx->*f_qnx)(
423 p1+r1*c1.x+u1*c1.y, r1*n1.x+u1*n1.y, df1, tu1, v1,
424 p2+r2*c1.x+u2*c1.y, r2*n1.x+u2*n1.y, df1, tu1, v2,
425 ip2+ir2*c2.x+iu2*c2.y, ir2*n2.x+iu2*n2.y, df2, tu2, v2,
426 ip1+ir1*c2.x+iu1*c2.y, ir1*n2.x+iu1*n2.y, df2, tu2, v1);
427 else (dump_nx->*f_qnx)(
428 p1+r1*c1.x+u1*c1.y, r1*n1.x+u1*n1.y, df1, tu1, v1,
429 p2+r2*c1.x+u2*c1.y, r2*n1.x+u2*n1.y, df1, tu1, v2,
430 p2+r2*c2.x+u2*c2.y, r2*n2.x+u2*n2.y, df2, tu2, v2,
431 p1+r1*c2.x+u1*c2.y, r1*n2.x+u1*n2.y, df2, tu2, v1);
432 }
433 }else{
434 if(iv1->m_IgnoreCant){
435 if(iv2->m_IgnoreCant) (dump_n->*f_qn)(
436 ip1+ir1*c1.x+iu1*c1.y, ir1*n1.x+iu1*n1.y, df1,
437 ip2+ir2*c1.x+iu2*c1.y, ir2*n1.x+iu2*n1.y, df1,
438 ip2+ir2*c2.x+iu2*c2.y, ir2*n2.x+iu2*n2.y, df2,
439 ip1+ir1*c2.x+iu1*c2.y, ir1*n2.x+iu1*n2.y, df2);
440 else (dump_n->*f_qn)(
441 ip1+ir1*c1.x+iu1*c1.y, ir1*n1.x+iu1*n1.y, df1,
442 ip2+ir2*c1.x+iu2*c1.y, ir2*n1.x+iu2*n1.y, df1,
443 p2+r2*c2.x+u2*c2.y, r2*n2.x+u2*n2.y, df2,
444 p1+r1*c2.x+u1*c2.y, r1*n2.x+u1*n2.y, df2);
445 }else{
446 if(iv2->m_IgnoreCant) (dump_n->*f_qn)(
447 p1+r1*c1.x+u1*c1.y, r1*n1.x+u1*n1.y, df1,
448 p2+r2*c1.x+u2*c1.y, r2*n1.x+u2*n1.y, df1,
449 ip2+ir2*c2.x+iu2*c2.y, ir2*n2.x+iu2*n2.y, df2,
450 ip1+ir1*c2.x+iu1*c2.y, ir1*n2.x+iu1*n2.y, df2);
451 else (dump_n->*f_qn)(
452 p1+r1*c1.x+u1*c1.y, r1*n1.x+u1*n1.y, df1,
453 p2+r2*c1.x+u2*c1.y, r2*n1.x+u2*n1.y, df1,
454 p2+r2*c2.x+u2*c2.y, r2*n2.x+u2*n2.y, df2,
455 p1+r1*c2.x+u1*c2.y, r1*n2.x+u1*n2.y, df2);
456 }
457 }
458 }
459 }
460 if(prev&4) ip->m_TexMapVTemp = v2-(int)v2;
461 }
462 if(prev&2){
463 devSetTexture(0, NULL);
464 devSetLineMaterial();
465 }
466 IWireframe iw = m_Wireframe.begin();
467 for(; iw!=m_Wireframe.end(); iw++){
468 if(!iw->CheckInterval(len)) continue;
469 MapPtrValue<CLineDumpN> &dump_n = iw->m_DumpN[g_Scene];
470 if(!(prev&2)) iw->PrepareDump();
471 IWireframeLine ir = iw->m_Line.begin();
472 for(; ir!=iw->m_Line.end(); ir++){
473 IWireframeVertex iv1 = ir->m_Vertex.begin(), iv2 = iv1;
474 iv2++;
475 for(; iv2!=ir->m_Vertex.end(); iv1++, iv2++){
476 VEC3 &c1 = iv1->m_Coord, &c2 = iv2->m_Coord;
477 D3DCOLOR &df1 = iv1->m_Diffuse, &df2 = iv2->m_Diffuse;
478 if(iv1->m_IgnoreCant){
479 if(iv2->m_IgnoreCant) (dump_n->*f_ll)(
480 CalcMidProfile(ip1, ir1, iu1, ip2, ir2, iu2, c1), df1,
481 CalcMidProfile(ip1, ir1, iu1, ip2, ir2, iu2, c2), df2);
482 else (dump_n->*f_ll)(
483 CalcMidProfile(ip1, ir1, iu1, ip2, ir2, iu2, c1), df1,
484 CalcMidProfile(p1, r1, u1, p2, r2, u2, c2), df2);
485 }else{
486 if(iv2->m_IgnoreCant) (dump_n->*f_ll)(
487 CalcMidProfile(p1, r1, u1, p2, r2, u2, c1), df1,
488 CalcMidProfile(ip1, ir1, iu1, ip2, ir2, iu2, c2), df2);
489 else (dump_n->*f_ll)(
490 CalcMidProfile(p1, r1, u1, p2, r2, u2, c1), df1,
491 CalcMidProfile(p1, r1, u1, p2, r2, u2, c2), df2);
492 }
493 }
494 }
495 }
496 AfterDump(p1, u1, ip1, iu1, p2, u2, ip2, iu2);
497 }
498
499 /*
500 * レンダリング
501 */
502 void CProfilePlugin::Render(
503 VEC3 &p1, VEC3 &r1, VEC3 &u1, VEC3 &d1, // 始点 (正規化済)
504 VEC3 &ip1, VEC3 &ir1, VEC3 &iu1, // 非カント始点 (正規化済)
505 VEC3 &p2, VEC3 &r2, VEC3 &u2, VEC3 &d2, // 終点 (正規化済)
506 VEC3 &ip2, VEC3 &ir2, VEC3 &iu2, // 非カント終点 (正規化済)
507 int close, // 閉鎖 (1: begin, 2: end)
508 float len, // テクスチャ延長長さ
509 MAT8 *altmat // 代替マテリアル
510 ){
511 float sx1, sy1, sx2, sy2;
512 float taperz = GetTaperZ(), sz = 1.0;
513 bool ftaper = UseTaper(), close1 = !!(close&1), close2 = !!(close&2);
514 if(ftaper){
515 sx1 = V3Len(&r1); sy1 = V3Len(&u1);
516 sx2 = V3Len(&r2); sy2 = V3Len(&u2);
517 if(taperz<0.0f) sz -= len*taperz;
518 }
519 BeforeDump(p1, r1, u1, p2, r2, u2);
520 VEC3 dir = p2-p1, idir = ip2-ip1, td1, td2;
521 V3Norm(&dir, &dir);
522 V3Norm(&idir, &idir);
523 V3Norm(&td1, V3Cross(&td1, &r1, &u1));
524 V3Norm(&td2, V3Cross(&td2, &r2, &u2));
525 if(g_ShadowNeeded){
526 ms_TempIndex.clear();
527 VEC3 vLight = svl.dir.Direction;
528 V3Norm(&vLight, &vLight);
529 IProfile ip = m_Profile.begin();
530 for(; ip!=m_Profile.end(); ip++){
531 IProfileFace ir = ip->m_Face.begin();
532 for(; ir!=ip->m_Face.end(); ir++){
533 IProfileVertex iv1 = ir->m_Vertex.begin(), iv2 = iv1;
534 iv2++;
535 for(; iv2!=ir->m_Vertex.end(); iv1++, iv2++){
536 VEC2 &c1 = iv1->m_Coord, &c2 = iv2->m_Coord;
537 VEC3 sp1, sp2, sp3, sp4;
538 if(iv1->m_IgnoreCant){
539 sp1 = ip1+ir1*c1.x+iu1*c1.y;
540 sp2 = ip2+ir2*c1.x+iu2*c1.y;
541 }else{
542 sp1 = p1+r1*c1.x+u1*c1.y;
543 sp2 = p2+r2*c1.x+u2*c1.y;
544 }
545 if(iv2->m_IgnoreCant){
546 sp3 = ip2+ir2*c2.x+iu2*c2.y;
547 sp4 = ip1+ir1*c2.x+iu1*c2.y;
548 }else{
549 sp3 = p2+r2*c2.x+u2*c2.y;
550 sp4 = p1+r1*c2.x+u1*c2.y;
551 }
552 VEC3 vNormal;
553 V3Cross(&vNormal, &(sp1-sp2), &(sp4-sp2));
554 if(V3Dot(&vNormal, &vLight)>=0.0f){
555 iv1->m_TransCoord[0] = sp1;
556 iv1->m_TransCoord[1] = sp2;
557 iv2->m_TransCoord[0] = sp3;
558 iv2->m_TransCoord[1] = sp4;
559 ms_TempIndex.push_back(&*iv1);
560 ms_TempIndex.push_back(&*iv2);
561 if(close1 || !iv2->m_ShadowDrawed)
562 g_ShadowVolume.AddFaceEdge(sp4, sp1, vLight);
563 if(close2) g_ShadowVolume.AddFaceEdge(sp2, sp3, vLight);
564 iv2->m_ShadowDrawed = true;
565 }else{
566 if(!close1 && iv2->m_ShadowDrawed)
567 g_ShadowVolume.AddFaceEdge(sp1, sp4, vLight);
568 iv2->m_ShadowDrawed = false;
569 }
570 }
571 }
572 }
573 sort(ms_TempIndex.begin(), ms_TempIndex.end());
574 DWORD i, dwNumEdges = ms_TempIndex.size();
575 for(i = 0; i<dwNumEdges; i++){
576 CProfileVertex *edge = ms_TempIndex[i];
577 while(i<dwNumEdges-1 && edge->IsSame(ms_TempIndex[i+1])){
578 i += 2;
579 while(i<dwNumEdges && edge->IsSame(ms_TempIndex[i])) i++;
580 if(i>=dwNumEdges) goto ENDDUMP;
581 edge = ms_TempIndex[i];
582 }
583 g_ShadowVolume.AddFaceEdge(edge->m_TransCoord[0], edge->m_TransCoord[1], vLight);
584 }
585 ENDDUMP:;
586 }
587 IInterval ii = m_Interval.begin();
588 for(; ii!=m_Interval.end(); ii++){
589 float v1 = ii->m_IntervalTemp;
590 while(v1<len){
591 if(v1>=0.0f){
592 float q2 = v1/len, q1 = 1.0f-q2;
593 if(ii->m_IgnoreCant){
594 ii->m_Object.SetPos(ip1+idir*v1);
595 ii->m_Object.SetDir(q1*d1+q2*d2, q1*iu1+q2*iu2);
596 }else{
597 ii->m_Object.SetPos(p1+dir*v1);
598 ii->m_Object.SetDir(q1*td1+q2*td2, q1*u1+q2*u2);
599 }
600 if(ftaper) ii->m_Object.SetScale(q1*sx1+q2*sx2, q1*sy1+q2*sy2, sz);
601 ii->m_Object.ResetMatFlag();
602 if(altmat) ii->m_Object.RenderSC(altmat); else ii->m_Object.Render();
603 CastShadow(&ii->m_Object);
604 }
605 v1 += ii->m_Interval*sz;
606 sz += ii->m_Interval*sz*taperz;
607 }
608 ii->m_IntervalTemp = v1-len;
609 }
610 AfterDump(p1, u1, ip1, iu1, p2, u2, ip2, iu2);
611 }
612
613 /*
614 * マッピング位置リセット
615 */
616 void CProfilePlugin::ResetMapTemp(){
617 IProfile ip = m_Profile.begin();
618 IInterval ii = m_Interval.begin();
619 for(; ip!=m_Profile.end(); ip++) ip->m_TexMapVTemp = 0.0f;
620 for(; ii!=m_Interval.end(); ii++) ii->m_IntervalTemp = ii->m_Offset;
621 }
622
623 /*
624 * マッピング位置コピー
625 */
626 void CProfilePlugin::CopyMapTemp(
627 vector<float> &mapv // 代入先
628 ){
629 int pn = m_Profile.size()+m_Interval.size();
630 if(!pn) return;
631 mapv.resize(pn);
632 vector<float>::iterator ptr = mapv.begin();
633 IProfile ip = m_Profile.begin();
634 IInterval ii = m_Interval.begin();
635 for(; ip!=m_Profile.end(); ip++, ptr++) *ptr = ip->m_TexMapVTemp;
636 for(; ii!=m_Interval.end(); ii++, ptr++) *ptr = ii->m_IntervalTemp;
637 }
638
639 /*
640 * マッピング位置加算
641 */
642 void CProfilePlugin::AddMapTemp(
643 float dist // 距離
644 ){
645 IProfile ip = m_Profile.begin();
646 IInterval ii = m_Interval.begin();
647 for(; ip!=m_Profile.end(); ip++){
648 ip->m_TexMapVTemp += dist*ip->m_TexVPerMeter;
649 ip->m_TexMapVTemp -= (int)ip->m_TexMapVTemp;
650 }
651 for(; ii!=m_Interval.end(); ii++){
652 ii->m_IntervalTemp += ii->m_Interval*(int)(dist/ii->m_Interval)-dist;
653 if(ii->m_IntervalTemp<0.0f) ii->m_IntervalTemp += ii->m_Interval;
654 }
655 }
656
657 /*
658 * マッピング位置セット
659 */
660 void CProfilePlugin::SetMapTemp(
661 vector<float> &mapv // 現在位置
662 ){
663 vector<float>::iterator ptr = mapv.begin();
664 IProfile ip = m_Profile.begin();
665 IInterval ii = m_Interval.begin();
666 for(; ip!=m_Profile.end(); ip++, ptr++) ip->m_TexMapVTemp = *ptr;
667 for(; ii!=m_Interval.end(); ii++, ptr++) ii->m_IntervalTemp = *ptr;
668 }
669
670 /*
671 * ダンパ解放
672 */
673 void CProfilePlugin::ClearDump(){
674 IProfile ip = m_Profile.begin();
675 IWireframe iw = m_Wireframe.begin();
676 for(; ip!=m_Profile.end(); ip++){
677 ip->m_DumpN[g_Scene].SafeDelete();
678 ip->m_DumpNX[g_Scene].SafeDelete();
679 }
680 for(; iw!=m_Wireframe.end(); iw++) iw->m_DumpN[g_Scene].SafeDelete();
681 }
682
683 /*
684 * ダンパすべて解放
685 */
686 void CProfilePlugin::ClearDumpAll(){
687 IProfile ip = m_Profile.begin();
688 IWireframe iw = m_Wireframe.begin();
689 for(; ip!=m_Profile.end(); ip++) ip->ClearAll();
690 for(; iw!=m_Wireframe.end(); iw++) iw->ClearAll();
691 }
692
693 /*
694 * バーテックス準備
695 */
696 void CProfilePlugin::PrepareVertex(){
697 IProfile ip = m_Profile.begin();
698 IWireframe iw = m_Wireframe.begin();
699 for(; ip!=m_Profile.end(); ip++){
700 MapPtrValue<CQuadDumpN> &dump_n = ip->m_DumpN[g_Scene];
701 MapPtrValue<CQuadDumpNX> &dump_nx = ip->m_DumpNX[g_Scene];
702 if(dump_n) dump_n->PrepareVertex();
703 if(dump_nx) dump_nx->PrepareVertex();
704 }
705 for(; iw!=m_Wireframe.end(); iw++){
706 MapPtrValue<CLineDumpN> &dump_n = iw->m_DumpN[g_Scene];
707 if(dump_n) dump_n->PrepareVertex();
708 }
709 }
710
711 /*
712 * 全てレンダリング
713 */
714 void CProfilePlugin::RenderAll(){
715 IProfile ip = m_Profile.begin();
716 IWireframe iw = m_Wireframe.begin();
717 devSetLighting(TRUE);
718 devResetMaterial();
719 for(; ip!=m_Profile.end(); ip++){
720 MapPtrValue<CQuadDumpN> &dump_n = ip->m_DumpN[g_Scene];
721 MapPtrValue<CQuadDumpNX> &dump_nx = ip->m_DumpNX[g_Scene];
722 if(dump_n) dump_n->Render(false);
723 if(dump_nx) dump_nx->Render(false);
724 }
725 devSetLineMaterial();
726 for(; iw!=m_Wireframe.end(); iw++){
727 MapPtrValue<CLineDumpN> &dump_n = iw->m_DumpN[g_Scene];
728 if(dump_n) dump_n->Render(false);
729 }
730 }
731
732 ////////////////////////////////////////////////////////////////////////////////
733 ////////////////////////////////////////////////////////////////////////////////
734
735 /*
736 * ダンパ解放
737 */
738 void CProfilePluginList::ClearDump(){
739 CProfilePlugin *ptr = Root();
740 while(ptr){
741 ptr->ClearDump();
742 ptr = ptr->Next();
743 }
744 }
745
746 /*
747 * ダンパすべて解放
748 */
749 void CProfilePluginList::ClearDumpAll(){
750 CProfilePlugin *ptr = Root();
751 while(ptr){
752 ptr->ClearDumpAll();
753 ptr = ptr->Next();
754 }
755 }
756
757 /*
758 * ダンパ準備
759 */
760 void CProfilePluginList::PrepareVertex(){
761 CProfilePlugin *ptr = Root();
762 while(ptr){
763 ptr->PrepareVertex();
764 ptr = ptr->Next();
765 }
766 }
767
768 /*
769 * 全てレンダリング
770 */
771 void CProfilePluginList::RenderAll(){
772 devResetMatrix();
773 devResetMaterial();
774 CProfilePlugin *ptr = Root();
775 while(ptr){
776 ptr->RenderAll();
777 ptr = ptr->Next();
778 }
779 }
780
781 ////////////////////////////////////////////////////////////////////////////////
782 ////////////////////////////////////////////////////////////////////////////////
783
784 /*
785 * マッピングベクトル読込
786 */
787 char *ReadMapVector(
788 char *str, // 対象文字列
789 char *pref, // プレフィックス
790 vector<float> &mapv // マッピングベクトル
791 ){
792 char *eee, *tmp;
793 if(tmp = Assignment(str, pref)){
794 str = tmp;
795 do{
796 if(mapv.size() && !(str = Character2(eee = str, ','))) throw CSynErr(eee);
797 float texv;
798 if(!(str = ConstFloat(eee = str, &texv))) throw CSynErr(eee);
799 mapv.push_back(texv);
800 } while(!(tmp = Character2(str, ';')));
801 str = tmp;
802 }
803 return str;
804 }
805
806 /*
807 * マッピングベクトル保存
808 */
809 void SaveMapVector(
810 FILE *df, // ファイル
811 char *pref, // プレフィックス
812 vector<float> &mapv // マッピングベクトル
813 ){
814 if(!mapv.size()) return;
815 fprintf(df, pref);
816 int i;
817 for(i = 0; i<mapv.size(); i++) fprintf(df, i ? ", %f" : "%f", mapv[i]);
818 fprintf(df, ";\n");
819 }

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