Exemple #1
0
        public Character(World world, CharacterConfiguration configuration, string colliderName)
            : base(world)
        {
            this.Configuration = configuration;
            if (Configuration.EntityNames.Length == 0)
                throw new ArgumentException("At least one body entity must be provided.");

            CharacterNode = World.WorldNode.CreateChildSceneNode();
            EyeNode = CharacterNode.CreateChildSceneNode(new Vector3(0, 1.7f, 0));
            FirstPersonModel = new FirstPersonModel(this, EyeNode);
            FirstPersonModel.Visible = false;
            ThirdPersonModel = new ThirdPersonModel(this, CharacterNode, Configuration.EntityNames);

            BodyCollisionTree = new BodyCollisionTree(ThirdPersonModel.BodyEntities[0], AllLowerBodyAnimations.Concat(AllUpperBodyAnimations));
            BodyColliders = ColliderLoader.ParseColliders(colliderName, BodyCollisionTree, "Alpha_").ToArray();

            BoundingSphere = new SphereNode(CharacterNode, new Vector3(0, 1, 0), 2);
            SimpleCollider = new UprightCylinderNode(CharacterNode, Vector3.ZERO, 1.7f, 0.7f);
            AnimationManagerMapper.Add(
                AnimationKind.LowerBody,
                new AnimationManager(
                    AllLowerBodyAnimations,
                    ThirdPersonModel.BodyEntities,
                    "Idle"
                )
            );
            AnimationManagerMapper.Add(
                AnimationKind.UpperBody,
                new AnimationManager(
                    AllUpperBodyAnimations,
                    ThirdPersonModel.BodyEntities,
                    "Wield_USP"
                )
            );
            Camera = World.CreateCamera(Vector3.ZERO, MathHelper.Forward);
            EyeNode.AttachObject(Camera);
            ViewFrustum = new FrustumNode(Camera);

            SpecialMoveHandlers = new SpecialMoveHandler[3];
            Reset();
        }
        protected static bool Intersects(UprightBoxNode a, UprightCylinderNode b)
        {
            Vector3 baseTransformed = a.ReferenceNode.ConvertWorldToLocalPosition(
                b.ReferenceNode.ConvertLocalToWorldPosition(b.BaseCenterPosition)
            );
            // Check if the two objects intersect the same horizontal (xz) plane
            // Simplification:
            // |a.yCenter - b.yCenter| > max(a.height / 2, b.height / 2)
            // |(a.min.y + a.max.y) / 2 - (b.base.y + b.base.y + b.height) / 2| > max((a.max.y - a.min.y) / 2, b.height / 2)
            // |(a.min.y + a.max.y) - (b.base.y * 2 + b.height)| / 2 > max((a.max.y - a.min.y), b.height) / 2
            if (System.Math.Abs(a.Min.y + a.Max.y - (b.BaseCenterPosition.y * 2 + b.Height)) > System.Math.Max(a.Max.y - a.Min.y, b.Height))
                return false;

            // Check if the two objects intersect when projected onto a horizontal (xz) plane
            Vector2 closest = baseTransformed.ToVectorXZ().Clamp(a.Min.ToVectorXZ(), a.Max.ToVectorXZ());
            return closest.SquaredDistance(baseTransformed.ToVectorXZ()) < b.Radius.Squared();
        }
Exemple #3
0
 public UprightBoxNode GetFirstIntersectingBuilding(UprightCylinderNode cylinder)
 {
     return Buildings.FirstOrDefault(building => building.Intersects(cylinder));
 }
Exemple #4
0
 public bool IntersectBuildings(UprightCylinderNode cylinder)
 {
     return GetFirstIntersectingBuilding(cylinder) != null;
 }
 public bool Intersects(UprightCylinderNode cylinder)
 {
     return PrimitiveNode.Intersects(this, cylinder);
 }