public void BuildCellArray(ref ObjCell newCell) { SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; ObjCell.find_cell_list(CellArray, ref newCell, SpherePath); }
public ObjCell BuildCellArray(ObjCell newCell = null) { SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; return(ObjCell.find_cell_list(CellArray, newCell, SpherePath)); }
public TransitionState CheckOtherCells(ObjCell currCell) { var result = TransitionState.OK; SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; ObjCell newCell = new ObjCell(); // null check? ObjCell.find_cell_list(CellArray, ref newCell, SpherePath); foreach (var cell in CellArray.Cells.Values) { if (cell == null || cell.Equals(currCell)) { continue; } var collides = cell.FindCollisions(this); switch (collides) { case TransitionState.Slid: CollisionInfo.ContactPlaneValid = false; CollisionInfo.ContactPlaneIsWater = false; return(collides); case TransitionState.Collided: case TransitionState.Adjusted: return(collides); } } SpherePath.CheckCell = newCell; if (newCell != null) { SpherePath.AdjustCheckPos(newCell.ID); return(result); } if (SpherePath.StepDown) { return(TransitionState.Collided); } var checkPos = SpherePath.CheckPos; if ((checkPos.ObjCellID & 0xFFFF) < 0x100) { LandDefs.AdjustToOutside(checkPos); } if (checkPos.ObjCellID != 0) { SpherePath.AdjustCheckPos(checkPos.ObjCellID); SpherePath.SetCheckPos(checkPos, null); SpherePath.CellArrayValid = true; return(result); } return(TransitionState.Collided); }
public bool FindTransitionalPosition() { if (SpherePath.BeginCell == null) { return(false); } var transitionState = TransitionState.OK; var offset = Vector3.Zero; var offsetPerStep = Vector3.Zero; var numSteps = 0; CalcNumSteps(ref offset, ref offsetPerStep, ref numSteps); // restructure as retval? //var maxSteps = 30; var maxSteps = 1000; if (numSteps > maxSteps && !ObjectInfo.Object.IsSightObj) { //Console.WriteLine("NumSteps: " + numSteps); return(false); } if ((ObjectInfo.State & ObjectInfoState.FreeRotate) != 0) { SpherePath.CurPos.Frame.set_rotate(SpherePath.EndPos.Frame.Orientation); } SpherePath.SetCheckPos(SpherePath.CurPos, SpherePath.CurCell); var redo = 0; if (numSteps <= 0) { if ((ObjectInfo.State & ObjectInfoState.FreeRotate) == 0) // ? { SpherePath.CurPos.Frame.set_rotate(SpherePath.EndPos.Frame.Orientation); } SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; ObjCell empty = null; ObjCell.find_cell_list(CellArray, ref empty, SpherePath); return(true); } for (var step = 0; step < numSteps; step++) { if ((ObjectInfo.State & ObjectInfoState.IsViewer) != 0) { var lastStep = numSteps - 1; if (step == lastStep) { var offsetLen = offset.Length(); if (offsetLen > PhysicsGlobals.EPSILON) { redo = lastStep; offsetPerStep = offset * (offsetLen - SpherePath.LocalSphere[0].Radius * lastStep) / offsetLen; } } } SpherePath.GlobalOffset = AdjustOffset(offsetPerStep); if ((ObjectInfo.State & ObjectInfoState.IsViewer) == 0) { if (SpherePath.GlobalOffset.LengthSquared() < PhysicsGlobals.EPSILON * PhysicsGlobals.EPSILON) { return(step != 0 && transitionState == TransitionState.OK); } } if ((ObjectInfo.State & ObjectInfoState.FreeRotate) == 0) { redo = step + 1; var delta = (float)redo / numSteps; SpherePath.CheckPos.Frame.InterpolateRotation(SpherePath.BeginPos.Frame, SpherePath.EndPos.Frame, delta); } CollisionInfo.SlidingNormalValid = false; CollisionInfo.ContactPlaneValid = false; CollisionInfo.ContactPlaneIsWater = false; if (SpherePath.InsertType != InsertType.Transition) { var insert = TransitionalInsert(3); transitionState = ValidatePlacementTransition(insert, ref redo); if (transitionState == TransitionState.OK) { return(true); } if (!SpherePath.PlacementAllowsSliding) { return(false); } SpherePath.AddOffsetToCheckPos(SpherePath.GlobalOffset); } else { SpherePath.AddOffsetToCheckPos(SpherePath.GlobalOffset); var transitionInsert = TransitionalInsert(3); transitionState = ValidateTransition(transitionInsert, ref redo); if (CollisionInfo.FramesStationaryFall > 0) { break; } } if (CollisionInfo.CollisionNormalValid && (ObjectInfo.State & ObjectInfoState.PathClipped) != 0) { break; } } return(transitionState == TransitionState.OK); }
public TransitionState CheckOtherCells(ObjCell currCell) { if (DateTime.Now > MaxTime) { if (ShowDebugInfo) { Debug(); ShowDebugInfo = false; Bailout = true; } return(TransitionState.OK); } var result = TransitionState.OK; SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; //ObjCell newCell = null; var newCell = new ObjCell(); // null check? ObjCell.find_cell_list(CellArray, ref newCell, SpherePath); for (var i = 0; i < CellArray.Cells.Count; i++) { var cell = CellArray.Cells.Values.ElementAt(i); if (cell == null || cell.Equals(currCell)) { continue; } var collides = cell.FindCollisions(this); switch (collides) { case TransitionState.Slid: CollisionInfo.ContactPlaneValid = false; CollisionInfo.ContactPlaneIsWater = false; return(collides); case TransitionState.Collided: case TransitionState.Adjusted: return(collides); } } SpherePath.CheckCell = newCell; if (newCell != null) { SpherePath.AdjustCheckPos(newCell.ID); return(result); } if (SpherePath.StepDown) { return(TransitionState.Collided); } var checkPos = new Position(SpherePath.CheckPos); if ((checkPos.ObjCellID & 0xFFFF) < 0x100) { LandDefs.AdjustToOutside(checkPos); } if (checkPos.ObjCellID != 0) { SpherePath.AdjustCheckPos(checkPos.ObjCellID); SpherePath.SetCheckPos(checkPos, null); SpherePath.CellArrayValid = true; return(result); } return(TransitionState.Collided); }