1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2010 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGDepthSortTreeBuilder.h"
40 #include "OSGRenderActionBase.h"
41 #include "OSGRenderPartition.h"
45 DepthSortTreeBuilder::DepthSortTreeBuilder(void) :
50 DepthSortTreeBuilder::~DepthSortTreeBuilder(void)
55 DepthSortTreeBuilder::add(RenderActionBase
*pAction
,
56 RenderPartitionBase
*pPart
,
57 DrawFunctor
&drawFunc
,
59 StateOverride
*pStateOverride
)
61 RenderPartition
*pRPart
= dynamic_cast<RenderPartition
*>(pPart
);
62 RenderTreeNode
*pNode
= _pNodePool
->create
<RenderTreeNode
>(_uiNodePoolIdx
);
64 OSG::Node
*pActNode
= pAction
->getActNode();
67 pActNode
->getVolume().getCenter(objPos
);
69 #ifndef OSG_ENABLE_DOUBLE_MATRIX_STACK
70 pRPart
->getModelViewMatrix().mult(objPos
, objPos
);
71 pRPart
->getProjectionTrans().mult(objPos
, objPos
);
73 pNode
->setScalar (objPos
[2] );
74 pNode
->setMatrixStore(pRPart
->getMatrixStackTop());
76 Pnt3d
tmpPos(objPos
[0], objPos
[1], objPos
[2]);
77 pRPart
->getModelViewMatrix().mult(tmpPos
, tmpPos
);
79 // convert back to Real32 (proj trans is only Matrix4f)
80 objPos
[0] = tmpPos
[0];
81 objPos
[1] = tmpPos
[1];
82 objPos
[2] = tmpPos
[2];
83 pRPart
->getProjectionTrans().mult(objPos
, objPos
);
86 tmpMat
.convertFrom(pRPart
->getModelViewMatrix());
87 MatrixStore
tmpMS(pRPart
->getMatrixStackTop().first
, tmpMat
);
89 pNode
->setScalar (objPos
[2]);
90 pNode
->setMatrixStore(tmpMS
);
93 pNode
->setState (pState
);
94 pNode
->setStateOverride(pStateOverride
);
95 pNode
->setLightState (pRPart
->getLightState());
97 pNode
->setNode (pActNode
);
98 pNode
->setFunctor(drawFunc
);
101 Inherited::addNode(pNode
);