#include "pointManip.h"
#include <maya/MMatrix.h>
#include <maya/MPoint.h>
#include <maya/MVector.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MFnTransform.h>
#include <maya/MGlobal.h>
#include <maya/MFnCamera.h>
#include <maya/MTemplateCommand.h>
pointManip::pointManip()
: fPortWidth(0)
, fPortHeight(0)
, fDepthMap(NULL)
, fIsMouseDragging(false)
, fMousePositionX(0)
, fMousePositionY(0)
, fMainColorIndex(0)
{
}
pointManip::~pointManip()
{
if (fDepthMap != NULL)
{
delete[] fDepthMap;
fDepthMap = NULL;
}
}
void pointManip::postConstructor()
{
glFirstHandle(fPointHandle);
}
void* pointManip::creator()
{
return new pointManip();
}
{
}
{
fIsMouseDragging = true;
return mousePosition(fMousePositionX, fMousePositionY);
}
{
return mousePosition(fMousePositionX, fMousePositionY);
}
{
fIsMouseDragging = false;
MStatus status = mousePosition(fMousePositionX, fMousePositionY);
{
status.
perror(
"Error fetching mouse position");
return status;
}
{
status.
perror(
"M3dView::portWidth");
return status;
}
{
status.
perror(
"M3dView::portHeight");
return status;
}
if (fMousePositionX >= w || fMousePositionY >= h)
{
status.
perror(
"Mouse out of the port rectangle");
return status;
}
if (w != fPortWidth || h != fPortHeight)
{
fPortWidth = w;
fPortHeight = h;
if (fDepthMap != NULL)
{
delete[] fDepthMap;
fDepthMap = NULL;
}
}
if (fDepthMap == NULL)
{
fDepthMap = new float[fPortWidth * fPortHeight];
}
status = view.
refresh(
false,
true);
{
status.
perror(
"Error refreshing the active view");
return status;
}
{
status.
perror(
"Error reading depth map");
return status;
}
double d = fDepthMap[fMousePositionY * fPortWidth + fMousePositionX];
if (!camera.isOrtho())
{
double Zn = camera.nearClippingPlane();
double Zf = camera.farClippingPlane();
d *= Zn / (Zf - d * (Zf - Zn));
}
if (d < 0.99)
{
view.
viewToWorld(fMousePositionX, fMousePositionY, nearPw, farPw);
fWorldPosition = nearPw + d * (farPw - nearPw);
MVector translation(fWorldPosition);
{
iter.getDependNode(node);
{
}
}
}
}
void pointManip::preDrawUI(
const M3dView &view)
{
fMainColorIndex = mainColor();
}
{
if (fIsMouseDragging)
{
}
else
{
setHandleColor(drawManager, fPointHandle, fMainColorIndex);
drawManager.
sphere(fWorldPosition, 0.1,
true);
drawManager.
text(fWorldPosition,
MString(
"point manip"));
}
}
char cmdName[] = "pointManipCmd";
char nodeName[] = "pointManip";
{
public:
pointManipCmd() {}
};
static pointManipCmd sPointManipCmd;
{
MFnPlugin plugin(obj, PLUGIN_COMPANY,
"2015",
"Any");
MStatus status = plugin.registerNode(nodeName,
pointManip::id,
pointManip::creator,
pointManip::initialize,
if (!status)
{
status.
perror(
"registerNode");
return status;
}
status = sPointManipCmd.registerCommand( obj );
if (!status)
{
status.
perror(
"registerCommand");
return status;
}
return status;
}
{
MStatus status = plugin.deregisterNode(pointManip::id);
if (!status)
{
status.
perror(
"deregisterNode");
return status;
}
status = sPointManipCmd.deregisterCommand(obj);
if (!status)
{
status.
perror(
"deregisterCommand");
return status;
}
return status;
}