PositionAttitudeTransform *VideoGeode::createVideoSphere(float size, bool texRepeat) { Geode *sphere = new Geode(); sphere->addDrawable(new ShapeDrawable(new Sphere(Vec3(0, 0, 4), size))); // assign the material to the sphere StateSet *sphereStateSet = sphere->getOrCreateStateSet(); sphereStateSet->ref(); sphereStateSet->setAttribute(_material); try { sphereStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON); } catch (char *e) { throw e; } PositionAttitudeTransform *sphereTransform = new PositionAttitudeTransform(); sphereTransform->addChild(sphere); return sphereTransform; }
virtual void apply(PositionAttitudeTransform& pat) { if (_useInverseMatrix) { Matrix matrix; _cp.getInverse(matrix); pat.setPosition(matrix.getTrans()); pat.setAttitude(_cp.getRotation().inverse()); pat.setScale(osg::Vec3(1.0f/_cp.getScale().x(),1.0f/_cp.getScale().y(),1.0f/_cp.getScale().z())); pat.setPivotPoint(_pivotPoint); } else { pat.setPosition(_cp.getPosition()); pat.setAttitude(_cp.getRotation()); pat.setScale(_cp.getScale()); pat.setPivotPoint(_pivotPoint); } }
/*************************************************************** * Function: ANIMCreateSingleIconToolkitSwitchAnimation() ***************************************************************/ void ANIMCreateSingleIconToolkitSwitchAnimation(int idx, ANIMIconToolkitSwitchEntry **iconToolkitEntry) { (*iconToolkitEntry)->mSwitch = new Switch; PositionAttitudeTransform *iconToolkitPATransFwd = new PositionAttitudeTransform; PositionAttitudeTransform *iconToolkitPATransBwd = new PositionAttitudeTransform; /* 'mSwitch' has two decendents for foward and backward animations */ (*iconToolkitEntry)->mSwitch->setAllChildrenOff(); (*iconToolkitEntry)->mSwitch->addChild(iconToolkitPATransFwd); (*iconToolkitEntry)->mSwitch->addChild(iconToolkitPATransBwd); /* attach the same 'CAVEGroupIconToolkit' object to both 'PositionAttitudeTransform' */ const CAVEGeodeIconToolkit::Type type = (CAVEGeodeIconToolkit::Type) idx; CAVEGroupIconToolkit *groupIconToolkit = new CAVEGroupIconToolkit(type); iconToolkitPATransFwd->addChild(groupIconToolkit); iconToolkitPATransBwd->addChild(groupIconToolkit); /* set up the forward / backward scale animation paths for toolkit icons */ AnimationPath* animScaleFwd = new AnimationPath; AnimationPath* animScaleBwd = new AnimationPath; animScaleFwd->setLoopMode(AnimationPath::NO_LOOPING); animScaleBwd->setLoopMode(AnimationPath::NO_LOOPING); Vec3 scaleFwd, scaleBwd; float step = 1.f / ANIM_GEOMETRY_EDITOR_TOOLKIT_SHOWUP_SAMPS; for (int i = 0; i < ANIM_GEOMETRY_EDITOR_TOOLKIT_SHOWUP_SAMPS + 1; i++) { float val = i * step; scaleFwd = Vec3(val, val, val); scaleBwd = Vec3(1.f-val, 1.f-val, 1.f-val); animScaleFwd->insert(val, AnimationPath::ControlPoint(Vec3(0,0,0), Quat(), scaleFwd)); animScaleBwd->insert(val, AnimationPath::ControlPoint(Vec3(0,0,0), Quat(), scaleBwd)); } (*iconToolkitEntry)->mFwdAnimCallback = new AnimationPathCallback(animScaleFwd, 0.0, 1.f / ANIM_GEOMETRY_EDITOR_TOOLKIT_SHOWUP_TIME); (*iconToolkitEntry)->mBwdAnimCallback = new AnimationPathCallback(animScaleBwd, 0.0, 1.f / ANIM_GEOMETRY_EDITOR_TOOLKIT_SHOWUP_TIME); iconToolkitPATransFwd->setUpdateCallback((*iconToolkitEntry)->mFwdAnimCallback); iconToolkitPATransBwd->setUpdateCallback((*iconToolkitEntry)->mBwdAnimCallback); }
/*************************************************************** * Function: ANIMLoadSketchBook() ***************************************************************/ void ANIMLoadSketchBook(PositionAttitudeTransform** xformScaleFwd, PositionAttitudeTransform** xformScaleBwd, int &numPages, ANIMPageEntry ***pageEntryArray) { *xformScaleFwd = new PositionAttitudeTransform; *xformScaleBwd = new PositionAttitudeTransform; MatrixTransform *sketchbookTrans = new MatrixTransform; Matrixf transMat, scaleMat; transMat.makeTranslate(Vec3(0, 0, ANIM_VIRTUAL_SPHERE_RADIUS)); scaleMat.makeScale(Vec3(ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR, ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR, ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR)); sketchbookTrans->setMatrix(transMat * scaleMat); (*xformScaleFwd)->addChild(sketchbookTrans); (*xformScaleBwd)->addChild(sketchbookTrans); // load sketch book node from VRML file, create page geodes Node* sketchbookNode = osgDB::readNodeFile(ANIMDataDir() + "VRMLFiles/SketchBook.WRL"); sketchbookTrans->addChild(sketchbookNode); // Load floorplan filenames from config file bool isFile = true; int j = 0, numTex; std::string file = "", dir, path; std::vector<std::string> filenames; dir = cvr::ConfigManager::getEntry("dir", "Plugin.CaveCADBeta.Floorplans", "/home/cehughes"); dir = dir + "/"; path = "Plugin.CaveCADBeta.Floorplans.0"; file = cvr::ConfigManager::getEntry(path, "", &isFile); while (isFile) { filenames.push_back(dir + file); j++; char buf[50]; sprintf(buf, "Plugin.CaveCADBeta.Floorplans.%d", j); std::string path = std::string(buf); file = cvr::ConfigManager::getEntry(path, "", &isFile); } numPages = j; //numPages = 3; // create tree structured page entry array *pageEntryArray = new ANIMPageEntry*[numPages]; for (int i = 0; i < numPages; i++) { /* char idxStr[16]; if (i < 10) { sprintf(idxStr, "0%d", i); } else if (i < 100) { sprintf(idxStr, "%d", i); }*/ string filename = filenames[i];//ANIMDataDir() + "Textures/Floorplans/Floorplan" + string(idxStr) + string(".JPG"); (*pageEntryArray)[i] = new ANIMPageEntry; Switch *singlePageSwitch = new Switch; PositionAttitudeTransform *flipUpTrans = new PositionAttitudeTransform; PositionAttitudeTransform *flipDownTrans = new PositionAttitudeTransform; sketchbookTrans->addChild(singlePageSwitch); singlePageSwitch->addChild(flipUpTrans); singlePageSwitch->addChild(flipDownTrans); singlePageSwitch->setAllChildrenOff(); // set up flip up / flip down animation paths for each page Geode *flipUpGeode, *flipDownGeode; AnimationPathCallback *flipUpCallback, *flipDownCallback; ANIMCreateSinglePageGeodeAnimation(filename, &flipUpGeode, &flipDownGeode, &flipUpCallback, &flipDownCallback); flipUpTrans->addChild(flipUpGeode); flipUpTrans->setUpdateCallback(flipUpCallback); flipDownTrans->addChild(flipDownGeode); flipDownTrans->setUpdateCallback(flipDownCallback); // write into page entry array record (*pageEntryArray)[i]->mSwitch = singlePageSwitch; (*pageEntryArray)[i]->mFlipUpAnim = flipUpCallback; (*pageEntryArray)[i]->mFlipDownAnim = flipDownCallback; (*pageEntryArray)[i]->mPageGeode = flipDownGeode; (*pageEntryArray)[i]->mTexFilename = filename; } (*pageEntryArray)[0]->mSwitch->setSingleChildOn(1); (*pageEntryArray)[1]->mSwitch->setSingleChildOn(0); // size of floorplan // FIX THIS - put sizes in the config file or something float alt = -2.9f; (*pageEntryArray)[0]->mLength = 32; (*pageEntryArray)[0]->mWidth = 16; (*pageEntryArray)[0]->mAlti = alt; (*pageEntryArray)[1]->mLength = 128; (*pageEntryArray)[1]->mWidth = 128; (*pageEntryArray)[1]->mAlti = alt; (*pageEntryArray)[2]->mLength = 32; (*pageEntryArray)[2]->mWidth = 16; (*pageEntryArray)[2]->mAlti = alt; (*pageEntryArray)[3]->mLength = 32; (*pageEntryArray)[3]->mWidth = 32; (*pageEntryArray)[3]->mAlti = alt; // set up the forward / backward scale animation paths for sketch book root switch AnimationPath* animationPathScaleFwd = new AnimationPath; AnimationPath* animationPathScaleBwd = new AnimationPath; animationPathScaleFwd->setLoopMode(AnimationPath::NO_LOOPING); animationPathScaleBwd->setLoopMode(AnimationPath::NO_LOOPING); Vec3 scaleFwd, scaleBwd; float step = 1.f / ANIM_VIRTUAL_SPHERE_NUM_SAMPS; for (int i = 0; i < ANIM_VIRTUAL_SPHERE_NUM_SAMPS + 1; i++) { float val = i * step; scaleFwd = Vec3(val, val, val); scaleBwd = Vec3(1.f-val, 1.f-val, 1.f-val); animationPathScaleFwd->insert(val, AnimationPath::ControlPoint(Vec3(),Quat(), scaleFwd)); animationPathScaleBwd->insert(val, AnimationPath::ControlPoint(Vec3(),Quat(), scaleBwd)); } AnimationPathCallback *animCallbackFwd = new AnimationPathCallback(animationPathScaleFwd, 0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME); AnimationPathCallback *animCallbackBwd = new AnimationPathCallback(animationPathScaleBwd, 0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME); (*xformScaleFwd)->setUpdateCallback(animCallbackFwd); (*xformScaleBwd)->setUpdateCallback(animCallbackBwd); }
PositionAttitudeTransform *VideoGeode::createVideoPlane(float sizeX, float sizeY, bool texRepeat) { // vertex array Vec3Array *vertexArray = new Vec3Array(); sizeX /= 2.0; sizeY /= 2.0; vertexArray->push_back(Vec3(-sizeX, 0, -sizeY)); vertexArray->push_back(Vec3(sizeX, 0, -sizeY)); vertexArray->push_back(Vec3(sizeX, 0, sizeY)); vertexArray->push_back(Vec3(-sizeX, 0, sizeY)); /*vertexArray->push_back(Vec3(-sizeX, -sizeY, 0)); vertexArray->push_back(Vec3(sizeX, -sizeY, 0)); vertexArray->push_back(Vec3(sizeX, sizeY, 0)); vertexArray->push_back(Vec3(-sizeX, sizeY, 0));*/ // face array DrawElementsUInt *faceArray = new DrawElementsUInt(PrimitiveSet::TRIANGLES, 0); faceArray->push_back(0); // face 1 faceArray->push_back(1); faceArray->push_back(2); faceArray->push_back(2); // face 2 faceArray->push_back(3); faceArray->push_back(0); // normal array Vec3Array *normalArray = new Vec3Array(); normalArray->push_back(Vec3(0, 0, 1)); // normal index TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4> *normalIndexArray; normalIndexArray = new TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4>(); normalIndexArray->push_back(0); normalIndexArray->push_back(0); normalIndexArray->push_back(0); normalIndexArray->push_back(0); // texture coordinates Vec2Array *texCoords = new Vec2Array(); texCoords->push_back(Vec2(0.0f, 0.0f)); texCoords->push_back(Vec2(1.0f, 0.0f)); texCoords->push_back(Vec2(1.0f, 1.0f)); texCoords->push_back(Vec2(0.0f, 1.0f)); Geometry *geometry = new Geometry(); geometry->setVertexArray(vertexArray); geometry->setNormalArray(normalArray); geometry->setNormalIndices(normalIndexArray); geometry->setNormalBinding(Geometry::BIND_PER_VERTEX); geometry->setTexCoordArray(0, texCoords); geometry->addPrimitiveSet(faceArray); Geode *plane = new Geode(); plane->addDrawable(geometry); // assign the material to the sphere StateSet *planeStateSet = plane->getOrCreateStateSet(); planeStateSet->ref(); planeStateSet->setAttribute(_material); try { planeStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON); } catch (char *e) { throw e; } PositionAttitudeTransform *planeTransform = new PositionAttitudeTransform(); planeTransform->addChild(plane); return planeTransform; }
/*************************************************************** * Function: ANIMLoadSketchBook() ***************************************************************/ void ANIMLoadSketchBook(PositionAttitudeTransform** xformScaleFwd, PositionAttitudeTransform** xformScaleBwd, int &numPages, ANIMPageEntry ***pageEntryArray) { *xformScaleFwd = new PositionAttitudeTransform; *xformScaleBwd = new PositionAttitudeTransform; MatrixTransform *sketchbookTrans = new MatrixTransform; Matrixf transMat, scaleMat; transMat.makeTranslate(Vec3(0, 0, ANIM_VIRTUAL_SPHERE_RADIUS)); scaleMat.makeScale(Vec3(ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR, ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR, ANIM_PARA_PAINT_FRAME_ZOOM_FACTOR)); sketchbookTrans->setMatrix(transMat * scaleMat); (*xformScaleFwd)->addChild(sketchbookTrans); (*xformScaleBwd)->addChild(sketchbookTrans); /* load sketch book node from VRML file, create page geodes */ Node* sketchbookNode = osgDB::readNodeFile(ANIMDataDir() + "VRMLFiles/SketchBook.WRL"); sketchbookTrans->addChild(sketchbookNode); /* create tree structured page entry array */ numPages = 3; *pageEntryArray = new ANIMPageEntry*[numPages]; for (int i = 0; i < numPages; i++) { char idxStr[16]; if (i < 10) sprintf(idxStr, "0%d", i); else if (i < 100) sprintf(idxStr, "%d", i); string filename = ANIMDataDir() + "Textures/Floorplans/Floorplan" + string(idxStr) + string(".JPG"); (*pageEntryArray)[i] = new ANIMPageEntry; Switch *singlePageSwitch = new Switch; PositionAttitudeTransform *flipUpTrans = new PositionAttitudeTransform; PositionAttitudeTransform *flipDownTrans = new PositionAttitudeTransform; sketchbookTrans->addChild(singlePageSwitch); singlePageSwitch->addChild(flipUpTrans); singlePageSwitch->addChild(flipDownTrans); singlePageSwitch->setAllChildrenOff(); /* set up flip up / flip down animation paths for each page */ Geode *flipUpGeode, *flipDownGeode; AnimationPathCallback *flipUpCallback, *flipDownCallback; ANIMCreateSinglePageGeodeAnimation(filename, &flipUpGeode, &flipDownGeode, &flipUpCallback, &flipDownCallback); flipUpTrans->addChild(flipUpGeode); flipUpTrans->setUpdateCallback(flipUpCallback); flipDownTrans->addChild(flipDownGeode); flipDownTrans->setUpdateCallback(flipDownCallback); /* write into page entry array record */ (*pageEntryArray)[i]->mSwitch = singlePageSwitch; (*pageEntryArray)[i]->mFlipUpAnim = flipUpCallback; (*pageEntryArray)[i]->mFlipDownAnim = flipDownCallback; (*pageEntryArray)[i]->mPageGeode = flipDownGeode; (*pageEntryArray)[i]->mTexFilename = filename; } (*pageEntryArray)[0]->mSwitch->setSingleChildOn(1); (*pageEntryArray)[1]->mSwitch->setSingleChildOn(0); /* size of floorplan */ (*pageEntryArray)[0]->mLength = 32; (*pageEntryArray)[0]->mWidth = 16; (*pageEntryArray)[0]->mAlti = -1.5f; (*pageEntryArray)[1]->mLength = 128; (*pageEntryArray)[1]->mWidth = 128; (*pageEntryArray)[1]->mAlti = -1.5f; (*pageEntryArray)[2]->mLength = 32; (*pageEntryArray)[2]->mWidth = 16; (*pageEntryArray)[2]->mAlti = -1.5f; /* set up the forward / backward scale animation paths for sketch book root switch */ AnimationPath* animationPathScaleFwd = new AnimationPath; AnimationPath* animationPathScaleBwd = new AnimationPath; animationPathScaleFwd->setLoopMode(AnimationPath::NO_LOOPING); animationPathScaleBwd->setLoopMode(AnimationPath::NO_LOOPING); Vec3 scaleFwd, scaleBwd; float step = 1.f / ANIM_VIRTUAL_SPHERE_NUM_SAMPS; for (int i = 0; i < ANIM_VIRTUAL_SPHERE_NUM_SAMPS + 1; i++) { float val = i * step; scaleFwd = Vec3(val, val, val); scaleBwd = Vec3(1.f-val, 1.f-val, 1.f-val); animationPathScaleFwd->insert(val, AnimationPath::ControlPoint(Vec3(),Quat(), scaleFwd)); animationPathScaleBwd->insert(val, AnimationPath::ControlPoint(Vec3(),Quat(), scaleBwd)); } AnimationPathCallback *animCallbackFwd = new AnimationPathCallback(animationPathScaleFwd, 0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME); AnimationPathCallback *animCallbackBwd = new AnimationPathCallback(animationPathScaleBwd, 0.0, 1.f / ANIM_VIRTUAL_SPHERE_LAPSE_TIME); (*xformScaleFwd)->setUpdateCallback(animCallbackFwd); (*xformScaleBwd)->setUpdateCallback(animCallbackBwd); }
/*************************************************************** * Function: ANIMCreateSingleShapeSwitchAnimation() ***************************************************************/ void ANIMCreateSingleShapeSwitchAnimation(ANIMShapeSwitchEntry **shapeEntry, const CAVEGeodeShape::Type &typ) { PositionAttitudeTransform *flipUpFwdTrans = new PositionAttitudeTransform; PositionAttitudeTransform *flipDownFwdTrans = new PositionAttitudeTransform; PositionAttitudeTransform *flipUpBwdTrans = new PositionAttitudeTransform; PositionAttitudeTransform *flipDownBwdTrans = new PositionAttitudeTransform; (*shapeEntry)->mSwitch->addChild(flipUpFwdTrans); // child #0 (*shapeEntry)->mSwitch->addChild(flipDownFwdTrans); // child #1 (*shapeEntry)->mSwitch->addChild(flipUpBwdTrans); // child #2 (*shapeEntry)->mSwitch->addChild(flipDownBwdTrans); // child #3 (*shapeEntry)->mSwitch->setAllChildrenOff(); osg::Vec3 pos(0, 0, 0); /* create shape geode based on 'ANIMShapeSwitchEntry::Type' */ Geode *shapeGeode = new Geode; if (typ == CAVEGeodeShape::BOX) { Box *box = new Box(osg::Vec3(), ANIM_VIRTUAL_SPHERE_RADIUS / 0.9); shapeGeode->addDrawable(new ShapeDrawable(box)); } else if (typ == CAVEGeodeShape::CYLINDER) { float r = ANIM_VIRTUAL_SPHERE_RADIUS / 1.5; Cylinder *cylinder = new Cylinder(osg::Vec3(), r, r * 2); shapeGeode->addDrawable(new ShapeDrawable(cylinder)); } flipUpFwdTrans->addChild(shapeGeode); flipDownFwdTrans->addChild(shapeGeode); flipUpBwdTrans->addChild(shapeGeode); flipDownBwdTrans->addChild(shapeGeode); /* set up flip up / flip down animation paths for shape switch */ AnimationPath* animationFlipUpFwd = new AnimationPath; AnimationPath* animationFlipDownFwd = new AnimationPath; AnimationPath* animationFlipUpBwd = new AnimationPath; AnimationPath* animationFlipDownBwd = new AnimationPath; animationFlipUpFwd->setLoopMode(AnimationPath::NO_LOOPING); animationFlipDownFwd->setLoopMode(AnimationPath::NO_LOOPING); animationFlipUpBwd->setLoopMode(AnimationPath::NO_LOOPING); animationFlipDownBwd->setLoopMode(AnimationPath::NO_LOOPING); Vec3 scaleUpVect, scaleDownVect; Quat flipUpFwdQuat, flipDownFwdQuat, flipUpBwdQuat, flipDownBwdQuat; float timestep = ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_TIME / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_SAMPS; float scalestep = 1.f / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_SAMPS; float anglestep = M_PI * 0.5 / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_SAMPS; if (typ == CAVEGeodeShape::BOX) pos[2] -= 0.5; else if (typ == CAVEGeodeShape::CYLINDER) pos[2] -= 1.0; osg::Vec3 diff, startPos(0,0,0), fwd, bwd; for (int i = 0; i < ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_SAMPS + 1; i++) { float t = i * timestep; float val = i * scalestep; scaleUpVect = Vec3(val, val, val); scaleDownVect = Vec3(1.f-val, 1.f-val, 1.f-val); flipUpFwdQuat = Quat(i * anglestep - M_PI / 2, Vec3(1, 0, 0)); flipDownFwdQuat = Quat(i * anglestep, Vec3(1, 0, 0)); flipUpBwdQuat = Quat(i * anglestep - M_PI / 2, Vec3(-1, 0, 0)); flipDownBwdQuat = Quat(i * anglestep, Vec3(-1, 0, 0)); diff = startPos - pos; for (int j = 0; j < 3; ++j) diff[j] *= val; fwd = startPos - diff; bwd = pos + diff; animationFlipUpFwd->insert(t, AnimationPath::ControlPoint(fwd, flipUpFwdQuat, scaleUpVect)); animationFlipDownFwd->insert(t, AnimationPath::ControlPoint(fwd, flipDownFwdQuat, scaleUpVect)); animationFlipUpBwd->insert(t, AnimationPath::ControlPoint(bwd, flipUpBwdQuat, scaleDownVect)); animationFlipDownBwd->insert(t, AnimationPath::ControlPoint(bwd, flipDownBwdQuat, scaleDownVect)); } AnimationPathCallback *animCallbackFlipUpFwd = new AnimationPathCallback(animationFlipUpFwd, 0.0, 1.f / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_TIME); AnimationPathCallback *animCallbackFlipDownFwd = new AnimationPathCallback(animationFlipDownFwd, 0.0, 1.f / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_TIME); AnimationPathCallback *animCallbackFlipUpBwd = new AnimationPathCallback(animationFlipUpBwd, 0.0, 1.f / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_TIME); AnimationPathCallback *animCallbackFlipDownBwd = new AnimationPathCallback(animationFlipDownBwd, 0.0, 1.f / ANIM_GEOMETRY_CREATOR_SHAPE_FLIP_TIME); flipUpFwdTrans->setUpdateCallback(animCallbackFlipUpFwd); flipDownFwdTrans->setUpdateCallback(animCallbackFlipDownFwd); flipUpBwdTrans->setUpdateCallback(animCallbackFlipUpBwd); flipDownBwdTrans->setUpdateCallback(animCallbackFlipDownBwd); /* write into shape switch entry array record*/ (*shapeEntry)->mFlipUpFwdAnim = animCallbackFlipUpFwd; (*shapeEntry)->mFlipDownFwdAnim = animCallbackFlipDownFwd; (*shapeEntry)->mFlipUpBwdAnim = animCallbackFlipUpBwd; (*shapeEntry)->mFlipDownBwdAnim = animCallbackFlipDownBwd; }