Merge branch '138-toggle-free-look-with-hotkey' into main/gingo-test
[ryzomcore.git] / ryzom / client / src / r2 / displayer_visual_road.cpp
blob629ca47295d69a4e22092df3d097879a348d5142
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
19 #include "displayer_visual_road.h"
20 #include "instance.h"
21 #include "editor.h"
22 #include "../global.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 using namespace NLMISC;
30 using namespace NL3D;
32 namespace R2
36 // *********************************************************************************************************
37 CPrimRender2::CPrimRender2()
39 _VertexMeshs.setShapeName("road_flag.shape");
40 _EdgeMeshs.setShapeName("instance_link.shape");
41 _VertexScale = 1.f;
44 // *********************************************************************************************************
45 void CPrimRender2::setVertexShapeName(const std::string &name)
47 _VertexMeshs.setShapeName(name);
50 // *********************************************************************************************************
51 void CPrimRender2::setEdgeShapeName(const std::string &name)
53 _EdgeMeshs.setShapeName(name);
56 // *********************************************************************************************************
57 void CPrimRender2::setPoints(const std::vector<NLMISC::CVector> &wp, bool lastIsValid, bool closed)
59 uint iclosed = closed ? 1 : 0;
60 _VertexMeshs.resize(wp.size());
61 _EdgeMeshs.resize(std::max((sint) (wp.size() - 1 + iclosed), (sint) 0));
62 for(uint k = 0; k < wp.size(); ++k)
64 if (!_VertexMeshs[k].empty())
66 _VertexMeshs[k].setTransformMode(UTransform::DirectMatrix);
67 CMatrix flagMat;
68 flagMat.setPos(wp[k]);
69 flagMat.setScale(_VertexScale);
70 _VertexMeshs[k].setMatrix(flagMat);
71 _VertexMeshs[k].enableCastShadowMap(true);
73 if ((sint) k < (sint) (wp.size() - 1 + iclosed))
75 if (!_EdgeMeshs[k].empty())
77 if ((sint) k == (sint) (wp.size() - 2) && !lastIsValid)
79 _EdgeMeshs[k].hide();
81 else
83 CVector I = wp[(k + 1) % wp.size()] - wp[k];
84 CVector INormed = I.normed();
85 CVector K = (CVector::K - (CVector::K * INormed) * INormed).normed();
86 CVector J = K ^ INormed;
87 CMatrix connectorMat;
88 static volatile float scale =0.5f;
89 connectorMat.setRot(I, scale * J, scale * K);
90 connectorMat.setPos(wp[k]);
91 _EdgeMeshs[k].setTransformMode(UTransform::DirectMatrix);
92 _EdgeMeshs[k].setMatrix(connectorMat);
93 _EdgeMeshs[k].show();
100 // *********************************************************************************************************
101 void CPrimRender2::setEmissive(NLMISC::CRGBA color)
103 _VertexMeshs.setEmissive(color);
104 _EdgeMeshs.setEmissive(color);
110 // *********************************************************************************************************
111 CDisplayerVisualRoad::~CDisplayerVisualRoad()
116 // *********************************************************************************************************
117 void CDisplayerVisualRoad::onCreate()
119 rebuild();
120 CVisualDisplayer::onCreate();
124 // *********************************************************************************************************
125 void CDisplayerVisualRoad::rebuild()
127 const CObject *points = getObject(&getProps(), "Points");
128 static volatile bool wantDump = false;
129 if (wantDump)
131 points->dump();
133 if (!points) return;
134 std::vector<CVector> wayPoints;
135 wayPoints.resize(points->getSize());
136 for(uint k = 0; k < points->getSize(); ++k)
138 wayPoints[k] = getVector(points->getValue((uint32) k));
140 _Road.setWayPoints(wayPoints, true);
144 } // R2