void arrowLocatorOverride::draw(
	const MHWRender::MDrawContext& context,
	const MUserData* data)
{
	MAngle rotationAngle;

	float color [3] ={ 0.0f, 1.0f, 0.0f } ;

	// data
	MStatus status;
	MHWRender::MStateManager* stateMgr = context.getStateManager();
	const arrowLocatorData* locatorData =
		dynamic_cast<const arrowLocatorData*>(data);
	if (!stateMgr || !locatorData) return;

	if ( locatorData )
		rotationAngle = locatorData->rotateAngle;

	// matrices
	const MMatrix transform =
		context.getMatrix(MHWRender::MFrameContext::kWorldViewMtx, &status);
	if (status != MStatus::kSuccess) return;
	const MMatrix projection =
		context.getMatrix(MHWRender::MFrameContext::kProjectionMtx, &status);
	if (status != MStatus::kSuccess) return;

	// get renderer
	MHWRender::MRenderer *theRenderer =MHWRender::MRenderer::theRenderer () ;
	if ( !theRenderer )
		return ;
	if ( theRenderer->drawAPIIsOpenGL () ) {
		
		glPushAttrib(GL_CURRENT_BIT);
		glColor4fv(color);

		glPushMatrix();
		glRotated(-rotationAngle.asDegrees(), 0.0, 1.0, 0.0);
		glBegin( GL_LINE_STRIP);
		glVertex3f(arrow[0][0],arrow[0][1],arrow[0][2]);
		glVertex3f(arrow[1][0],arrow[1][1],arrow[1][2]);
		glVertex3f(arrow[2][0],arrow[2][1],arrow[2][2]);
		glEnd();

		glBegin( GL_LINE_STRIP );
		glVertex3f(arrow[2][0],arrow[2][1],arrow[2][2]);
		glVertex3f(arrow[3][0],arrow[3][1],arrow[3][2]);
		glVertex3f(arrow[0][0],arrow[0][1],arrow[0][2]);
		glEnd();
		glPopMatrix();

	}
}
//- This method draw this locator in current scene by calling openGL functions
//		view -- 3D view that is being drawn into 
//		path -- path to this locator in the DAG 
//		style -- style to draw object in 
//		status -- selection status of object 
//
void arrowLocator::draw(M3dView &view,const MDagPath & path,M3dView::DisplayStyle style, M3dView::DisplayStatus status)
{
	MObject thisNode = thisMObject();

	//- We're in the draw routine, not the compute method
	//- therefore it is safe to grab plugs in the following way and
	//- get/set values.  You would never do something like this in
	//- the compute method because it might start a cycle in the
	//- graph.  Here we just need the value of our winddirection
	//- plug so that we can draw our arrow pointing the right way.
	MPlug wdPlug(thisNode, windDirection);
	MAngle angle;
	wdPlug.getValue(angle);

	//- Start drawing by OpenGL
	view.beginGL(); 
	
	//- If the drawing style is shaded, set color and draw opaque shape
	if ( ( style == M3dView::kFlatShaded ) || ( style == M3dView::kGouraudShaded ) ) 
	{
		//- Push to save current color settings
		glPushAttrib( GL_CURRENT_BIT );
		if ( status == M3dView::kActive ) 
		{
			view.setDrawColor( 13, M3dView::kActiveColors );
		}
		else
		{
			view.setDrawColor( 13, M3dView::kDormantColors );
		}  

		//- Push the old matrix on the stack, rotate the current one,
		//- draw the shape, then pop the old matrix off the stack for
		//- maya to use again.
		glPushMatrix();
		glRotated(-angle.asDegrees(), 0.0, 1.0, 0.0);
			glBegin( GL_TRIANGLE_FAN );
			glVertex3f(arrow[0][0],arrow[0][1],arrow[0][2]);
			glVertex3f(arrow[1][0],arrow[1][1],arrow[1][2]);
			glVertex3f(arrow[2][0],arrow[2][1],arrow[2][2]);
			glEnd();

			glBegin( GL_TRIANGLE_FAN );
			glVertex3f(arrow[2][0],arrow[2][1],arrow[2][2]);
			glVertex3f(arrow[3][0],arrow[3][1],arrow[3][2]);
			glVertex3f(arrow[0][0],arrow[0][1],arrow[0][2]);
			glEnd();
		glPopMatrix();

		glPopAttrib();
	}

	//- Draw the outline of the arrow shape
	glPushMatrix();
	glRotated(-angle.asDegrees(), 0.0, 1.0, 0.0);
	glBegin( GL_LINE_STRIP);
	glVertex3f(arrow[0][0],arrow[0][1],arrow[0][2]);
	glVertex3f(arrow[1][0],arrow[1][1],arrow[1][2]);
	glVertex3f(arrow[2][0],arrow[2][1],arrow[2][2]);
	glEnd();

	glBegin( GL_LINE_STRIP );
	glVertex3f(arrow[2][0],arrow[2][1],arrow[2][2]);
	glVertex3f(arrow[3][0],arrow[3][1],arrow[3][2]);
	glVertex3f(arrow[0][0],arrow[0][1],arrow[0][2]);
	glEnd();
	glPopMatrix();

	view.endGL();
}
예제 #3
0
	/********************************************************************************************************
	*                           Method to translate a single camera                                        *
	********************************************************************************************************/
	MStatus OgreExporter::writeCamera(MFnCamera& camera)
	{
		MPlug plug;
		MPlugArray srcplugarray;
		double dist;
		MAngle angle;
		MFnTransform* cameraTransform = NULL;
		MFnAnimCurve* animCurve = NULL;
		// get camera transform
		for (int i=0; i<camera.parentCount(); i++)
		{
			if (camera.parent(i).hasFn(MFn::kTransform))
			{
				cameraTransform = new MFnTransform(camera.parent(i));
				continue;
			}
		}
		// start camera description
		m_params.outCameras << "camera " << cameraTransform->partialPathName().asChar() << "\n";
		m_params.outCameras << "{\n";

		//write camera type
		m_params.outCameras << "\ttype ";
		if (camera.isOrtho())
			m_params.outCameras << "ortho\n";
		else
			m_params.outCameras << "persp\n";

		// write translation data
		m_params.outCameras << "\ttranslation\n";
		m_params.outCameras << "\t{\n";
		//translateX
		m_params.outCameras << "\t\tx ";
		plug = cameraTransform->findPlug("translateX");
		if (plug.isConnected() && m_params.exportCamerasAnim)
		{
			plug.connectedTo(srcplugarray,true,false,&stat);
			for (int i=0; i < srcplugarray.length(); i++)
			{
				if (srcplugarray[i].node().hasFn(MFn::kAnimCurve))
				{
					if (animCurve)
						delete animCurve;
					animCurve = new MFnAnimCurve(srcplugarray[i].node());
					continue;
				}
				else if (i == srcplugarray.length()-1)
				{
					std::cout << "Invalid link to translateX attribute\n";
					return MS::kFailure;
				}
			}
			m_params.outCameras << "anim " << animCurve->name().asChar() << "\n";
		}
		else
		{
			plug.getValue(dist);
			m_params.outCameras << "= " << dist << "\n";
		}
		//translateY
		m_params.outCameras << "\t\ty ";
		plug = cameraTransform->findPlug("translateY");
		if (plug.isConnected() && m_params.exportCamerasAnim)
		{
			plug.connectedTo(srcplugarray,true,false,&stat);
			for (int i=0; i< srcplugarray.length(); i++)
			{
				if (srcplugarray[i].node().hasFn(MFn::kAnimCurve))
				{
					if (animCurve)
						delete animCurve;
					animCurve = new MFnAnimCurve(srcplugarray[i].node());
					continue;
				}
				else if (i == srcplugarray.length()-1)
				{
					std::cout << "Invalid link to translateY attribute\n";
					return MS::kFailure;
				}
			}
			m_params.outCameras << "anim " << animCurve->name().asChar() << "\n";
		}
		else
		{
			plug.getValue(dist);
			m_params.outCameras << "= " << dist << "\n";
		}
		//translateZ
		m_params.outCameras << "\t\tz ";
		plug = cameraTransform->findPlug("translateZ");
		if (plug.isConnected() && m_params.exportCamerasAnim)
		{
			plug.connectedTo(srcplugarray,true,false,&stat);
			for (int i=0; i< srcplugarray.length(); i++)
			{
				if (srcplugarray[i].node().hasFn(MFn::kAnimCurve))
				{
					if (animCurve)
						delete animCurve;
					animCurve = new MFnAnimCurve(srcplugarray[i].node());
					continue;
				}
				else if (i == srcplugarray.length()-1)
				{
					std::cout << "Invalid link to translateZ attribute\n";
					return MS::kFailure;
				}
			}
			m_params.outCameras << "anim " << animCurve->name().asChar() << "\n";
		}
		else
		{
			plug.getValue(dist);
			m_params.outCameras << "= " << dist << "\n";
		}
		m_params.outCameras << "\t}\n";

		// write rotation data
		m_params.outCameras << "\trotation\n";
		m_params.outCameras << "\t{\n";
		m_params.outCameras << "\t\tx ";
		//rotateX
		plug = cameraTransform->findPlug("rotateX");
		if (plug.isConnected() && m_params.exportCamerasAnim)
		{
			plug.connectedTo(srcplugarray,true,false,&stat);
			for (int i=0; i< srcplugarray.length(); i++)
			{
				if (srcplugarray[i].node().hasFn(MFn::kAnimCurve))
				{
					if (animCurve)
						delete animCurve;
					animCurve = new MFnAnimCurve(srcplugarray[i].node());
					continue;
				}
				else if (i == srcplugarray.length()-1)
				{
					std::cout << "Invalid link to rotateX attribute\n";
					return MS::kFailure;
				}
			}
			m_params.outCameras << "anim " << animCurve->name().asChar() << "\n";
		}
		else
		{
			plug.getValue(angle);
			m_params.outCameras << "= " << angle.asDegrees() << "\n";
		}
		//rotateY
		m_params.outCameras << "\t\ty ";
		plug = cameraTransform->findPlug("rotateY");
		if (plug.isConnected() && m_params.exportCamerasAnim)
		{
			plug.connectedTo(srcplugarray,true,false,&stat);
			for (int i=0; i< srcplugarray.length(); i++)
			{
				if (srcplugarray[i].node().hasFn(MFn::kAnimCurve))
				{
					if (animCurve)
						delete animCurve;
					animCurve = new MFnAnimCurve(srcplugarray[i].node());
					continue;
				}
				else if (i == srcplugarray.length()-1)
				{
					std::cout << "Invalid link to rotateY attribute\n";
					return MS::kFailure;
				}
			}
			m_params.outCameras << "anim " << animCurve->name().asChar() << "\n";
		}
		else
		{
			plug.getValue(angle);
			m_params.outCameras << "= " << angle.asDegrees() << "\n";
		}
		//rotateZ
		m_params.outCameras << "\t\tz ";
		plug = cameraTransform->findPlug("rotateZ");
		if (plug.isConnected() && m_params.exportCamerasAnim)
		{
			plug.connectedTo(srcplugarray,true,false,&stat);
			for (int i=0; i< srcplugarray.length(); i++)
			{
				if (srcplugarray[i].node().hasFn(MFn::kAnimCurve))
				{
					if (animCurve)
						delete animCurve;
					animCurve = new MFnAnimCurve(srcplugarray[i].node());
					continue;
				}
				else if (i == srcplugarray.length()-1)
				{
					std::cout << "Invalid link to rotateZ attribute\n";
					return MS::kFailure;
				}
			}
			m_params.outCameras << "anim " << animCurve->name().asChar() << "\n";
		}
		else
		{
			plug.getValue(angle);
			m_params.outCameras << "= " << angle.asDegrees() << "\n";
		}
		m_params.outCameras << "\t}\n";

		// end camera description
		m_params.outCameras << "}\n\n";
		if (cameraTransform != NULL)
			delete cameraTransform;
		if (animCurve != NULL)
			delete animCurve;
		return MS::kSuccess;
	}