Action::ResultE ShadingCallbacks::matDrawableRenderEnter(CNodePtr &pNode, Action *action) { ShadingAction *a = dynamic_cast<ShadingAction *>(action ); MaterialDrawable *pMD = dynamic_cast<MaterialDrawable *>(pNode.getCPtr()); Material::DrawFunctor func; func = osgTypedMethodFunctor1ObjPtr(pMD, &MaterialDrawable::drawPrimitives); Material *m = a->getMaterial(); if(m == NULL) { if(pMD->getMaterial() != NullFC) { m = pMD->getMaterial().getCPtr(); } else { fprintf(stderr, "MaterialDrawable::render: no Material!?!\n"); return Action::Continue; } } a->dropFunctor(func, m); return Action::Continue; }
Action::ResultE ShadingCallbacks::switchRender(CNodePtr &pNode, Action *action) { Action::ResultE returnValue = Action::Continue; DrawActionBase *da = dynamic_cast<DrawActionBase *>(action ); Switch *pSw = dynamic_cast<Switch *>(pNode.getCPtr()); if((pSw->getChoice() >= 0 ) && (pSw->getChoice() < action->getNNodes()) ) { da->useNodeList(); if(da->isVisible(action->getNode(pSw->getChoice()).getCPtr())) { da->addNode(action->getNode(pSw->getChoice())); } } else if(pSw->getChoice() == Switch::ALL) { if(da->selectVisibles() == 0) returnValue = Action::Skip; } else { returnValue = Action::Skip; } return returnValue; }
Action::ResultE ShadingCallbacks::spotlightRenderLeave(CNodePtr &pNode, Action *action) { SpotLight *pSp = dynamic_cast<SpotLight *>(pNode.getCPtr()); if(pSp->getOn() == false) return Action::Continue; return lightRenderLeave(pSp, action); }
Action::ResultE ShadingCallbacks::pointlightRenderLeave(CNodePtr &pNode, Action *action) { PointLight *pPl = dynamic_cast<PointLight *>(pNode.getCPtr()); if(pPl->getOn() == false) return Action::Continue; return lightRenderLeave(pPl, action); }
Action::ResultE ShadingCallbacks::dirlightRenderLeave(CNodePtr &pNode, Action *action) { DirectionalLight *pDl = dynamic_cast<DirectionalLight *>(pNode.getCPtr()); if(pDl->getOn() == false) return Action::Continue; return lightRenderLeave(pDl, action); }
Action::ResultE ShadingCallbacks::transformRenderEnter(CNodePtr &pNode, Action *action) { ShadingAction *pAct = dynamic_cast<ShadingAction *>(action ); Transform *pTr = dynamic_cast<Transform *>(pNode.getCPtr()); pAct->push_matrix(pTr->getMatrix()); pAct->selectVisibles(); return Action::Continue; }
Action::ResultE ShadingCallbacks::matGroupRenderEnter(CNodePtr &pNode, Action *action) { ShadingAction *da = dynamic_cast<ShadingAction *>(action ); MaterialGroup *pMG = dynamic_cast<MaterialGroup *>(pNode.getCPtr()); if(da != NULL && pMG->getSFMaterial()->getValue() != NullFC) { da->setMaterial(&(*(pMG->getSFMaterial()->getValue()))); } return Action::Continue; }
Action::ResultE ShadingCallbacks::spotlightRenderEnter(CNodePtr &pNode, Action *action) { SpotLight *pSp = dynamic_cast<SpotLight *>(pNode.getCPtr()); if(pSp->getOn() == false) return Action::Continue; DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); da->getStatistics()->getElem(SpotLight::statNSpotLights)->inc(); return pointlightRenderEnter(pNode, action); }
Action::ResultE ShadingCallbacks::dirlightRenderEnter(CNodePtr &pNode, Action *action) { DirectionalLight *pDl = dynamic_cast<DirectionalLight *>(pNode.getCPtr()); if(pDl->getOn() == false) return Action::Continue; DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); da->getStatistics()->getElem( DirectionalLight::statNDirectionalLights)->inc(); return lightRenderEnter(pDl, action); }
OSG_USING_NAMESPACE Action::ResultE ShadingCallbacks::billboardRenderEnter(CNodePtr &pNode, Action *action) { ShadingAction *pAct = dynamic_cast<ShadingAction *>(action ); Billboard *pBB = dynamic_cast<Billboard *>(pNode.getCPtr()); Matrix mMat; // cerr << "BB::render" << std::endl; pBB->calcMatrix(pAct, pAct->top_matrix(), mMat); pAct->push_matrix(mMat); // !!! can't use visibles, as ToWorld gives garbage leading to wrong culling // pAct->selectVisibles(); return Action::Continue; }
Action::ResultE ShadingCallbacks::distanceLODRender(CNodePtr &pNode, Action *action) { DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); ShadingAction *ra = dynamic_cast<ShadingAction *>(action); DistanceLOD *pDLOD = dynamic_cast<DistanceLOD *>(pNode.getCPtr()); UInt32 numLevels = action->getNNodes (); UInt32 numRanges = pDLOD ->getMFRange()->size(); UInt32 limit = osgMin(numLevels, numRanges); Int32 index = -1; Pnt3f eyepos(0.f, 0.f, 0.f); Pnt3f objpos; da->getCameraToWorld().mult(eyepos); if(ra != NULL) { ra->top_matrix() .mult(pDLOD->getCenter(), objpos); } else { da->getActNode()->getToWorld().mult(pDLOD->getCenter(), objpos); } Real32 dist = osgsqrt((eyepos[0] - objpos[0])*(eyepos[0] - objpos[0]) + (eyepos[1] - objpos[1])*(eyepos[1] - objpos[1]) + (eyepos[2] - objpos[2])*(eyepos[2] - objpos[2])); da->useNodeList(); if(numRanges != 0 && numLevels!=0 ) { if(dist < (*(pDLOD->getMFRange()))[0]) { index = 0; } else if(dist >= (*(pDLOD->getMFRange()))[numRanges-1]) { index = (numLevels > numRanges) ? numRanges : (limit-1); } else { UInt32 i = 1; while( (i < numRanges) && !( ((*(pDLOD->getMFRange()))[i-1] <= dist) && (dist < (*(pDLOD->getMFRange()))[i] ) ) ) { i++; } index = osgMin(i, limit-1); } if(da->isVisible(action->getNode(index).getCPtr())) { da->addNode(action->getNode(index)); } } return Action::Continue; }