Game Development Community

Melv (or anyone who can answer)

by Jonathan Tarbox · in Torque Game Engine · 09/18/2002 (10:38 pm) · 0 replies

In going over your quadtree code from the fxFoliageReplicator object (wonderfull work btw), I have a question in regards to what you did in IsQuadrantVisible()..

1. You take the quadrant box, save it to a temp variable. no problem there.

2. Multiply it by the inverse of the render transform matrix. (convert the box from world matrix to scene or camera matrix, I believe..)

3. Grab the center point, and the three axis-radius vectors.

4. Then multiply the point and vectors to the render transform matrix. (thus bringing them from scene matrix to world matrix)

Now, my questions are:

- Why did you transform the quadrant coord info from world to scene to world matricies? Am I missing something or do the quadrants have the ability to be at weird angles?

- Are the planes from your SetupClipPlanes() function world coord or scene coord? This probably will answer the next question..

- If I have a Point3F in world coords and want to test them against the planes made by your code, do I need to transform them or no?

Below is the default IsQuadrantVisible() function from the fxFoliageReplicator resource...

-jtarbox

bool fxFoliageRenderList::IsQuadrantVisible(const Box3F VisBox, const MatrixF& RenderTransform)
{
	// Can we trivially accept the visible box?
	if (mBox.isOverlapped(VisBox))
	{
		// Yes, so calculate Object-Space Box.
		MatrixF InvXForm = RenderTransform;
		InvXForm.inverse();
		Box3F OSBox = VisBox;
		InvXForm.mulP(OSBox.min);
		InvXForm.mulP(OSBox.max);

		// Yes, so fetch Box Center.
		Point3F Center;
		OSBox.getCenter(&Center);

		// Scale.
		Point3F XRad(OSBox.len_x() * 0.5, 0, 0);
		Point3F YRad(0, OSBox.len_y() * 0.5, 0);
		Point3F ZRad(0, 0, OSBox.len_z() * 0.5);

		// Render Transformation.
		RenderTransform.mulP(Center);
		RenderTransform.mulV(XRad);
		RenderTransform.mulV(YRad);
		RenderTransform.mulV(ZRad);

		// Check against View-planes.
		for (U32 i = 0; i < 5; i++)
		{
			// Reject if not visible.
			if (ViewPlanes[i].whichSideBox(Center, XRad, YRad, ZRad, Point3F(0, 0, 0)) == PlaneF::Back) return false;
		}

		// Visible.
		return true;
	}

	// Not visible.
	return false;
}