-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRoad_Edit.cpp
761 lines (629 loc) · 18.6 KB
/
Road_Edit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
#include "pch.h"
#include "Def_Str.h"
#include "dbl.h"
#include "Road.h"
#include "CScene.h"
#include "CData.h"
#include "SceneXml.h"
#include "PresetsXml.h"
#ifdef SR_EDITOR
#include "CApp.h"
#else
#include "CGame.h"
#endif
#include "Terra.h"
#include <OgreCamera.h>
#include <OgreVector3.h>
#include <OgreSceneNode.h>
#include <OgreMaterialManager.h>
using namespace Ogre;
// choose, selection
//--------------------------------------------------------------------------------------
void SplineEdit::ChoosePoint()
{
iChosen = iSelPoint;
}
void SplineEdit::CopyNewPoint()
{
if (iChosen == -1) return;
newP = mP[iChosen];
}
// next
void SplineEdit::PrevPoint()
{
if (getNumPoints() != 0)
iChosen = (iChosen-1 + getNumPoints()) % getNumPoints();
}
void SplineEdit::NextPoint()
{
if (getNumPoints() != 0)
iChosen = (iChosen+1) % getNumPoints();
}
void SplineEdit::FirstPoint()
{
if (getNumPoints() != 0)
iChosen = 0;
}
void SplineEdit::LastPoint()
{
if (getNumPoints() != 0)
iChosen = getNumPoints()-1;
}
// mark need to rebuild geometry
void SplineEdit::Rebuild(bool full)
{
//return; // test no road
rebuild = true;
if (full)
iDirtyId = -1;
else
iDirtyId = iChosen;
}
#ifdef SR_EDITOR // ed
//-----------------------------------------------------------------------------------------------------------------------------------------
// add/rem select
void SplineEdit::SelAddPoint()
{
int id = -1;
if (iChosen != -1) id = iChosen; else
if (iSelPoint != -1) id = iSelPoint;
if (id != -1)
{
if (vSel.find(id) == vSel.end())
vSel.insert(id);
else
vSel.erase(id);
}
}
void SplineEdit::SelClear()
{
vSel.clear();
}
void SplineEdit::SelAll()
{
vSel.clear();
for (size_t i=0; i < mP.size(); ++i)
vSel.insert(i);
}
int SplineEdit::GetSelCnt()
{
return vSel.size();
}
// Move point
///-------------------------------------------------------------------------------------
#endif
void SplineEdit::Move1(int id, Vector3 relPos)
{
Vector3 pos = getPos(id) + relPos;
if (mP[id].onTer)
pos.y = getTerH(pos) + g_Height;
setPos(id, pos);
vMarks[id].setPos(pos); // upd marker
}
Real SplineEdit::getTerH(const Vector3& p)
{
if (!scn) return 0.f; // tool
Vector3 pos(p);
scn->getTerH(pos);
return pos.y;
}
#ifdef SR_EDITOR // ed
void SplineEdit::Move(Vector3 relPos)
{
if (!vSel.empty()) // move sel
{ for (auto it = vSel.begin(); it != vSel.end(); ++it)
Move1(*it, relPos);
bSelChng = true;
return;
}
if (iChosen == -1) { // move one
newP.pos.y += relPos.y; return; }
else
{ Move1(iChosen, relPos);
Rebuild(); }
}
// Scale1 (for tools)
void SplineEdit::Scale1(int id, Real posMul, Real hMul)
{
Vector3 pos = getPos(id);
if (posMul != 0.f)
{ pos.x *= posMul; pos.z *= posMul; }
if (hMul != 0.f)
pos.y *= hMul;
if (mP[id].onTer)
pos.y = getTerH(pos) + g_Height;
setPos(id, pos);
vMarks[id].setPos(pos); // upd marker
}
// Update Points onTer
void SplineEdit::UpdPointsH()
{
for (int id=0; id < getNumPoints(); ++id)
{
Vector3 pos = getPos(id);
if (mP[id].onTer)
{ pos.y = getTerH(pos) + g_Height;
setPos(id, pos);
}
vMarks[id].setPos(pos); // upd marker
}
}
/// Edit Selected
///-------------------------------------------------------------------------------------
Vector3 SplineEdit::getPos0()
{
Vector3 pos0(0,0,0);
if (iChosen == -1) // geom center
{
for (auto it = vSel.begin(); it != vSel.end(); ++it)
pos0 += getPos(*it);
pos0 /= Real(vSel.size());
}
else // or chosen point
pos0 = getPos(iChosen);
return pos0;
}
// Scale selected
void SplineEdit::ScaleSel(Real posMul)
{
Vector3 pos0(0,0,0); // = getPos0() ?
if (iChosen != -1) // 0 or chosen point
pos0 = getPos(iChosen);
for (auto it = vSel.begin(); it != vSel.end(); ++it)
{ int id = *it;
Vector3 pos = (getPos(id) - pos0) * (1.f + posMul) + pos0;
if (mP[id].onTer)
pos.y = getTerH(pos) + g_Height;
setPos(id, pos);
vMarks[id].setPos(pos); // upd marker
}
}
// Rotate selected
void SplineEdit::RotateSel(Real relA, Vector3 axis, int addYawRoll)
{
if (vSel.empty()) return;
Vector3 pos0 = getPos0();
Quaternion q; q.FromAngleAxis(Degree(relA), axis);
Matrix3 m; q.ToRotationMatrix(m);
// rotate 2d yaw around center
for (auto it = vSel.begin(); it != vSel.end(); ++it)
{
Vector3 pos = getPos(*it) - pos0;
Vector3 npos = pos * m + pos0;
pos = npos;
if (mP[*it].onTer)
pos.y = getTerH(pos) + g_Height;
setPos(*it, pos);
if (addYawRoll==1) // todo: get from axis?
mP[*it].mYaw -= relA; // rot point yaw
else if (addYawRoll==2)
// todo: * mul by cos of yaw ?..
mP[*it].mRoll -= relA; // rot point roll
vMarks[*it].setPos(pos);
//Move1(*it, npos);
}
bSelChng = true;
}
// Mirror selected
void SplineEdit::MirrorSel(bool alt)
{
if (vSel.empty()) return;
std::vector<SplinePoint> mRev;
for (auto it = vSel.rbegin(); it != vSel.rend(); ++it)
mRev.push_back(mP[*it]);
int i = 0;
for (auto it = vSel.begin(); it != vSel.end(); ++it, ++i)
{
SplinePoint& p = mP[*it];
p = mRev[i];
p.mRoll = -p.mRoll;
if (p.aType == AT_Manual)
{ p.mYaw = p.mYaw+180.f;
if (p.mYaw > 360.f) p.mYaw -= 360.f;
}
}
recalcTangents();
Rebuild(true);
}
// Edit modify, controls +-
//--------------------------------------------------------------------------------------
void SplineEdit::AddWidth(Real relW) /// Width
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].width += relW;
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.width += relW; return; }
mP[iChosen].width += relW;
Rebuild();
}
void SplineEdit::AddYaw(Real relA, Real snapA, bool alt) /// Yaw
{
if (!vSel.empty()) { // rotate sel
RotateSel(snapA==0.f ? relA : (relA > 0.f ? snapA : -snapA),
// todo: get Z from camera
alt ? Vector3::UNIT_Z : Vector3::UNIT_Y, alt ? 2 : 1); return; }
if (iChosen == -1) { newP.mYaw += relA; return; }
if (snapA == 0.f) mP[iChosen].mYaw += relA;
else
{ Real a = mP[iChosen].mYaw; int i = a / snapA + (relA > 0.f ? 1 :-1); mP[iChosen].mYaw = i * snapA; }
Rebuild();
}
void SplineEdit::AddRoll(Real relA, Real snapA, bool alt) /// Roll
{
if (!vSel.empty()) { // scale sel
ScaleSel(relA * 0.02f);
bSelChng = true; return; }
if (iChosen == -1) { newP.mRoll += relA; return; }
if (snapA == 0.f) mP[iChosen].mRoll += relA;
else
{ Real a = mP[iChosen].mRoll; int i = a / snapA + (relA > 0.f ? 1 :-1); mP[iChosen].mRoll = i * snapA; }
Rebuild();
}
void SplineEdit::AddPipe(Real relP) /// Pipe
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].pipe = std::max(0.f, std::min(1.f, mP[*it].pipe + relP));
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.pipe = std::max(0.f, std::min(1.f, newP.pipe + relP)); return; }
mP[iChosen].pipe = std::max(0.f, std::min(1.f, mP[iChosen].pipe + relP));
Rebuild();
}
// toggle
void SplineEdit::ToggleOnTerrain() /// ⛰️ On Ter
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].onTer = !mP[*it].onTer;
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.onTer = !newP.onTer; return; }
mP[iChosen].onTer = !mP[iChosen].onTer;
if (mP[iChosen].onTer)
Move(Vector3::ZERO);
}
void SplineEdit::ToggleColumn() /// Column
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].cols = 1-mP[*it].cols;
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.cols = 1-newP.cols; return; }
mP[iChosen].cols = 1-mP[iChosen].cols;
Move(Vector3::ZERO);
}
void SplineEdit::ToggleOnPipe(bool old) /// ⭕ On Pipe (old for stats only, new also flips normal)
{
#define onp(o) old ? (o ? 0 : 1) : (o ? 0 : 2)
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].onPipe = onp(mP[*it].onPipe);
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.onPipe = onp(newP.onPipe); return; }
mP[iChosen].onPipe = onp(mP[iChosen].onPipe);
Move(Vector3::ZERO);
}
void SplineEdit::ToggleNotReal() /// Not Real (not drivable road)
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].notReal = !mP[*it].notReal;
return; }
if (iChosen == -1) { // one
newP.notReal = !newP.notReal; return; }
mP[iChosen].notReal = !mP[iChosen].notReal;
}
void SplineEdit::ChgLoopType(int rel) /// ➰ Loop type, (camera change on chk, pacenotes)
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].loop = (LoopTypes+ mP[*it].loop + rel)%LoopTypes;
return; }
if (iChosen == -1) { // one
newP.loop = (LoopTypes+ newP.loop + rel)%LoopTypes; return; }
mP[iChosen].loop = (LoopTypes+ mP[iChosen].loop + rel)%LoopTypes;
}
void SplineEdit::ChgMtrId(int rel) /// Mtr Id
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].idMtr = std::max(-1, std::min(MTRs-1, mP[*it].idMtr + rel));
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.idMtr = std::max(-1, std::min(MTRs-1, newP.idMtr + rel)); return; }
mP[iChosen].idMtr = std::max(-1, std::min(MTRs-1, mP[iChosen].idMtr + rel));
Move(Vector3::ZERO);
}
void SplineEdit::ChgWallId(int rel) /// Wall Id
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].idWall = std::max(-1, std::min(MTRs-1, mP[*it].idWall + rel));
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.idWall = std::max(-1, std::min(MTRs-1, newP.idWall + rel)); return; }
mP[iChosen].idWall = std::max(-1, std::min(MTRs-1, mP[iChosen].idWall + rel));
Move(Vector3::ZERO);
}
void SplineEdit::ChgAngType(int rel) /// Ang Type
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mP[*it].aType = (AngType)std::max(0, std::min(AT_ALL-1, mP[*it].aType + rel));
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.aType = (AngType)std::max(0, std::min(AT_ALL-1, newP.aType + rel)); return; }
mP[iChosen].aType = (AngType)std::max(0, std::min(AT_ALL-1, mP[iChosen].aType + rel));
Move(Vector3::ZERO);
}
void SplineEdit::AngZero() /// Angles set 0
{
if (!vSel.empty()) { // sel
for (auto it = vSel.begin(); it != vSel.end(); ++it)
{ mP[*it].mYaw = 0; mP[*it].mRoll = 0; }
bSelChng = true; return; }
if (iChosen == -1) { // one
newP.mYaw = 0; newP.mRoll = 0; return; }
mP[iChosen].mYaw = 0; mP[iChosen].mRoll = 0;
Move(Vector3::ZERO);
}
#endif
//-----------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
// util
bool SplineRoad::isPipe(int seg)
{
int seg1 = (seg+1) % getNumPoints();
return mP[seg].pipe > 0.f || mP[seg1].pipe > 0.f;
}
// materials
// info text only
const String& SplineRoad::getMtrStr(int seg)
{
static String sHid = TR("#{Hidden}");
if (seg < 0) // new
{
int i = newP.idMtr;
if (i==-1) return sHid;
return newP.pipe == 0.f ? sMtrRoad[i] : sMtrPipe[i];
}
int i = mP[seg].idMtr;
if (i==-1) return sHid;
return !isPipe(seg) ? sMtrRoad[i] : sMtrPipe[i];
}
const String& SplineRoad::getWallMtrStr(int seg)
{
static String sHid = TR("#{Hidden}");
if (seg < 0) // new
{
int i = newP.idWall;
if (i==-1) return sHid;
return newP.pipe == 0.f ? sMtrWall : sMtrWallPipe;
}
int i = mP[seg].idWall;
if (i==-1) return sHid;
return !isPipe(seg) ? sMtrWall : sMtrWallPipe; //todo: more [i]..
}
void SplineRoad::SetMtrPipe(int i, String sMtr)
{
sMtrPipe[i] = sMtr; // check if glass in mtr name
bMtrPipeGlass[i] = strstr(sMtr.c_str(), "lass") != 0;
// LogO("bMtrPipeGlass: " + sMtr +" ="+ toStr(bMtrPipeGlass[i] ? 1 : 0));
}
void SplineRoad::updMtrRoadTer()
{
auto* pre = pApp->scn->data->pre;
HlmsManager* hlms = pApp->mRoot->getHlmsManager();
for (int i=0; i < MTRs; ++i)
{
bMtrRoadTer[i] = hlms->getDatablockNoDefault( sMtrRoad[i] + "_ter" );
bMtrPipeGlass[i] = strstr(sMtrPipe[i].c_str(), "lass") != 0;
auto* rd = pre->GetRoad(sMtrRoad[i]);
bMtrAlpha[i] = rd && rd->alpha;
// LogO("bMtrAlpha: " + sMtrRoad[i] +" ="+ toStr(bMtrAlpha[i] ? 1 : 0));
}
}
/// Add point
///-------------------------------------------------------------------------------------
void SplineRoad::Insert(eIns ins)
{
RoadSeg rs; SplinePoint pt = newP; // new
pt.chk1st = false; // clear 1st chk
if (pt.onTer)
pt.pos.y = getTerH(pt.pos) + g_Height;
if (ins == INS_Begin)
iChosen = -1;
if (ins == INS_End) // end
{
mP.push_back(pt); //recalcTangents();
vSegs.push_back(rs);
iChosen = getNumPoints()-1; //sel last
}
else if (iChosen == -1) // begin or none sel
{
mP.push_front(pt);
vSegs.push_front(rs); //recalcTangents();
}
else // middle
{
if (ins == INS_CurPre) // divide in middle
{
SplinePoint p1 = mP[iChosen];
SplinePoint p2 = mP[getNext(iChosen)];
pt = p1;
pt.pos = interpolate(iChosen, 0.5f);
pt.width = interpWidth(iChosen, 0.5f);
pt.aRoll += (p2.aRoll - p1.aRoll) * 0.5f;
pt.aYaw += (p2.aYaw - p1.aYaw ) * 0.5f;
pt.pipe += (p2.pipe - p1.pipe ) * 0.5f;
}
mP.insert(mP.begin()+iChosen+1, pt);
vSegs.insert(vSegs.begin()+iChosen+1, rs);
if (ins == INS_Cur) // INS_CurPre
++iChosen;
}
recalcTangents();
AddMarker(pt.pos);
if (ins != INS_End)
UpdAllMarkers();/**/
Rebuild(/*true*/);
}
#ifdef SR_EDITOR
//-----------------------------------------------------------------------------------------------------------------------------------------
/// Delete point
///-------------------------------------------------------------------------------------
void SplineRoad::Delete()
{
if (iChosen == -1) return;
bool last = (iChosen == getNumPoints()-1);
// remove from sel all ?.
vSel.erase(getNumPoints()-1);
DestroySeg(iChosen);
DelLastMarker();/**/
lastNdChosen = 0;
if (last) mP.pop_back();
else mP.erase(mP.begin() + iChosen);
if (last) vSegs.pop_back();
else vSegs.erase(vSegs.begin() + iChosen);
if (iChosen >= getNumPoints())
iChosen = getNumPoints()-1;
//iChosen = -1; // cancel sel-
recalcTangents();
UpdAllMarkers();
Rebuild(/*true*/);
}
/// selection copy, paste, delete
//--------------------------------------------------------------------------------------
std::deque<SplinePoint> SplineBase::mPc; // copy points
bool SplineRoad::CopySel()
{
if (vSel.empty()) return false;
mPc.clear();
for (auto it = vSel.begin(); it != vSel.end(); ++it)
mPc.push_back(mP[*it]);
return true;
}
void SplineRoad::Paste(bool reverse)
{
if (!bHitTer || iChosen==-1 || mPc.size()==0) return;
Vector3 c(0,0,0); // center of sel points
for (int i=0; i < mPc.size(); ++i)
c += mPc[i].pos;
c *= 1.f / Real(mPc.size());
c.y = 0.f; //c xz only
vSel.clear();
for (int i=0; i < mPc.size(); ++i)
{
newP = mPc[i]; // [!reverse ? i : mPc.size()-1-i];
newP.pos += posHit - c; // move center to hit pos
Insert(INS_Cur/*INS_CurPre*/);
vSel.insert(iChosen); // select just inserted
}
if (reverse) // rot 180
RotateSel(180, Vector3::UNIT_Y, 1);
Rebuild(true);
}
void SplineRoad::DelSel()
{
if (vSel.empty()) return;
for (auto it = vSel.rbegin(); it != vSel.rend(); ++it)
{
iChosen = *it;
//Delete();
bool last = (iChosen == getNumPoints()-1);
DestroySeg(iChosen);
DelLastMarker();/**/
lastNdChosen = 0;
if (last) mP.pop_back();
else mP.erase(mP.begin() + iChosen);
if (last) vSegs.pop_back();
else vSegs.erase(vSegs.begin() + iChosen);
}
if (iChosen >= getNumPoints())
iChosen = getNumPoints()-1;
vSel.clear();
recalcTangents();
UpdAllMarkers();
Rebuild(true);
}
/// 👆📍 Pick marker // Mr Mick Parker
//---------------------------------------------------------------------------------------------------------------
void SplineRoad::Pick(Camera* mCamera, Real mx, Real my,
bool bRay, bool bAddH, bool bHide, Real terSize)
{
iSelPoint = -1;
//if (vMarkNodes.size() != getNumPoints())
// return; // assert
const Ray ray = mCamera->getCameraToViewportRay(mx,my); // 0..1
Vector3 pos = mCamera->getDerivedPosition();
const Vector3 dir = ray.getDirection();
const Plane& pl = mCamera->getFrustumPlane(FRUSTUM_PLANE_NEAR);
Real plDist = FLT_MAX;
const Real sphR = 2.4f; //par
for (int i=0; i < (int)getNumPoints(); ++i)
{
// ray to sphere dist
const Vector3& posSph = getPos(i);
const Vector3 ps = pos - posSph;
Vector3 crs = ps.crossProduct(dir);
Real dist = crs.length() / dir.length();
// dist to camera
Real plD = pl.getDistance(posSph);
if (dist < sphR &&
plD > 0 && plD < plDist)
{
plDist = plD;
iSelPoint = i;
}
}
SelectMarker(bHide);
// hide/show all markers
int iHide = bHide ? 1 : 0;
if (iHide != iOldHide)
{ iOldHide = iHide;
for (size_t i=0; i < vMarks.size(); ++i)
vMarks[i].setVis(!bHide);
}
// ⛰️📍 Terrain hit pos, ray step --------
if (!bRay || !ndHit || !scn) return;
bHitTer = false;
/// 🎯 manual ray cast -----------
const Real minStep = 0.001f, maxDist = terSize * 1.5f; // par?
Real dist = 0.f, step = terSize * 0.001f;
bool ok = true;
while (dist < maxDist && step > minStep && ok)
{
Vector3 posTer = pos + dir * (dist + step),
pos1 = posTer;
scn->getTerH( scn->terCur, posTer );
bool hit = pos1.y < posTer.y;
if (!hit)
dist += step; // move forward
if (hit)
{ step *= 0.1f; // lower step, don't move
// if (posTer.y - pos1.y <= step)
// ok = false;
bHitTer = true;
posHit = posTer;
auto d = pos - posHit;
fHitDist = d.length();
}
}
ndHit->setVisible(bHitTer && pApp->bEdit() );
if (bHitTer)
{
Vector3 pos = posHit;
//if (iChosen == -1) // for new
if (!newP.onTer && bAddH)
pos.y = newP.pos.y;
ndHit->setPosition(pos);
ndHit->_getFullTransformUpdated();
}
}
#endif
//-----------------------------------------------------------------------------------------------------------------------------------------