Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Frustum::checkSphere(const PrimitiveSphere& sphere, const WorldPoint& were) const noexcept {
- const auto pos = were.position + sphere.center;
- for (const auto& plane : planes) {
- const float radius = sphere.radius * were.scale.unitMagnitude(); //unit magnitude is just x + y + z / 3
- const float dist =
- plane.x * pos.x +
- plane.y * pos.y +
- plane.z * pos.z + plane.w;
- if (dist < -radius)
- return false;
- }
- return true;
- }
- void Frustum::fromViewProj(const float* const vp) noexcept {
- const float xw = vp[3];
- const float yw = vp[7];
- const float zw = vp[11];
- const float ww = vp[15];
- const float xz = vp[2];
- const float yz = vp[6];
- const float zz = vp[10];
- const float wz = vp[14];
- PrimitivePlane& near = planes[0];
- PrimitivePlane& far = planes[1];
- PrimitivePlane& left = planes[2];
- PrimitivePlane& right = planes[3];
- PrimitivePlane& top = planes[4];
- PrimitivePlane& bottom = planes[5];
- near.x = xw - xz;
- near.y = yw - yz;
- near.z = zw - zz;
- near.w = ww - wz;
- far.x = xw + xz;
- far.y = yw + yz;
- far.z = zw + zz;
- far.w = ww + wz;
- const float xx = vp[0];
- const float yx = vp[4];
- const float zx = vp[8];
- const float wx = vp[12];
- left.x = xw - xx;
- left.y = yw - yx;
- left.z = zw - zx;
- left.w = ww - wx;
- right.x = xw + xx;
- right.y = yw + yx;
- right.z = zw + zx;
- right.w = ww + wx;
- const float xy = vp[1];
- const float yy = vp[5];
- const float zy = vp[9];
- const float wy = vp[13];
- top.x = xw + xy;
- top.y = yw + yy;
- top.z = zw + zy;
- top.w = ww + wy;
- bottom.x = xw - xy;
- bottom.y = yw - yy;
- bottom.z = zw - zy;
- bottom.w = ww - wy;
- for (auto& plane : planes)
- plane.normalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement