Vvvv sdk hit test example

has anyone a simple example on how to check if a vector2d point is over a matrix4x4. basically a simple quad hittest.

i checked the SDK but the hittest nodes use some dated getmatrix stuff. i’m working with v2.

i don’t have an overview of all the utils,vmath helpers and pluginspecs/ isn’t really helpful so far.

cheers

are you refering to this node in the sdk? QuadHitTestNode.cs
if so, the interesting part are the lines

Vector2D trv = ((!trobject) * v).xy;
if (trv > -0.5 && trv < 0.5)

the !trobject computes the inverse of the matrix.
in v2 i’d recommend you to use the SlimDX.Matrix for performance reasons by simply defining a spread of that type. that should give you a transform input, access it like any spread and compute the inverse of one matrix by calling Matrix.Invert(matrix) - see http://slimdx.org/docs/html/T_SlimDX_Matrix.htm

thank you, to be honest, i need to look into matrixoperations first to understand what’s going on.

ok, and how can i convert a ISpread to SlimDX Matrix or vice versa ?

edit: got it, pluginspecs/html/M_VVVV_Utils_VMath_Matrix4x4Extensions_ToSlimDXMatrix.htm

next question, what happens here in the previous code

Vector2D trv = ((!trobject) * v).xy;

getting x and y out of a 4x4matrix ? there seems no equivalent extension in slimdx, right ?

my not working line using SlimDX:

Vector2 trv = (SlimDX.Matrix.Invert(mySlimMatrix) * v).xy;

BTW…thanks for reducing the messages in codeEditor

no need to convert from Matrix4x4 to SlimDX.Matrix
just define the input pin as ISpread it will show up as normal Transform Input pin.

Vector2D trv = ((!trobject) * v).xy;

is not getting xy of the matrix. but as you assumed correctly in the code below the vector is multiplied with the inverse matrix.
and there is no overload for the * operator. so i guess you should be using the SlimDX.Vector2.TransformCoordinate method

Vector2 trv = SlimDX.Vector2.TransformCoordinate(v, invMatrix);

thanks woei, this is it !

just converting to from v4 matrix to slimdx matrix because i’m using v4 sdk matrix methods at some point in code. but i’ll look into slimdx now

dirty code for hittest with slimdx for the record:

mySlimMatrix = SlimDX.Matrix.Invert(mySlimMatrix);
Vector2 v = new Vector2(FMouse[0](0), FMouse[1](1));
Vector2 trv = SlimDX.Vector2.TransformCoordinate(v, mySlimMatrix);
			
if (trv.X > -0.5f && trv.Y > -0.5f && trv.X < 0.5f && trv.Y < 0.5f) 
{
FHit[0](0) = true;
}
else FHit[0](0) = false;

well if you have a vvvv matrix anyways, don’t convert your code… the speed improvement is only a cast from double to float for each matrix element. the most expensive operation is the matrix inversion which is super fast in VMath. if the inversion is not that optimized in slimDX its slower and not as elegant with the slimDX code.

cheers tonfilm. i’d prefer the vvvv sdk way. whats the v2 method for matrix inversion? and maybe a stupid question: is there a search in sdk specs (page with members,methods etc.)

it’s !matrix, like here

!trobject

danke woei