void ColladaNode::handleRotate(domRotate *rotate) { if(rotate == NULL) return; domNodeRef node = getDOMElementAs<domNode>(); Vec3f axis(rotate->getValue()[0], rotate->getValue()[1], rotate->getValue()[2]); Real32 angle(rotate->getValue()[3]); if(getGlobal()->getOptions()->getFlattenNodeXForms()) { RotationTransformationElementUnrecPtr RotationElement = RotationTransformationElement::create(); RotationElement->setAxis(axis); RotationElement->setAngle(angle); setName(RotationElement, rotate->getSid()); appendStackedXForm(RotationElement, node); if(getGlobal()->editAnimationMap()[rotate] != NULL) { SLOG << "Found Rotation Animation" << std::endl; getGlobal()->editAnimationMap()[rotate]->getAnimation()->setAnimatedField(RotationElement,std::string("Angle")); } } else { TransformUnrecPtr xform = Transform::create(); NodeUnrecPtr xformN = makeNodeFor(xform); xform->editMatrix().setRotate(Quaternion(axis, osgDegree2Rad(angle))); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && node->getName() != NULL ) { std::string nodeName = node->getName(); if(rotate->getSid() != NULL&& getGlobal()->getOptions()->getFlattenNodeXForms() == false) { nodeName.append("." ); nodeName.append(rotate->getSid()); } setName(xformN, nodeName); } appendXForm(xformN); } }
void handleUpdate(UpdateEventDetails* const details, Transform* const TheSphereTransform) { static Real32 _TotalTime(0.0f); _TotalTime += details->getElapsedTime(); Matrix Translate; Translate.setTranslate(0.0,0.0,-5.0); Matrix Rotation; Rotation.setRotate(Quaternion(Vec3f(0.0,1.0,0.0), osgDegree2Rad(_TotalTime*80.0))); Matrix Total(Rotation); Total.mult(Translate); TheSphereTransform->setMatrix(Total); }
void particleCollision(ParticleGeometryCollisionEventDetails* const details) { ParticleSystemRefPtr TheSystem= details->getSystem(); UInt32 ParticleIndex(details->getParticleIndex()); Real32 phi= osgACos((-TheSystem->getVelocity(ParticleIndex).dot(details->getHitNormal()))/(TheSystem->getVelocity(ParticleIndex).length()*details->getHitNormal().length())); if( phi < osgDegree2Rad(80.0) ) { TheSystem->killParticle(ParticleIndex); } else { //Reflect the Particle Vec3f Reflect(TheSystem->getVelocity(ParticleIndex).reflect(details->getHitNormal())); TheSystem->setVelocity(Reflect, ParticleIndex); TheSystem->setPosition(details->getHitPoint() + (0.00001f*Reflect), ParticleIndex); } }
DXFResult DXFSpline::endEntity(void) { // float angleBase = DXFHeader::getAngBase(); int dir = DXFHeader::getAngDir(); double x, y, z; if(dir) //clockwise { _startAngle= 360 - _startAngle; _endAngle = 360 - _endAngle; } _startAngle += 360; _endAngle += 360; while(_startAngle > _endAngle) { _endAngle += 360; } x= _centerPoint[0] + _radius * cos(osgDegree2Rad(_startAngle)); y= _centerPoint[1] + _radius * sin(osgDegree2Rad(_startAngle)); z = _centerPoint[2]; _pointsP->push_back(OSG::Pnt3f(x,y,z)); int div = 10; int num = abs(_endAngle - _startAngle) / div; for(int i=1;i<num-1;i++) { x= _centerPoint[0] + _radius * cos(osgDegree2Rad(_startAngle + div * i)); y= _centerPoint[1] + _radius * sin(osgDegree2Rad(_startAngle + div * i)); z = _centerPoint[2]; _pointsP->push_back(OSG::Pnt3f(x,y,z)); } x= _centerPoint[0] + _radius * cos(osgDegree2Rad(_endAngle)); y= _centerPoint[1] + _radius * sin(osgDegree2Rad(_endAngle)); z = _centerPoint[2]; _pointsP->push_back(OSG::Pnt3f(x,y,z)); _faceTypeP->clear(); _faceLengthP->clear(); _faceTypeP ->push_back(GL_LINE_STRIP); _faceLengthP->push_back(num); flushGeometry(false); endGeometry(); return DXFStateContinue; }
void PlaneMoveManipulator::onCreate(const PlaneMoveManipulator* source) { // Skip direct parent, don't want the default geometry creation Transform::onCreate(source); SimpleMaterialUnrecPtr pMat = SimpleMaterial::create(); pMat->setDiffuse(Color3f(.5, .5, .5)); pMat->setLit (false ); setMaterialX(pMat); pMat = SimpleMaterial::create(); pMat->setDiffuse(Color3f(0, 1, 0)); pMat->setLit (false ); LineChunkUnrecPtr lc = LineChunk::create(); lc->setWidth(3); pMat->addChunk(lc); setMaterialY(pMat); pMat = SimpleMaterial::create(); pMat->setDiffuse(Color3f(0., 0., 1.)); pMat->setLit (true ); setMaterialZ(pMat); // SimpleMaterial *simpleMat; // Geometry *geo; setExternalUpdateHandler(NULL); // add a name attachment NameUnrecPtr nameN = Name::create(); nameN->editFieldPtr()->setValue("XYManipulator"); addAttachment(nameN); // make the axis line. Not really a handle, but easier to manage this way. GeoBuilder b; b.vertex(Pnt3f(0,0,0)); b.vertex(Pnt3f(0,getLength()[1],0)); b.line(0, 1); GeometryUnrecPtr g = b.getGeometry(); g->setMaterial(getMaterialY()); NodeUnrecPtr pNode = makeNodeFor(g); setTransYNode(pNode); // make the plane handle pNode = Node::create(); setTransXNode(pNode); g = makePlaneGeo(getLength()[0] / 2.f, getLength()[2] / 2.f, 1, 1); g->setMaterial(getMaterialX()); pNode = makeNodeFor(g); OSG::ComponentTransformUnrecPtr transHandleXC = ComponentTransform::create(); setHandleXNode(pNode); getTransXNode()->setCore (transHandleXC ); getTransXNode()->addChild(getHandleXNode()); transHandleXC->setTranslation(Vec3f(0, getLength()[1], 0)); transHandleXC->setRotation (Quaternion(Vec3f(1, 0, 0), osgDegree2Rad(90))); // // make the rotate handle pNode = Node::create(); setTransZNode(pNode); g = makeCylinderGeo(0.05f, 0.1f, 16, true, true, true); g->setMaterial(getMaterialZ()); pNode = makeNodeFor(g); OSG::ComponentTransformUnrecPtr transHandleZC = ComponentTransform::create(); setHandleZNode(pNode); getTransZNode()->setCore (transHandleZC ); getTransZNode()->addChild(getHandleZNode()); transHandleZC->setTranslation(Vec3f(0, getLength()[1], 0)); commitChanges(); }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Torus Node (creates Torus in background of scene) NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16); // Make Main Scene Node and add the Torus NodeRecPtr scene = Node::create(); scene->setCore(Group::create()); scene->addChild(TorusGeometryNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); //Create the nessicary parts for a viewport Matrix TransformMatrix; TransformMatrix.setTranslate(0.0f,0.0f, 0.0f); TransformRecPtr CameraBeaconTransform = Transform::create(); CameraBeaconTransform->setMatrix(TransformMatrix); NodeRecPtr CameraBeaconNode = Node::create(); CameraBeaconNode->setCore(CameraBeaconTransform); // Make Torus Node (creates Torus in background of scene) NodeRecPtr GeometryNode = makeTorus(.5, 2, 32, 32); //Make a light Node NodeRecPtr LightBeaconNode = makeCoredNode<Transform>(); DirectionalLightRecPtr SceneLight = DirectionalLight::create(); SceneLight->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f)); SceneLight->setDiffuse(Color4f(0.8f,0.8f,0.8f,1.0f)); SceneLight->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f)); SceneLight->setOn(true); SceneLight->setBeacon(LightBeaconNode); NodeRecPtr LightNode = makeNodeFor(SceneLight); LightNode->addChild(GeometryNode); // Make Main Scene Node and add the Torus NodeRecPtr DefaultRootNode = Node::create(); DefaultRootNode->setCore(Group::create()); DefaultRootNode->addChild(LightNode); DefaultRootNode->addChild(LightBeaconNode); DefaultRootNode->addChild(CameraBeaconNode); //Camera PerspectiveCameraRecPtr DefaultCamera = PerspectiveCamera::create(); DefaultCamera->setBeacon(CameraBeaconNode); DefaultCamera->setFov (osgDegree2Rad(60.f)); DefaultCamera->setNear (0.1f); DefaultCamera->setFar (100.f); //Background GradientBackgroundRecPtr DefaultBackground = GradientBackground::create(); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f); DefaultBackground->addLine(Color3f(0.0f,0.0f,1.0f), 1.0f); //Viewport ViewportRecPtr DefaultViewport = Viewport::create(); DefaultViewport->setCamera (DefaultCamera); DefaultViewport->setRoot (DefaultRootNode); DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f); DefaultViewport->setBackground (DefaultBackground); //GL Viewport Component LineBorderRecPtr TheGLViewportBorder = LineBorder::create(); TheGLViewportBorder->setColor(Color4f(1.0,0.0,0.0,1.0)); TheGLViewportBorder->setWidth(3.0); GLViewportRecPtr TheGLViewport = GLViewport::create(); TheGLViewport->setPort(DefaultViewport); TheGLViewport->setPreferredSize(Vec2f(400.0f,400.0f)); TheGLViewport->setBorders(TheGLViewportBorder); TheGLViewport->lookAt(Pnt3f(0.0f,0.0f,10.0f), //From Pnt3f(0.0f,0.0f,0.0f), //At Vec3f(0.0f,1.0f,0.0f)); //Up ButtonRecPtr ExampleButton = Button::create(); ExampleButton->setText("Example"); // Create The Main InternalWindow // Create Background to be used with the Main InternalWindow ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create(); MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5)); InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); LayoutRecPtr MainInternalWindowLayout = FlowLayout::create(); MainInternalWindow->pushToChildren(TheGLViewport); MainInternalWindow->pushToChildren(ExampleButton); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(MainInternalWindowBackground); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Create the UI Foreground Object UIForegroundRecPtr TutorialUIForeground = UIForeground::create(); TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface); // Tell the Manager what to manage sceneManager.setRoot(scene); // Add the UI Foreground Object to the Scene ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0); TutorialViewport->addForeground(TutorialUIForeground); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); // Show the whole Scene sceneManager.showAll(); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "41GLViewportComponent"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
void Manipulator::onCreate(const Manipulator* source) { Inherited::onCreate(source); SimpleMaterialUnrecPtr pMat; // SimpleMaterial *simpleMat; Geometry *geo; setExternalUpdateHandler(NULL); // add a name attachment NameUnrecPtr nameN = Name::create(); nameN->editFieldPtr()->setValue("XManipulator"); addAttachment(nameN); // make the axis lines NodeUnrecPtr pNode = makeCoordAxis(getLength()[0], 2.0, false); setAxisLinesN(pNode); // make the red x-axis transform and handle pNode = Node::create(); setTransXNode(pNode); OSG::ComponentTransformUnrecPtr transHandleXC = ComponentTransform::create(); pNode = makeHandleGeo(); setHandleXNode(pNode); pMat = SimpleMaterial::create(); setMaterialX (pMat ); getTransXNode()->setCore (transHandleXC ); getTransXNode()->addChild(getHandleXNode()); transHandleXC->setTranslation(Vec3f(getLength()[0], 0, 0) ); transHandleXC->setRotation (Quaternion(Vec3f(0, 0, 1), osgDegree2Rad(-90))); pMat->setDiffuse(Color3f(1, 0, 0)); pMat->setLit (true ); geo = dynamic_cast<Geometry *>(getHandleXNode()->getCore()); geo->setMaterial(pMat); // // make the green y-axis transform and handle pNode = Node::create(); setTransYNode(pNode); OSG::ComponentTransformUnrecPtr transHandleYC = ComponentTransform::create(); pNode = makeHandleGeo(); setHandleYNode(pNode); pMat = SimpleMaterial::create(); setMaterialY(pMat); getTransYNode()->setCore (transHandleYC ); getTransYNode()->addChild(getHandleYNode()); transHandleYC->setTranslation(Vec3f(0, getLength()[1], 0) ); // transHandleYC->setRotation ( Quaternion(Vec3f(0, 0, 1), osgDegree2Rad(-90))); pMat->setDiffuse(Color3f(0, 1, 0)); pMat->setLit (true ); geo = dynamic_cast<Geometry *>(getHandleYNode()->getCore()); geo->setMaterial(pMat); // // make the blue z-axis transform and handle pNode = Node::create(); setTransZNode(pNode); OSG::ComponentTransformUnrecPtr transHandleZC = ComponentTransform::create(); pNode = makeHandleGeo(); setHandleZNode(pNode); pMat = SimpleMaterial::create(); setMaterialZ (pMat); getTransZNode()->setCore (transHandleZC ); getTransZNode()->addChild(getHandleZNode()); transHandleZC->setTranslation(Vec3f(0, 0, getLength()[2]) ); transHandleZC->setRotation (Quaternion(Vec3f(1, 0, 0), osgDegree2Rad(90))); pMat->setDiffuse(Color3f(0, 0, 1)); pMat->setLit (true ); geo = dynamic_cast<Geometry *>(getHandleZNode()->getCore()); geo->setMaterial(pMat); // // make the yellow pivot transform and handle pNode = Node::create(); setPivotNode(pNode); OSG::ComponentTransformUnrecPtr transHandlePivotC = ComponentTransform::create(); pNode = makeSphere(2, 0.05f); setHandlePNode(pNode); pMat = SimpleMaterial::create(); setMaterialPivot (pMat); getPivotNode()->setCore (transHandlePivotC ); getPivotNode()->addChild(getHandlePNode()); transHandlePivotC->setTranslation(Vec3f(0, 0, 0)); pMat->setDiffuse(Color3f(1, 1, 0)); pMat->setLit (true ); geo = dynamic_cast<Geometry *>(getHandlePNode()->getCore()); geo->setMaterial(pMat); if (!getEnablePivot()) { getPivotNode()->setTravMask(0x0); } commitChanges(); }
void ApplicationStartScreen::attachApplication(void) { Inherited::attachApplication(); //Camera Transformation Node Matrix CameraTransformMatrix; CameraTransformMatrix.setTranslate(0.0f,0.0f, 5.0f); TransformRefPtr CameraBeaconTransform = Transform::create(); CameraBeaconTransform->setMatrix(CameraTransformMatrix); NodeRefPtr CameraBeaconNode = Node::create(); CameraBeaconNode->setCore(CameraBeaconTransform); // Make Torus Node (creates Torus in background of scene) NodeRefPtr TorusGeometryNode = NULL; //BoostPath TorusKnotFile(MainApplication::the()->getSettings()->getDataDirectory() / std::string("Models") / std::string("TorusKnot.osb")); //SLOG << "Loading Torus Knot from: " << TorusKnotFile.string() << std::endl; //if(boost::filesystem::exists(TorusKnotFile)) //{ //TorusGeometryNode = SceneFileHandler::the()->read(TorusKnotFile.native_file_string().c_str()); //} //if(TorusGeometryNode == NULL) //{ //SWARNING << "Could not load Torus Knot from: " //<< TorusKnotFile.string() << " because this file doesn't exist." << std::endl; TorusGeometryNode = makeTorus(.5, 2, 64, 64); //} //Scene Transformation TransformRefPtr SceneTransformCore = Transform::create(); NodeRefPtr SceneTransformNode = Node::create(); SceneTransformNode->setCore(SceneTransformCore); SceneTransformNode->addChild(TorusGeometryNode); //Light NodeRefPtr LightBeaconNode = Node::create(); LightBeaconNode->setCore(Transform::create()); DirectionalLightRefPtr SceneLightCore = DirectionalLight::create(); SceneLightCore->setDirection(1.0,0.0,0.0); SceneLightCore->setBeacon(LightBeaconNode); NodeRefPtr SceneLightNode = Node::create(); SceneLightNode->setCore(SceneLightCore); SceneLightNode->addChild(SceneTransformNode); // Make Main Scene Node and add the Torus NodeRefPtr DefaultRootNode = OSG::Node::create(); DefaultRootNode->setCore(OSG::Group::create()); DefaultRootNode->addChild(CameraBeaconNode); DefaultRootNode->addChild(SceneLightNode); DefaultRootNode->addChild(LightBeaconNode); //Camera PerspectiveCameraRefPtr DefaultCamera = PerspectiveCamera::create(); DefaultCamera->setBeacon(CameraBeaconNode); DefaultCamera->setFov (osgDegree2Rad(60.f)); DefaultCamera->setNear (0.1f); DefaultCamera->setFar (10000.f); //Background GradientBackgroundRefPtr DefaultBackground = GradientBackground::create(); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f); DefaultBackground->addLine(Color3f(0.0f,0.0f,0.5f), 1.0f); //Animation //KeyFrames KeyframeTransformationSequenceRefPtr TransformationKeyframes = KeyframeTransformationSequenceMatrix4f::create(); OSG::Matrix TempMat; TransformationKeyframes->addKeyframe(TempMat,0.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*0.5)); TransformationKeyframes->addKeyframe(TempMat,4.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.0)); TransformationKeyframes->addKeyframe(TempMat,8.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 3.14159f*1.5)); TransformationKeyframes->addKeyframe(TempMat,12.0f); TempMat.setRotate(Quaternion(Vec3f(0.0f,1.0f,0.0f), 0.0f)); TransformationKeyframes->addKeyframe(TempMat,16.0f); //Animator KeyframeAnimatorRefPtr TorusAnimator = OSG::KeyframeAnimator::create(); TorusAnimator->setKeyframeSequence(TransformationKeyframes); //Animation _TorusAnimation = FieldAnimation::create(); _TorusAnimation->setAnimator(TorusAnimator); _TorusAnimation->setInterpolationType(Animator::LINEAR_INTERPOLATION); _TorusAnimation->setCycling(-1); _TorusAnimation->setAnimatedField(SceneTransformCore, std::string("matrix")); _TorusAnimation->attachUpdateProducer(MainApplication::the()->getMainWindow()->editEventProducer()); _TorusAnimation->start(); //Foreground //ImageForegroundRefPtr LogoForeground = ImageForeground::create(); //BoostPath LogoPath(MainApplication::the()->getSettings()->getDataDirectory() / "Images/Logo.png"); //ImageRefPtr LoadedImage = ImageFileHandler::the().read(LogoPath.string().c_str()); // LogoForeground->addImage( LoadedImage, Pnt2f( 0,0 ) ); ForegroundRefPtr UserInterfaceForeground = createInterface(); _TheUIDrawingSurface->setEventProducer(MainApplication::the()->getMainWindow()); if(MainApplication::the()->getMainWindow() != NULL && MainApplication::the()->getMainWindow()->getMFPort()->size() == 0) { ViewportRefPtr DefaultViewport = Viewport::create(); DefaultViewport->setCamera (DefaultCamera); DefaultViewport->setRoot (DefaultRootNode); DefaultViewport->setSize (0.0f,0.0f, 1.0f,1.0f); DefaultViewport->setBackground (DefaultBackground); DefaultViewport->addForeground (UserInterfaceForeground); MainApplication::the()->getMainWindow()->addPort(DefaultViewport); } MainApplication::the()->getMainWindow()->addKeyListener(&_StartScreenKeyListener); MainApplication::the()->getMainWindow()->addUpdateListener(&_ScreenUpdateListener); }
CubeMapGeneratorStageDataTransitPtr CubeMapGenerator::setupStageData( RenderActionBase *pAction) { CubeMapGeneratorStageDataTransitPtr returnValue = CubeMapGeneratorStageData::createLocal(); if(returnValue == NULL) return returnValue; FrameBufferObjectUnrecPtr pCubeTarget = NULL; RenderBufferUnrecPtr pDepthBuffer = NULL; if(this->getRenderTarget() == NULL) { pCubeTarget = FrameBufferObject::createLocal(); pDepthBuffer = RenderBuffer ::createLocal(); pDepthBuffer->setInternalFormat (GL_DEPTH_COMPONENT24); pCubeTarget ->setDepthAttachment(pDepthBuffer ); returnValue ->setRenderTarget (pCubeTarget ); } else { pCubeTarget = this->getRenderTarget(); } TextureObjChunkUnrecPtr pCubeTex = NULL; if(0x0000 != (_sfSetupMode.getValue() & SetupTexture)) { pCubeTex = TextureObjChunk::createLocal(); ImageUnrecPtr pImg = Image::createLocal(); pImg->set(Image::OSG_RGB_PF, getWidth (), getHeight(), 1, 1, 1, 0.0, 0, Image::OSG_UINT8_IMAGEDATA, false, 6); pCubeTex ->setImage (pImg ); pCubeTex ->setMinFilter (GL_LINEAR ); pCubeTex ->setMagFilter (GL_LINEAR ); pCubeTex ->setWrapS (GL_CLAMP_TO_EDGE ); pCubeTex ->setWrapT (GL_CLAMP_TO_EDGE ); pCubeTex ->setWrapR (GL_CLAMP_TO_EDGE ); pCubeTex ->setInternalFormat(getTextureFormat()); } else { pCubeTex = _sfTexture.getValue(); } TextureEnvChunkUnrecPtr pCubeTexEnv = NULL; if(0x0000 != (_sfSetupMode.getValue() & SetupTexEnv)) { pCubeTexEnv = TextureEnvChunk::createLocal(); pCubeTexEnv->setEnvMode (GL_REPLACE ); } TexGenChunkUnrecPtr pCubeTexGen = NULL; TextureTransformChunkUnrecPtr pCubeTexTrans = NULL; if(0x0000 != (_sfSetupMode.getValue() & SetupTexGen)) { pCubeTexGen = TexGenChunk::createLocal(); pCubeTexGen->setGenFuncS(GL_REFLECTION_MAP); pCubeTexGen->setGenFuncT(GL_REFLECTION_MAP); pCubeTexGen->setGenFuncR(GL_REFLECTION_MAP); pCubeTexTrans = TextureTransformChunk::createLocal(); pCubeTexTrans->setUseCameraBeacon(true); } static GLenum targets[6] = { GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB }; for(UInt32 i = 0; i < 6; ++i) { TextureBufferUnrecPtr pCubeTexBuffer = TextureBuffer::createLocal(); pCubeTexBuffer->setTexture (pCubeTex ); pCubeTexBuffer->setTexTarget(targets[i]); pCubeTarget->setColorAttachment(pCubeTexBuffer, i); } pCubeTarget->setSize(getWidth (), getHeight()); if(0x0000 != (_sfSetupMode.getValue() & OverrideTex)) { returnValue->addChunk(pCubeTex, getTexUnit()); } if(0x0000 != (_sfSetupMode.getValue() & SetupTexEnv)) { returnValue->addChunk(pCubeTexEnv, getTexUnit()); } if(0x0000 != (_sfSetupMode.getValue() & SetupTexGen)) { returnValue->addChunk(pCubeTexGen, getTexUnit()); returnValue->addChunk(pCubeTexTrans, getTexUnit()); returnValue->setTexTransform(pCubeTexTrans); } if(this->getCamera() == NULL) { PerspectiveCameraUnrecPtr pCam = PerspectiveCamera::createLocal(); pCam->setNear(pAction->getCamera()->getNear()); pCam->setFar (pAction->getCamera()->getFar ()); pCam->setFov (osgDegree2Rad(90.f)); returnValue->setCamera(pCam); } return returnValue; }
/* Insert one or more shallow copies of a block (created by DXFBlock as * Transform Group) into a layer (created by DXFLayer as MaterialGroup) or * another block. * \todo * Could there be a INSERT inside a block referring to another block which has * not been read yet? We then have to find a solution to enable deferred * instantiation of INSERT entities :-( */ DXFResult DXFInsert::endEntity(void) { NodeUnrecPtr ctrafoNodeP = NULL; // ComponentTransformUnrecPtr ctrafoCoreP = NULL; TransformUnrecPtr ctrafoCoreP = NULL; NodeUnrecPtr blockNodeP = NULL; Node *parentNodeP = getParentNode(); StringToNodePtrMap::iterator itr = _blocksMapP->find(_blockName); if (itr != _blocksMapP->end() && parentNodeP != NULL) { blockNodeP = itr->second; // TODO: check fetched INSERT Data for consistency! // Insert multiple times in a grid... Vec3f offset(0.0, 0.0, 0.0); for(Int16 column = 0; column < _columnCount; ++ column) { offset[0] = column * _columnSpacing; for(Int16 row = 0; row < _rowCount; ++ row) { offset[1] = row * _rowSpacing; // TODO: find out about DXF insert semantics! ctrafoNodeP = Node::create(); ctrafoCoreP = Transform::create(); #if 0 beginEditCP(ctrafoCoreP); #endif { if(_blockName == std::string("Rectangular Mullion - 64 x 128 rectangular-V1-Level 1")) { std::cout << blockNodeP->getNChildren() << std::endl; } OSG::TransformationMatrix<Real32> transMat; transMat.setIdentity(); transMat.setTranslate(_insertionPoint + offset); OSG::TransformationMatrix<Real32> rotMat; rotMat.setIdentity(); OSG::Quaternion rot(OSG::Vec3f(0,0,1),osgDegree2Rad(_rotationAngle)); rotMat.setRotate(rot); OSG::TransformationMatrix<Real32> scaleMat; scaleMat.setIdentity(); scaleMat.setScale(_scaleFactor); OSG::Vec3f vin(-40, 65, 0); OSG::Vec3f vout; transMat.mult(rotMat); transMat.mult(scaleMat); if(_extrusionDirection[2]<0) { transMat[0][0] *= -1.0; transMat[1][0] *= -1.0; transMat[2][0] *= -1.0; transMat[3][0] *= -1.0; } ctrafoCoreP->setMatrix(transMat); } #if 0 endEditCP(ctrafoCoreP); #endif #if 0 beginEditCP(ctrafoNodeP); #endif { ctrafoNodeP->setCore(ctrafoCoreP); #if 0 ctrafoNodeP->addChild(blockNodeP->clone()); #endif NodeUnrecPtr pClone = cloneTree(blockNodeP); ctrafoNodeP->addChild(pClone); } #if 0 endEditCP(ctrafoNodeP); #endif #if 0 beginEditCP(parentNodeP); #endif { parentNodeP->addChild(ctrafoNodeP); } #if 0 endEditCP(parentNodeP); #endif } } // Warn for details not implemented or assured yet! TODO: better // implement missing features! /*if(fabs(_rotationAngle) > Eps) FWARNING(("DXF Loader: before line %d: " "DXFInsert does not yet support ROTATION " "(group code 50). " "Most likely the graphics are incorrect!\n", DXFRecord::getLineNumber() ));*/ /*if(_scaleFactor != Vec3f(1.0,1.0,1.0)) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret SCALING " "(group codes 41, 42, 43) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() ));*/ if(_columnCount != 1 || _rowCount != 1) FWARNING(("DXF Loader: before line %d: " "DXFInsert may not interpret REPEATED INSERTION " "(group codes 70, 71, 44, 45) correctly." "Graphics may be incorrect!\n", DXFRecord::getLineNumber() )); } else { if(itr == _blocksMapP->end()) FWARNING(("DXF Loader: before line %d (inside %s section): " "BLOCK '%s' to be inserted not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _blockName.c_str() )); if(parentNodeP == NULL) FWARNING(("DXF Loader: before line %d (inside %s section): " "layer %s to be inserted to not found!\n", DXFRecord::getLineNumber(), _parent->getEntityTypeName(), _layerName.c_str() )); } //set back to default value; _insertionPoint.setNull(), _scaleFactor[0]=_scaleFactor[1]=_scaleFactor[2]=1.0; _rotationAngle=0.0; _columnCount=1; _rowCount=1; _columnSpacing=0.0; _rowSpacing=0.0; _extrusionDirection[0]=0; _extrusionDirection[1]=0; _extrusionDirection[2]=1; return DXFStateContinue; }
Node * ColladaLight::createInstanceCommon( ColladaLightInstInfo *colInstInfo, domLight::domTechnique_common *tech) { domLightRef light = getDOMElementAs<domLight>(); OSG_COLLADA_LOG(("ColladaLight::createInstanceCommon id [%s]\n", light->getId())); NodeUnrecPtr lightN = NULL; domLight::domTechnique_common::domAmbientRef ambient = tech->getAmbient(); domLight::domTechnique_common::domDirectionalRef directional = tech->getDirectional(); domLight::domTechnique_common::domPointRef point = tech->getPoint(); domLight::domTechnique_common::domSpotRef spot = tech->getSpot(); if(ambient != NULL) { Color4f lightColor(ambient->getColor()->getValue()[0], ambient->getColor()->getValue()[1], ambient->getColor()->getValue()[2], 1.f); LightLoaderState *state = getGlobal()->getLoaderStateAs<LightLoaderState>(_loaderStateName); OSG_ASSERT(state != NULL); LightModelChunkUnrecPtr lmChunk = state->getLightModelChunk(); if(state->getLightModelChunk() == NULL) { lmChunk = LightModelChunk::create(); lmChunk->setAmbient(Color4f(0.f, 0.f, 0.f, 1.f)); state->setLightModelChunk(lmChunk); // only place one instance into the inst queue, it will // add the LightModelChunk with the accumulated ambient // for the scene ColladaInstInfoRefPtr ambientInstInfo = ColladaLightAmbientInstInfo::create( colInstInfo->getColInstParent(), dynamic_cast<ColladaInstanceLight *>( colInstInfo->getColInst()) ); getGlobal()->editInstQueue().push_back(ambientInstInfo); } lightColor[0] = osgClamp(0.f, lmChunk->getAmbient()[0] + lightColor[0], 1.f); lightColor[1] = osgClamp(0.f, lmChunk->getAmbient()[1] + lightColor[1], 1.f); lightColor[2] = osgClamp(0.f, lmChunk->getAmbient()[2] + lightColor[0], 1.f); lmChunk->setAmbient(lightColor); } if(directional != NULL) { Color4f lightColor(directional->getColor()->getValue()[0], directional->getColor()->getValue()[1], directional->getColor()->getValue()[2], 1.f); DirectionalLightUnrecPtr dl = DirectionalLight::create(); lightN = makeNodeFor(dl); dl->setBeacon (colInstInfo->getBeacon()); dl->setDiffuse (lightColor ); dl->setSpecular(lightColor ); } if(point != NULL) { Color4f lightColor(point->getColor()->getValue()[0], point->getColor()->getValue()[1], point->getColor()->getValue()[2], 1.f); PointLightUnrecPtr pl = PointLight::create(); lightN = makeNodeFor(pl); Real32 constAtt = 1.f; Real32 linAtt = 0.f; Real32 quadAtt = 0.f; if(point->getConstant_attenuation() != NULL) constAtt = point->getConstant_attenuation()->getValue(); if(point->getLinear_attenuation() != NULL) linAtt = point->getLinear_attenuation()->getValue(); if(point->getQuadratic_attenuation() != NULL) quadAtt = point->getQuadratic_attenuation()->getValue(); pl->setBeacon (colInstInfo->getBeacon()); pl->setDiffuse (lightColor ); pl->setSpecular (lightColor ); pl->setConstantAttenuation (constAtt ); pl->setLinearAttenuation (linAtt ); pl->setQuadraticAttenuation(quadAtt ); } if(spot != NULL) { Color4f lightColor(spot->getColor()->getValue()[0], spot->getColor()->getValue()[1], spot->getColor()->getValue()[2], 1.f); SpotLightUnrecPtr sl = SpotLight::create(); lightN = makeNodeFor(sl); Real32 constAtt = 1.f; Real32 linAtt = 0.f; Real32 quadAtt = 0.f; Real32 cutOff = 180.f; Real32 exponent = 0.f; if(spot->getConstant_attenuation() != NULL) constAtt = spot->getConstant_attenuation()->getValue(); if(spot->getLinear_attenuation() != NULL) linAtt = spot->getLinear_attenuation()->getValue(); if(spot->getQuadratic_attenuation() != NULL) quadAtt = spot->getQuadratic_attenuation()->getValue(); if(spot->getFalloff_angle() != NULL) cutOff = spot->getFalloff_angle()->getValue(); if(spot->getFalloff_exponent() != NULL) exponent = spot->getFalloff_exponent()->getValue(); sl->setBeacon (colInstInfo->getBeacon()); sl->setDiffuse (lightColor ); sl->setSpecular (lightColor ); sl->setConstantAttenuation (constAtt ); sl->setLinearAttenuation (linAtt ); sl->setQuadraticAttenuation(quadAtt ); sl->setSpotCutOff (osgDegree2Rad(cutOff) ); sl->setSpotExponent (exponent ); } if(lightN != NULL) { editInstStore().push_back(lightN); if(getGlobal()->getOptions()->getCreateNameAttachments() == true && light->getName() != NULL ) { setName(lightN, light->getName()); } } return lightN; }