# Constrained Quad, need some help (complex)

This topic is 5030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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;

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);

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);

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);

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!

##### Share on other sites
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.

##### Share on other sites
You are absoluty right, I'll try that now... for some reason I thought it was asking for the absolute value of the vector.

##### Share on other sites
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!

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013550
×