Example #1
0
        public void SetPhysics(Mogre.Entity entity, Mogre.SceneNode node, float mass)
        {
            MogreNewt.ConvexCollision collision = new MogreNewt.CollisionPrimitives.Cylinder(
                Core.Singleton.NewtonWorld,

                Core.Singleton.PhysicsManager.getCollisionCylinderRadius(entity, node),
                Core.Singleton.PhysicsManager.getCollisionCylinderHeight(entity, node),
                new Mogre.Quaternion(new Mogre.Radian(1.57f), new Mogre.Vector3(0f, 0f, 1f)),
                Core.Singleton.GetUniqueBodyId()
                );

            Mogre.Vector3 inertia, offset;
            collision.CalculateInertialMatrix(out inertia, out offset);
            inertia *= mass;

            m_Body = new MogreNewt.Body(Core.Singleton.NewtonWorld, collision, true);
            m_Body.AttachNode(node);
            m_Body.SetMassMatrix(mass, inertia);
            m_Body.SetPositionOrientation(node.Position + new Vector3(0, 1, 0), node.Orientation);
            m_Body.MaterialGroupID = Core.Singleton.PhysicsManager.getMaterialID("Metal");
        }
Example #2
0
        public Character(CharacterProfile profile)
        {
            Profile = profile.Clone();

            _Orientation = Quaternion.IDENTITY;

            Entity = Engine.Singleton.SceneManager.CreateEntity(Profile.MeshName);
            Node   = Engine.Singleton.SceneManager.RootSceneNode.CreateChildSceneNode();
            Node.AttachObject(Entity);

            Vector3 scaledSize = Entity.BoundingBox.HalfSize * Profile.BodyScaleFactor;

            ConvexCollision collision = new MogreNewt.CollisionPrimitives.Capsule(
                Engine.Singleton.NewtonWorld,
                System.Math.Min(scaledSize.x, scaledSize.z),
                scaledSize.y * 2,
                Vector3.UNIT_X.GetRotationTo(Vector3.UNIT_Y),
                Engine.Singleton.GetUniqueBodyId());



            Vector3 inertia, offset;

            collision.CalculateInertialMatrix(out inertia, out offset);

            inertia *= Profile.BodyMass;

            Body = new Body(Engine.Singleton.NewtonWorld, collision, true);
            Body.AttachNode(Node);
            Body.SetMassMatrix(Profile.BodyMass, inertia);
            Body.AutoSleep = false;

            Body.Transformed   += BodyTransformCallback;
            Body.ForceCallback += BodyForceCallback;

            Body.UserData        = this;
            Body.MaterialGroupID = Engine.Singleton.MaterialManager.CharacterMaterialID;

            Joint upVector = new MogreNewt.BasicJoints.UpVector(
                Engine.Singleton.NewtonWorld, Body, Vector3.UNIT_Y);

            collision.Dispose();

            SensorNode = Node.CreateChildSceneNode(new Vector3(0, 0, System.Math.Min(scaledSize.x, scaledSize.z) * 1.5f));

            collision = new MogreNewt.CollisionPrimitives.Cylinder(
                Engine.Singleton.NewtonWorld,
                System.Math.Min(scaledSize.x, scaledSize.z) * 1.5f,
                scaledSize.y * 1,
                Vector3.UNIT_X.GetRotationTo(Vector3.UNIT_Y),
                Engine.Singleton.GetUniqueBodyId());
            ObjectSensor = new Body(Engine.Singleton.NewtonWorld, collision, true);
            ObjectSensor.SetMassMatrix(1, new Vector3(1, 1, 1));

            ObjectSensor.UserData        = this;
            ObjectSensor.MaterialGroupID = Engine.Singleton.MaterialManager.CharacterSensorMaterialID;

            Contacts = new List <GameObject>();

            Inventory = new List <DescribedProfile>();
            Inventory = Profile.Inventory;

            AnimBlender = new CharacterAnimBlender();
            AnimBlender.SetEntity(Entity);

            ActiveQuests = new QuestManager();

            _Statistics = Profile.Statistics.statistics_Clone();

            FriendlyType = Profile.FriendlyType;

            State = Enemy.StateTypes.IDLE;

            DropExp  = 0;
            ProfName = Profile.ProfileName;

            if (Profile.DialogRoot != null && Profile.DialogRoot != "")
            {
                TalkRoot = Conversations.D[Profile.DialogRoot].Reactions.Values.ElementAt(0);
            }

            Activities = new ActivityManager();
            Waiting    = false;
        }