//------------------------------------------------------------------------------
//
void GLPickingSelect::processBoundingBox(
    const SubNode::Ptr rootNode,
    const double       seconds
)
{
    // Allocate select buffer.
    const unsigned int bufferSize = 12;
    GLuint buffer[12*4];

    // Get the current viewport.
    M3dView view = fSelectInfo.view();

    // Get the bounding box.
    MBoundingBox boundingBox = BoundingBoxVisitor::boundingBox(rootNode, seconds);

    // Draw the bounding box.
    view.beginSelect(buffer, bufferSize*4);
    view.pushName(0);
    {
        VBOProxy vboProxy;
        vboProxy.drawBoundingBox(boundingBox);
    }
    view.popName();
    int nbPick = view.endSelect();

    // Determine the closest point.
    if (nbPick > 0) {
        unsigned int Zdepth = closestElem(nbPick, buffer);    
        float depth = float(Zdepth)/MAX_HW_DEPTH_VALUE;
        fMinZ = std::min(depth,fMinZ);
    }
}
Exemplo n.º 2
0
void fishVizNode::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{
	view.beginGL(); 
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	unsigned num_ptc = ptc_positions.length();

	glBegin(GL_LINES);
	glColor3f(0,0,1);
	for(unsigned i=0; i<num_ptc; i++)
	{
		glVertex3f(ptc_positions[i].x, ptc_positions[i].y, ptc_positions[i].z);
		glVertex3f(ptc_positions[i].x+ptc_velocities[i].x, ptc_positions[i].y+ptc_velocities[i].y, ptc_positions[i].z+ptc_velocities[i].z);
	}
	//glColor3f(0,1,0);
	//for(unsigned i=0; i<num_ptc; i++)
	//{
	//	glVertex3f(ptc_positions[i].x, ptc_positions[i].y, ptc_positions[i].z);
	//	glVertex3f(ptc_positions[i].x+ptc_ups[i].x*m_fish_length, ptc_positions[i].y+ptc_ups[i].y*m_fish_length, ptc_positions[i].z+ptc_ups[i].z*m_fish_length);
	//}
	glColor3f(1,0,0);
	for(unsigned i=0; i<num_ptc; i++)
	{
		glVertex3f(ptc_positions[i].x, ptc_positions[i].y, ptc_positions[i].z);
		glVertex3f(ptc_positions[i].x-ptc_views[i].x*m_fish_length, ptc_positions[i].y-ptc_views[i].y*m_fish_length, ptc_positions[i].z-ptc_views[i].z*m_fish_length);
	}
	glEnd();
	glPopAttrib();
	view.endGL();
}
Exemplo n.º 3
0
void MannequinMoveManipulator::draw(M3dView &view,
  const MDagPath &path,
  M3dView::DisplayStyle style,
  M3dView::DisplayStatus status) {
  static MGLFunctionTable *gGLFT = 0;
  if (0 == gGLFT) {
    gGLFT = MHardwareRenderer::theRenderer()->glFunctionTable();
  }

  recalcMetrics();

  float size = _manipScale * MFnManip3D::globalSize();
  float handleSize = MFnManip3D::handleSize() / 100.0f; // Probably on [0, 100].
  float handleHeight = size * handleSize * 0.5f;
  float handleOfs = size - handleHeight;
  float handleRadius = handleHeight * 0.25f;

  float origin[4];
  _origin.get(origin);

  float x[4], y[4], z[4];
  (_origin + (_x * size)).get(x);
  (_origin + (_y * size)).get(y);
  (_origin + (_z * size)).get(z);

  view.beginGL();

  GLUquadricObj* quadric = gluNewQuadric();
  gluQuadricNormals(quadric, GLU_SMOOTH);
  gluQuadricTexture(quadric, true);
  gluQuadricDrawStyle(quadric, GLU_FILL);

  colorAndName(view, _glPickableItem + 0, true, xColor());
  gGLFT->glBegin(MGL_LINES);
    gGLFT->glVertex3fv(origin);
    gGLFT->glVertex3fv(x);
  gGLFT->glEnd();
  glDrawCone(quadric, _origin + (_x * handleOfs), _x, handleHeight,
    handleRadius);

  colorAndName(view, _glPickableItem + 1, true, yColor());
  gGLFT->glBegin(MGL_LINES);
    gGLFT->glVertex3fv(origin);
    gGLFT->glVertex3fv(y);
  gGLFT->glEnd();
  glDrawCone(quadric, _origin + (_y * handleOfs), _y, handleHeight,
    handleRadius);

  colorAndName(view, _glPickableItem + 2, true, zColor());
  gGLFT->glBegin(MGL_LINES);
    gGLFT->glVertex3fv(origin);
    gGLFT->glVertex3fv(z);
  gGLFT->glEnd();
  glDrawCone(quadric, _origin + (_z * handleOfs), _z, handleHeight,
    handleRadius);

  gluDeleteQuadric(quadric);

  view.endGL();
}
Exemplo n.º 4
0
void octreeVizNode::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{
	MDagPath camera;
	view = M3dView::active3dView();
	view.getCamera(camera);
	
	MATRIX44F mat;
	double clipNear, clipFar, fov;
	int ispersp;
	
	parseCamera(camera, mat, clipNear, clipFar, fov, ispersp);
	
	view.beginGL(); 
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glShadeModel(GL_SMOOTH);
	glPointSize(3);

	if(m_pTex) {
		XYZ ori(0,0,0);
		m_pTex->setProjection(mat, fov, ispersp);
		int port[4];
	glGetIntegerv(GL_VIEWPORT, port);
		m_pTex->setPortWidth(port[2]);
		m_pTex->drawCube();
		m_pTex->testRaster(ori);
	}
	
	glPopAttrib();
	view.endGL();
}
Exemplo n.º 5
0
MStatus marqueeContext::doRelease( MEvent & event )
//
// Selects objects within the marquee box.
{
	if (fsDrawn) {
#if CUSTOM_XOR_DRAW
		xorDraw XORdraw(&view);
		XORdraw.beginXorDrawing();
#else
		view.beginXorDrawing();
#endif
		// Redraw the marquee at its old position to erase it.
		drawMarqueeGL();

#if CUSTOM_XOR_DRAW
		XORdraw.endXorDrawing();
#else
		view.endXorDrawing();
#endif
	}

	doReleaseCommon( event );

	return MS::kSuccess;
}
Exemplo n.º 6
0
void kgLocator::draw( M3dView & view, const MDagPath & path, 
					 M3dView::DisplayStyle style, M3dView::DisplayStatus status )
{
	MStatus stat;

	//First get the value of the height attribute
	//of the assocuated locator
	MObject thisNode = thisMObject();
	MFnDagNode dagFn( thisNode  );  	
	MPlug heightPlug = dagFn.findPlug( height, &stat );
	float heightValue;
	heightPlug.getValue( heightValue );
		
	view.beginGL();
	glPushAttrib( GL_CURRENT_BIT );
	
	
	glBegin( GL_LINES );
	//Draw a cross
	for(unsigned int i=0; i < pts.length(); i+= 2 )
	{
		glVertex3f(pts[i].x, pts[i].y, pts[i].z );
		glVertex3f(pts[i+1].x, pts[i+1].y, pts[i+1].z );
	}
	//And a vertical spindle
	//of the same height as 
	//the height attribute
	glVertex3f( 0.0f, 0.0f, 0.0f );
	glVertex3f( 0.0f, heightValue, 0.0f );
	
	glEnd();
	
	glPopAttrib();
	view.endGL();
}
Exemplo n.º 7
0
void mtmEnvLight::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{ 
	// Get the size
	//
	//MObject thisNode = thisMObject();
	//MPlug plug( thisNode, size );
	//MDistance sizeVal;
	//plug.getValue( sizeVal );

	//float multiplier = (float) sizeVal.asCentimeters();

	view.beginGL(); 
	float size2 = 0.7f * .5f;
	float scale = 2.0f;

	if ( ( style == M3dView::kFlatShaded ) || 
		 ( style == M3dView::kGouraudShaded ) ) 
	{  
		// Push the color settings
		// 
		glPushAttrib( GL_CURRENT_BIT );

		if ( status == M3dView::kActive ) {
			view.setDrawColor( 13, M3dView::kActiveColors );
		} else {
			view.setDrawColor( 13, M3dView::kDormantColors );
		}  

		glBegin( GL_TRIANGLE_FAN );
	        int i;
			int last = mtmCount - 1;
			for ( i = 0; i < last; ++i ) {
				glVertex3f( (mtm[i][0] - size2) * scale,
							(mtm[i][1]) * scale,
							(mtm[i][2] - .15f) * scale );
			} 
		glEnd();
		glPopAttrib();
	}

	// Draw the outline of the foot
	//
	glBegin( GL_LINES );
	    int i;
	    int last = mtmCount - 1;
	    for ( i = 0; i < last; ++i ) { 
				glVertex3f( (mtm[i][0] - size2) * scale,
							(mtm[i][1]),
							(mtm[i][2] - .15f) * scale );
				glVertex3f( (mtm[i+1][0] - size2) * scale,
							(mtm[i+1][1]),
							(mtm[i+1][2] - .15f) * scale );
		} 
	glEnd();
		

	view.endGL();
}
Exemplo n.º 8
0
MStatus customAttrCtx::doRelease( MEvent & event )
//
// Description
//     This method is called when a mouse button is released while this context is
//    the current context.
//
{
	// Let the parent class handle the event.
	MStatus stat = MPxSelectionContext::doRelease( event );

	// If an object is selected, process the event if the middle mouse button
	// was lifted.
	if ( !isSelecting() ) {
		if (event.mouseButton() == MEvent::kMiddleMouse)
		{
			event.getPosition( endPos_x, endPos_y );

			// Delete the move command if we have moved less then 2 pixels
			// otherwise call finalize to set up the journal and add the
			// command to the undo queue.
			//
			if ( abs(startPos_x - endPos_x) < 2 ) {
				delete cmd;
				view.refresh( true );
			}
			else {
				stat = cmd->finalize();
				view.refresh( true );
			}
			setCursor(MCursor::defaultCursor);
		}
	}

	return stat;
}
Exemplo n.º 9
0
void retargetLocator::draw( M3dView& view, const MDagPath& DAGPath, 
							M3dView::DisplayStyle style, M3dView::DisplayStatus status )
{
	view.beginGL();
	glPushAttrib( GL_CURRENT_BIT );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glDepthMask( GL_FALSE );
	if ( status == M3dView::kActive ) viewMode = 0;
	else if ( status == M3dView::kLead ) viewMode = 1;
    else  viewMode = 2;
	glDepthFunc( GL_ALWAYS );
	drawDiscAll( discLineAlpha*0.5f, discFillAlpha*0.5f );
	for( int i =0; i<lineAlpha.length(); i++ )
	{
		drawArrowAll( lineAlpha[i]*0.5f, fillAlpha[i]*0.5f, i );
	}
	glDepthFunc( GL_LESS );
	drawDiscAll( discLineAlpha, discFillAlpha );
	for( int i =0; i<lineAlpha.length(); i++ )
	{
		drawArrowAll( lineAlpha[i], fillAlpha[i], i );
	}
	glDepthMask( GL_TRUE );
	glDisable( GL_BLEND );
	glPopAttrib();
    view.endGL();
}
// Load the vertexProgram and fill in the necessary constants used in the vertex program.
//
void hwRefractReflectShader_NV20::loadVertexProgramGL( M3dView& view )
{
	view.beginGL();
	{
		// Don't load/initialize the vertex program more than once.
		//
		if (vertex_program_id == 0)	
			initVertexProgram(vertexProgramString, &vertex_program_id);

		// Set up the constant values.
		//
		// CONSTANTS:
		//  0- 3	4x4 ModelView-Projection composite matrix
		//  4- 7	4x4 ModelView	inverseTranspose matrix
		//  8- 11	4x4 ModelView	matrix
		//  12-15	4x4 Texture		matrix
		//
		glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0,  GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);
		glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4,  GL_MODELVIEW,               GL_INVERSE_TRANSPOSE_NV);
		glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 8,  GL_MODELVIEW,               GL_IDENTITY_NV);
		glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 12, GL_TEXTURE,                 GL_IDENTITY_NV);
		
		float rIdx = fRefractionIndex;
		glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 58, rIdx, rIdx*rIdx, 0.0, 0.0);	// refraction index
		glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 59, 0.0, 0.0, 0.0, 1.0);			// eye position
		glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 64, 0.0, 1.0, 2.0, 3.0);			// misc constants
	}
	view.endGL();
}
Exemplo n.º 11
0
// Pre-render callback
//
void refreshCompute::preRenderCB(const MString& panelName, void * data)
{
	refreshCompute *thisCompute = (refreshCompute *) data;
	if (!thisCompute)
		return;

	M3dView view;
	MStatus status = M3dView::getM3dViewFromModelPanel(panelName, view);
	if (status != MS::kSuccess)
		return;

	int width = 0, height = 0;
	width = view.portWidth( &status );
	if (status != MS::kSuccess || (width < 2))
		return;
	height = view.portHeight( &status );
	if (status != MS::kSuccess || (height < 2))
		return;

	unsigned int vx,vy,vwidth,vheight;
	vx = 0;
	vy = 0;
	vwidth = width / 2;
	vheight = height / 2;
	status = view.pushViewport (vx, vy, vwidth, vheight);

	if (thisCompute->mBufferOperation != kDrawDepthBuffer)
	{
		M3dView view;
		MStatus status = M3dView::getM3dViewFromModelPanel(panelName, view);
		MPoint origin;
		status = view.drawText( MString("Pre render callback: ") + panelName, origin );
	}
}
void BasicLocator::draw( M3dView & view, const MDagPath & path,
M3dView::DisplayStyle style, M3dView::DisplayStatus status )
{ 
view.beginGL(); 
glPushAttrib( GL_CURRENT_BIT );

MPointArray pts;
getCirclePoints( pts );

glBegin(GL_LINE_STRIP);
for( unsigned int i=0; i < pts.length(); i++ )
	glVertex3f( float(pts[i].x), float(pts[i].y), float(pts[i].z) );
glEnd();

glBegin(GL_LINES);
	glVertex3f( -0.5f, 0.0f, 0.0f );
	glVertex3f( 0.5f, 0.0f, 0.0f );

	glVertex3f( 0.0f, 0.0f, -0.5f );
	glVertex3f( 0.0f, 0.0f, 0.5f );
glEnd();

glPopAttrib();
view.endGL();       
}
Exemplo n.º 13
0
MStatus marqueeContext::doDrag( MEvent & event )
//
// Drag out the marquee (using OpenGL)
//
{
#if CUSTOM_XOR_DRAW
	xorDraw XORdraw(&view);
	XORdraw.beginXorDrawing();
#else
	view.beginXorDrawing();
#endif

	if (fsDrawn) {
		// Redraw the marquee at its old position to erase it.
		drawMarqueeGL();
	}

	fsDrawn = true;

	//	Get the marquee's new end position.
	event.getPosition( last_x, last_y );

	// Draw the marquee at its new position.
	drawMarqueeGL();

#if CUSTOM_XOR_DRAW
	XORdraw.endXorDrawing();
#else
	view.endXorDrawing();
#endif

	return MS::kSuccess;		
}
Exemplo n.º 14
0
void curvedArrows::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{ 
	// Get the size
	//
	MObject thisNode = thisMObject();
	MPlug tPlug = MPlug( thisNode, aTransparency ); 
	MPlug cPlug = MPlug( thisNode, aTheColor ); 

	float r, g, b, a; 
	MObject color; 

	cPlug.getValue( color ); 
	MFnNumericData data( color ); 
	data.getData( r, g, b ); 
	tPlug.getValue( a ); 

	view.beginGL(); 

	if( (style == M3dView::kFlatShaded) ||
	    (style == M3dView::kGouraudShaded) ) {
		// Push the color settings
		// 
		glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | 
					  GL_PIXEL_MODE_BIT ); 
	
		if ( a < 1.0f ) { 
			glEnable( GL_BLEND );
			glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
		}
		
		glColor4f( r, g, b, a );			
	
		glBegin( GL_TRIANGLES ); 
		unsigned int i;
		for ( i = 0; i < fsFaceListSize; i ++ ) { 
			unsigned int *vid = fsFaceList[i];
			unsigned int *nid = fsFaceVertexNormalList[i]; 
			for ( unsigned int j = 0; j < 3; j ++ ) { 
				glNormal3d( fsNormalList[nid[j]-1][0], 
							fsNormalList[nid[j]-1][1], 
							fsNormalList[nid[j]-1][2] );
				glVertex3d( fsVertexList[vid[j]-1][0], 
							fsVertexList[vid[j]-1][1],
							fsVertexList[vid[j]-1][2] ); 
			}
		}
		glEnd(); 
	
		glPopAttrib(); 

		drawEdgeLoop( view, status ); 
	} else { 
		drawEdgeLoop( view, status ); 
	}

	view.endGL(); 
}
Exemplo n.º 15
0
// Currently, Maya leaves lights in GL when you reduce the number of active lights in 
// your scene. It fills the GL light space from 0 with the visible lights, so, we simply 
// need to reset the potentially 'old' state of lights after the last one we know to be 
// visible. We'll put it all back as we found it though. For the moment, this assumes 
// Maya is filling GL consecutively, if they stop doing that, we'll need to get the 
// actual light indexes from the view. Its just a bit quicker to assume this, whilst we can.
bool ProceduralHolderUI::cleanupLights( const MDrawRequest &request, M3dView &view, LightingState *s ) const
{
		
	if( !(request.displayStyle()==M3dView::kFlatShaded || request.displayStyle()==M3dView::kGouraudShaded) )
	{
		return false;
	}
	
	M3dView::LightingMode mode;
	view.getLightingMode(mode);
	
	if (mode == M3dView::kLightDefault)
	{
		s->numMayaLights = 1;
	}
	else
	{
		view.getLightCount( s->numMayaLights );
	}
	
	int sGlMaxLights = 0;
	glGetIntegerv( GL_MAX_LIGHTS, &sGlMaxLights );
	s->numGlLights = sGlMaxLights;	

	if( s->numMayaLights >= s->numGlLights || s->numGlLights == 0 )
	{
		return false;
	}		
	
	unsigned int vectorSize = s->numGlLights - s->numMayaLights;
	
	s->diffuses.resize( vectorSize );
	s->specs.resize( vectorSize );
	s->ambients.resize( vectorSize );

	static float s_defaultColor[] = { 0.0, 0.0, 0.0, 1.0 };
	
	GLenum light;
	unsigned int j = 0;
	
	for( unsigned int i = s->numMayaLights; i < s->numGlLights; i++ )
	{		
		light = GL_LIGHT0 + i;
		
		glGetLightfv( light, GL_DIFFUSE, s->diffuses[j].getValue() );
		glLightfv( light, GL_DIFFUSE, s_defaultColor );
			
		glGetLightfv( light, GL_SPECULAR, s->specs[j].getValue() );
		glLightfv( light, GL_SPECULAR, s_defaultColor );
			
		glGetLightfv( light, GL_AMBIENT, s->ambients[j].getValue() );
		glLightfv( light, GL_AMBIENT, s_defaultColor );
		
		j++;
	}
	
	return true;
}
Exemplo n.º 16
0
void VmIslandNode::draw( M3dView& i_view, const MDagPath& i_path, M3dView::DisplayStyle i_style, M3dView::DisplayStatus i_status )
{
    //fprintf( stderr, "VmIslandNode::Draw()\n" );
    
    //Start OpenGL
    i_view.beginGL();
    
    // Get all the values we need from the plugs.
    //
    // Note that for the oa_update plug, we don't actually
    // care about the value we get from it. But we do ask
    // for it to be computed, since that computation process
    // will get the internal structures up to date. But, the
    // drawStyle() plug we do care about the value of. At the
    // same time though, in the compute() method, nothing
    // needs to be computed for it.
    
    MPlug updatePlug( thisMObject(), VmIslandNode::oa_update );
    const bool updateOK = updatePlug.asBool();
    if( updateOK == false)
    {
        MGlobal::displayError( "VmIslandNode::draw() - update failed\n" );
    }
    
    MPlug drawStylePlug( thisMObject(), VmIslandNode::ia_drawStyle );
    const int drawStyle = drawStylePlug.asInt();
    
    //Check plugs
    if (drawStyle == 0){        
        drawBB();
    } else if (drawStyle == 1){        
        drawSubBB();
    } else if ( drawStyle == 2 ){
        drawPlane();
    } else if( drawStyle == 3)  {
        drawPlane();
        drawTerrainNormals();
    }else if (drawStyle == 4 ) {
        drawPlane();
        drawInstances();        
    } else if (drawStyle == 5 ) {
        drawPlane();
        drawInstances();
        drawWindVelocities();
    } else if (drawStyle == 6 ) {
        drawPlane();
        drawBB();
        drawSubBB();
        drawInstances();
        drawTerrainNormals();
        drawWindVelocities();
    }
        
    
    //Close OpenGL
    i_view.endGL();
}
Exemplo n.º 17
0
//MStatus pointLightNode::compute(const MPlug &plug, MDataBlock &data)
//{
//	MStatus stat;
//	return stat=MStatus::kSuccess;
//}
void pointLightNode::draw(M3dView &view, const MDagPath &path, M3dView::DisplayStyle style, M3dView::DisplayStatus status)
{
	MColor drawColor;

	drawColor.set(MColor::kRGB,1,1,0);

	if (status==M3dView::kDormant)
	{
		drawColor.set(MColor::kRGB,1,0,0);
	}
	if (status==M3dView::kTemplate)
	{
		drawColor.set(MColor::kRGB,0,1,0);
	}
	view.setDrawColor(drawColor);
	view.beginGL();
	glBegin(GL_LINES);
	                        glVertex3f(0.0f,0.1f,0.0f);
		                    glVertex3f(0.1f,0.0f,0.0f);

							glVertex3f(0.0f,0.1f,0.0f);
		                    glVertex3f(-0.1f,0.0f,0.0f);

							glVertex3f(0.0f,0.1f,0.0f);
		                    glVertex3f(0.0f,0.0f,0.1f);

							glVertex3f(0.0f,0.1f,0.0f);
		                    glVertex3f(0.0f,0.0f,-0.1f);

							glVertex3f(0.0f,-0.1f,0.0f);
		                    glVertex3f(0.1f,0.0f,0.0f);

							glVertex3f(0.0f,-0.1f,0.0f);
		                    glVertex3f(-0.1f,0.0f,0.0f);

							glVertex3f(0.0f,-0.1f,0.0f);
		                    glVertex3f(0.0f,0.0f,0.1f);

							glVertex3f(0.0f,-0.1f,0.0f);
		                    glVertex3f(0.0f,0.0f,-0.1f);

							glVertex3f(-0.1f,0.0f,0.0f);
		                    glVertex3f(0.0f,0.0f,0.1f);

							glVertex3f(0.0f,0.0f,0.1f);
		                    glVertex3f(0.1f,0.0f,0.0f);

							glVertex3f(0.1f,0.0f,0.0f);
		                    glVertex3f(0.0f,0.0f,-0.1f);

							glVertex3f(0.0f,0.0f,-0.1f);
		                    glVertex3f(-0.1f,0.0f,0.0f);


    glEnd();
	view.endGL();
}
void areaLightNode::draw(M3dView &view, const MDagPath &path, M3dView::DisplayStyle style, M3dView::DisplayStatus status)
{

	MColor drawColor;

	drawColor.set(MColor::kRGB,1,1,0,0.5);

	if (status==M3dView::kDormant)
	{
		drawColor.set(MColor::kRGB,1,0,0,0.5);
	}

	view.setDrawColor(drawColor);
	view.beginGL();
	glBegin(GL_LINES);
	    //these are useful
	    glVertex3f(-1.0f,-1.0f,0.0f);
		glVertex3f(-1.0f,1.0f,0.0f);

		glVertex3f(-1.0f,1.0f,0.0f);
		glVertex3f(1.0f,1.0f,0.0f);

		glVertex3f(1.0f,1.0f,0.0f);
		glVertex3f(1.0f,-1.0f,0.0f);

		glVertex3f(1.0f,-1.0f,0.0f);
		glVertex3f(-1.0f,-1.0f,0.0f);

		glVertex3f(0.0f,0.0f,0.0f);
		glVertex3f(0.0f,0.0f,-3.0f);

		glVertex3f(0.0f,0.0f,-3.0f);
		glVertex3f(0.0f,-0.1f,-2.8f);

		glVertex3f(0.0f,0.0f,-3.0f);
		glVertex3f(0.0f,0.1f,-2.8f);

		//these just for fun......
		glVertex3f(-0.3f,0.5f,0.0f);
		glVertex3f(-0.85f,-0.3f,0.0f);

		glVertex3f(0.3f,0.5f,0.0f);
		glVertex3f(0.85f,-0.3f,0.0f);

		glVertex3f(-0.4f,-1.0f,0.0f);
		glVertex3f(-0.4f,-0.2f,0.0f);

		glVertex3f(-0.4f,-0.2f,0.0f);
		glVertex3f(0.4f,-0.2f,0.0f);

		glVertex3f(0.4f,-0.2f,0.0f);
		glVertex3f(0.4f,-1.0f,0.0f);

	glEnd();
	view.endGL();

}
Exemplo n.º 19
0
//------------------------------------------------------------------------------
//
RasterSelect::RasterSelect(
    MSelectInfo& selectInfo
) 
    : fSelectInfo(selectInfo),
      fMinZ(std::numeric_limits<float>::max())
{
    M3dView view = fSelectInfo.view();

    view.beginGL();

    unsigned int sxl, syl, sw, sh;
    fSelectInfo.selectRect(sxl, syl, sw, sh);

    unsigned int vxl, vyl, vw, vh;
    view.viewport(vxl, vyl, vw, vh);

    // Compute a new matrix that, when it is post-multiplied with the
    // projection matrix, will cause the picking region to fill only
    // a small region.

    const unsigned int width = (MAX_RASTER_SELECT_RENDER_SIZE < sw) ?
        MAX_RASTER_SELECT_RENDER_SIZE : sw;
    const unsigned int height = (MAX_RASTER_SELECT_RENDER_SIZE < sh) ?
        MAX_RASTER_SELECT_RENDER_SIZE : sh;

    const double sx = double(width) / double(sw);
    const double sy = double(height) / double(sh);

    const double fx = 2.0 / double(vw);
    const double fy = 2.0 / double(vh);
    
    MMatrix  selectMatrix;
    selectMatrix.matrix[0][0] = sx;
    selectMatrix.matrix[1][1] = sy;
    selectMatrix.matrix[3][0] = -1.0 - sx * (fx * (sxl - vxl) - 1.0);
    selectMatrix.matrix[3][1] = -1.0 - sy * (fy * (syl - vyl) - 1.0);
    
        
    MMatrix projMatrix;
    view.projectionMatrix(projMatrix);

    ::glMatrixMode(GL_PROJECTION);
    ::glPushMatrix();
    ::glLoadMatrixd(selectMatrix[0]);
    ::glMultMatrixd(projMatrix[0]);
    ::glMatrixMode(GL_MODELVIEW);

    ::glScissor(vxl, vyl, width, height);
    ::glEnable(GL_SCISSOR_TEST);
    ::glClear(GL_DEPTH_BUFFER_BIT);

    fWasDepthTestEnabled = ::glIsEnabled(GL_DEPTH_TEST);
    if (!fWasDepthTestEnabled) {
        ::glEnable(GL_DEPTH_TEST);
    }
}
Exemplo n.º 20
0
void bruiseMapNode::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{
	view.beginGL(); 
	glPointSize(2);
	if(m_base->hasBase()) m_base->draw();

	view.endGL();
}
Exemplo n.º 21
0
MStatus PluginTestUserOperation::execute(const MHWRender::MDrawContext & drawContext)
{
	//return MStatus::kSuccess;
	M3dView view;
	if(M3dView::getM3dViewFromModelPanel(panelName, view) == MStatus::kSuccess)
	{
		// Get the current viewport and scale it relative to that
		//
		int targetW, targetH;
		drawContext.getRenderTargetSize(targetW, targetH);

		// Some user drawing of scene bounding boxes
		//
		MDagPath cameraPath;
		MFnCamera fnCamera;
		view.getCamera(cameraPath);
		MMatrix m3dViewProjection, m3dViewModelView;
		view.projectionMatrix(m3dViewProjection);
		view.modelViewMatrix(m3dViewModelView);
		MFloatMatrix m3dFloatViewProjection(m3dViewProjection.matrix);
		MFloatMatrix m3dFloatViewModelView(m3dViewModelView.matrix);
		MFloatMatrix viewProjection = m3dFloatViewModelView * m3dFloatViewProjection;
		SurfaceDrawTraversal traversal;
		traversal.enableFiltering(true);
		traversal.setFrustum(cameraPath, targetW, targetH);
		traversal.traverse();
		unsigned int numItems = traversal.numberOfItems();
		MFnMesh fnMesh;
		for (int i = 0; i < numItems; i++)
		{
			MDagPath path;
			traversal.itemPath(i, path);
			if (path.hasFn(MFn::kMesh))
			{
				fnMesh.setObject(path);
				MFloatMatrix modelWorld(path.inclusiveMatrix().matrix);
				MTransformationMatrix transformMatrix;
				MFloatMatrix modelViewProjection = modelWorld * viewProjection;
				modelViewProjection = modelViewProjection.transpose();
				MIntArray triangleCounts;
				MIntArray triangleVertices; // This is the index list for all the triangles in the mesh in one big list. Ie. first 3 are for tri 1 etc. Index into getPoints()
				fnMesh.getTriangles(triangleCounts, triangleVertices);
				//int indices[100];
				//triangleVertices.get(indices);
				MFloatPointArray vertexArray;
				//float points[1000][4];
				fnMesh.getPoints(vertexArray);
				//vertexArray.get(points);
				UserSceneRenderer::get()->render(triangleVertices, vertexArray, modelViewProjection);
			}
		}
	}
	return MStatus::kSuccess;
}
// Load the textures, update the necessary variable values, initialize register combiners,
// save and load the matrices with the proper values
//
MStatus	hwRefractReflectShader_NV20::preDraw(const MDrawRequest& request, M3dView& view)
{
	MStatus stat = loadTextures( request, view);

	if( MS::kSuccess != stat )		return stat;

	// get the reflectivity value
	//
	MPlug	tPlug(thisMObject(), reflectivity);
	if( tPlug.getValue( fReflectivity ) )
	{
		if( fReflectivity < 0.01f )	fReflectivity = 0.01f;
		if( fReflectivity > 1.0f )	fReflectivity = 1.0f;
	}
	else	fReflectivity = 0.5f;
	
	// get the refraction index value
	//
	MPlug	rPlug(thisMObject(), refractionIndex);
	if( rPlug.getValue( fRefractionIndex ) )
	{
		if ( fRefractionIndex < 1.0f )	fRefractionIndex = 1.0f;
		if ( fRefractionIndex > 2.0f )	fRefractionIndex = 2.0f;
	}
	else	fRefractionIndex = 1.0f;
	
	initCombiners( request, view );
	
	// Compute the camera rotation angle and axis
	//
	MDagPath	cameraPath;
	MStatus		status = view.getCamera( cameraPath );
	MMatrix		mmatrix = cameraPath.inclusiveMatrix( &status );
	MTransformationMatrix tmatrix( mmatrix );
	
	MQuaternion camRotation = tmatrix.rotation();
	MVector		camAxis;
	double		camTheta;
	camRotation.getAxisAngle(  camAxis, camTheta );
	
	// Convert to degrees from radians
	camTheta *= 57.295779513082320876798154814105;	// == (180 / M_PI)
	
	view.beginGL();
		glMatrixMode( GL_TEXTURE );
		glPushMatrix();
		glLoadIdentity();
		glScalef(1.0, -1.0, 1.0);
		glRotated( camTheta, camAxis[0], camAxis[1], camAxis[2]);
		glMatrixMode( GL_MODELVIEW );
	view.endGL();

	return stat;
}
Exemplo n.º 23
0
void sixdofConstraintNode::draw( M3dView & view, const MDagPath &path,
                             M3dView::DisplayStyle style,
                             M3dView::DisplayStatus status )
{
  //  std::cout << "sixdofConstraintNode::draw" << std::endl;

    update();

    view.beginGL();
    glPushAttrib( GL_ALL_ATTRIB_BITS );

//	glPushMatrix();
    glDisable(GL_LIGHTING);

    if( !(status == M3dView::kActive ||
        status == M3dView::kLead ||
        status == M3dView::kHilite ||
        ( style != M3dView::kGouraudShaded && style != M3dView::kFlatShaded )) ) {
        glColor3f(1.0, 1.0, 0.0); 
    }

	vec3f posA;
	vec3f posB;
	if (m_constraint) {
		vec3f world;
		m_constraint->get_world(world);
		quatf rotA;
		m_constraint->rigid_bodyA()->get_transform(posA, rotA);
		posA = posA - world;
		quatf rotB;
		m_constraint->rigid_bodyB()->get_transform(posB, rotB);
		posB = posB - world;
	}

//	glLoadIdentity();
    glBegin(GL_LINES);
    glVertex3f(posA[0], posA[1], posA[2]);
    glVertex3f(posB[0], posB[1], posB[2]);

    glVertex3f(-1.0, 0.0, 0.0);
    glVertex3f(1.0, 0.0, 0.0);

    glVertex3f(0.0, -1.0, 0.0);
    glVertex3f(0.0, 1.0, 0.0);

    glVertex3f(0.0, 0.0, -1.0);
    glVertex3f(0.0, 0.0, 1.0);
    glEnd();

//	glPopMatrix();

    glPopAttrib();
    view.endGL();
}
Exemplo n.º 24
0
/* virtual */
MStatus	hwUnlitShader::unbind(const MDrawRequest& request,
			   M3dView& view)
{
	view.beginGL();	
	glPopClientAttrib();
	glPopAttrib();

	view.endGL();

	return MS::kSuccess;
}
Exemplo n.º 25
0
void rigidBodyNode::draw( M3dView & view, const MDagPath &path,
                             M3dView::DisplayStyle style,
                             M3dView::DisplayStatus status )
{
	
  //  std::cout << "rigidBodyNode::draw" << std::endl;
	MObject thisObject(thisMObject());
    update();
	
    view.beginGL();
    glPushAttrib( GL_ALL_ATTRIB_BITS );

    if(m_rigid_body) {
        //remove the scale, since it's already included in the node transform 
        vec3f scale;
        m_rigid_body->collision_shape()->get_scale(scale);

        glPushMatrix();
        glScalef(1/scale[0], 1/scale[1], 1/scale[2]); 
    
        if(style == M3dView::kFlatShaded || style == M3dView::kGouraudShaded) {
            glEnable(GL_LIGHTING);
			MPlug plug(thisObject, rigidBodyNode::ia_mass);
			float mass;
			plug.getValue(mass);
			if (mass) {
				float material[] = { 0.2f, 1.0f, 0.2f, 1.0f };
				glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, material);
			} else {
				float material[] = { 1.0f, 0.3f, 0.1f, 1.0f };
				glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, material);
			}
            //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, material);
            m_rigid_body->collision_shape()->gl_draw(collision_shape_t::kDSSolid);
        } 
    
    
        if( status == M3dView::kActive ||
            status == M3dView::kLead ||
            status == M3dView::kHilite ||
            ( style != M3dView::kGouraudShaded && style != M3dView::kFlatShaded ) ) {
            
            glDisable(GL_LIGHTING);
            m_rigid_body->collision_shape()->gl_draw(collision_shape_t::kDSWireframe);
    
        }
        glPopMatrix();
    }
    glPopAttrib();
    view.endGL();
}
Exemplo n.º 26
0
bool MannequinMoveManipulator::intersectManip(MPxManipulatorNode* manip) const {
  M3dView view = M3dView::active3dView();

  float size = _manipScale * MFnManip3D::globalSize();
  MPoint xEnd = _origin + (_x * size);
  MPoint yEnd = _origin + (_y * size);
  MPoint zEnd = _origin + (_z * size);

  short mx, my;
  manip->mousePosition(mx, my);

  short ox, oy, xx, xy, yx, yy, zx, zy;
  view.worldToView(_origin, ox, oy);
  view.worldToView(xEnd, xx, xy);
  view.worldToView(yEnd, yx, yy);
  view.worldToView(zEnd, zx, zy);

  // Calculate approximate handle size in view space.
  float viewLength = 0.0f;
  viewLength = std::max(viewLength,
    sqrtf(pow(float(xx) - float(ox), 2) + pow(float(xy) - float(oy), 2)));
  viewLength = std::max(viewLength,
    sqrtf(pow(float(yx) - float(ox), 2) + pow(float(yy) - float(oy), 2)));
  viewLength = std::max(viewLength,
    sqrtf(pow(float(zx) - float(ox), 2) + pow(float(zy) - float(oy), 2)));

  float handleSize = MFnManip3D::handleSize() / 100.0f; // Probably on [0, 100].
  float handleHeight = viewLength * handleSize * 0.5f;
  float handleRadius = std::max(handleHeight * 0.3f, 4.0f);
  // Note: slightly exaggerated; normally handleHeight * 0.25f.

  // Determine if we're in range to any of the lines.
  float curDist, t;

  curDist = Util::distanceToLine(ox, oy, xx, xy, mx, my, &t);
  if (curDist < handleRadius && t >= 0.0f && t <= 1.0f) {
    return true;
  }

  curDist = Util::distanceToLine(ox, oy, yx, yy, mx, my, &t);
  if (curDist < handleRadius && t >= 0.0f && t <= 1.0f) {
    return true;
  }

  curDist = Util::distanceToLine(ox, oy, zx, zy, mx, my, &t);
  if (curDist < handleRadius && t >= 0.0f && t <= 1.0f) {
    return true;
  }

  return false;
}
MStatus initializePlugin(MObject obj)
{
	MFnPlugin plugin(obj, "David Kouril", "1.0", "Any");

	MStatus status = plugin.registerNode(CustomLocator::typeName,
		CustomLocator::typeId,
		CustomLocator::creator,
		CustomLocator::initialize,
		MPxNode::kLocatorNode); // is this why it didn't work before????????? yep, looks like it

	// register startStreamingCommand command
	status = plugin.registerCommand("startM2CVStreaming", startStreamingCommand::creator);
	status = plugin.registerCommand("endM2CVStreaming", endStreamingCommand::creator);
	status = plugin.registerCommand("showM2CVWindow", showStreamingWindowCommand::creator);

	streamer = new Streamer;

	// add a custom menu with items: Start streaming, Stop streaming
	MGlobal::executeCommand("global string $gMainWindow");
	MGlobal::executeCommand("setParent $gMainWindow");
	MGlobal::executeCommand("menu -label \"MayaToCellVIEW\" mayaToCelViewMenu");

	MGlobal::executeCommand("setParent -menu mayaToCelViewMenu");
	MGlobal::executeCommand("menuItem -label \"Start Streaming\" -command \"startM2CVStreaming\" startStreamingItem");
	MGlobal::executeCommand("menuItem -label \"End Streaming\" -command \"endM2CVStreaming\" -enable false endStreamingItem");
	MGlobal::executeCommand("menuItem -label \"Show Streaming Window\" -command \"showM2CVWindow\" -enable true showWindowItem");

	if (!status)
	{
		status.perror("Failed to register customLocator\n");
		return status;
	}

	std::cout << "initializePlugin successful." << std::endl;

	MStatus status1;
	M3dView viewport = M3dView::active3dView(&status1);
	std::cerr << "viewport dims: " << viewport.portWidth() << ", " << viewport.portHeight() << std::endl;

	// just testing the callbacks:
	MStatus callBackStatus;
	//MCallbackId callBackId = MUiMessage::add3dViewPostRenderMsgCallback(MString("persp"), &simpleCallBackTest, nullptr, &callBackStatus);
	MCallbackId callBackId = MUiMessage::add3dViewPostRenderMsgCallback(MString("modelPanel4"), &simpleCallBackTest, nullptr, &callBackStatus);
	if (callBackId == 0)
	{
		std::cerr << "Something's f****d up" << ", status: " << callBackStatus << std::endl;
	}

	return status;
}
Exemplo n.º 28
0
void DrawableHolderUI::draw( const MDrawRequest &request, M3dView &view ) const
{
	MDrawData drawData = request.drawData();
	DrawableHolder *drawableHolder = (DrawableHolder *)drawData.geometry();
	assert( drawableHolder );

	IECoreGL::ConstScenePtr s = drawableHolder->scene();
	if( !s )
	{
		return;
	}

	view.beginGL();

		// maya can sometimes leave an error from it's own code,
		// and we don't want that to confuse us in our drawing code.
		while( glGetError()!=GL_NO_ERROR )
		{
		}

		// if we're being drawn as part of a selection operation we need
		// to make sure there's a name on the name stack, as the IECoreGL::NameStateComponent
		// expects to be able to load a name into it (it fails with an invalid operation if
		// there's no name slot to load into).
		if( view.selectMode() )
		{
			view.pushName( 0 );
		}

		try
		{
			// do the main render
			s->render( m_displayStyle.baseState( request.displayStyle() ) );

			// do a wireframe render over the top if we're selected and we just did a solid
			// draw.
			bool selected = request.displayStatus()==M3dView::kActive || request.displayStatus()==M3dView::kLead;
			bool solid = request.displayStyle()==M3dView::kFlatShaded || request.displayStyle()==M3dView::kGouraudShaded;
			if( selected && solid )
			{
				s->render( m_displayStyle.baseState( M3dView::kWireFrame ) );
			}
		}
		catch( std::exception &e )
		{
			IECore::msg( IECore::Msg::Error, "DrawableHolderUI::draw", e.what() );
		}

	view.endGL();
}
Exemplo n.º 29
0
//------------------------------------------------------------------------------
//
void GLPickingSelect::processTriangles(
    const SubNode::Ptr rootNode,
    const double seconds,
    const size_t numTriangles,
    VBOProxy::VBOMode vboMode
)
{
    const unsigned int bufferSize = (unsigned int)std::min(numTriangles,size_t(100000));
    boost::shared_array<GLuint>buffer (new GLuint[bufferSize*4]);

    M3dView view = fSelectInfo.view();

    MMatrix projMatrix;
    view.projectionMatrix(projMatrix);
    MMatrix modelViewMatrix;
    view.modelViewMatrix(modelViewMatrix);

    unsigned int x, y, w, h;
    view.viewport(x, y, w, h);
    double viewportX = static_cast<int>(x);   // can be less than 0
    double viewportY = static_cast<int>(y);   // can be less than 0
    double viewportW = w;
    double viewportH = h;

    fSelectInfo.selectRect(x, y, w, h);
    double selectX = static_cast<int>(x);  // can be less than 0
    double selectY = static_cast<int>(y);  // can be less than 0
    double selectW = w;
    double selectH = h;

    MMatrix selectAdjustMatrix;
    selectAdjustMatrix[0][0] = viewportW / selectW;
    selectAdjustMatrix[1][1] = viewportH / selectH;
    selectAdjustMatrix[3][0] = ((viewportX + viewportW/2.0) - (selectX + selectW/2.0)) / 
        viewportW * 2.0 * selectAdjustMatrix[0][0];
    selectAdjustMatrix[3][1] = ((viewportY + viewportH/2.0) - (selectY + selectH/2.0)) /
        viewportH * 2.0 * selectAdjustMatrix[1][1];

    MMatrix localToPort = modelViewMatrix * projMatrix * selectAdjustMatrix;

    view.beginSelect(buffer.get(), bufferSize*4);
    view.pushName(0);
    {
        Frustum frustum(localToPort.inverse());
        MMatrix xform(modelViewMatrix);
        
        DrawShadedState state(frustum, seconds, vboMode);
        DrawShadedTraversal traveral(state, xform, false, Frustum::kUnknown);
        rootNode->accept(traveral);
    }
    view.popName();
    int nbPick = view.endSelect();

    if (nbPick > 0) {
        unsigned int Zdepth = closestElem(nbPick, buffer.get());    
        float depth = float(Zdepth)/MAX_HW_DEPTH_VALUE;
        fMinZ = std::min(depth,fMinZ);
    }
}
Exemplo n.º 30
0
void wingVizNode::draw( M3dView & view, const MDagPath & /*path*/, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{ 
	view.beginGL(); 

	//glPushAttrib( GL_POLYGON_BIT );
	//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
	//glFrontFace(GL_CW);
	//glEnable(GL_CULL_FACE);
	//if(i_show_v) m_base->drawVelocity();
	m_base->draw();
	//glPopAttrib();
	view.endGL();
}