Is there any nice way of pointing the individual rects in a mesh towards the camera eye? Was thinking it should be possible with having the normal and center of the rect available for each vertex in the vertex shader. But then there is some shady math involved of changing base or something. Quaternions to the rescue!?
I presume these are rects added with addRect, where can you specify a centre x,y point, height, width, and rotation (around the z axis).
I also presume you want to rotate the rect around its original x,y point, so that point won’t change.
What you need to do is rotate the model matrix for each rect, so it’s pointing in the right direction. But there is only one model matrix per mesh, ie you can’t rotate individual parts of a mesh in different directions from each other.
So I think you need separate meshes for each rect, then you can calculate the direction between each rect and the camera (by subtracting the rect centre from the camera position) and rotate.
If all of this is happening in real time, quaternions will ensure you don’t get jumpy graphics. Andrew is the expert, but if he doesn’t have time, I have (I think) got quaternions working for my flying app, and can share that with you (if you need it).
If your camera (or the rects) move enough that they get in front of each other, you maybe also need to sort the rects from furthest to nearest each time you draw, to avoid graphic effects.
No need for Quaternions, but the problem as stated is a little under specified. Suppose I take the unit rectangle in the x-y plane, but with an eye at (10,10,10). What should I see? You want a rectangle (square) with centre the same as the given rectangle but oriented to the viewer? You’d need to designate a bottom edge as well, and how big should the rectangle be? Should it simply rotate the given rectangle so that it is the same size as it would be if at that point?
I’d do this in a vertex shader, myself.
If you really want quaternions, they can be found as part of my Library Maths project on CC. I haven’t looked in detail at Ignatz’s version (on my TODO list) so can’t comment on that, but I know that mine is pretty complete in terms of what you can do with quaternions.