private bool LoadBrushSideLump(Q3BSPDirEntry dir, BinaryReader fileReader) { int brushSideCount = dir.Length / Q3BSPConstants.sizeBrushSide; brushSides = new Q3BSPBrushSide[brushSideCount]; for (int i = 0; i < brushSideCount; i++) { brushSides[i] = Q3BSPBrushSide.FromStream(fileReader); } bspLogger.WriteLine("No of brushsides: " + brushSideCount); return(true); }
private void CheckBrush(ref Q3BSPBrush brush, ref Q3BSPCollisionData cd) { float startFraction = -1.0f; float endFraction = 1.0f; bool startsOut = false; bool endsOut = false; for (int i = 0; i < brush.NumberOfSides; i++) { Q3BSPBrushSide brushSide = brushSides[brush.StartBrushSide + i]; Plane plane = planes[brushSide.PlaneIndex]; float startDistance = 0, endDistance = 0; if (cd.type == Q3BSPCollisionType.Ray) { startDistance = Vector3.Dot(cd.startPosition, plane.Normal) - plane.D; endDistance = Vector3.Dot(cd.endPosition, plane.Normal) - plane.D; } else if (cd.type == Q3BSPCollisionType.Sphere) { startDistance = Vector3.Dot(cd.startPosition, plane.Normal) - (plane.D + cd.sphereRadius); endDistance = Vector3.Dot(cd.endPosition, plane.Normal) - (plane.D + cd.sphereRadius); } else if (cd.type == Q3BSPCollisionType.Box) { Vector3 offset = new Vector3(); if (plane.Normal.X < 0) { offset.X = cd.boxMaximums.X; } else { offset.X = cd.boxMinimums.X; } if (plane.Normal.Y < 0) { offset.Y = cd.boxMaximums.Y; } else { offset.Y = cd.boxMinimums.Y; } if (plane.Normal.Z < 0) { offset.Z = cd.boxMaximums.Z; } else { offset.Z = cd.boxMinimums.Z; } startDistance = (cd.startPosition.X + offset.X) * plane.Normal.X + (cd.startPosition.Y + offset.Y) * plane.Normal.Y + (cd.startPosition.Z + offset.Z) * plane.Normal.Z - plane.D; endDistance = (cd.endPosition.X + offset.X) * plane.Normal.X + (cd.endPosition.Y + offset.Y) * plane.Normal.Y + (cd.endPosition.Z + offset.Z) * plane.Normal.Z - plane.D; } if (startDistance > 0) { startsOut = true; } if (endDistance > 0) { endsOut = true; } if (startDistance > 0 && endDistance > 0) { return; } if (startDistance <= 0 && endDistance <= 0) { continue; } if (startDistance > endDistance) { float fraction = (startDistance - Q3BSPConstants.Epsilon) / (startDistance - endDistance); if (fraction > startFraction) { startFraction = fraction; } } else { float fraction = (startDistance + Q3BSPConstants.Epsilon) / (startDistance - endDistance); if (fraction < endFraction) { endFraction = fraction; } } } if (false == startsOut) { cd.startOutside = false; if (false == endsOut) { cd.inSolid = true; } return; } if (startFraction < endFraction) { if (startFraction > -1.0f && startFraction < cd.ratio) { if (startFraction < 0) { startFraction = 0; } cd.ratio = startFraction; } } }