/***************************************************************
* Function: acceptCAVEGeodeShape()
*
* 'refShapeCenter' is reference center of 'CAVEGeodeShape', use
*  this vector as reference center in design object space, which
*  is associated with center of BoundingBox. Apply the offset of
* 'shapeCenter - refShapeCenter' on top level of scene graph and
*  then rescale them in lower levels to fit into the scale of 
*  surface icon space. 
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::acceptCAVEGeodeShape(CAVEGeodeShape *shapeGeode, const osg::Vec3 &refShapeCenter)
{
    mRefShapeCenter = refShapeCenter;
    updateCAVEGeodeShape(shapeGeode);

    /* create 'MOVE' operational wireframe geode[0] */
    MatrixTransform *moveTrans = new MatrixTransform;
    CAVEGeodeEditWireframeMove *moveGeode = new CAVEGeodeEditWireframeMove;
    mMoveSwitch->addChild(moveTrans);
    mMoveMatTransVector.push_back(moveTrans);
    moveTrans->addChild(moveGeode);
    moveTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat);

    /* create 'ROTATE' operational wireframe geode[0] */
    MatrixTransform *rotateTrans = new MatrixTransform;
    CAVEGeodeEditWireframeRotate *rotateGeode = new CAVEGeodeEditWireframeRotate;
    mRotateSwitch->addChild(rotateTrans);
    mRotateMatTransVector.push_back(rotateTrans);
    rotateTrans->addChild(rotateGeode);
    rotateTrans->setMatrix(mBoundSphereScaleMat * mAccRootMat);

    /* create 'MANIPULATE' operational wireframe geode[0] */
    MatrixTransform *manipulateTrans = new MatrixTransform;
    CAVEGeodeEditWireframeManipulate *manipulateGeode = new CAVEGeodeEditWireframeManipulate;
    mManipulateSwitch->addChild(manipulateTrans);
    mManipulateMatTransVector.push_back(manipulateTrans);
    manipulateTrans->addChild(manipulateGeode);
    manipulateTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat);
}
Exemplo n.º 2
0
TextureWidget::TextureWidget(Interaction* interaction, float width, float height) :  Widget(), Events()
{
  StateSet* stateSet;

  _interaction = interaction;

  _width = width;
  _height = height;

  createBackground();
  createTexturesGeometry();
  initLabels();
  initTextures();

  _texture[0] = new Geode();
  _texture[0]->addDrawable(_geom);
  _texture[0]->addDrawable(_label0);
  _texture[0]->addDrawable(_texGeom0);
  stateSet = _texGeom0->getOrCreateStateSet();
  stateSet->setMode(GL_LIGHTING, StateAttribute::OFF);
  stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
  stateSet->setTextureAttributeAndModes(StateAttribute::TEXTURE, _tex0, StateAttribute::ON);

  _texture[1] = new Geode();
  _texture[1]->addDrawable(_geom);
  _texture[1]->addDrawable(_label1);
  _texture[1]->addDrawable(_texGeom1);
  stateSet = _texGeom1->getOrCreateStateSet();
  stateSet->setMode(GL_LIGHTING, StateAttribute::OFF);
  stateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
  stateSet->setTextureAttributeAndModes(StateAttribute::TEXTURE, _tex1, StateAttribute::ON);

  _swTexture = new Switch();
  _swTexture->addChild(_texture[0]);
  _swTexture->addChild(_texture[1]);
  _swTexture->setSingleChildOn(0);

  _node->addChild(_swTexture.get());

  _leftGeode = new Geode();
  _rightGeode = new Geode();

  MatrixTransform* transLeft = new MatrixTransform();
  MatrixTransform* transRight = new MatrixTransform();

  Matrix trans;

  trans.makeTranslate(Vec3(-_width/2.0, -_height/2.0 - DEFAULT_LABEL_HEIGHT/2.0, 3*EPSILON_Z));
  transLeft->setMatrix(trans);
  transLeft->addChild(_leftGeode);

  trans.makeTranslate(Vec3(+_width/2.0, -_height/2.0 - DEFAULT_LABEL_HEIGHT/2.0, 3*EPSILON_Z));
  transRight->setMatrix(trans);
  transRight->addChild(_rightGeode);

  _node->addChild(transLeft);
  _node->addChild(transRight);

  _interaction->addListener(this, this);
}
Exemplo n.º 3
0
ref_ptr<Group> VBSPEntity::createModelGeometry()
{
    std::string      modelFile;
    ref_ptr<Node>    modelNode;
    ref_ptr<Group>   entityGroup;

    // Try to load the model
    modelNode = osgDB::readRefNodeFile(entity_model);
    if (modelNode.valid())
    {
        // Create a group and add the model to it
        if (entity_transformed)
        {
            // Create a matrix transform
            MatrixTransform * entityXform = new MatrixTransform();

            // Set it up with the entity's transform information (scale
            // the position from inches to meters)
            Matrixf transMat, rotMat;
            Quat roll, yaw, pitch;
            transMat.makeTranslate(entity_origin * 0.0254);
            pitch.makeRotate(osg::DegreesToRadians(entity_angles.x()),
                             Vec3f(0.0, 1.0, 0.0));
            yaw.makeRotate(osg::DegreesToRadians(entity_angles.y()),
                           Vec3f(0.0, 0.0, 1.0));
            roll.makeRotate(osg::DegreesToRadians(entity_angles.z()),
                            Vec3f(1.0, 0.0, 0.0));
            rotMat.makeRotate(roll * pitch * yaw);

            // Set the transform matrix
            entityXform->setMatrix(rotMat * transMat);

            // Use the transform node as the main entity group
            entityGroup = entityXform;
        }
        else
        {
            // Create a group to represent the entire entity
            entityGroup = new Group();
        }

        // Add the model node to the group
        entityGroup->addChild(modelNode.get());

        // Set the group's name
        entityGroup->setName(class_name + std::string(":") + entity_model);
    }
    else
    {
        OSG_WARN << "Couldn't find prop \"" << entity_model << "\".";
        OSG_WARN << std::endl;

        // Leave the group empty (no model to show)
        entityGroup = NULL;
    }

    return entityGroup;
}
Exemplo n.º 4
0
 virtual void apply(MatrixTransform& mt)
 {
     Matrix matrix;
     if (_useInverseMatrix)
         _cp.getInverse(matrix);
     else
         _cp.getMatrix(matrix);
         
     mt.setMatrix(osg::Matrix::translate(-_pivotPoint)*matrix);
 }
