/// <summary> /// Performs movement and collision detection in the Z plane. /// </summary> protected virtual void DoZMovement() { Accum velZAbs = FixedMath.Abs(vel.Z); if (vel.Z == Accum.Zero) { DoZCollisionDetection(true); } else if (velZAbs < this.Height) { bCylinder.Position += vel; if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } else { Accum moveCount = FixedMath.Ceil(velZAbs / this.Height); Accum stepVel = vel.Z / this.Height; for (int i = 0; i < moveCount; i += 1) { bCylinder.Position += stepVel; if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; return; } } if (DoZCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } }
/// <summary> /// Performs movement and collision detection in the XY plane. /// </summary> protected virtual void DoMovement() { if ((vel.X | vel.Y) == Accum.Zero) { DoXYCollisionDetection(true); } else if (FixedMath.Abs(vel.X * vel.X + vel.Y * vel.Y) < (this.Radius * this.Radius)) { bCylinder.X += vel.X; bCylinder.Y += vel.Y; if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } else { Accum moveCount = FixedMath.Ceil((vel.X * vel.X + vel.Y * vel.Y) / this.Radius); Vector3k stepVel = new Vector3k(vel.X / this.Radius, vel.Y / this.Radius, Accum.Zero); for (int i = 0; i < moveCount; i += 1) { bCylinder.X += vel.X; bCylinder.Y += vel.Y; if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; return; } } if (DoXYCollisionDetection(true) == CollisionType.SpcColResp_StopMovement) { vel = Vector3k.Zero; } } }