Random Vectors with angle offset

Started by
12 comments, last by SimonTheSorcerer 18 years, 5 months ago
The previous reply is from me, someusername, I don't know how that "Anonymous Poster" got there... I probably logged out by accident
Advertisement
Quote:Original post by Anonymous Poster
Quote:Original post by SimonTheSorcerer
Let's say my offset is PI/2 (90 Degrees).
Then i would only have to offset one of theta OR phi by PI/2 to get a new vector that is perpendicular to the original vector.


hmm, you mean you have to offset 'theta XOR phi' by PI/2 to get a perpendicular vector? I'm not quite sure... First glance, I think you'll get perpendicular vectors if you offset either any single one or both of them. I don't think I can proove this within this reply, but there's a very easy way to see if this holds true on not.
2 vectors are perpendicular (in any number of dimensions) if and only if their dot product is zero. So you can feed your algorithm a random vector and try offseting just phi first, then just theta, and then both phi and theta by PI/2 and each time test the dot product of the initial and final vector to see if it's zero.

I guess it wouldn't hurt mentioning that the dot product of two vectors is the sum of the products of their respective components (it's just a number, not a vector)

If you need anything else just shoot, I can provide all the info you want on the theoretical side but I can't help that much on the actual implementation...
Btw, how do you guys post source code snippets in your replies?


Yes that's exactly what i meant.

And i did test that in my code (see above). I just wanted to tell you. The dot product was zero. (or like 8e^-18 or some REALLY small value atleast)

Regarding code snippets... check out the FAQ.
for code, the tag is ["source"] and ["/source"] (without the "")

Quote:Original post by d00fus
If you already have a transform for the particle system you can use the following method to emit particles within the specified cone half-angle around the z axis of the particle system:


That looks really interesting and efficient. However, i'm still a bit of a noob in OpenGL, and i'm not sure how to get from the Identity Matrix to a matrix whose Z-Axis is aligned with a Vector.

glLoadIdentity();
Vec3 _emit = Vec3(3,4,5);
//Do some rotations or matrix-operations here i guess.
glRotate() etc..

//When i then do
glTranslate(0,0,1) i wanna go along the direction of _emit.

Because thats the matrix that is required in your Function, am i right?

[Edited by - SimonTheSorcerer on November 15, 2005 11:34:34 AM]
Debugging in progress...
If you don't already have a matrix hanging around it'll be a bit more work. In our engine our scene nodes all have a world transform so the particle system can just use this. You can can generate a matrix to rotate a vector onto another (in your case the identity Z vector onto your emit direction) reasonably easily though, you can either generate the matrix directly (see for example http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/fromtorot.txt) or produce a quaternion and generate a matrix from that.
Quote:Original post by d00fus
If you don't already have a matrix hanging around it'll be a bit more work. In our engine our scene nodes all have a world transform so the particle system can just use this. You can can generate a matrix to rotate a vector onto another (in your case the identity Z vector onto your emit direction) reasonably easily though, you can either generate the matrix directly (see for example http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/fromtorot.txt) or produce a quaternion and generate a matrix from that.


I don't have world transforms for my scenenodes, with the exception of my emitternodes, where the world transform is calculated with every render, using the ModelView Matrix.
Unfortunately that link doesn't seem to work. However i do own the book "Real-Time Rendering, Second Edition" by Akenine_Moller. Perhaps it can give some insight. (havn't read too much from it really... [embarrass])
Quaternions are, at this stage of my engine, not an option [smile]. Perhaps i'll implement quats later. But thanks for the info!
Debugging in progress...

This topic is closed to new replies.

Advertisement