fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / RenderingBackend / OSGDepthSortTreeBuilder.cpp
blob42d01ac8667d50bc37290a44410a1eab9f914c7f
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2010 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 #include "OSGDepthSortTreeBuilder.h"
40 #include "OSGRenderActionBase.h"
41 #include "OSGRenderPartition.h"
43 OSG_BEGIN_NAMESPACE
45 DepthSortTreeBuilder::DepthSortTreeBuilder(void) :
46 Inherited()
50 DepthSortTreeBuilder::~DepthSortTreeBuilder(void)
54 void
55 DepthSortTreeBuilder::add(RenderActionBase *pAction,
56 RenderPartitionBase *pPart,
57 DrawFunctor &drawFunc,
58 State *pState,
59 StateOverride *pStateOverride)
61 RenderPartition *pRPart = dynamic_cast<RenderPartition *>(pPart);
62 RenderTreeNode *pNode = _pNodePool->create<RenderTreeNode>(_uiNodePoolIdx);
64 OSG::Node *pActNode = pAction->getActNode();
65 Pnt3f objPos;
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());
75 #else
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);
85 Matrix4f tmpMat;
86 tmpMat.convertFrom(pRPart->getModelViewMatrix());
87 MatrixStore tmpMS(pRPart->getMatrixStackTop().first, tmpMat);
89 pNode->setScalar (objPos[2]);
90 pNode->setMatrixStore(tmpMS );
91 #endif
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);
104 OSG_END_NAMESPACE