Sign in to follow this  
codingsolo

[Solved] Orienting quads along an arbitrary axis

Recommended Posts

Before I confuse anyone that reads this, let me explain what I am trying to accomplish: I am making particles spawn in a distance away in a 3D space from a center move to that center point. This gives the effect that the particles are being sucked into the center point. Everything works and looks great when the texture on the quad is a dot or circle. The effect looks ridiculous with its intended texture of a horizontal dash, -. The reason for this is that it isn't naturally pointing to the center point when it is being moved. Now this begins where I am failing at. Assuming that I only spawn the particles on the X and Y-axes, under the assumption that since the texture has the - that is horizontal, that it's vector is (1,0,0) if I get the dot product between that vector and the lookAt vector of the particle to the center point, it should result in the angle to rotate the particle to have it properly orient the dash aligned with the vector of travel. It does not. The problem exacerbates when permitting the point to spawn in a 3D space. I assume that if I get a lookAt vector between the particle and the center point, that will become the new right vector for the quad. I am quite accomplished at starting out with a true forward vector and then building the up and right from it to create the new matrix, a la billboarding, but cannot reference on finding any information on starting with the right vector to fill in the forward and the up. Via the use of the a paper sheet with a marker drawn - on it and a doorknob acting as center point, I have visualized that I need to project the paper's center point onto an unknown to me plane, calculate the rotation that needs to happen, unproject the paper back to its world space and utilize the vector from the doorknob to the paper's center point as the paper's new right vector. I could rotate around an arbitrary axis if I could find the theta and the axis that I need to rotate around. I'm missing something (besides a thorough knowledge of linear algebra) and could use any help to point it my way. Thanks! Brandon ----------- Solution: The solution resides in the latter part of the problem explanation. As per billboarding, I create a forward vector that faces the center point. Next, create the rest of the matrix with normalizing(forward), cross((0,1,0),forward) to make the right, normalizing the right, and creating the new up with a cross(forward,right). Now as expected, the forward vector needs to be the quad's new right vector. So with the result of the forward above, building the new matrix, assigning as its right vector the -forward gives the axis the correct orientation. The forward of the new matrix is actually right that we got when building it. The up is the same as the up. Presto! All particles correctly aligned. Brandon
[source="hlsl"]
         // This is done in the vertex shader, of course
         // CenterPoint is the point to where all particles are attracted
         // pPos is world offset of the quad that the vert is attached to
	float3 look = normalize(CenterPoint - IN.pPos);
	float3 right = normalize(cross(float3(0.0f,1.0f,0.0f),look));
	float3 up = cross(look,right);

	float4x4 mat;
	mat[0] = float4(-look,0.0f);
	mat[1] = float4(up, 0.0f);
	mat[2] = float4(right, 0.0f);
	mat[3] = float4(IN.pPos, 1.0f);  

[Edited by - codingsolo on May 24, 2007 10:48:35 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this