#include <iostream>
#include <assert.h>
#include <math.h>
#include <limits>
#include "selectClosestPointLocator.h"
#include <maya/MMatrix.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MGlobal.h>
#include <maya/MFnPlugin.h>
#define SCPL_EPSILON std::numeric_limits<double>::epsilon()
MTypeId selectClosestPointLocator::d_id(0x00081050);
MObject selectClosestPointLocator::aPlaneSizeAttr;
MObject selectClosestPointLocator::aNumDivsAttr;
selectClosestPointLocator::selectClosestPointLocator()
{
}
selectClosestPointLocator::~selectClosestPointLocator()
{
}
void* selectClosestPointLocator::creator()
{
return (void*) new selectClosestPointLocator;
}
selectClosestPointLocator::initialize()
{
aPlaneSizeAttr =
status = addAttribute(aPlaneSizeAttr);
aNumDivsAttr =
status = addAttribute(aNumDivsAttr);
return MS::kSuccess;
}
void selectClosestPointLocator::draw(
M3dView & view,
{
int numDivs = handle.
asInt();
glPushAttrib( GL_ALL_ATTRIB_BITS);
int i, j;
float min = (float)-planeSize, max = (float)planeSize;
float step = (float)(( planeSize * 2.0 ) / (float)numDivs);
float u = min;
glBegin(GL_LINES);
for(i=0; i<numDivs+1; i++ )
{
glVertex3f(u,0.0,min);
glVertex3f(u,0.0,max);
u+=step;
}
glEnd();
float v = min;
glBegin(GL_LINES);
for(j=0; j<numDivs+1; j++ )
{
glVertex3f(min,0.0,v);
glVertex3f(max,0.0,v);
v+=step;
}
glEnd();
if(isHighlighted)
else{
}
u = min;
for(i=0; i<numDivs; i++ )
{
glBegin(GL_TRIANGLE_STRIP);
v=min;
for(j=0; j<numDivs+1; j++)
{
glVertex3f(u,0.0,v);
glVertex3f(u+step,0.0,v);
v+= step;
}
glEnd();
u+= step;
}
glPopAttrib();
}
MPoint selectClosestPointLocator::closestPoint(
MPoint cursorRayPoint,
MVector cursorRayDir)
const
{
MString str(
"PLUGIN - inside selectClosestPointLocator::closestPoint\n");
printf("\nPLUGIN - inside selectClosestPointLocator::closestPoint\n");
double t;
if ( fabs(cursorRayDir.
y) < SCPL_EPSILON )
{
}else{
t = (-cursorRayPoint.
y) / cursorRayDir.
y;
point = (cursorRayDir * t) + cursorRayPoint;
}
printf(
"Ray Point: %f %f %f\n",cursorRayPoint.
x, cursorRayPoint.
y, cursorRayPoint.
z);
str += "Ray Point: ";
str += ", ";
str += ", ";
printf(
"Ray Dir: %f %f %f\n",cursorRayDir.
x, cursorRayDir.
y, cursorRayDir.
z);
str += "\nRay Dir: ";
str += ", ";
str += ", ";
str += "\n";
printf(
"Intersection Point: %f %f %f\n",point.
x, point.
y, point.
z);
str += "\nIntersection Point: ";
str += ", ";
str += ", ";
str += "\n";
return point;
}
{
MFnPlugin plugin(obj,
"Selection Target Node",
"1.0",
"any");
status = plugin.registerNode("selectClosestPointLocator",
selectClosestPointLocator::d_id,
selectClosestPointLocator::creator,
selectClosestPointLocator::initialize,
return status;
}
{
status = plugin.deregisterNode(selectClosestPointLocator::d_id);
return status;
}