Exemplo n.º 5
0
void EgoMovement::update(const int delta_time)
{
  move(delta_time);
  rotate();

  MatrixTransform* transform = (MatrixTransform*)parent;
  glm::mat4 parent_matrix = transform->getMatrix();

  glm::mat4 delta_matrix = glm::translate(glm::mat4(), position)
                         * glm::rotate(glm::mat4(), rotation.y, glm::vec3(0, 1, 0))
                         * glm::rotate(glm::mat4(), rotation.x, glm::vec3(1, 0, 0));

  transform->setMatrix(delta_matrix);
}
Exemplo n.º 6
0
//
// INIT
//
bool MathematicPlugin::init()
{
    if (plugin)
        return false;

    if (cover->debugLevel(3))
        fprintf(stderr, "\nMathematicPlugin::MathematicPlugin\n");

    // set plugin
    MathematicPlugin::plugin = this;

    // rotate scene so that x axis is in front
    MatrixTransform *trafo = VRSceneGraph::instance()->getTransform();
    Matrix m;
    m.makeRotate(inDegrees(-90.0), 0.0, 0.0, 1.0);
    trafo->setMatrix(m);

    // bounding box
    boundary_ = (double)coCoviseConfig::getFloat("max", "COVER.Plugin.Mathematic.Boundary", boundary_);
    boundingBox_ = new BoundingBox(-boundary_, -boundary_, -boundary_,
                                   boundary_, boundary_, boundary_);
    coVRPoint::setBoundingBox(boundingBox_);
    coVRLine::setBoundingBox(boundingBox_);
    coVRPlane::setBoundingBox(boundingBox_);
    coVRDirection::setBoundingBox(boundingBox_);
    coVRDistance::setBoundingBox(boundingBox_);
    drawBoundingBox(boundingBox_);

    // mathematics menu
    makeMathematicsMenu();

    // make the menus state label, it shows which objects intersects, etc
    stateLabel_ = new coLabelMenuItem(" ");
    mathematicsMenu_->insert(stateLabel_, mainMenuSepPos_ - 1);

    // colored axis
    axis_ = new coVRCoordinateAxis(0.07, boundary_, true);

    // zoom scene
    VRSceneGraph::instance()->viewAll();

    return true;
}
Exemplo n.º 7
0
MatrixTransform* loadModel(std::string name, float scale, float rotX, float rotY, float rotZ, osg::Vec3 translate)
{
	__FUNCTION_HEADER__

	Node* n = NULL;
	
	//did we already load (or try to load) this one?
	std::map<std::string, osg::ref_ptr<osg::Node> >::iterator i;
	bool haz = false;
	for(i = gLoadedModels.begin(); i != gLoadedModels.end(); i++)
	{
		if(i->first == name)
		{
			haz = true;
//			printf("We already have %s\n", name.c_str());
			n = i->second;
		}
	}
	

	if(!haz)		//if we didn't try to laod it before, do so now
	{
		n = osgDB::readNodeFile(findDataFile(name));
		gLoadedModels[name] = n;
		if(!n)
			logError("Unable to load model %s\n", name.c_str());
		else	printf("Loaded %s\n", name.c_str());
	}
	if(!n) return NULL;

	MatrixTransform* m = new MatrixTransform();
	m->setName(name);
	m->addChild(n);
	
	Matrix mat = Matrix::scale(scale, scale, scale);
	mat = mat * Matrix::rotate(rotX / 57.296, Vec3(1, 0, 0));
	mat = mat * Matrix::rotate(rotY / 57.296, Vec3(0, 1, 0));
	mat = mat * Matrix::rotate(rotZ / 57.296, Vec3(0, 0, 1));
	mat = mat * Matrix::translate(translate);
	m->setMatrix(mat);
	return m;
}
/***************************************************************
* Function: applyScaling()
*
* 'gridUnitScaleVect' is guranteed to be non-negative vector
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyScaling( const short &nOffsetSegs, const Vec3 &gridUnitScaleVect, 
						const std::string &gridUnitScaleInfo)
{
    mManipulateSwitch->setAllChildrenOn();

    /* scale to other direction: clear all children of 'mManipulateSwitch' except child[0], rebuild offset tree */
    if (mScaleNumSegs * nOffsetSegs <= 0)
    {
	unsigned int numChildren = mManipulateSwitch->getNumChildren();
	if (numChildren > 1)
	{
	    mManipulateSwitch->removeChildren(1, numChildren - 1);
	    MatrixTransVector::iterator itrMatTrans = mManipulateMatTransVector.begin();
	    mManipulateMatTransVector.erase(itrMatTrans + 1, itrMatTrans + numChildren);
	}
	mScaleNumSegs = 0;
    }

    /* decide unit offset vector and start/end index of children under 'mManipulateSwitch' */
    short idxStart = 0, idxEnd = 0;
    if (nOffsetSegs != 0)
    {
	idxStart = mScaleNumSegs;
	idxEnd = nOffsetSegs;
    }
    idxStart = idxStart > 0 ? idxStart: -idxStart;
    idxEnd = idxEnd > 0 ? idxEnd : -idxEnd;

    /* update the first wireframe with global translation and rotation */
    if (idxStart == 0) mManipulateMatTransVector[0]->setMatrix(mBoundBoxScaleMat * mAccRootMat);

    /* create or remove a sequence of extra children under 'mMoveSwitch' */
    if (idxStart < idxEnd)
    {
	for (short i = idxStart + 1; i <= idxEnd; i++)
	{
	    /* generate scaling vector with non-negative values */
	    Vec3 scaleVect = Vec3(1, 1, 1);
	    if (nOffsetSegs > 0) scaleVect += gridUnitScaleVect * i;
	    else scaleVect -= gridUnitScaleVect * i;
	    scaleVect.x() = scaleVect.x() > 0 ? scaleVect.x() : 0;
	    scaleVect.y() = scaleVect.y() > 0 ? scaleVect.y() : 0;
	    scaleVect.z() = scaleVect.z() > 0 ? scaleVect.z() : 0;

	    Matrixd scaleMat;
	    scaleMat.makeScale(scaleVect);
	    MatrixTransform *scaleTrans = new MatrixTransform;
	    CAVEGeodeEditWireframeManipulate *manipulateGeode = new CAVEGeodeEditWireframeManipulate;
	    mManipulateSwitch->addChild(scaleTrans);
	    mManipulateMatTransVector.push_back(scaleTrans);
	    scaleTrans->addChild(manipulateGeode);
	    scaleTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat * scaleMat);
	}
    }
    else if (idxStart > idxEnd)
    {
	mManipulateSwitch->removeChildren(idxEnd + 1, idxStart - idxEnd);
	MatrixTransVector::iterator itrMatTrans = mManipulateMatTransVector.begin();
	itrMatTrans += idxEnd + 1;
	mManipulateMatTransVector.erase(itrMatTrans, itrMatTrans + (idxStart - idxEnd));
    }

    mScaleNumSegs = nOffsetSegs;
    mScaleUnitVect = gridUnitScaleVect;

    if (!mPrimaryFlag) return;

    /* update info text if 'this' wireframe is primary */
    mEditInfoTextSwitch->setAllChildrenOn();

    float scaleUnit = gridUnitScaleVect.x() > 0 ? gridUnitScaleVect.x() : gridUnitScaleVect.y();
    scaleUnit = scaleUnit > 0 ? scaleUnit : gridUnitScaleVect.z();

    char info[128];
    float scaleval = scaleUnit * nOffsetSegs + 1.0f;
    scaleval = scaleval > 0 ? scaleval:0;
    sprintf(info, "Scale = %3.2f \nSnapping = ", scaleval);
    mEditInfoText->setText(info + gridUnitScaleInfo);
}
/***************************************************************
* Function: applyRotation()
*
* 'axisSVect': rotational snapping values around each axis,
*  for instance, Vec3(2, 0, 0) means rotation around X-axis by
*  two times of 'gridUnitAngle'
*  only one component of 'axisIntVect' is supposed to be non-zero
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyRotation(const osg::Vec3s &axisSVect, const float &gridUnitAngle,
						const string &gridUnitAngleInfo)
{
    if (!mPrimaryFlag) return;

    mRotateSwitch->setAllChildrenOn();

    /* rotate in other direction: clear all children of 'mRotateSwitch' except child[0], rebuild offset tree */
    if ((mRotateSVect.x() * axisSVect.x() + mRotateSVect.y() * axisSVect.y() + mRotateSVect.z() * axisSVect.z()) <= 0)
    {
	unsigned int numChildren = mRotateSwitch->getNumChildren();
	if (numChildren > 1)
	{
	    mRotateSwitch->removeChildren(1, numChildren - 1);
	    MatrixTransVector::iterator itrMatTrans = mRotateMatTransVector.begin();
	    mRotateMatTransVector.erase(itrMatTrans + 1, itrMatTrans + numChildren);
	}
	mRotateSVect = Vec3s(0, 0, 0);
    }

    /* decide unit rotation quat and start/end index of children under 'mRotateSwitch' */
    Vec3 gridRotationAxis;
    short idxStart = 0, idxEnd = 0;
    if (axisSVect.x() != 0)
    {
	idxStart = mRotateSVect.x();
	idxEnd = axisSVect.x();
	if (axisSVect.x() > 0) gridRotationAxis = Vec3(1, 0, 0);
	else gridRotationAxis = Vec3(-1, 0, 0);
    }
    else if (axisSVect.y() != 0)
    {
	idxStart = mRotateSVect.y();
	idxEnd = axisSVect.y();
	if (axisSVect.y() > 0) gridRotationAxis = Vec3(0, 1, 0);
	else gridRotationAxis = Vec3(0, -1, 0);
    }
    else if (axisSVect.z() != 0)
    {
	idxStart = mRotateSVect.z();
	idxEnd = axisSVect.z();
	if (axisSVect.z() > 0) gridRotationAxis = Vec3(0, 0, 1);
	else gridRotationAxis = Vec3(0, 0, -1);
    }
    idxStart = idxStart > 0 ? idxStart: -idxStart;
    idxEnd = idxEnd > 0 ? idxEnd : -idxEnd;

    /* create or remove a sequence of extra children under 'mRotateSwitch' */
    if (idxStart < idxEnd)
    {
	for (short i = idxStart + 1; i <= idxEnd; i++)
	{
	    Matrixd rotMat;
	    rotMat.makeRotate(gridUnitAngle * i, gridRotationAxis);
	    MatrixTransform *rotateTrans = new MatrixTransform;
	    CAVEGeodeEditWireframeRotate *rotateGeode = new CAVEGeodeEditWireframeRotate;
	    mRotateSwitch->addChild(rotateTrans);
	    mRotateMatTransVector.push_back(rotateTrans);
	    rotateTrans->addChild(rotateGeode);
	    rotateTrans->setMatrix(mBoundSphereScaleMat * rotMat);
	}
    }
    else if (idxStart > idxEnd)
    {
	mRotateSwitch->removeChildren(idxEnd + 1, idxStart - idxEnd);
	MatrixTransVector::iterator itrMatTrans = mRotateMatTransVector.begin();
	itrMatTrans += idxEnd + 1;
	mRotateMatTransVector.erase(itrMatTrans, itrMatTrans + (idxStart - idxEnd));
    }

    mRotateSVect = axisSVect;

    /* update info text if 'this' wireframe is primary */
    mEditInfoTextSwitch->setAllChildrenOn();

    char info[128];
    const float gridUnitAngleDegree = gridUnitAngle * 180 / M_PI;
    sprintf(info, "Angle = %3.2f\nSnapping = ", gridUnitAngleDegree * idxEnd);
    mEditInfoText->setText(info + gridUnitAngleInfo);
}
/***************************************************************
* Function: applyTranslation()
*
* 'gridSVect': number of snapping segments along each direction
* 'gridUnitLegnth': actual length represented by each segment,
*  only one component of 'gridSVect' is supposed to be non-zero
*
***************************************************************/
void CAVEGroupEditGeodeWireframe::applyTranslation(const osg::Vec3s &gridSVect, const float &gridUnitLegnth,
							const string &gridUnitLegnthInfo)
{
    mMoveSwitch->setAllChildrenOn();

    /* move to other direction: clear all children of 'mMoveSwitch' except child[0], rebuild offset tree */
    if ((mMoveSVect.x() * gridSVect.x() + mMoveSVect.y() * gridSVect.y() + mMoveSVect.z() * gridSVect.z()) <= 0)
    {
	unsigned int numChildren = mMoveSwitch->getNumChildren();
	if (numChildren > 1)
	{
	    mMoveSwitch->removeChildren(1, numChildren - 1);
	    MatrixTransVector::iterator itrMatTrans = mMoveMatTransVector.begin();
	    mMoveMatTransVector.erase(itrMatTrans + 1, itrMatTrans + numChildren);
	}
	mMoveSVect = Vec3s(0, 0, 0);
    }

    /* decide unit offset vector and start/end index of children under 'mMoveSwitch' */
    Vec3 gridOffsetVect;
    short idxStart = 0, idxEnd = 0;
    if (gridSVect.x() != 0)
    {
	idxStart = mMoveSVect.x();
	idxEnd = gridSVect.x();
	if (gridSVect.x() > 0) gridOffsetVect = Vec3(gridUnitLegnth, 0, 0);
	else gridOffsetVect = Vec3(-gridUnitLegnth, 0, 0);
    }
    else if (gridSVect.y() != 0)
    {
	idxStart = mMoveSVect.y();
	idxEnd = gridSVect.y();
	if (gridSVect.y() > 0) gridOffsetVect = Vec3(0, gridUnitLegnth, 0);
	else gridOffsetVect = Vec3(0, -gridUnitLegnth, 0);
    }
    else if (gridSVect.z() != 0)
    {
	idxStart = mMoveSVect.z();
	idxEnd = gridSVect.z();
	if (gridSVect.z() > 0) gridOffsetVect = Vec3(0, 0, gridUnitLegnth);
	else gridOffsetVect = Vec3(0, 0, -gridUnitLegnth);
    } 
    idxStart = idxStart > 0 ? idxStart: -idxStart;
    idxEnd = idxEnd > 0 ? idxEnd : -idxEnd;

    /* update the first wireframe with global translation and rotation */
    if (idxStart == 0) mMoveMatTransVector[0]->setMatrix(mBoundBoxScaleMat * mAccRootMat);

    /* create or remove a sequence of extra children under 'mMoveSwitch' */
    if (idxStart < idxEnd)
    {
	for (short i = idxStart + 1; i <= idxEnd; i++)
	{
	    Matrixd transMat;
	    transMat.makeTranslate(gridOffsetVect * i);
	    MatrixTransform *moveTrans = new MatrixTransform;
	    CAVEGeodeEditWireframeMove *moveGeode = new CAVEGeodeEditWireframeMove;
	    mMoveSwitch->addChild(moveTrans);
	    mMoveMatTransVector.push_back(moveTrans);
	    moveTrans->addChild(moveGeode);
	    moveTrans->setMatrix(mBoundBoxScaleMat * mAccRootMat * transMat);
	}
    }
    else if (idxStart > idxEnd)
    {
	mMoveSwitch->removeChildren(idxEnd + 1, idxStart - idxEnd);
	MatrixTransVector::iterator itrMatTrans = mMoveMatTransVector.begin();
	itrMatTrans += idxEnd + 1;
	mMoveMatTransVector.erase(itrMatTrans, itrMatTrans + (idxStart - idxEnd));
    }

    mMoveSVect = gridSVect;

    if (!mPrimaryFlag) return;

    /* update info text if 'this' wireframe is primary */
    mEditInfoTextSwitch->setAllChildrenOn();

    char info[128];
    sprintf(info, "Offset = %3.2f m\nSnapping = ", gridUnitLegnth * idxEnd);
    mEditInfoText->setText(info + gridUnitLegnthInfo);
}
Exemplo n.º 11
0
/***************************************************************
* 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);
}
Exemplo n.º 12
0
ref_ptr<Group> VBSPEntity::createBrushGeometry()
{
    int                 i;
    int                 numGeoms;
    VBSPGeometry **     vbspGeomList;
    Model               currentModel;
    Face                currentFace;
    TexInfo             currentTexInfo;
    TexData             currentTexData;
    const char *        texName;
    char                currentTexName[256];
    int                 currentGeomIndex;
    VBSPGeometry *      currentGeom;
    ref_ptr<Group>      entityGroup;
    ref_ptr<Group>      geomGroup;
    std::stringstream   groupName;

    // Create a list of VBSPGeometry objects for each texdata entry in the
    // scene.  These objects will hold the necessary geometry data until we
    // convert them back into OSG geometry objects.  We potentially will need
    // one for each state set in the map
    numGeoms = bsp_data->getNumStateSets();
    vbspGeomList = new VBSPGeometry *[numGeoms];

    // Initialize the list to all NULL for now.  We'll create the geometry
    // objects as we need them
    memset(vbspGeomList, 0, sizeof(VBSPGeometry *) * numGeoms);

    // Get this entity's internal model from the bsp data
    currentModel = bsp_data->getModel(entity_model_index);

    // Iterate over the face list and assign faces to the appropriate geometry
    // objects
    for (i = 0; i < currentModel.num_faces; i++)
    {
        // Get the current face
        currentFace = bsp_data->getFace(currentModel.first_face + i);

        // Get the texdata used by this face
        currentTexInfo = bsp_data->getTexInfo(currentFace.texinfo_index);
        currentTexData = bsp_data->getTexData(currentTexInfo.texdata_index);

        // Get the texture name
        texName = bsp_data->
            getTexDataString(currentTexData.name_string_table_id).c_str();
        strcpy(currentTexName, texName);

        // See if this is a non-drawable surface
        if ((strcasecmp(currentTexName, "tools/toolsareaportal") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsblocklos") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsblockbullets") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsblocklight") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsclip") != 0) &&
            (strcasecmp(currentTexName, "tools/toolscontrolclip") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsdotted") != 0) &&
            (strcasecmp(currentTexName, "tools/toolshint") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsinvisible") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsinvisibleladder") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsnodraw") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsnpcclip") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsoccluder") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsorigin") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsskip") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsskybox") != 0) &&
            (strcasecmp(currentTexName, "tools/toolsskyfog") != 0) &&
            (strcasecmp(currentTexName, "tools/toolstrigger") != 0))
        {
            // Get or create the corresponding VBSPGeometry object from the
            // list
            currentGeomIndex = currentTexInfo.texdata_index;
            currentGeom = vbspGeomList[currentGeomIndex];
            if (currentGeom == NULL)
            {
                // Create the geometry object
                vbspGeomList[currentGeomIndex] = new VBSPGeometry(bsp_data);
                currentGeom = vbspGeomList[currentGeomIndex];
            }

            // Add the face to the appropriate VBSPGeometry object
            currentGeom->addFace(currentModel.first_face + i);
        }
    }

    // Create a top-level group to hold the geometry objects
    if (entity_transformed)
    {
        // Create a matrix transform
        MatrixTransform * entityXform = new MatrixTransform();

        // Set it up with the entity's transform information (scale the
        // position from inches to meters)
        Matrixf transMat, rotMat;
        Quat roll, yaw, pitch;
        transMat.makeTranslate(entity_origin * 0.0254);
        pitch.makeRotate(osg::DegreesToRadians(entity_angles.x()),
                         Vec3f(0.0, 1.0, 0.0));
        yaw.makeRotate(osg::DegreesToRadians(entity_angles.y()),
                       Vec3f(0.0, 0.0, 1.0));
        roll.makeRotate(osg::DegreesToRadians(entity_angles.z()),
                        Vec3f(1.0, 0.0, 0.0));
        rotMat.makeRotate(roll * pitch * yaw);

        // Set the transform matrix
        entityXform->setMatrix(rotMat * transMat);

        // Use the transform node as the main entity group
        entityGroup = entityXform;
    }
    else
    {
        // Create a group to represent the entire entity
        entityGroup = new Group();
    }

    // Iterate over the geometry array and convert each geometry object
    // into OSG geometry
    for (i = 0; i < numGeoms; i++)
    {
        // Get the next geometry object (if any)
        currentGeom = vbspGeomList[i];
        if (currentGeom != NULL)
        {
            // Convert the BSP geometry to OSG geometry
            geomGroup = currentGeom->createGeometry();

            // Make sure the geometry converted properly
            if (geomGroup.valid())
            {
                // Set this group's state set
                geomGroup->setStateSet(bsp_data->getStateSet(i));

                // Add the geometry group to the entity group
                entityGroup->addChild(geomGroup.get());
            }
        }
    }

    // Name the entity group
    groupName << class_name << ":" << entity_model_index;
    entityGroup->setName(groupName.str());

    // Return the group we created
    return entityGroup;
}
Exemplo n.º 13
0
/***************************************************************
* 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);
}
Exemplo n.º 14
0
void BezierCurvePlugin::changeStatus()
{
    int size = controlPoints.size();
    for (int i = 0; i < size; i++)
    {
        removePoint();
    }

    makeCurve();

    MatrixTransform *trafo = VRSceneGraph::instance()->getTransform();
    Matrix m;
    m.makeIdentity();
    trafo->setMatrix(m);

    switch (presentationStepCounter)
    {
    case 0:
        curve->showCasteljau(false);
        showCasteljauAnimation = false;
        showCasteljauStep = false;
        showTangents = false;
        break;

    case 1:
        curve->showCasteljau(false);
        showCasteljauAnimation = false;
        showCasteljauStep = false;
        showTangents = false;
        break;

    case 2:
        curve->showCasteljau(false);
        showCasteljauAnimation = false;
        showCasteljauStep = false;
        showTangents = true;
        break;

    case 3:
        setParameterValueAnimation(0);
        setParameterValueStep(0.5);
        curve->showCasteljau(true);
        showCasteljauAnimation = true;
        showCasteljauStep = false;
        showTangents = false;
        break;

    case 4:
        showCasteljauAnimation = false;
        curve->showCasteljau(false);
        showCasteljauStep = false;
        showTangents = false;
        break;

    case 5:
        curve->showCasteljau(false);
        showCasteljauAnimation = false;
        showCasteljauStep = false;
        showTangents = false;
        break;

    case 6:
        setParameterValueAnimation(0);
        setParameterValueStep(0.5);
        curve->showCasteljau(false);
        showCasteljauAnimation = false;
        showCasteljauStep = false;
        showTangents = false;
        break;

    case 7:
        curve->showCasteljau(false);
        showCasteljauAnimation = false;
        showCasteljauStep = false;
        showTangents = false;
        break;
    }
}
Exemplo n.º 15
0
osg::Node* Shape::createOSGAxes(const base::Dimension3& dim)
{
  const Real s = 1.5;
  Real d = Math::minimum(0.06,Math::minimum(dim.x,dim.y,dim.z)/16.0);

  Group* g = NewObj Group;
  g->setName("debug");

  // color the axes X:red, Y:green and Z:blue, with white end cones
  StateSet* red = NewObj StateSet();
  osg::Material* rmat = NewObj osg::Material();
  Vec4 cred(1,0,0,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  rmat->setDiffuse( osg::Material::FRONT_AND_BACK, cred );
  rmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  rmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  red->setAttribute( rmat );

  StateSet* green = NewObj StateSet();
  osg::Material* gmat = NewObj osg::Material();
  Vec4 cgreen(0,1,0,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  gmat->setDiffuse( osg::Material::FRONT_AND_BACK, cgreen );
  gmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  gmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  green->setAttribute( gmat );
  
  StateSet* blue = NewObj StateSet();
  osg::Material* bmat = NewObj osg::Material();
  Vec4 cblue(0,0,1,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  bmat->setDiffuse( osg::Material::FRONT_AND_BACK, cblue );
  bmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  bmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  blue->setAttribute( bmat );

  StateSet* white = NewObj StateSet();
  osg::Material* wmat = NewObj osg::Material();
  Vec4 cwhite(1,1,1,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  wmat->setDiffuse( osg::Material::FRONT_AND_BACK, cwhite );
  wmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  wmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  white->setAttribute( wmat );


  // a long Clyinder for the axis and a cone-like cylinder 
  //  for the arrow head of each X,Y and Z.

  MatrixTransform* xrot = NewObj MatrixTransform();
  xrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(0,1,0)));
  xrot->postMult(osg::Matrix::translate(s*dim.x/4.0,0,0));
  g->addChild(xrot);
		
  MatrixTransform* yrot = NewObj MatrixTransform();
  yrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(-1,0,0)));
  yrot->postMult(osg::Matrix::translate(0,s*dim.y/4.0,0));
  g->addChild(yrot);
		
  MatrixTransform* zrot = NewObj MatrixTransform();
  zrot->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0));
  g->addChild(zrot);
		
  // the cylinder axes
  ref<Cylinder> xc(NewObj Cylinder(s*dim.x/2.0,d));
  xrot->addChild(xc->createOSGVisual());
  xrot->setStateSet(red);

  ref<Cylinder> yc(NewObj Cylinder(s*dim.y/2.0,d));
  yrot->addChild(yc->createOSGVisual());
  yrot->setStateSet(green);

  ref<Cylinder> zc(NewObj Cylinder(s*dim.z/2.0,d));
  zrot->addChild(zc->createOSGVisual());
  zrot->setStateSet(blue);

  // Translate each axis cone to the end
  MatrixTransform* xtrans = NewObj MatrixTransform();
  xtrans->setMatrix(osg::Matrix::translate(0,0,s*dim.x/4.0+d));
  xrot->addChild(xtrans);
  
  MatrixTransform* ytrans = NewObj MatrixTransform();
  ytrans->setMatrix(osg::Matrix::translate(0,0,s*dim.y/4.0+d));
  yrot->addChild(ytrans);
  
  MatrixTransform* ztrans = NewObj MatrixTransform();
  ztrans->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0+d));
  zrot->addChild(ztrans);
  
  // the end cones
  ref<Cone> cone(NewObj Cone(4*d,2*d));
  osg::Node* coneNode = cone->createOSGVisual();
  coneNode->setStateSet(white);
  
  xtrans->addChild(coneNode);
  ytrans->addChild(coneNode);
  ztrans->addChild(coneNode);

  return g;
}
Exemplo n.º 16
0
//
// INIT
//
bool ConicSectionPlugin::init()
{
    if (plugin)
        return false;

    if (cover->debugLevel(3))
        fprintf(stderr, "\nConicSectionPlugin::ConicSectionPlugin\n");

    // set plugin
    ConicSectionPlugin::plugin = this;

    // rotate scene
    MatrixTransform *trafo = VRSceneGraph::instance()->getTransform();
    Matrix m;
    m.makeRotate(inDegrees(-90.0), 0.0, 0.0, 1.0);
    trafo->setMatrix(m);

    makeMenu();

    // create the cones
    topCone_ = new osg::Cone(Vec3(0, 0, 0), 0.5, 1);
    bottomCone_ = new osg::Cone(Vec3(0, 0, -1.5), 0.5, 1);
    topConeTransform_ = new MatrixTransform();
    topConeDraw_ = new ShapeDrawable();
    bottomConeDraw_ = new ShapeDrawable();
    topConeGeode_ = new Geode();
    bottomConeGeode_ = new Geode();
    Cone_ = new MatrixTransform();
    Cone_->setNodeMask(Cone_->getNodeMask() & (~Isect::Intersection));

    topCone_->ref();
    bottomCone_->ref();
    topConeTransform_->ref();
    topConeDraw_->ref();
    bottomConeDraw_->ref();
    topConeGeode_->ref();
    bottomConeGeode_->ref();
    Cone_->ref();

    // rotate the cone on top
    Matrix mCone;
    mCone.makeRotate(inDegrees(180.0), 1, 0, 0);
    topConeTransform_->setMatrix(mCone);

    topConeDraw_->setShape(topCone_.get());
    bottomConeDraw_->setShape(bottomCone_.get());
    topConeGeode_->addDrawable(topConeDraw_.get());
    bottomConeGeode_->addDrawable(bottomConeDraw_.get());
    topConeTransform_->addChild(topConeGeode_.get());
    Cone_->addChild(topConeTransform_.get());
    Cone_->addChild(bottomConeGeode_.get());

    cover->getObjectsRoot()->addChild(Cone_.get());

    // call viewall
    VRSceneGraph::instance()->viewAll();

    // geode for plane
    plane_ = new Geometry();
    plane_->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, 6));
    plane_->setNormalBinding(Geometry::BIND_PER_VERTEX);
    plane_->setUseDisplayList(false);
    plane_->ref();

    planeGeode_ = new Geode();
    planeGeode_->ref();
    planeGeode_->addDrawable(plane_.get());
    planeGeode_->setNodeMask(planeGeode_->getNodeMask() & (Isect::Visible) & (~Isect::Intersection) & (~Isect::Pick));
    material_ = new Material();
    material_->ref();
    material_->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.545, 0.0, 0.545, 0.5));
    material_->setAmbient(Material::FRONT_AND_BACK, Vec4(0.545, 0.0, 0.545, 0.5));
    stateSet_ = VRSceneGraph::instance()->loadDefaultGeostate();
    stateSet_->ref();
    stateSet_->setMode(GL_BLEND, StateAttribute::ON);
    stateSet_->setAttributeAndModes(material_.get());
    stateSet_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
    planeGeode_->setStateSet(stateSet_.get());
    //cover->getObjectsRoot()->addChild(planeGeode_.get());

    oldPlane = Vec4(0, 0, 0, 0);

    // init plane and coordinates
    helperPlane_ = new coPlane(Vec3(0, 1, 0), Vec3(0, 0, 0));

    polyCoords_ = new osg::Vec3Array(6);
    polyCoords_->ref();
    (*polyCoords_)[0].set(-0.05, 0.0, -0.05);
    (*polyCoords_)[1].set(0.05, 0.0, -0.05);
    (*polyCoords_)[2].set(0.05, 0.0, 0.05);
    (*polyCoords_)[3].set(-0.05, 0.0, 0.05);
    (*polyCoords_)[4].set(-0.05, 0.0, -0.05);
    (*polyCoords_)[5].set(-0.05, 0.0, -0.05);
    plane_->setVertexArray(polyCoords_.get());

    polyNormal_ = new osg::Vec3Array(6);
    polyNormal_->ref();
    for (int i = 0; i < 6; i++)
    {
        (*polyNormal_)[i].set(0, 1, 0);
    }
    plane_->setNormalArray(polyNormal_.get());

    return true;
}