[Sidefx-houdini-list] Expression syntax for matrices and  vectors

Mario Marengo mario at axyzfx.com
Tue Oct 30 12:45:49 EDT 2007


On October 30, 2007 10:38 am, Andy Nicholas wrote:

> i.e. this syntax (a trivial example):
>
> {
>    float a = ch("sparevar_a");
>    float b = ch("sparevar_b");
>    return a*b;
> }

OK. That's the "expression language" -- part of "hscript", now replaced (or 
"superceded", I guess is a better term) with Python.

Here's one way to extract elements or rows from a matrix using the expression 
language (either in-line like you're using it, or in a standalone custom 
expression function):

Extracting the translation 3-vector
{
string m = stripmatrix(optransform("/obj/ground"));
vector T = vector3(arg(m,12),arg(m,13),arg(m,14));
return T;
}

A single element from the translation (x in this case)
{
string m = stripmatrix(optransform("/obj/ground"));
vector T = vector3(arg(m,12),arg(m,13),arg(m,14));
return T[0];
}

Arbitrary element extraction:
{
string m = stripmatrix(optransform("/obj/ground"));
float m11 = arg(m,0);
float m12 = arg(m,1);
float m13 = arg(m,2);
float m14 = arg(m,3);
float m21 = arg(m,4);
float m22 = arg(m,5);
float m23 = arg(m,6);
float m24 = arg(m,7);
float m31 = arg(m,8);
float m32 = arg(m,9);
float m33 = arg(m,10);
float m34 = arg(m,11);
float m41 = arg(m,12);
float m42 = arg(m,13);
float m43 = arg(m,14);
float m44 = arg(m,15);
return m41;
}

And so on. Basically: stripmatrix() converts the usual bracketed syntax into a 
space-separated list of components that the arg() function can then extract 
elements from.

>
>
> Actually, you've just uncovered a bigger confusion for me here. What are
> expressions? Are they supposed to be HScript? If so, what's the
> difference?

Expressions are used inside parameters to calculate some value. The list of 
functions that can be used in these expressions is given by typing "exhelp" 
in the textport. The hscript commands are used to manipulate your houdini 
session via text commands, and the commands available are given when you type 
"help" in the textport.

>
> >>so not clear what you mean.
>
> Yes, you're right, I meant to type Matrix and Vector as lowercase. But
> I've just figured that the only way (that I've found as yet) to create a
> vector is to do this:
>
> vector v = vector("["+unitz_x+","+unitz_y+","+unitz_z+"]");

vector v = vector3(<expr>,<expr>,<expr>);


HTH. Cheers!

-- 
......................................................................
Mario Marengo                                  mailto:mario at axyzfx.com
AXYZ ANIMATION                                 http://www.axyzfx.com
......................................................................



More information about the Sidefx-houdini-list mailing list