1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "group_in_scene.h"
28 #include "interface_manager.h"
29 #include "nel/gui/view_renderer.h"
30 #include "nel/misc/xml_auto_ptr.h"
33 using namespace NLMISC
;
35 extern CMatrix MainSceneViewMatrix
;
36 extern CMatrix InvMainSceneViewMatrix
;
39 // ***************************************************************************
40 const float CGroupInScene::NearDrawClip
= 1.f
;
43 // ***************************************************************************
44 NLMISC_REGISTER_OBJECT(CViewBase
, CGroupInScene
, std::string
, "in_scene");
46 REGISTER_UI_CLASS(CGroupInScene
)
48 CGroupInScene::CGroupInScene(const TCtorParam
¶m
)
49 : CInterfaceGroup(param
)
51 // Group in scene must update each frame
52 _NeedFrameUpdatePos
= true;
62 Position
= CVector::Null
;
64 _ProjCenter
= CVector::Null
;
65 _IsGroupInScene
= true;
68 // ***************************************************************************
69 CGroupInScene::~CGroupInScene()
73 // ***************************************************************************
74 void CGroupInScene::computeWindowPos(sint32
&newX
, sint32
&newY
, CVector
&newProjCenter
)
76 // don't change X/Y by default
79 newProjCenter
.x
= float(_X
) - _OffsetX
;
80 newProjCenter
.y
= float(_Y
) - _OffsetY
;
84 CViewRenderer
&pVR
= *CViewRenderer::getInstance();
85 nlassert(isValidDouble(Position
.x
) && isValidDouble(Position
.y
) && isValidDouble(Position
.z
));
86 CVector tmp
= MainSceneViewMatrix
* Position
;
89 tmp
= pVR
.getFrustum().projectZ (tmp
);
91 // Get the width and height
93 CViewRenderer::getInstance()->getScreenSize(width
, height
);
97 // position without offset, in float
98 newProjCenter
.x
= tmp
.x
;
99 newProjCenter
.y
= tmp
.y
;
102 newProjCenter
.z
= -tmp
.z
;
103 _DepthForZSort
= newProjCenter
.z
;
104 // Add ZBias (only if won't be clipped)
105 if(newProjCenter
.z
> NearDrawClip
)
107 newProjCenter
.z
+= getZBias();
108 const float zthreshold
= 0.01f
;
109 newProjCenter
.z
= max(newProjCenter
.z
, pVR
.getFrustum().Near
+zthreshold
);
110 newProjCenter
.z
= max(newProjCenter
.z
, NearDrawClip
+ zthreshold
);
114 newX
= (sint
)floor (tmp
.x
+0.5f
) + _OffsetX
;
115 newY
= (sint
)floor (tmp
.y
+0.5f
) + _OffsetY
;
119 _DepthForZSort
= newProjCenter
.z
= tmp
.y
;
124 _DepthForZSort
= newProjCenter
.z
= -1.f
;
127 nlassert (isValidDouble (newProjCenter
.z
));
130 // ***************************************************************************
131 void CGroupInScene::updateCoords()
133 // Get the x and the y
134 computeWindowPos(_X
, _Y
, _ProjCenter
);
136 CInterfaceGroup::updateCoords();
139 // ***************************************************************************
140 void CGroupInScene::onFrameUpdateWindowPos (sint dx
, sint dy
)
142 // I am the root group, so I decide of the new window position.
144 computeWindowPos(newX
, newY
, _ProjCenter
);
149 // Change the X and Y only here
153 // CInterfaceGroup::onFrameUpdateWindowPos will apply the delta on XReal / YReal
154 CInterfaceGroup::onFrameUpdateWindowPos(dx
, dy
);
157 // ***************************************************************************
158 void CGroupInScene::draw()
160 H_AUTO( RZ_Interface_CGroupInScene_draw
)
162 if (_ProjCenter
.z
> NearDrawClip
)
164 CViewRenderer
&pVR
= *CViewRenderer::getInstance();
166 // Set the current Z, and projCenter / scale
168 pVR
.setInterfaceDepth (_ProjCenter
, Scale
);
170 pVR
.setInterfaceDepth (_ProjCenter
, 1);
172 CInterfaceGroup::draw();
176 // ***************************************************************************
178 bool CGroupInScene::parse (xmlNodePtr cur
, CInterfaceGroup
*parent
)
180 if (!CInterfaceGroup::parse (cur
, parent
))
186 ptr
= xmlGetProp (cur
, (xmlChar
*)"in_scene_offset_x");
188 fromString((const char*)ptr
, _OffsetX
);
190 ptr
= xmlGetProp (cur
, (xmlChar
*)"in_scene_offset_y");
192 fromString((const char*)ptr
, _OffsetY
);
194 ptr
= xmlGetProp (cur
, (xmlChar
*)"user_scale");
196 _UserScale
= convertBool(ptr
);
201 // ***************************************************************************
202 void CGroupInScene::setUserScale(bool swd
)
207 // ***************************************************************************
208 void CGroupInScene::serial(NLMISC::IStream
&f
)
210 CInterfaceGroup::serial(f
);
213 f
.serial(_UserScale
);