Esempio n. 1
0
void DotNodeGadget::updateLabel()
{
	const Dot *dot = dotNode();

	const Dot::LabelType labelType = (Dot::LabelType)dot->labelTypePlug()->getValue();
	if( labelType == Dot::None )
	{
		m_label.clear();
	}
	else if( labelType == Dot::NodeName )
	{
		m_label = dot->getName();
	}
	else if( labelType == Dot::UpstreamNodeName )
	{
		const Node *n = upstreamNode();
		m_label = n ? n->getName() : "";
	}
	else
	{
		m_label = dot->labelPlug()->getValue();
	}

	Edge labelEdge = RightEdge;
	if( const Plug *p = dot->inPlug<Plug>() )
	{
		if( noduleTangent( nodule( p ) ).x != 0 )
		{
			labelEdge = TopEdge;
		}
	}

	const Imath::Box3f thisBound = bound();
	if( labelEdge == TopEdge )
	{
		const Imath::Box3f labelBound = style()->textBound( Style::LabelText, m_label );
		m_labelPosition = V2f(
			-labelBound.size().x / 2.0,
			thisBound.max.y + 1.0
		);
	}
	else
	{
		const Imath::Box3f characterBound = style()->characterBound( Style::LabelText );
		m_labelPosition = V2f(
			thisBound.max.x,
			thisBound.center().y - characterBound.size().y / 2.0
		);
	}

	requestRender();
}
Esempio n. 2
0
void CameraController::focusOnBounds(const Imath::Box3f& bounds)
{
	using namespace Imath;
	V3f fwd = m_parameters->forwardUnitVector();
	V3f center = bounds.center();
	float distance = bounds.size().length() / (2.0f * tan(m_parameters->fovY() / 2));
	m_parameters->setEyeTarget(center - fwd * distance, center);
}
Esempio n. 3
0
 bool rayPassesNearOrThrough(const V3d& rayOrigin, const V3d& rayDir) const
 {
     const double diagRadius = 1.2*bbox.size().length()/2; // Sphere diameter is length of box diagonal
     const V3d o2c = bbox.center() - rayOrigin; // vector from rayOrigin to box center
     const double l = o2c.length();
     if(l < diagRadius)
         return true; // rayOrigin lies within bounding sphere
     // rayOrigin lies outside of bounding sphere
     const double cosA = o2c.dot(rayDir)/l;  // cosine of angle between rayDir and vector from origin to center
     if(cosA < DBL_MIN)
         return false; // rayDir points to side or behind with respect to direction from origin to center of box
     const double sinA = sqrt(1 - cosA*cosA); // sine of angle between rayDir and vector from origin to center
     return sinA/cosA < diagRadius/l;
 }
Esempio n. 4
0
void AuxiliaryNodeGadget::doRenderLayer( Layer layer, const Style *style ) const
{

	if( layer != GraphLayer::Nodes )
	{
		return NodeGadget::doRenderLayer( layer, style );
	}

	Style::State state = getHighlighted() ? Style::HighlightedState : Style::NormalState;
	style->renderNodeFrame( Box2f( V2f( 0 ), V2f( 0 ) ), m_radius, state, m_userColor.get_ptr() );

	Imath::Box3f bound = style->textBound( Style::LabelText, m_label );
	Imath::V3f offset = bound.size() / 2.0;

	glPushMatrix();
		glTranslatef( -offset.x, -offset.y, 0.0f );
		style->renderText( Style::LabelText, m_label );
	glPopMatrix();
}
Esempio n. 5
0
Imath::M44f computeMeshTransform(const Imath::Box3f& bounds, const Imath::V3i& voxelResolution)
{
	using namespace Imath;
	M44f meshTransform;

	// set mesh transform so that the mesh fits within the unit cube. This will
	// be changed later when we let the user manipulate the mesh transform and
	// the mesh/volume intersection.
	V3f voxelMargin = V3f(1.0f) / voxelResolution; // 1 voxel
	int majorAxis = bounds.majorAxis();
	float s = (1.0f - 2.0 * voxelMargin[majorAxis] ) / bounds.size()[majorAxis];
	V3f t = -bounds.min + voxelMargin / s;
	meshTransform.x[0][0] = s ; meshTransform.x[0][1] = 0 ; meshTransform.x[0][2] = 0 ; meshTransform.x[0][3] = t.x  * s ;
	meshTransform.x[1][0] = 0 ; meshTransform.x[1][1] = s ; meshTransform.x[1][2] = 0 ; meshTransform.x[1][3] = t.y  * s ;
	meshTransform.x[2][0] = 0 ; meshTransform.x[2][1] = 0 ; meshTransform.x[2][2] = s ; meshTransform.x[2][3] = t.z  * s ;
	meshTransform.x[3][0] = 0 ; meshTransform.x[3][1] = 0 ; meshTransform.x[3][2] = 0 ; meshTransform.x[3][3] = 1.0f	 ;

	return meshTransform;
}