Constrained Quad, need some help (complex)

Started by
2 comments, last by necreia 19 years, 1 month ago
I've been fideling with this for a while, what I'm trying to do is create a custom billboard type Quad in 3D space that pivots on the Z-axis. (Like a fire animation, you walk around and it always faces the camera, but doesn't conform if you look above/below). The equasion I am using is from the book "Mathematics for 3D Game Programming & Computer Graphics" by Eric Lengyel: Camera world space point = C, Quad centered at point P, Q1 - Q4 are the coordinates of the quad in counter-clockwise, w is the width, h is the height, and define Vector X as: X = <Py - Cy,Cx - Px, 0> Q1 = P + (w/2)(X/|X|) + <0,0,h/2> Q2 = P - (w/2)(X/|X|) + <0,0,h/2> Q3 = P - (w/2)(X/|X|) - <0,0,h/2> Q4 = P + (w/2)(X/|X|) - <0,0,h/2> So, With this equasion, I wrote the following code:

	D3DXVECTOR3 X, AbX,Q1,Q2,Q3,Q4;					// Vector Variables
	float CameraX, CameraY, CameraZ;				// temp camera values
	g_Camera.GetPosition(CameraX,CameraY,CameraZ);	// get camera position
	X.x = m_CenterLocation.y - CameraY;				// fill X's x value
	X.y = CameraX - m_CenterLocation.x;				// fill X's y value
	X.z = 0.0f;										// fill X's z value

	// fill in the asbolute values
	if(X.x < 0.0f)
		AbX.x = X.x * -1;
	else
		AbX.x = X.x;
	if(X.y < 0.0f)
		AbX.y = X.y * -1;
	else
		AbX.y = X.y;
	if(X.z < 0.0f)
		AbX.z = X.z * -1;
	else
		AbX.z = X.z;

	// fill Quad point 1
	Q1.x = m_CenterLocation.x + (m_Width/2)*(X.x/AbX.x);
	Q1.y = m_CenterLocation.y + (m_Width/2)*(X.y/AbX.y);
	Q1.z = m_CenterLocation.z + (m_Width/2)*(X.z/AbX.z) + (m_Height/2);

	// fill Quad point 2
	Q2.x = m_CenterLocation.x - (m_Width/2)*(X.x/AbX.x);
	Q2.y = m_CenterLocation.y - (m_Width/2)*(X.y/AbX.y);
	Q2.z = m_CenterLocation.z - (m_Width/2)*(X.z/AbX.z) + (m_Height/2);

	// fill Quad point 3
	Q3.x = m_CenterLocation.x - (m_Width/2)*(X.x/AbX.x);
	Q3.y = m_CenterLocation.y - (m_Width/2)*(X.y/AbX.y);
	Q3.z = m_CenterLocation.z - (m_Width/2)*(X.z/AbX.z) - (m_Height/2);

	// fill Quad point 4
	Q4.x = m_CenterLocation.x + (m_Width/2)*(X.x/AbX.x);
	Q4.y = m_CenterLocation.y + (m_Width/2)*(X.y/AbX.y);
	Q4.z = m_CenterLocation.z + (m_Width/2)*(X.z/AbX.z) - (m_Height/2);

then I apply the values, however they are totally off (I can't see the quad at all). Did I really goof my code up, did I get the equasion wrong, or am I doing something else? Thanks!
Advertisement
Off the top of my head, I'd say that you're not interpreting |X| correctly. It's supposed to be the norm of X, which is a scalar computed as follows:

AbX = sqrt( X.x*X.x + X.y*X.y + X.z * X.z)

It's basically the length of the vector.
You are absoluty right, I'll try that now... for some reason I thought it was asking for the absolute value of the vector.
For the most part it works great now, I have some oddities (such as it is flat at some angles it shouldn't be), but I can at least work from here, you were a great help thanks!

This topic is closed to new replies.

Advertisement