We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › force particles to face the exterior of a sphere
Page Index Toggle Pages: 1
force particles to face the exterior of a sphere (Read 745 times)
force particles to face the exterior of a sphere
Jul 15th, 2008, 11:58pm
 
Hi,

I'm struggling with something that must be really simple to do.

I'm 'making' a sphere from particles [a texture on a quad]. And I don't seem to be able to force those particles to always face the exterior of the sphere.

Each particles is a 3d vector. So I'm using Math.atan2 [via the methods headingXY(), headingXZ() and headingYZ() from toxi's geom lib] to get the rotation angles [for each planes] that a particle needs depending of its coord.

Here is what I do:

Code:


gl.glTranslatef(pPos.x, pPos.y, pPos.z);

gl.glRotatef(p.degrees(pPos.headingXY()), 0, 0, 1);
gl.glRotatef(p.degrees(pPos.headingXZ()), 0, 1, 0);
gl.glRotatef(p.degrees(pPos.headingYZ()), 1, 0, 0);




The following, on its own, works:

Code:

gl.glTranslatef(pPos.x, pPos.y, pPos.z);

gl.glRotatef(p.degrees(pPos.headingXY()), 0, 0, 1);


but the the rotations on the y and x axes gives strange results.

Thanks,
Re: force particles to face the exterior of a sphe
Reply #1 - Jul 17th, 2008, 7:23pm
 
I'm back on this. I think I need a break because I still don't get it Smiley. Almost there though.

...

It seems that the rotation around the z axis is off.

Code:

gl.glRotatef(90.0f-p.degrees(_loc.headingYZ())+90.0f, 1.0f, 0.0f, 0.0f);
gl.glRotatef(90.0f+p.abs(p.degrees(_loc.headingXZ())), 0.0f, 1.0f, 0.0f);
gl.glRotatef(p.degrees(_loc.headingXY()), 0.0f, 0.0f, 1.0f);
Re: force particles to face the exterior of a sphe
Reply #2 - Jul 22nd, 2008, 11:17am
 
here's what i do to rotate a plane so its normal faces another vector:

your particle would by in the XY plane correct so ill use its normal (0,0,1)

U vector is (0,1,0) (normalized)

V is your sphere normal at a certain point (normalized)


N = U.cross( V ) // axis of rotation
N.normalize()
float dot = U.dot( V );// cos angle
float angle = acos(dot); // angle of rotation

// quat from an angle and a rotation axis
Quaternion quat = new Quaternion();
quat.rotateAxis( N, angle);
// transform vertex
Vector3 dv = quat.mul( P );

_position.set( dv );
// translate to right position
_position.add( offset );


i used quaternions to rotate the vector, but you could create a matrix using the UVN vectors.
offset is the translation vector. which means, the position where u want the particle to be

so then transform your plane's vertices and u should be ok
Re: force particles to face the exterior of a sphe
Reply #3 - Jul 27th, 2008, 11:18am
 
Thanks for the help.

I'm almost there. I have the surface normal and two perpendicular vectors.

...

Now I need to figure out, how to use those coord./vectors to correctly rotate my planes/particles [which are 'stored' in a display list].

Re: force particles to face the exterior of a sphe
Reply #4 - Jul 28th, 2008, 7:00am
 
Anything here that might be helpful?
http://seltar.org/projects/MarchingTriangleWar2/
Re: force particles to face the exterior of a sphe
Reply #5 - Jul 29th, 2008, 1:30am
 
well, I'm quite sure I will find something helpful in your code.
Thanks for the link.

Someone else directed me to VBOs.
I'm going to look into this first.
Page Index Toggle Pages: 1