:wumpus: wrote:I don't know if it is the easiest way but you can solve this using manual clipping planes (RenderSystem::setClipPlanes).
Thanks, I'll give that a shot. I got it working on a per object basis, but the entire ground mesh is still showing up and I'd like for that to be cut at the frustrum too.
Also, we are supposed to make it so that you can turn on a wireframe display of the player cam's frustrum. I did this using Camera::getWorldSpaceCorners() and the Line3D add-on class, but I feel like there has to be a better way. Here is my approach:
// draws a wireframe frustrum for the player's cam
void PlayState::updateFrustrum() {
SceneNode::ObjectIterator itr = mFrustrumNode->getAttachedObjectIterator();
while (itr.hasMoreElements()) {
delete itr.getNext();
}
Vector3 facingDir = mCamera->getDirection().normalisedCopy();
const Vector3 *topRightNear = mCamera->getWorldSpaceCorners();
const Vector3 *topLeftNear = topRightNear + 1;
const Vector3 *botLeftNear = topLeftNear + 1;
const Vector3 *botRightNear = botLeftNear + 1;
const Vector3 *topRightFar = botRightNear + 1;
const Vector3 *topLeftFar = topRightFar + 1;
const Vector3 *botLeftFar = topLeftFar + 1;
const Vector3 *botRightFar = botLeftFar + 1;
mFrustrumNode->detachAllObjects();
/*
facingDir offsets keep the frustrum from being
displayed in the player's viewport
*/
Line3D *nearRect = new Line3D();
nearRect->addPoint(*topRightNear - facingDir);
nearRect->addPoint(*topLeftNear - facingDir);
nearRect->addPoint(*botLeftNear - facingDir);
nearRect->addPoint(*botRightNear - facingDir);
nearRect->addPoint(*topRightNear - facingDir);
nearRect->drawLines();
mFrustrumNode->attachObject(nearRect);
Line3D *farRect = new Line3D();
farRect->addPoint(*topRightFar + facingDir);
farRect->addPoint(*topLeftFar + facingDir);
farRect->addPoint(*botLeftFar + facingDir);
farRect->addPoint(*botRightFar + facingDir);
farRect->addPoint(*topRightFar + facingDir);
farRect->drawLines();
mFrustrumNode->attachObject(farRect);
Line3D *rightEdges = new Line3D();
rightEdges->addPoint(*topRightFar + facingDir);
rightEdges->addPoint(*topRightNear - facingDir);
rightEdges->addPoint(*botRightNear - facingDir);
rightEdges->addPoint(*botRightFar + facingDir);
rightEdges->drawLines();
mFrustrumNode->attachObject(rightEdges);
Line3D *leftEdges = new Line3D();
leftEdges->addPoint(*topLeftFar + facingDir);
leftEdges->addPoint(*topLeftNear - facingDir);
leftEdges->addPoint(*botLeftNear - facingDir);
leftEdges->addPoint(*botLeftFar + facingDir);
leftEdges->drawLines();
mFrustrumNode->attachObject(leftEdges);
}