1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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 "nel/3d/u_transform.h"
20 #include "nel/3d/transform.h"
21 #include "nel/3d/instance_group_user.h"
22 #include "nel/misc/hierarchical_timer.h"
23 #include "nel/3d/scene_group.h"
24 #include "nel/3d/scene.h"
26 H_AUTO_DECL( NL3D_Transform_Set_Cluster_System
)
28 #define NL3D_HAUTO_SET_CLUSTER_SYSTEM H_AUTO_USE( NL3D_Transform_Set_Cluster_System )
31 using namespace NLMISC
;
40 // ***************************************************************************
41 void UTransform::setClusterSystem (UInstanceGroup
*pIG
)
43 NL3D_HAUTO_SET_CLUSTER_SYSTEM
45 CTransform
*object
= getObjectPtr();
46 if (object
->getForceClipRoot())
48 nlwarning("Transform has been flagged to be glued to the root, and thus can't be clusterized. See UTransform::setForceClipRoot(bool).");
51 if ((pIG
== NULL
) || (pIG
== (UInstanceGroup
*)-1))
54 object
->setClusterSystem (NULL
);
56 object
->setClusterSystem ((CInstanceGroup
*)-1);
59 object
->setClusterSystem (&((CInstanceGroupUser
*)pIG
)->getInternalIG());
62 // ***************************************************************************
63 UInstanceGroup
*UTransform::getClusterSystem () const
65 CTransform
*object
= getObjectPtr();
66 CInstanceGroup
*ig
= object
->getClusterSystem();
67 if(ig
==((CInstanceGroup
*)-1))
68 return ((UInstanceGroup
*)-1);
72 return ig
->getUserInterface();
75 // ***************************************************************************
76 void UTransform::getLastParentClusters(std::vector
<CCluster
*> &clusters
) const
78 CTransform
*object
= getObjectPtr();
79 CScene
*scene
= object
->getOwnerScene();
80 // look in the list of parent of the transform object and extract the CCluster parents
84 CClipTrav
&clipTrav
= scene
->getClipTrav();
86 uint num
= object
->clipGetNumParents();
87 for(uint i
=0;i
<num
;i
++)
89 CCluster
*pcluster
= dynamic_cast<CCluster
*>(object
->clipGetParent(i
));
91 clusters
.push_back(pcluster
);
94 // If the object is link to a QuadCluster, add the RootCluster to the list
95 CTransformShape
*trShp
= dynamic_cast<CTransformShape
*>( object
);
96 if( trShp
&& trShp
->isLinkToQuadCluster() )
97 clusters
.push_back(clipTrav
.RootCluster
);
101 // ***************************************************************************
102 void UTransform::freezeHRC()
104 CTransform
*object
= getObjectPtr();
108 // ***************************************************************************
109 void UTransform::unfreezeHRC()
111 CTransform
*object
= getObjectPtr();
114 object
->unfreezeHRC();
115 object
= object
->hrcGetParent();
120 // ***************************************************************************
121 void UTransform::setLoadBalancingGroup(const std::string
&group
)
123 CTransform
*object
= getObjectPtr();
124 object
->setLoadBalancingGroup(group
);
126 // ***************************************************************************
127 const std::string
&UTransform::getLoadBalancingGroup() const
129 CTransform
*object
= getObjectPtr();
130 return object
->getLoadBalancingGroup();
133 // ***************************************************************************
134 void UTransform::setMeanColor(NLMISC::CRGBA color
)
136 CTransform
*object
= getObjectPtr();
137 object
->setMeanColor(color
);
139 // ***************************************************************************
140 NLMISC::CRGBA
UTransform::getMeanColor() const
142 CTransform
*object
= getObjectPtr();
143 return object
->getMeanColor();
146 // ***************************************************************************
147 const CMatrix
&UTransform::getLastWorldMatrixComputed() const
149 CTransform
*object
= getObjectPtr();
150 return object
->getWorldMatrix();
153 // ***************************************************************************
154 void UTransform::enableCastShadowMap(bool state
)
156 CTransform
*object
= getObjectPtr();
157 object
->enableCastShadowMap(state
);
160 // ***************************************************************************
161 bool UTransform::canCastShadowMap() const
163 CTransform
*object
= getObjectPtr();
164 return object
->canCastShadowMap();
167 // ***************************************************************************
168 void UTransform::enableReceiveShadowMap(bool state
)
170 CTransform
*object
= getObjectPtr();
171 object
->enableReceiveShadowMap(state
);
174 // ***************************************************************************
175 bool UTransform::canReceiveShadowMap() const
177 CTransform
*object
= getObjectPtr();
178 return object
->canReceiveShadowMap();
181 // ***************************************************************************
182 void UTransform::parent(UTransform newFather
)
184 CTransform
*object
= getObjectPtr();
185 if (object
->getForceClipRoot())
187 nlwarning("Transform has been flagged to be glued to the root, can't change parent. See UTransform::setForceClipRoot(bool).");
190 if(!newFather
.empty())
193 CTransform
*other
= newFather
.getObjectPtr();
194 if(other
->getOwnerScene()!=object
->getOwnerScene())
195 nlerror("Try to parent 2 object from 2 differnet scenes!!");
196 other
->hrcLinkSon( object
);
201 object
->getOwnerScene()->getRoot()->hrcLinkSon( object
);
205 // ***************************************************************************
206 void UTransform::hide()
208 CTransform
*object
= getObjectPtr();
212 // ***************************************************************************
214 void UTransform::show()
216 CTransform
*object
= getObjectPtr();
220 // ***************************************************************************
222 void UTransform::setUserClipping(bool enable
)
224 CTransform
*object
= getObjectPtr();
225 object
->setUserClipping(enable
);
228 // ***************************************************************************
230 bool UTransform::getUserClipping() const
232 CTransform
*object
= getObjectPtr();
233 return object
->getUserClipping();
236 // ***************************************************************************
238 void UTransform::heritVisibility()
240 CTransform
*object
= getObjectPtr();
241 object
->heritVisibility();
244 // ***************************************************************************
246 UTransform::TVisibility
UTransform::getVisibility()
248 CTransform
*object
= getObjectPtr();
249 return (UTransform::TVisibility
)(uint32
)object
->getVisibility();
252 // ***************************************************************************
254 void UTransform::setOrderingLayer(uint layer
)
256 CTransform
*object
= getObjectPtr();
257 object
->setOrderingLayer(layer
);
260 // ***************************************************************************
262 uint
UTransform::getOrderingLayer() const
264 CTransform
*object
= getObjectPtr();
265 return object
->getOrderingLayer();
268 // ***************************************************************************
270 void UTransform::setUserLightable(bool enable
)
272 CTransform
*object
= getObjectPtr();
273 object
->setUserLightable(enable
);
276 // ***************************************************************************
278 bool UTransform::getUserLightable() const
280 CTransform
*object
= getObjectPtr();
281 return object
->getUserLightable();
284 // ***************************************************************************
286 void UTransform::setLogicInfo(ILogicInfo
*logicInfo
)
288 CTransform
*object
= getObjectPtr();
289 object
->setLogicInfo(logicInfo
);
292 // ***************************************************************************
294 bool UTransform::getLastWorldVisState() const
296 CTransform
*object
= getObjectPtr();
297 return object
->isHrcVisible();
300 // ***************************************************************************
302 bool UTransform::getLastClippedState() const
304 CTransform
*object
= getObjectPtr();
305 return object
->isClipVisible();
308 // ***************************************************************************
310 void UTransform::setTransparency(bool v
)
312 CTransform
*object
= getObjectPtr();
313 object
->setTransparency(v
);
316 // ***************************************************************************
318 void UTransform::setOpacity(bool v
)
320 CTransform
*object
= getObjectPtr();
321 object
->setOpacity(v
);
324 // ***************************************************************************
325 void UTransform::setBypassLODOpacityFlag(bool bypass
)
327 CTransform
*object
= getObjectPtr();
328 object
->setBypassLODOpacityFlag(bypass
);
331 // ***************************************************************************
333 uint32
UTransform::isOpaque()
335 CTransform
*object
= getObjectPtr();
336 return object
->isOpaque();
339 // ***************************************************************************
341 uint32
UTransform::isTransparent()
343 CTransform
*object
= getObjectPtr();
344 return object
->isTransparent();
347 // ***************************************************************************
349 void UTransform::setForceClipRoot(bool forceClipRoot
)
351 CTransform
*object
= getObjectPtr();
352 object
->setForceClipRoot(forceClipRoot
);
355 // ***************************************************************************
357 bool UTransform::getForceClipRoot() const
359 CTransform
*object
= getObjectPtr();
360 return object
->getForceClipRoot();
363 // ***************************************************************************
365 void UTransform::setTransparencyPriority(uint8 priority
)
367 CTransform
*object
= getObjectPtr();
368 object
->setTransparencyPriority(priority
);
371 // ***************************************************************************
372 void UTransform::setShadowMapDirectionZThreshold(float zthre
)
374 CTransform
*object
= getObjectPtr();
375 object
->setShadowMapDirectionZThreshold(zthre
);
378 // ***************************************************************************
379 float UTransform::getShadowMapDirectionZThreshold() const
381 CTransform
*object
= getObjectPtr();
382 return object
->getShadowMapDirectionZThreshold();
385 // ***************************************************************************
386 void UTransform::setShadowMapMaxDepth(float depth
)
388 CTransform
*object
= getObjectPtr();
389 object
->setShadowMapMaxDepth(depth
);
392 // ***************************************************************************
393 float UTransform::getShadowMapMaxDepth() const
395 CTransform
*object
= getObjectPtr();
396 return object
->getShadowMapMaxDepth();
399 // ***************************************************************************
400 bool UTransform::supportFastIntersect() const
402 CTransform
*object
= getObjectPtr();
403 return object
->supportFastIntersect();
406 // ***************************************************************************
407 bool UTransform::fastIntersect(const NLMISC::CVector
&p0
, const NLMISC::CVector
&dir
, float &dist2D
, float &distZ
, bool computeDist2D
)
409 CTransform
*object
= getObjectPtr();
410 return object
->fastIntersect(p0
, dir
, dist2D
, distZ
, computeDist2D
);