protected static bool Intersects(BoxNode a, SphereNode b)
 {
     Vector3 bTransformedCenter;
     float bTransformedSquaredRadius;
     TransformSphere(b, a.ReferenceNode, out bTransformedCenter, out bTransformedSquaredRadius);
     Vector3 closest = bTransformedCenter.Clamp(a.Min, a.Max);
     return closest.SquaredDistance(bTransformedCenter) < bTransformedSquaredRadius;
 }
 protected static float? Intersects(SphereNode a, Ray b)
 {
     Ray bTransformed = b.TransformRay(a.ReferenceNode);
     Pair<bool, float> result = bTransformed.Intersects(a.ToMogreSphere());
     if (result.first)
         return result.second;
     return null;
 }
Exemple #3
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(FrustumNode a, SphereNode b)
 {
     Vector3 bTransformedCenter = b.ReferenceNode.ConvertLocalToWorldPosition(b.Position);
     Vector3 bTransformedTop = b.ReferenceNode.ConvertLocalToWorldPosition(MathHelper.Up * b.Radius);
     float bTransformedRadius = bTransformedCenter.Distance(bTransformedTop);
     return a.Camera.IsVisible(new Sphere(bTransformedCenter, bTransformedRadius));
 }
 private static void TransformSphere(SphereNode sphere, Node destWorld, out Vector3 transformedCenter, out float transformedSquaredRadius)
 {
     transformedCenter = destWorld.ConvertWorldToLocalPosition(sphere.ReferenceNode.ConvertLocalToWorldPosition(Vector3.ZERO));
     Vector3 bTransformedTop = destWorld.ConvertWorldToLocalPosition
     (
         sphere.ReferenceNode.ConvertWorldToLocalPosition(MathHelper.Up * sphere.Radius)
     );
     transformedSquaredRadius = bTransformedTop.SquaredDistance(transformedCenter);
 }
 protected static bool Intersects(SphereNode a, SphereNode b)
 {
     Vector3 bTransformedCenter;
     float bTransformedSquaredRadius;
     TransformSphere(b, a.ReferenceNode, out bTransformedCenter, out bTransformedSquaredRadius);
     // Remember that `a` sits in the origin of its local space, so the squared distance is the center of `b` - (0, 0, 0).
     float squaredDistance = bTransformedCenter.SquaredLength;
     return squaredDistance < System.Math.Min(bTransformedSquaredRadius, a.Radius.Squared());
 }
Exemple #7
0
 public bool Intersects(SphereNode sphere)
 {
     return PrimitiveNode.Intersects(this, sphere);
 }
Exemple #8
0
 public bool Intersects(SphereNode sphere)
 {
     return sphere.Intersects(this);
 }