mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Added More Vector math functions
Added VectorMul (vector multiply), VectorDiv (vector divide, and VectorMidPoint to find the midpoint of two vectors.
This commit is contained in:
parent
c98e95e6ff
commit
2efe1a9c0a
1 changed files with 88 additions and 0 deletions
|
|
@ -659,6 +659,66 @@ DefineConsoleFunction( VectorScale, VectorF, ( VectorF a, F32 scalar ),,
|
||||||
{
|
{
|
||||||
return a * scalar;
|
return a * scalar;
|
||||||
}
|
}
|
||||||
|
DefineConsoleFunction( VectorMul, VectorF, ( VectorF a, VectorF b ),,
|
||||||
|
"Multiplies two vectors.\n"
|
||||||
|
"@param a The first vector.\n"
|
||||||
|
"@param b The second vector.\n"
|
||||||
|
"@return The vector @a a * @a b.\n\n"
|
||||||
|
"@tsexample\n"
|
||||||
|
"//-----------------------------------------------------------------------------\n"
|
||||||
|
"//\n"
|
||||||
|
"// VectorMul( %a, %b );\n"
|
||||||
|
"//\n"
|
||||||
|
"// The multiplication of vector a, (ax, ay, az), and vector b, (bx, by, bz) is:\n"
|
||||||
|
"//\n"
|
||||||
|
"// a * b = ( ax * bx, ay * by, az * bz )\n"
|
||||||
|
"//\n"
|
||||||
|
"//-----------------------------------------------------------------------------\n\n"
|
||||||
|
|
||||||
|
"%a = \"1 0 0\";\n"
|
||||||
|
"%b = \"0 1 0\";\n\n"
|
||||||
|
|
||||||
|
"// %r = \"( 1 * 0, 0 * 1, 0 * 0 )\";\n"
|
||||||
|
"// %r = \"0 0 0\";\n"
|
||||||
|
"%r = VectorMul( %a, %b );\n"
|
||||||
|
"@endtsexample\n\n"
|
||||||
|
"@ingroup Vectors" )
|
||||||
|
{
|
||||||
|
return a * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineConsoleFunction( VectorDiv, VectorF, ( VectorF a, VectorF b ),,
|
||||||
|
"Divide two vectors.\n"
|
||||||
|
"@param a The first vector.\n"
|
||||||
|
"@param b The second vector.\n"
|
||||||
|
"@return The vector @a a / @a b.\n\n"
|
||||||
|
"@tsexample\n"
|
||||||
|
"//-----------------------------------------------------------------------------\n"
|
||||||
|
"//\n"
|
||||||
|
"// VectorDiv( %a, %b );\n"
|
||||||
|
"//\n"
|
||||||
|
"// The division of vector a, (ax, ay, az), and vector b, (bx, by, bz) is:\n"
|
||||||
|
"//\n"
|
||||||
|
"// a * b = ( ax / bx, ay / by, az / bz )\n"
|
||||||
|
"//\n"
|
||||||
|
"//-----------------------------------------------------------------------------\n\n"
|
||||||
|
|
||||||
|
"%a = \"1 1 1\";\n"
|
||||||
|
"%b = \"2 2 2\";\n\n"
|
||||||
|
|
||||||
|
"// %r = \"( 1 / 2, 1 / 2, 1 / 2 )\";\n"
|
||||||
|
"// %r = \"0.5 0.5 0.5\";\n"
|
||||||
|
"%r = VectorDiv( %a, %b );\n"
|
||||||
|
"@endtsexample\n\n"
|
||||||
|
"@ingroup Vectors" )
|
||||||
|
{
|
||||||
|
//this is kind of bad, but so is dividing by 0
|
||||||
|
if(b.x == 0) b.x = 0.000001f;
|
||||||
|
if(b.y == 0) b.y = 0.000001f;
|
||||||
|
if(b.z == 0) b.z = 0.000001f;
|
||||||
|
|
||||||
|
return a / b;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -789,6 +849,34 @@ DefineConsoleFunction( VectorDist, F32, ( VectorF a, VectorF b ),,
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DefineConsoleFunction( VectorMidPoint, VectorF, ( VectorF a, VectorF b ),,
|
||||||
|
"Gets the midpoint between the two vectors.\n"
|
||||||
|
"@param a The first vector.\n"
|
||||||
|
"@param b The second vector.\n"
|
||||||
|
"@return The vector (@a a + @a b) / 2.\n\n"
|
||||||
|
"@tsexample\n"
|
||||||
|
"//-----------------------------------------------------------------------------\n"
|
||||||
|
"//\n"
|
||||||
|
"// VectorMidPoint( %a, %b );\n"
|
||||||
|
"//\n"
|
||||||
|
"// The midpoint of vector a, (ax, ay, az), and vector b, (bx, by, bz) is:\n"
|
||||||
|
"//\n"
|
||||||
|
"// (a + b)/2 = ( (ax + bx) /2, ay + by) /2, (az + bz) /2 )\n"
|
||||||
|
"//\n"
|
||||||
|
"//-----------------------------------------------------------------------------\n"
|
||||||
|
// "%a = \"1 0 0\";\n"
|
||||||
|
// "%b = \"0 1 0\";\n\n"
|
||||||
|
// "// %r = \"( 1 + 0, 0 + 1, 0 + 0 )\";\n"
|
||||||
|
// "// %r = \"1 1 0\";\n"
|
||||||
|
// "%r = VectorAdd( %a, %b );\n"
|
||||||
|
"@endtsexample\n\n"
|
||||||
|
"@ingroup Vectors")
|
||||||
|
{
|
||||||
|
return (a + b)/2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
DefineConsoleFunction( VectorLen, F32, ( VectorF v ),,
|
DefineConsoleFunction( VectorLen, F32, ( VectorF v ),,
|
||||||
"Calculate the magnitude of the given vector.\n"
|
"Calculate the magnitude of the given vector.\n"
|
||||||
"@param v A vector.\n"
|
"@param v A vector.\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue