ConsoleFunctions VectorConvolve() and VectorConvolveInverse()
by Orion Elenzil · 05/14/2007 (3:06 pm) · 3 comments
trivial exposure of engine functions VectorConvolve() and VectorConvolveInverse() to script.
in vector math speak, "convolution" is exactly like "addition" but replace "+" with "*",
and "inverse convolution" replaces "+" with "/".
anybody who wants this resource is probably more than capable of spending the five minutes it takes to implement it yourself, but here it is anyway. personally i'd like to see these in HEAD, but it's certainly not very important.
based on TGE 1.3.5
in mathTypes.cc, right after the console function VectorSub, add this:
that's it!
if you don't have access to the C++ code,
the same thing can be done in script like so:
in vector math speak, "convolution" is exactly like "addition" but replace "+" with "*",
and "inverse convolution" replaces "+" with "/".
anybody who wants this resource is probably more than capable of spending the five minutes it takes to implement it yourself, but here it is anyway. personally i'd like to see these in HEAD, but it's certainly not very important.
based on TGE 1.3.5
in mathTypes.cc, right after the console function VectorSub, add this:
ConsoleFunction( VectorConvolve, const char*, 3, 3, "(Vector3F a, Vector3F b) Returns (a.x * b.x, a.y * b.y, a.z * b.z)")
{
VectorF v1(0,0,0),v2(0,0,0);
dSscanf(argv[1],"%f %f %f",&v1.x,&v1.y,&v1.z);
dSscanf(argv[2],"%f %f %f",&v2.x,&v2.y,&v2.z);
v1.convolve(v2);
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer,256,"%g %g %g",v1.x,v1.y,v1.z);
return returnBuffer;
}
ConsoleFunction( VectorConvolveInverse, const char*, 3, 3, "(Vector3F a, Vector3F b) Returns (a.x / b.x, a.y / b.y, a.z / b.z)")
{
VectorF v1(0,0,0),v2(0,0,0);
dSscanf(argv[1],"%f %f %f",&v1.x,&v1.y,&v1.z);
dSscanf(argv[2],"%f %f %f",&v2.x,&v2.y,&v2.z);
v1.convolveInverse(v2);
char* returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer,256,"%g %g %g",v1.x,v1.y,v1.z);
return returnBuffer;
}that's it!
if you don't have access to the C++ code,
the same thing can be done in script like so:
function vectorConvolve(%v1, %v2)
{
%result = "";
%delim = "";
%numComponents = mMin(getWordCount(%v1, %v2));
for (%n = 0; %n < %numComponents; %n++)
{
%result = %result @ %delim @ (getWord(%v1, %n) * getWord(%v2, %n));
%delim = " ";
}
return %result;
}
function vectorConvolveInverse(%v1, %v2)
{
%result = "";
%delim = "";
%numComponents = mMin(getWordCount(%v1, %v2));
for (%n = 0; %n < %numComponents; %n++)
{
%result = %result @ %delim @ (getWord(%v1, %n) / getWord(%v2, %n));
%delim = " ";
}
return %result;
}About the author

Associate Orion Elenzil
Real Life Plus