IVElement::IVElement(string ivfile, KthReal sc) { for(int i=0;i<3;i++){ position[i]= 0.0f; orientation[i]=0.0f; } orientation[2]=1.0f; orientation[3]=0.0f; scale=sc; trans= new SoTranslation; rot = new SoRotation; sca = new SoScale(); color = new SoMaterial; posVec = new SoSFVec3f; trans->translation.connectFrom(posVec); posVec->setValue((float)position[0],(float)position[1],(float)position[2]); rotVec = new SoSFRotation; rotVec->setValue(SbVec3f((float)orientation[0],(float)orientation[1], (float)orientation[2]),(float)orientation[3]); rot->rotation.connectFrom(rotVec); scaVec= new SoSFVec3f; scaVec->setValue((float)scale,(float)scale,(float)scale); sca->scaleFactor.connectFrom(scaVec); SoInput input; ivmodel = new SoSeparator; ivmodel->ref(); ivmodel->addChild(sca); if(input.openFile(ivfile.c_str())) ivmodel->addChild(SoDB::readAll(&input)); else { //ivmodel->addChild(new SoSphere()); static const char *str[] = { "#VRML V1.0 ascii\n", "DEF pointgoal Separator {\n", " Separator {\n", " MaterialBinding { value PER_PART }\n", " Coordinate3 {\n", " point [\n", " 0.0 0.0 0.0\n", " ]\n", " }\n", " DrawStyle { pointSize 5 }\n", " PointSet { }\n", " }\n", "}\n", NULL }; input.setStringArray(str); SoSeparator *sep = SoDB::readAll(&input); sep->ref(); while (sep->getNumChildren() > 0) { ivmodel->addChild(sep->getChild(0)); sep->removeChild(0); } sep->unref(); } ivmodel->ref(); }
SoCamera * SoSceneTextureCubeMapP::ensureCamera(void) { if (this->hasSceneChanged == FALSE) return this->cachedCamera; this->hasSceneChanged = FALSE; SoCamera * camera = this->findCamera(); SbBool hasCamera = (camera != NULL); // does the scene provide a camera? if (hasCamera) { if (this->cachedCamera != camera) { if (this->cachedCamera) this->cachedCamera->unref(); this->cachedCamera = camera; this->cachedCamera->ref(); } } else if (this->hadSceneCamera || this->cachedCamera == NULL) { // create default camera: static int didwarn = 0; if (!didwarn) { SoDebugError::postWarning("SoSceneTextureCubeMap::ensureCamera", "The scene does not provide a camera. " "A perspective camera at position (0,0,0) " "will be used."); didwarn = 1; } if (this->cachedCamera) this->cachedCamera->unref(); this->cachedCamera = new SoPerspectiveCamera; this->cachedCamera->position = SbVec3f(0, 0, 0); this->cachedCamera->nearDistance = 0.1f; this->cachedCamera->farDistance = 100; ((SoPerspectiveCamera*)this->cachedCamera)->heightAngle = (float) (M_PI / 2.0f); this->cachedCamera->ref(); } assert(this->cachedCamera); SoNode * scene = PUBLIC(this)->scene.getValue(); if (hasCamera) { if (scene != this->cachedScene) { if (this->cachedScene) this->cachedScene->unref(); this->cachedScene = scene; this->cachedScene->ref(); } } else if (this->cachedScene == NULL || this->hadSceneCamera) { if (this->cachedScene) this->cachedScene->unref(); SoSeparator * root = new SoSeparator(); root->addChild(this->cachedCamera); root->addChild(scene); this->cachedScene = (SoNode *)root; this->cachedScene->ref(); } else { assert(this->cachedScene->isOfType(SoSeparator::getClassTypeId())); SoSeparator * root = (SoSeparator*)this->cachedScene; assert(root->getNumChildren() == 2); if (root->getChild(1) != scene) ((SoSeparator *)this->cachedScene)->replaceChild(1, scene); } this->hadSceneCamera = hasCamera; return this->cachedCamera; }