changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGScreenGroup.cpp
blob96dcd082d784884ddf3c115266ed71a8ddcb0207
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <stdlib.h>
44 #include <stdio.h>
46 #include "OSGConfig.h"
48 #include "OSGScreenGroup.h"
49 #include "OSGIntersectAction.h"
50 #include "OSGRenderAction.h"
51 #include "OSGViewport.h"
52 #include "OSGCamera.h"
54 OSG_BEGIN_NAMESPACE
56 /***************************************************************************\
57 * Description *
58 \***************************************************************************/
60 /*! \class OSG::ScreenGroup
63 /***************************************************************************\
64 * Class variables *
65 \***************************************************************************/
67 /***************************************************************************\
68 * Class methods *
69 \***************************************************************************/
71 void ScreenGroup::initMethod(InitPhase ePhase)
73 Inherited::initMethod(ePhase);
75 if(ePhase == TypeObject::SystemPost)
77 IntersectAction::registerEnterDefault(
78 ScreenGroup::getClassType(),
79 reinterpret_cast<Action::Callback>(&ScreenGroup::intersectEnter));
81 IntersectAction::registerLeaveDefault(
82 ScreenGroup::getClassType(),
83 reinterpret_cast<Action::Callback>(&ScreenGroup::intersectLeave));
85 RenderAction::registerEnterDefault(
86 ScreenGroup::getClassType(),
87 reinterpret_cast<Action::Callback>(&ScreenGroup::renderEnter));
89 RenderAction::registerLeaveDefault(
90 ScreenGroup::getClassType(),
91 reinterpret_cast<Action::Callback>(&ScreenGroup::renderLeave));
96 /***************************************************************************\
97 * Instance methods *
98 \***************************************************************************/
100 /*-------------------------------------------------------------------------*\
101 - private -
102 \*-------------------------------------------------------------------------*/
104 /*----------------------- constructors & destructors ----------------------*/
106 ScreenGroup::ScreenGroup(void) :
107 Inherited (),
108 _camTransform()
112 ScreenGroup::ScreenGroup(const ScreenGroup &source) :
113 Inherited (source ),
114 _camTransform(source._camTransform)
118 ScreenGroup::~ScreenGroup(void)
122 /*----------------------------- class specific ----------------------------*/
124 void ScreenGroup::changed(ConstFieldMaskArg whichField,
125 UInt32 origin,
126 BitVector details)
128 Inherited::changed(whichField, origin, details);
131 void ScreenGroup::dump( UInt32 ,
132 const BitVector ) const
134 SLOG << "Dump ScreenGroup NI" << std::endl;
138 /*------------------------- volume update -------------------------------*/
140 void ScreenGroup::adjustVolume(Volume &volume)
142 volume.transform(_camTransform);
145 void ScreenGroup::accumulateMatrix(Matrix &result)
147 result.mult(_camTransform);
150 void ScreenGroup::calcMatrix( RenderAction *pAction,
151 const Matrix &mToWorld,
152 Matrix &mResult )
154 const DrawEnv &oEnv = pAction->getActivePartition()->getDrawEnv();
156 Matrix mToScreen = oEnv.getVPWorldToScreen();
158 #if 0
159 Viewport *viewport = pAction->getViewport();
160 pAction->getCamera()->getWorldToScreen(mToScreen, *viewport);
161 #endif
163 mToScreen.mult(mToWorld);
165 Pnt3f origin(0.f, 0.f, 0.f);
167 mToScreen.multFull(origin, origin);
169 Pnt3f xAxis(1.f, 0.f, 0.f);
171 mToScreen.multFull(xAxis, xAxis);
173 Real32 scaleX =
174 2.f / oEnv.getPixelWidth() / (xAxis - origin).length();
176 Pnt3f yAxis(0.f, 1.f, 0.f);
178 mToScreen.multFull(yAxis, yAxis);
180 Real32 scaleY =
181 2.f / oEnv.getPixelHeight() / (yAxis - origin).length();
183 mResult.setScale (scaleX, scaleY, 1.f);
184 mResult.setTranslate(0.375 * scaleX, 0.375 * scaleY, 0.f);
186 bool equal = mResult.equals(_camTransform, 0.00001f);
188 _camTransform = mResult;
190 if(!equal)
191 this->invalidateVolume();
194 /*-------------------------------------------------------------------------*/
195 /* Intersect */
197 Action::ResultE ScreenGroup::intersectEnter(Action *action)
199 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
200 Matrix m(_camTransform);
202 m.invert();
204 Pnt3f pos;
205 Vec3f dir;
207 m.multFull(ia->getLine().getPosition (), pos);
208 m.mult (ia->getLine().getDirection(), dir);
210 ia->setLine(Line(pos, dir), ia->getMaxDist());
211 ia->scale(dir.length());
213 return Action::Continue;
216 Action::ResultE ScreenGroup::intersectLeave(Action *action)
218 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
219 Matrix m(_camTransform);
221 Pnt3f pos;
222 Vec3f dir;
224 m.multFull(ia->getLine().getPosition (), pos);
225 m.mult (ia->getLine().getDirection(), dir);
227 ia->setLine(Line(pos, dir), ia->getMaxDist());
228 ia->scale(dir.length());
230 return Action::Continue;
233 /*-------------------------------------------------------------------------*/
234 /* Render */
236 Action::ResultE ScreenGroup::renderEnter(Action *action)
238 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
240 Matrix mMat;
242 #if 0
243 if(!pAction->getEffectsPass())
244 calcMatrix(pAction, pAction->top_matrix(), mMat);
245 else
246 mMat = _camTransform;
247 #else
248 calcMatrix(pAction, pAction->topMatrix(), mMat);
249 #endif
251 pAction->pushMatrix(mMat);
253 // !!! can't use visibles, as ToWorld gives garbage leading to wrong culling
254 // pAction->selectVisibles();
256 return Action::Continue;
259 Action::ResultE ScreenGroup::renderLeave(Action *action)
261 RenderAction *pAction = dynamic_cast<RenderAction *>(action);
263 pAction->popMatrix();
265 return Action::Continue;
268 OSG_END_NAMESPACE