1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
19 #include "displayer_visual_road.h"
22 #include "../global.h"
29 using namespace NLMISC
;
36 // *********************************************************************************************************
37 CPrimRender2::CPrimRender2()
39 _VertexMeshs.setShapeName("road_flag.shape");
40 _EdgeMeshs.setShapeName("instance_link.shape");
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);
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)
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;
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);
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()
120 CVisualDisplayer::onCreate();
124 // *********************************************************************************************************
125 void CDisplayerVisualRoad::rebuild()
127 const CObject *points = getObject(&getProps(), "Points");
128 static volatile bool wantDump = false;
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);