#include "cgfxShaderCommon.h"
#include "cgfxVector.h"
#include <maya/MMatrix.h>
#include <maya/MFnMatrixAttribute.h>
#include <maya/MFnMatrixData.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MPlug.h>
#ifdef _WIN32
MTypeId cgfxVector::sId( 4084862001 );
#else
MTypeId cgfxVector::sId( 0xF37A0C31 );
#endif
cgfxVector::cgfxVector()
{
}
cgfxVector::~cgfxVector()
{
}
#ifdef CGFX_DEBUG
#include <stdarg.h>
#ifdef _WIN32
#endif
#else
static inline void dprintf(char* format, ...)
{
}
#endif
{
if( plug == sWorldVector ||
plug == sWorldVectorX ||
plug == sWorldVectorY ||
plug == sWorldVectorZ ||
plug == sWorldVectorW)
{
if (!status)
{
status.
perror(
"cgfxVector: isDirection handle");
return status;
}
if (!status)
{
status.
perror(
"cgfxVector: vector handle");
return status;
}
MPlug matrixPlug(thisMObject(), sMatrix);
if (matrixPlug.isNull())
{
OutputDebugString("matrixPlug is NULL!\n");
}
matrixPlug.getValue(oMatrix);
if (!status)
{
status.
perror(
"cgfxVector: matrix data");
}
matrix= fndMatrix.
matrix(&status);
if (!status)
{
status.
perror(
"cgfxVector: get matrix");
}
#if 0
if (!status)
{
status.
perror(
"cgfxVector: matrix handle");
}
oMatrix = dhMatrix.
data();
if (!status)
{
status.
perror(
"cgfxVector: matrix function set");
}
#endif
bool isDirection = dhIsDirection.
asBool();
double mat[4][4];
double ix, iy, iz, iw;
float ox, oy, oz, ow;
ix = vector[0];
iy = vector[1];
iz = vector[2];
iw = isDirection ? 0.0 : 1.0;
ox = (float)(mat[0][0] * ix +
mat[1][0] * iy +
mat[2][0] * iz +
mat[3][0] * iw);
oy = (float)(mat[0][1] * ix +
mat[1][1] * iy +
mat[2][1] * iz +
mat[3][1] * iw);
oz = (float)(mat[0][2] * ix +
mat[1][2] * iy +
mat[2][2] * iz +
mat[3][2] * iw);
ow = (float)(mat[0][3] * ix +
mat[1][3] * iy +
mat[2][3] * iz +
mat[3][3] * iw);
if (!status)
{
status.
perror(
"cgfxVector: worldVector handle");
return status;
}
if (!status)
{
status.
perror(
"cgfxVector: worldVectorW handle");
return status;
}
dhWVector.
set(ox, oy, oz);
}
else
{
}
}
void* cgfxVector::creator()
{
return new cgfxVector;
}
{
sVectorX = nAttr.
create(
"vectorX",
"vx",
if (!status)
{
status.
perror(
"cgfxVector: create vectorX");
return status;
}
sVectorY = nAttr.
create(
"vectorY",
"vy",
if (!status)
{
status.
perror(
"cgfxVector: create vectorY");
return status;
}
sVectorZ = nAttr.
create(
"vectorZ",
"vz",
if (!status)
{
status.
perror(
"cgfxVector: create vectorZ");
return status;
}
sVector = nAttr.
create(
"vector",
"v",
sVectorX, sVectorY, sVectorZ, &status);
if (!status)
{
status.
perror(
"cgfxVector: create vector");
return status;
}
sIsDirection = nAttr.
create(
"isDirection",
"id",
if (!status)
{
status.
perror(
"cgfxVector: create isDirection");
return status;
}
sMatrix = mAttr.
create(
"matrix",
"m",
if (!status)
{
status.
perror(
"cgfxVector: create matrix");
return status;
}
sWorldVectorX = nAttr.
create(
"worldVectorX",
"wvx",
if (!status)
{
status.
perror(
"cgfxVector: create worldVectorX");
return status;
}
sWorldVectorY = nAttr.
create(
"worldVectorY",
"wvy",
if (!status)
{
status.
perror(
"cgfxVector: create worldVectorY");
return status;
}
sWorldVectorZ = nAttr.
create(
"worldVectorZ",
"wvz",
if (!status)
{
status.
perror(
"cgfxVector: create worldVectorZ");
return status;
}
sWorldVectorW = nAttr.
create(
"worldVectorW",
"wvw",
if (!status)
{
status.
perror(
"cgfxVector: create worldVectorW");
return status;
}
sWorldVector = nAttr.
create(
"worldVector",
"wv",
sWorldVectorX, sWorldVectorY, sWorldVectorZ,
&status);
if( !status )
{
status.
perror(
"cgfxVector: create worldVector");
return status;
}
status = addAttribute(sVector);
if (!status)
{
status.
perror(
"cgfxVector: addAttribute vector");
return status;
}
status = addAttribute(sIsDirection);
if (!status)
{
status.
perror(
"cgfxVector: addAttribute isDirection");
return status;
}
status = addAttribute(sMatrix);
if (!status)
{
status.
perror(
"cgfxVector: addAttribute matrix");
return status;
}
status = addAttribute(sWorldVector);
if (!status)
{
status.
perror(
"cgfxVector: addAttribute worldVector");
return status;
}
status = addAttribute(sWorldVectorW);
if (!status)
{
status.
perror(
"cgfxVector: addAttribute worldVectorW");
return status;
}
status = attributeAffects(sVector, sWorldVector);
if (!status)
{
status.
perror(
"cgfxVector: attributeAffects vector -> worldVector");
return status;
}
status = attributeAffects(sIsDirection, sWorldVector);
if (!status)
{
status.
perror(
"cgfxVector: attributeAffects isDirection -> worldVector");
return status;
}
status = attributeAffects(sMatrix, sWorldVector);
if (!status)
{
status.
perror(
"cgfxVector: attributeAffects matrix -> worldVector");
return status;
}
status = attributeAffects(sVector, sWorldVectorW);
if (!status)
{
status.
perror(
"cgfxVector: attributeAffects vector -> worldVectorW");
return status;
}
status = attributeAffects(sIsDirection, sWorldVectorW);
if (!status)
{
status.
perror(
"cgfxVector: attributeAffects isDirection -> worldVectorW");
return status;
}
status = attributeAffects(sMatrix, sWorldVectorW);
if (!status)
{
status.
perror(
"cgfxVector: attributeAffects matrix -> worldVectorW");
return status;
}
}