Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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;
		AbX.x = X.x;
	if(X.y < 0.0f)
		AbX.y = X.y * -1;
		AbX.y = X.y;
	if(X.z < 0.0f)
		AbX.z = X.z * -1;
		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!

Share this post

Link to post
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 this post

Link to post
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 this post

Link to post
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!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!