void BoundingBoxMarker::create(const BoundingBox& bbox, const Vector3f& color, float transparency, double width)
{
    SgShape* shape = new SgShape;
    MeshGenerator meshGenerator;
    shape->setMesh(meshGenerator.generateBox(Vector3(width, width, width)));
    
    SgMaterial* material = shape->setMaterial(new SgMaterial);
    material->setTransparency(transparency);
    material->setDiffuseColor(color);
    material->setEmissiveColor(color);

    const double& x0 = bbox.min().x();
    const double& x1 = bbox.max().x();
    const double& y0 = bbox.min().y();
    const double& y1 = bbox.max().y();
    const double& z0 = bbox.min().z();
    const double& z1 = bbox.max().z();
    
    addMarker(shape, x0, y0, z0);
    addMarker(shape, x0, y0, z1);
    addMarker(shape, x0, y1, z0);
    addMarker(shape, x0, y1, z1);

    addMarker(shape, x1, y0, z0);
    addMarker(shape, x1, y0, z1);
    addMarker(shape, x1, y1, z0);
    addMarker(shape, x1, y1, z1);
}
void HlModel::SetTextures( SgNode *pNode, BtU32 index, RsTexture *pTexture )
{
	// Cache the materials
	SgMaterial* pMaterials = pNode->pMaterial();

	// Cache the number of materials
	BtU32 numMaterials = pMaterials->NumMaterials();

	for( BtU32 i=0; i<numMaterials; i++)
	{
		// Cache the material
		RsMaterial* pMaterial = pMaterials->GetMaterial( i );

		// Set the texture
		pMaterial->SetTexture( index, pTexture );
	}
	
	// Cache the first child
	SgNode* pChild = pNode->pFirstChild();

	// Loop through the children
	while( pChild != BtNull )
	{
		// Set the materials
		SetTextures( pChild, index, pTexture );

		// Move to the next child
		pChild = pChild->pNextSibling();
	}
}
void HlModel::SetSortOrders( SgNode *pNode, BtU32 sortOrder )
{
	if( pNode->HasMaterials() )
	{
		SgMaterial* pMaterials = pNode->pMaterial();

		// Cache the number of materials
		BtU32 numMaterials = pMaterials->NumMaterials();

		for( BtU32 i=0; i<numMaterials; i++)
		{
			// Cache the material
			RsMaterial* pMaterial = pMaterials->GetMaterial( i );

			// Set the sort order
			pMaterial->SetSortOrder( sortOrder );

			// Set the material
			pMaterials->SetMaterial( i, pMaterial );
		}
	}

	// Cache the first child
	SgNode* pChild = pNode->pFirstChild();

	// Loop through the children
	while( pChild != BtNull )
	{
		// Set the materials
		SetSortOrders( pChild, sortOrder );

		// Move to the next child
		pChild = pChild->pNextSibling();
	}
}
ForceSensorVisualizerItem::ForceSensorVisualizerItem()
    : SensorVisualizerItemBase(this)
{
    setName("ForceSensor");
    
    scene = new SgGroup;

    SgMaterial* material = new SgMaterial;
    Vector3f color(1.0f, 0.2f, 0.2f);
    material->setDiffuseColor(Vector3f::Zero());
    material->setEmissiveColor(color);
    material->setAmbientIntensity(0.0f);
    material->setTransparency(0.6f);

    MeshGenerator meshGenerator;
    cone = new SgShape;
    cone->setMesh(meshGenerator.generateCone(0.03,  0.04));
    cone->setMaterial(material);

    cylinder = new SgShape;
    cylinder->setMesh(meshGenerator.generateCylinder(0.01, 1.0));
    cylinder->setMaterial(material);

    visualRatio = 0.002;
}
Beispiel #5
0
TranslationDragger::TranslationDragger(bool setDefaultAxes)
{
    draggableAxes_ = TX | TY | TZ;
    
    axisCylinderNormalizedRadius = 0.04;

    defaultAxesScale = new SgScaleTransform;
    customAxes = new SgGroup;

    for(int i=0; i < 3; ++i){
        SgMaterial* material = new SgMaterial;
        Vector3f color(0.2f, 0.2f, 0.2f);
        color[i] = 1.0f;
        material->setDiffuseColor(Vector3f::Zero());
        material->setEmissiveColor(color);
        material->setAmbientIntensity(0.0f);
        material->setTransparency(0.6f);
        axisMaterials[i] = material;
    }

    if(setDefaultAxes){
        MeshGenerator meshGenerator;
        SgMeshPtr mesh = meshGenerator.generateArrow(1.8, 0.08, 0.1, 2.5);
        for(int i=0; i < 3; ++i){
            SgShape* shape = new SgShape;
            shape->setMesh(mesh);
            shape->setMaterial(axisMaterials[i]);
            
            SgPosTransform* arrow = new SgPosTransform;
            arrow->addChild(shape);
            if(i == 0){
                arrow->setRotation(AngleAxis(-PI / 2.0, Vector3::UnitZ()));
            } else if(i == 2){
                arrow->setRotation(AngleAxis( PI / 2.0, Vector3::UnitX()));
            }
            SgInvariantGroup* invariant = new SgInvariantGroup;
            invariant->setName(axisNames[i]);
            invariant->addChild(arrow);
            SgSwitch* axis = new SgSwitch;
            axis->addChild(invariant);
            defaultAxesScale->addChild(axis);
        }
        addChild(defaultAxesScale);
    }

    isContainerMode_ = false;
}
void HlModel::SetMaterialTechnique( SgNode *pNode, const BtChar *technique )
{
	if( pNode->GetMesh() )
	{
		// Cache the materials
		SgMaterial* pMaterials = pNode->pMaterial();

		// Cache the number of materials
		BtU32 numMaterials = pMaterials->NumMaterials();

		for( BtU32 i=0; i<numMaterials; i++)
		{
			// Cache the material
			RsMaterial* pMaterial = pMaterials->GetMaterial( i )->GetDuplicate();

			// Cache the current technique name
			BtChar *currentTechniqueName = pMaterial->GetTechniqueName();
			(void)currentTechniqueName;

			// Set the technique name
			pMaterial->SetTechniqueName( technique );

			// Set the material
			pMaterials->SetMaterial( i, pMaterial );
		}
	}

	// Cache the first child
	SgNode* pChild = pNode->pFirstChild();

	// Loop through the children
	while( pChild != BtNull )
	{
		// Set the materials
		SetMaterialTechnique( pChild, technique );

		// Move to the next child
		pChild = pChild->pNextSibling();
	}
}
Beispiel #7
0
RotationDragger::RotationDragger()
{
    draggableAxes_ = RX | RY | RZ;

    MeshGenerator meshGenerator;
    meshGenerator.setDivisionNumber(36);
    SgMeshPtr beltMesh1 = meshGenerator.generateDisc(1.0, 1.0 - 0.2);
    meshGenerator.setDivisionNumber(24);
    SgMeshPtr beltMesh2 = meshGenerator.generateCylinder(1.0, 0.2, false, false);

    scale = new SgScaleTransform;
    
    // make dragger belts
    for(int i=0; i < 3; ++i){
        
        SgMaterial* material = new SgMaterial;
        Vector3f color(0.2f, 0.2f, 0.2f);
        color[i] = 1.0f;
        material->setDiffuseColor(Vector3f::Zero());
        material->setEmissiveColor(color);
        material->setAmbientIntensity(0.0f);
        material->setTransparency(0.6f);

        SgShape* beltShape1 = new SgShape;
        beltShape1->setMesh(beltMesh1);
        beltShape1->setMaterial(material);

        SgShape* beltShape2 = new SgShape;
        beltShape2->setMesh(beltMesh2);
        beltShape2->setMaterial(material);
        
        ViewpointDependentRenderingSelector* selector = new ViewpointDependentRenderingSelector;
        
        SgPosTransform* transform1 = new SgPosTransform;
        if(i == 0){ // x-axis
            selector->setAxis(Vector3::UnitX());
            transform1->setRotation(AngleAxis(PI / 2.0, Vector3::UnitY()));
        } else if(i == 1){ // y-axis
            selector->setAxis(Vector3::UnitY());
            transform1->setRotation(AngleAxis(-PI / 2.0, Vector3::UnitX()));
        } else if(i == 2) { // z-axis
            selector->setAxis(Vector3::UnitZ());
        }
        transform1->addChild(beltShape1);
        SgInvariantGroup* belt1 = new SgInvariantGroup;
        belt1->setName(axisNames[i]);
        belt1->addChild(transform1);
        selector->addChild(belt1);

        SgPosTransform* transform2 = new SgPosTransform;
        if(i == 0){ // x-axis
            transform2->setRotation(AngleAxis(-PI / 2.0, Vector3::UnitZ()));
        } else if(i == 2) { // z-axis
            transform2->setRotation(AngleAxis(PI / 2.0, Vector3::UnitX()));
        }
        transform2->addChild(beltShape2);
        SgInvariantGroup* belt2 = new SgInvariantGroup;
        belt2->setName(axisNames[i]);
        belt2->addChild(transform2);
        selector->addChild(belt2);

        SgSwitch* axis = new SgSwitch;
        axis->addChild(selector);

        scale->addChild(axis);
    }

    addChild(scale);

    isContainerMode_ = false;
}