PDA

View Full Version : Billboard lookat with pFlow


Swahn
12-12-2008, 09:42 AM
I'll try and post this question here in the pFlow section as well. Pehaps someone knows how to do this without scripting and plugins?


[original post:]
Hello, i have been desperately trying to create a billboard behaviour for particles (used for a forest of 2d trees were only one axis should rotate.)
I found a script in this forum wich creates a transform matrix that matches a vector looking at the target (thanks to the original creator! hope you don't mind me using it)
Being the beginner scripter i am i need some hints and tips.

The script is inside the standard "update each particle each step" script in pFlow.

-- References to the used nodes
source = pf_node_current
target = $camera01

-- We need the source node to look at the target node, so...

-- Calculates the vector from the source to the target (the view or look vector)
look = normalize (target.pos - source.pos)

-- Take the target's up vector as the temporal source's up vector
tempUp = target.transform.row2

-- Calculates the right vector
right = cross look tempUp

-- Calculates the source's real up vector
up = cross look right

-- Finally calculates the source's matrix transformation
newTM = matrix3 right up look source.transform.translation

This code works well for single mesh objects wich uses quat rotations.
But particles uses XYZ orientation and i'm not sure how to convert the quats in the resulting matrix so they work with the particles.

Also the rotation should only affect one axis (Z) and i'm not sure how to do that with code either. There is a workaround for that issue though, by simply creating a target object that uses the cameras X and Y positions but not the Z. But i rather use code for this if i only knew how.

I know this forum holds many maxscript masterminds who could help me and i would greatly appreciate it. Or if anyone know a better solution than to use raw code i'm happy with that too as long as it don't involve buying plugins or extra tools.

Thanks!

Glacierise
12-12-2008, 12:44 PM
You don't need scripting to do that at all. You just create a helper (a point, for example), align it with the camera on X and Y, and make the Z axis 0. Then parent the helper to the camera, and in the hierarchy tab of the command panel, in link info, disable the inheritance of the Z axis movement. Then put a 'shape facing' operator in your flow, and choose the helper as a target. That's it!

Bobo
12-12-2008, 01:05 PM
You need just minimal changes to the code:

Use the world up [0,0,1] as the Up Vector.
Take the LookAt vector and calculate the cross product with the Up Vector - this gives you a vector pointing to the side, orthogonal to both.
Now calculate the cross product of this new vector and the Up Vector - the result will be a vector perpendicular to both. Since the Up Vector is aligned to the world Z and this third vector has to be perpendicular to it, it has no other way to go but lie in the XY plane and represent the projection of your LookAt vector on the XY plane.

Now take the Projection of the LookAt instead of LookAt, the result of the cross product of the LookAt and the Up Vector and the World Up Vector itself and build the matrix as before. This will give you a matrix that looks at the camera while keeping its Z axis parallel to the world Z, which is what you wanted!

Swahn
12-12-2008, 01:38 PM
You don't need scripting to do that at all. You just create a helper (a point, for example), align it with the camera on X and Y, and make the Z axis 0. Then parent the helper to the camera, and in the hierarchy tab of the command panel, in link info, disable the inheritance of the Z axis movement. Then put a 'shape facing' operator in your flow, and choose the helper as a target. That's it!

Yeah that's a very smart solution similar to mine minus all he code!
Why haven't i thought of that before :)

And thanks Bobo, i will look into your answer still, to learn new stuff.

CGTalk Moderation
12-12-2008, 01:38 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.