public void SetCheckPos(Position position, ObjCell cell) { CheckPos = position; CheckCell = cell; CellArrayValid = false; CacheGlobalSphere(Vector3.Zero); }
public void RemoveParts(ObjCell cell) { foreach (var part in Parts) { cell.RemovePart(part); } }
public ObjCell BuildCellArray(ObjCell newCell = null) { SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; return(ObjCell.find_cell_list(CellArray, newCell, SpherePath)); }
public void calc_cross_cells_static(ObjCell cell, CellArray cellArray) { if (cell != null) // fixme { cell.find_transit_cells(NumParts, Parts, cellArray); } }
public void SetCheckPos(Position position, ObjCell cell) { CheckPos = new Position(position); CheckCell = cell; CellArrayValid = false; CacheGlobalSphere(null); }
public void RestoreCheckPos() { CheckPos = new Position(BackupCheckPos); CheckCell = BackupCell; CellArrayValid = false; CacheGlobalSphere(null); }
public void BuildCellArray(ref ObjCell newCell) { SpherePath.CellArrayValid = true; SpherePath.HitsInteriorCell = false; ObjCell.find_cell_list(CellArray, ref 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 TransitionState InsertIntoCell(ObjCell cell, int num_insertion_attempts) { if (cell == null) { return(TransitionState.Collided); } var transitionState = TransitionState.OK; for (var i = 0; i < num_insertion_attempts; i++) { transitionState = cell.FindCollisions(this); switch (transitionState) { case TransitionState.OK: case TransitionState.Collided: return(transitionState); case TransitionState.Slid: CollisionInfo.ContactPlaneValid = false; CollisionInfo.ContactPlaneIsWater = false; break; } } return(transitionState); }
public Transition() { ObjectInfo = new ObjectInfo(); SpherePath = new SpherePath(); CollisionInfo = new CollisionInfo(); CellArray = new CellArray(); NewCellPtr = new ObjCell(); }
public void SetCollide(Vector3 collisionNormal) { Collide = true; BackupCell = CheckCell; BackupCheckPos = new Position(CheckPos); StepUpNormal = new Vector3(collisionNormal.X, collisionNormal.Y, collisionNormal.Z); WalkInterp = 1.0f; }
public void SetCollide(Vector3 collisionNormal) { Collide = true; BackupCell = CheckCell; BackupCheckPos = CheckPos; // reference? StepUpNormal = new Vector3(collisionNormal.X, collisionNormal.Y, collisionNormal.Z); WalkInterp = 1.0f; }
public void RestoreCheckPos() { CheckPos.ObjCellID = BackupCheckPos.ObjCellID; CheckPos.Frame = BackupCheckPos.Frame; CheckCell = BackupCell; CellArrayValid = false; CacheGlobalSphere(Vector3.Zero); }
public void Init() { ObjectInfo = new ObjectInfo(); SpherePath = new SpherePath(); CollisionInfo = new CollisionInfo(); CellArray = new CellArray(); NewCellPtr = new ObjCell(); }
public void SetCollide(Vector3 collisionNormal) { Collide = true; BackupCell = CheckCell; BackupCheckPos.ObjCellID = CheckPos.ObjCellID; BackupCheckPos.Frame = CheckPos.Frame; StepUpNormal = collisionNormal; WalkInterp = 1; // 1065353216 & 0x0000FFFF; }
public void AddPartsShadow(ObjCell objCell, int numShadowParts) { List <int> clipPlaneList = null; if (numShadowParts > 1) { clipPlaneList = objCell.ClipPlanes; } for (var i = 0; i < NumParts; i++) { if (Parts[i] != null) { objCell.AddPart(Parts[i], clipPlaneList, objCell.Pos.Frame, numShadowParts); } } }
public void InitPath(ObjCell beginCell, Position beginPos, Position endPos) { if (beginPos != null) { CurPos.ObjCellID = beginPos.ObjCellID; CurPos.Frame = beginPos.Frame; // copy constructor CurCell = beginCell; CacheGlobalCurrCenter(); InsertType = InsertType.Transition; } else { CurPos.ObjCellID = endPos.ObjCellID; CurPos.Frame = endPos.Frame; CurCell = beginCell; // sure? CacheGlobalCurrCenter(); InsertType = InsertType.Placement; } }
public void InitPath(ObjCell beginCell, Position beginPos, Position endPos) { BeginPos = beginPos; BeginCell = beginCell; EndPos = endPos; if (beginPos != null) { InsertType = InsertType.Transition; CurPos = beginPos; } else { InsertType = InsertType.Placement; CurPos = endPos; } CurCell = beginCell; CacheGlobalCurrCenter(); }
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); }
public void InitPath(ObjCell beginCell, Position beginPos, Position endPos) { SpherePath.InitPath(beginCell, beginPos, endPos); }
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 ValidateTransition(TransitionState transitionState, ref int redo) { redo = 0; var _redo = 1; Plane contactPlane = new Plane(); if (transitionState != TransitionState.OK || SpherePath.CheckPos.Equals(SpherePath.CurPos)) { _redo = 0; if (transitionState != TransitionState.OK) { if (transitionState != TransitionState.Invalid) { if (CollisionInfo.LastKnownContactPlaneValid) { ObjectInfo.StopVelocity(); var angle = Vector3.Dot(CollisionInfo.LastKnownContactPlane.Normal, SpherePath.GlobalCurrCenter[0].Center) + CollisionInfo.LastKnownContactPlane.D; if (SpherePath.GlobalSphere[0].Radius + PhysicsGlobals.EPSILON > Math.Abs(angle)) { CollisionInfo.SetContactPlane(CollisionInfo.LastKnownContactPlane, CollisionInfo.LastKnownContactPlaneIsWater); CollisionInfo.ContactPlaneCellID = CollisionInfo.LastKnownContactPlaneCellID; if (ObjectInfo.State.HasFlag(ObjectInfoState.OnWalkable)) { _redo = 1; } } } if (!CollisionInfo.CollisionNormalValid) { contactPlane.Normal = Vector3.UnitZ; CollisionInfo.SetCollisionNormal(contactPlane.Normal); } SpherePath.SetCheckPos(SpherePath.CurPos, SpherePath.CurCell); ObjCell empty = null; BuildCellArray(ref empty); transitionState = TransitionState.OK; } } else { SetCurrentCheckPos(); } } else { SetCurrentCheckPos(); } if (CollisionInfo.CollisionNormalValid) { CollisionInfo.SetSlidingNormal(CollisionInfo.CollisionNormal); } if (!ObjectInfo.State.HasFlag(ObjectInfoState.IsViewer)) { if (ObjectInfo.Object.State.HasFlag(PhysicsState.Gravity)) { if (_redo == 0) { if (CollisionInfo.FramesStationaryFall > 0) { if (CollisionInfo.FramesStationaryFall > 1) { CollisionInfo.FramesStationaryFall = 3; contactPlane.Normal = Vector3.UnitZ; contactPlane.D = SpherePath.GlobalSphere[0].Radius - SpherePath.GlobalSphere[0].Center.Z; CollisionInfo.SetContactPlane(contactPlane, false); CollisionInfo.ContactPlaneCellID = SpherePath.CheckPos.ObjCellID; if (!ObjectInfo.State.HasFlag(ObjectInfoState.Contact)) { CollisionInfo.SetCollisionNormal(contactPlane.Normal); CollisionInfo.CollidedWithEnvironment = true; } } else { CollisionInfo.FramesStationaryFall = 2; } } else { CollisionInfo.FramesStationaryFall = 1; } } else { CollisionInfo.FramesStationaryFall = 0; } } } CollisionInfo.LastKnownContactPlaneValid = CollisionInfo.ContactPlaneValid; if (CollisionInfo.ContactPlaneValid) { CollisionInfo.LastKnownContactPlane = CollisionInfo.ContactPlane; CollisionInfo.LastKnownContactPlaneCellID = CollisionInfo.ContactPlaneCellID; CollisionInfo.LastKnownContactPlaneIsWater = CollisionInfo.ContactPlaneIsWater; ObjectInfo.State |= ObjectInfoState.Contact; if (ObjectInfo.IsValidWalkable(CollisionInfo.ContactPlane.Normal)) { ObjectInfo.State |= ObjectInfoState.OnWalkable; } else { ObjectInfo.State &= ~ObjectInfoState.OnWalkable; } } else { ObjectInfo.State &= ~(ObjectInfoState.Contact | ObjectInfoState.OnWalkable); } return(transitionState); }
public void SaveCheckPos() { BackupCell = CheckCell; BackupCheckPos = CheckPos; // reference? }
public void SaveCheckPos() { BackupCell = CheckCell; BackupCheckPos = new Position(CheckPos); }
public void InitPath(ObjCell cell, Position oldPos, Position newPos) { }
public ShadowObj(PhysicsObj physicsObj, ObjCell cell) { PhysicsObj = physicsObj; Cell = cell; }
public void SaveCheckPos() { BackupCell = CheckCell; BackupCheckPos.ObjCellID = CheckPos.ObjCellID; BackupCheckPos.Frame = CheckPos.Frame; }
public void calc_cross_cells_static(ObjCell cell, CellArray cellArray) { cell.find_transit_cells(NumParts, Parts, cellArray); }
public void RemoveLightsFromCell(ObjCell cell) { }