Jump to content

Rotating Sprites in relation to their normal direction


Recommended Posts

Hello peoples

I'm playing around with sprites and have followed a few tutorials that show you how to randomize their rotations by writing some simple vex code to control the attribute spriterot.

I saw a really cool illustration of a tree and it's roots drawn with hairs along it's bark all going in the direction of the branch they where on.

I've been trying to reproduce this with an Lsystem tree, scattering points along it, then sticking my hairs as sprites along the points.

I can randomize their direction but not control it in a satisfying way.

So far I've tried playing with the point normals, getting them to point in the direction that I want to , then struggled with getting the

Normals and altering them in some way to control the spriterot.

I thought maybe of making two groups of points , the first with normals facing away from the camera , and then the second with normals pointing in their desired direction. you could calculate the angle between the two groups of points along the axis of the first set of normals?

I've created the 2 groups but haven't a clue how to do the rest, has anyone got any ideas?

Ta everyone

Edit: not my own hairs...

Edited by mrx2008
Link to comment
Share on other sites

I believe there is an orient attribute you should be able to play with in sprites.. Remember, spriterot is just a single float that rotates the sprite around the eye normal (good for spinning/rolling).. Orient should do what I believe you are wanting, however it's been a while since I did some sprite stuff and don't have H in front of me to check right now..

Link to comment
Share on other sites

Thanks for that Deecue , I'm very new to vex so it's a bit of a sharp learning curve ,

I've followed your lead , and have started playing around with the orient and lookat nodes , but I'm still not getting the results I want.

I'm trying to work this out in a vopsop network so that I can get an immediate visual response in my display.

Do you think there might be a way of avoiding any scary maths, or should I bite the bullet and do a refreshers course ;) ?

From what I've glibed from the internet the problem if done in Vopsops could be solved like this:

The "I" normal facing the camera is a vector,

The Point normal (the direction I want to point my sprites in) is a vector.

calculate the Euler or quaternion rotations using the "I" normal as the z axis between the two vectors (using the cross product?)

and then some how convert this into a single float which will be our spriterot attribute .

What you reckon ?

Thanks again for your thoughts

Link to comment
Share on other sites

i should have been a bit more clear.. sorry about that.. the orient i was referring to wasn't the vop op but an actual attribute you can create in sop land and use to orient them.. to be honest, i don't believe I've actually used it before but remember a thread back in the day talking about it...

ahh, here it is (look towards the bottom):

http://forums.odforce.net/index.php?showto...orient++sprites

maybe jason can chime in or someone else that's actually had experience with using the attr before..

cheers,

dave

Link to comment
Share on other sites

  • 2 weeks later...

Cheers Dave

Sorry about the slow response I was holding back until I finally found a fix, but I'm still scratching my slow brain.

I checked out the link, Miguel is replacing grids with sprites and so is able to use the orient attribute to control his "sprites".

This would work with what I'm doing, but I'm being stubborn headed and trying to fix it in vops instead, as I think I could reuse this technique in some other non-photo realistic projects.

this is where I am so far:

I want to use vops to calculate the angle I can rotate sprites with,

so that they point in the same direction as the normals of the point's they are attached to, relative to the view through a camera.

I can create a vector attribute that points away from the camera by object merging the cameras origin, then copying my geometry onto this point ,

then after shrinking this geometry to zero I use a point sop to create normals created by subtracting the 1st geometry's positions and the second geometry.

this gives me the "I" vector about which I'd like to rotate my sprites,

now I just need to calculate the angles that would rotate my sprites in the direction of their original normals.

The cameras rotation needs to be included somehow as well.

What do you think I should do with my two vectors in vops to calculate this spriterot angle?

John

Link to comment
Share on other sites

That's brilliant Anim

I've just been playing with it and it almost does exactly what I want, the sprites don't always line up with normals , but I see now that I can play around with the comb sop

and get the sprites facing the way I want that way.

Thank you very much indeed!

I'll post an image of my results in a few weeks

Thanks again

John

Link to comment
Share on other sites

...

the sprites don't always line up with normals

...

well, they should

but only when you are looking through cam1, so keep it locked when you are navigating the view

also notice that there are 2 texture projections both must have the same camera specified, so if you create new camera specify it in both or create reference for the parameters

second thing to keep in mind (but i think you are aware of this since the question is about sprites and spriterot)

the sprites are primairly faced to the camera as is their nature

the normal is used only as an upvector

but unless you are looking along normal, the sprite should point its way

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...