View Full Version : Align a sprite to a face

09 September 2009, 04:03 PM
Hi, I'm new in this forum and in MS too.

I'm writing a script to align sprite on selected faces of a object.
But I dont know how to rotate the sprites to align them to the face normal.

A friend talk to me about "quaterion" , I search on internet and MS ref but i'm not familiar with matrix (yes I know, its bad if i want to use MS but I begin ^^ ) so I dont know how to use it well to do what I want.

here is the fonction where I start working on my sprite:

function WorkOnSprite FaceID NumID ScaleVar = (
AttaSprite_Copy = copy AttachSprite_Sprite = "Sprite_Face"+FaceID as string+"_"+NumID as string
--print ("Sprite copy name : "
AttaSprite_Copy.scale *= random (1-(ScaleVar/100)) (1+(ScaleVar/100))
--print ("getFaceCenter : "+polyOp.getFaceCenter AttachSprite_Source FaceID as string)
--print ("getFaceNormal : "+polyOp.getFaceNormal AttachSprite_Source FaceID as string)
--print ("getFaceArea : "+polyOp.getFaceArea AttachSprite_Source FaceID as string)
AttaSprite_Copy.pos = polyOp.getFaceCenter AttachSprite_Source FaceID
--here i want to rotate the sprite copy to align it with the normal of the face
return AttaSprite_Copy

I'll ask other question but I prefer solve this one first ;)

ps : sorry for my english, I'm a french user.

09 September 2009, 12:42 PM

09 September 2009, 01:04 PM
Try if you can set AttaSprite_Copy.dir to face normal direction or something.

09 September 2009, 03:09 PM
Insert this line
AttaSprite_Copy.rotation /= (matrixFromNormal (polyOp.getFaceNormal AttachSprite_Source FaceID))
before this
AttaSprite_Copy.pos = polyOp.getFaceCenter AttachSprite_Source FaceID

09 September 2009, 10:27 AM
ty for your help.
I dont really know how, but i understand you aply a transformation matrix

Now, to be more familiar with matrix, i'll try to offset each sprite depending on the normal face (to avoid Z-fight). Any advise before I start ? ^^

After, I'll use "getFaceArea" to have a random position on each sprite (not always on a face center). Its a good way to do this ?

CGTalk Moderation
09 September 2009, 10:27 AM
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.