align image to vertex pair

Let us know if you have a nice R.U.B.E script to share!
Post Reply
tescott
Posts: 68
Joined: Wed Feb 06, 2013 6:32 pm

align image to vertex pair

Post by tescott »

I've got "grass" that I align to the surface of a fixture. This script requires the user to select two vertices and an image, and then automatically aligns the image to the angle of the vertices:

Code: Select all

vertex[] vertList = getSelectedVertices();
image [] images = getSelectedImages();

if ((vertList.length == 2) || (images.length == 0))
{
	vertex directedVert;
	directedVert.wx = vertList[0].wx - vertList[1].wx;
	directedVert.wy = vertList[0].wy - vertList[1].wy;
	float angle = atan2(directedVert.wy,directedVert.wx);
	
	for (int i = 0; i < images.length; i++)
	{
		images[i].setAngle(angle);
	}
}
Attachments
Example
Example
align.png (32.6 KiB) Viewed 20374 times
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: align image to vertex pair

Post by iforce2d »

Nice!!
Post Reply