Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Rendering a quad about a plane

This topic is 3719 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

Hi, I asked something along these lines a while ago but I can't find the thread (are threads older than 20 days being deleted?). As it stands I want to render a quad representing a plane given a 3d vector for the normal, a 3d vector for a point in space on the plane, and two floats representing extent of the quad (centred about the point on the plane). As it stands the top and bottom of the box look ok, but the sides are all rotated 90 degrees about the x axis too much. Additionally, I don't think the method works too well in general, as non axis-aligned planes seem to look wrong. Is there a better approach than the one I'm using?
void PlanePhysicsClass::Render()
{

	float xCos = acos(Dot(this->mNormal, Vector3(1.0f,0.0f,0.0f)));
	float xRot = RADIAN_TO_DEGREE * xCos - 90.0f;

	float yCos = acos(Dot(this->mNormal, Vector3(0.0f,1.0f,0.0f)));
	float yRot = RADIAN_TO_DEGREE * yCos - 90.0f;

	float zCos = acos(Dot(this->mNormal, Vector3(0.0f,0.0f,1.0f)));
	float zRot = RADIAN_TO_DEGREE * zCos - 90.0f;



	mCorners[0].x = this->mPos.x - (this->mExtents.x/2);
	mCorners[0].z = this->mPos.z - (this->mExtents.y/2);
	mCorners[0].y = 0.0f;

	mCorners[1].x = this->mPos.x - (this->mExtents.x/2);
	mCorners[1].z = this->mPos.z + (this->mExtents.y/2);
	mCorners[1].y = 0.0f;

	mCorners[2].x = this->mPos.x + (this->mExtents.x/2);
	mCorners[2].z = this->mPos.z + (this->mExtents.y/2);
	mCorners[2].y = 0.0f;

	mCorners[3].x = this->mPos.x + (this->mExtents.x/2);
	mCorners[3].z = this->mPos.z - (this->mExtents.y/2);
	mCorners[3].y = 0.0f;

	glPushMatrix();
		glTranslatef(this->mPos.x, this->mPos.y, this->mPos.z);
		glRotatef(xRot, 1.0f,0.0f,0.0f);
		glRotatef(yRot, 0.0f,1.0f,0.0f);
		glRotatef(zRot, 0.0f,0.0f,1.0f);
		glBegin(GL_QUADS);												// Start Drawing Quads
			glTexCoord2f(1.0f, 0.0f); glVertex3f(mCorners[0].x, mCorners[0].y, mCorners[0].z);	// Point 1 (Back)
			glTexCoord2f(1.0f, 1.0f); glVertex3f(mCorners[1].x, mCorners[1].y, mCorners[1].z);	// Point 2 (Back)
			glTexCoord2f(0.0f, 1.0f); glVertex3f(mCorners[2].x, mCorners[2].y, mCorners[2].z);	// Point 3 (Back)
			glTexCoord2f(0.0f, 0.0f); glVertex3f(mCorners[3].x, mCorners[3].y, mCorners[3].z);	// Point 4 (Back)
		glEnd();
	glPopMatrix();

}

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!