private void calculateVectors() { Vector4 bottomLeft = new Vector4(-1, -1, 1, 1); bottomLeft = GenericMethods.Mult(bottomLeft, invModelviewProjectionMatrix); bottomLeft /= bottomLeft.W; Vector4 bottomRight = new Vector4(1, -1, 1, 1); bottomRight = GenericMethods.Mult(bottomRight, invModelviewProjectionMatrix); bottomRight /= bottomRight.W; Vector4 topLeft = new Vector4(-1, 1, 1, 1); topLeft = GenericMethods.Mult(topLeft, invModelviewProjectionMatrix); topLeft /= topLeft.W; pointingDirectionUp = topLeft.Xyz - bottomLeft.Xyz; pointingDirectionRight = bottomRight.Xyz - bottomLeft.Xyz; }
public virtual bool frustrumCheck(Drawable drawable) { Vector4 vSpacePos = GenericMethods.Mult(new Vector4(drawable.Position, 1), modelviewProjectionMatrix); float range = drawable.boundingSphere; float distToDrawAble = (position - drawable.Position).Length; if (distToDrawAble < range * 1.5f) { return(true); } if (distToDrawAble - range > zFar) { return(false); } if (vSpacePos.W <= 0) { return(false); } range /= vSpacePos.W * 0.6f; if (float.IsNaN(range) || float.IsInfinity(range)) { return(false); } vSpacePos /= vSpacePos.W; return( vSpacePos.X < (1f + range) && vSpacePos.X > -(1f + range) && vSpacePos.Y < (1f + range * aspect) && vSpacePos.Y > -(1f + range * aspect) ); }