Notifications
Clear all

[Closed] position object like the autogrid options

Hi
I’m creating a script that needs to position objects in the face center and rotate it like the autogrid option in the create panel does.
so I created this:

	fn trovaAngoloDa3Punti A B C =
 	(
 		n1=normalize(B-A)
 		n2=normalize(C-A)
 		
 		return(acos(dot n1 n2))
 	)	
 	
 	fn calculateOrientation norm =
 	(
 		A=[0,0,0]
 		
 		B=[0,-1,0]
 
 		C=norm
 		C.z=0
 		C=normalize C
 
 		X=C.x
 		if X!=0 then
 			((trovaAngoloDa3Punti A B C)*(X/abs X))
 		else
 			(trovaAngoloDa3Punti A B C)
 	)
 
 
 
 obj=$Object02
 theNormal=polyop.getFaceNormal obj 1 
 	
 	
 orientation=calculateOrientation (copy theNormal)
 
 theNormalMatrix=matrixFromNormal  (theNormal)
 
 theFaceCenter=polyOp.getFaceCenter obj  1
 
 testMat=matrix3 1
 rotateZ testMat (orientation)
 rotate testMat (theNormalMatrix.rotationpart)
 translate testMat theFaceCenter
 
 	
 theAngle=angle  angle_width:30 angle_length:90 angle_thickness:10 wirecolor:red
 
 theAngle.transform=testMat

here is the test scene: http://forums.cgsociety.org/attachment.php?attachmentid=143343&stc=1

the image below shows my problem:
http://forums.cgsociety.org/attachment.php?attachmentid=143344&stc=1

the Black object is created using the autogrid function.
The red one is created from the script.
as you can see the red one doesn’t have the same rotation of the black one.
This happens only if the lower edge of the face I’m working on is not orthogonal to world axes.
any ideas?

sorry for my english

cheers