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

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

}



1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013229
×