Esempio n. 1
0
 void testConstruct( void )
 {
     Vector3d a(1,2,3);
     Vector3d b(4,6,8);
     BoundingBox3d3f bb(a,b);
     TS_ASSERT_EQUALS(bb.min(),a);
     TS_ASSERT_EQUALS(bb.max(),b);
     TS_ASSERT_EQUALS(bb.across(),Vector3f(3,4,5));
     BoundingBox3f3f bba(bb);
     TS_ASSERT_EQUALS(Vector3f(bb.min()),bba.min());
     TS_ASSERT_EQUALS(Vector3f(bb.max()),bba.max());
     
 }
Esempio n. 2
0
void
SoXipMenuBase::GLRender( SoGLRenderAction* action )
{
	if( on.getValue() == FALSE )
		return ;

	// Compute the 3D position of the menu, given the mouse 2D position
	saveViewInformation( action );

	mMenuOffset->translation.setValue( mPlaneProj->project( position.getValue() ) );

	SoGetBoundingBoxAction bba( action->getViewportRegion() );
	bba.apply( mMenuSeparator );

	SbBox3f bbox = bba.getBoundingBox();
	bbox.transform( mModelMatrix );

	float viewportAR = mViewport.getViewportAspectRatio();
	SbVec3f screenOffset(0, 0, 0);
	if( viewportAR < 1. )
	{
		screenOffset[0] = bbox.getMax()[0] - 1.;
		screenOffset[1] = bbox.getMax()[1] - 1. / viewportAR;
	}
	else
	{
		screenOffset[0] = bbox.getMax()[0] - viewportAR;
		screenOffset[1] = bbox.getMax()[1] - 1;
	}

	if( screenOffset[0] < 0 )
		screenOffset[0] = 0;
	if( screenOffset[1] < 0 )
		screenOffset[1] = 0;

	SbVec3f worldOffset;
	mModelMatrix.inverse().multVecMatrix( screenOffset, worldOffset );

	mMenuOffset->translation.setValue( mMenuOffset->translation.getValue() - worldOffset );

	glPushAttrib( GL_ENABLE_BIT );
	glDisable( GL_DEPTH_TEST );

	SoXipKit::GLRender( action );

	glPopAttrib();
}
Esempio n. 3
0
 void testMerge ( void )
 {
     Vector3d a(1,2,3);
     Vector3d b(4,6,8);
     BoundingBox3d3f bba(a,b);
     Vector3d aB(0,1,2);
     Vector3d bB(3,4,5);
     BoundingBox3d3f bbb(aB,bB);
     BoundingBox3d3f bb=bba;
     bb.mergeIn(bbb);
     BoundingBox3d3f bbc=bbb;
     bbc.mergeIn(bba);
     TS_ASSERT_EQUALS(bb.min(),bbb.min());
     TS_ASSERT_EQUALS(bb.max(),bba.max());
     TS_ASSERT_EQUALS(bbc.min(),bbb.min());
     TS_ASSERT_EQUALS(bbc.max(),bba.max());
     
 }
Esempio n. 4
0
static SoSeparator *
setUpGraph(const SbViewportRegion &vpReg,
	   SoInput *sceneInput,
	   Options &options)
//
//////////////////////////////////////////////////////////////
{

    // Create a root separator to hold everything. Turn
    // caching off, since the transformation will blow
    // it anyway.
    SoSeparator *root = new SoSeparator;
    root->ref();
    root->renderCaching = SoSeparator::OFF;

    // Add a camera to view the scene
    SoPerspectiveCamera *camera = new SoPerspectiveCamera;
    root->addChild(camera);

    // Add a transform node to spin the scene
    SoTransform *sceneTransform = new SoTransform;
    sceneTransform->setName(SCENE_XFORM_NAME);
    root->addChild(sceneTransform);

    // Read and add input scene graph
    SoSeparator *inputRoot = SoDB::readAll(sceneInput);
    if (inputRoot == NULL) {
	fprintf(stderr, "Cannot read scene graph\n");
	root->unref();
	exit(1);
    }
    root->addChild(inputRoot);

    SoPath 	*path;
    SoGroup	*parent, *group;
    SoSearchAction	act;

    // expand out all File nodes and replace them with groups
    //    containing the children
    SoFile 	*fileNode;
    act.setType(SoFile::getClassTypeId());
    act.setInterest(SoSearchAction::FIRST);
    act.apply(inputRoot);
    while ((path = act.getPath()) != NULL) {
	fileNode = (SoFile *) path->getTail();
	path->pop();
	parent = (SoGroup *) path->getTail();
	group = fileNode->copyChildren();
	if (group) {
	    parent->replaceChild(fileNode, group);
	    // apply action again and continue
	    act.apply(inputRoot);
	}
    }

    // expand out all node kits and replace them with groups
    //    containing the children
    SoBaseKit	*kitNode;
    SoChildList	*childList;
    act.setType(SoBaseKit::getClassTypeId());
    act.setInterest(SoSearchAction::FIRST);
    act.apply(inputRoot);
    while ((path = act.getPath()) != NULL) {
	kitNode = (SoBaseKit *) path->getTail();
	path->pop();
	parent = (SoGroup *) path->getTail();
	group = new SoGroup;
	childList = kitNode->getChildren();
	for (int i=0; i<childList->getLength(); i++) 
	    group->addChild((*childList)[i]);
	parent->replaceChild(kitNode, group);
	act.apply(inputRoot);
    }

    // check to see if there are any lights
    // if no lights, add a directional light to the scene
    act.setType(SoLight::getClassTypeId());
    act.setInterest(SoSearchAction::FIRST);
    act.apply(inputRoot);
    if (act.getPath() == NULL) { // no lights
	SoDirectionalLight *light = new SoDirectionalLight;
	root->insertChild(light, 1);
    }
    else 
	options.hasLights = TRUE;

    // check to see if there are any texures in the scene
    act.setType(SoTexture2::getClassTypeId());
    act.setInterest(SoSearchAction::FIRST);
    act.apply(inputRoot);
    if (act.getPath() != NULL)
	options.hasTextures = TRUE;

    camera->viewAll(root, vpReg);

    // print out information about the scene graph

    int32_t numTris, numLines, numPoints, numNodes;
    countPrimitives( inputRoot, numTris, numLines, numPoints, numNodes );
    printf("Number of nodes in scene graph:     %d\n", numNodes );
    printf("Number of triangles in scene graph: %d\n", numTris );
    printf("Number of lines in scene graph:     %d\n", numLines );
    printf("Number of points in scene graph:    %d\n\n", numPoints );

    // Make the center of rotation the center of
    // the scene
    SoGetBoundingBoxAction	bba(vpReg);
    bba.apply(root);
    sceneTransform->center = bba.getBoundingBox().getCenter();

    return root;
}