Пример #1
0
 public void UpdateWorld()
 {
     world.SetDampingFactors(angularDamping, linearDamping);
     world.SetInactivityThreshold(sleepAngularVelocity, sleepVelocity, .5f);
     if (defaultMaterial != null)
     {
         defaultPhysicsMaterial = defaultMaterial.ToMaterial();
     }
 }
Пример #2
0
    public Material ToMaterial()
    {
        var material = new Material
        {
            KineticFriction = KineticFriction,
            StaticFriction  = StaticFriction,
            Restitution     = Restitution,
        };

        return(material);
    }
Пример #3
0
    private RigidBody CreateBody()
    {
        Material material;

        if (JMaterial != null)
        {
            material = JMaterial.ToMaterial();
        }
        else if (JPhysics.defaultPhysicsMaterial != null)
        {
            material = JPhysics.defaultPhysicsMaterial;
        }
        else
        {
            material = new Material();
        }

        var result = new RigidBody(Shape, material);

        result.AffectedByGravity = AffectedByGravity;
        result.IsStatic          = IsStatic;
        result.AllowDeactivation = AllowDeactivation;
        result.Damping           = (LinearDamping ? RigidBody.DampingType.Linear : 0) | (AngularDamping ? RigidBody.DampingType.Angular : 0);
        result.EnableDebugDraw   = EnableDebugDraw;

        if (isKinematic)
        {
            result.AffectedByGravity = false;
            result.Mass = 1e6f;
        }
        else if (Mass > 0)
        {
            result.Mass = Mass;
        }
        else
        {
            result.SetMassProperties();
        }

        return(result);
    }
Пример #4
0
 public MassPoint(Shape shape, SoftBody owner, Material material)
     : base(shape, material, true)
 {
     this.SoftBody = owner;
 }
Пример #5
0
 public Collider(Shape shape, Jitter.Dynamics.Material material, bool isParticle = false)
     : base(shape, material, isParticle)
 {
     BoundingBoxSize     = BoundingBox.Max - BoundingBox.Min;
     BoundingBoxSizeHalf = 0.5f * BoundingBoxSize;
 }
Пример #6
0
 public MassPoint(Shape shape, SoftBody owner, Material material)
     : base(shape, material)
 {
     this.isMassPoint = true; this.SoftBody = owner;
     useShapeMassProperties = false;
 }
Пример #7
0
        public static ItemComponent CreateNewItem(MessageProvider messageProvider, GameState state,
            string name, string imageLocation, string description,
            string modelPath, Vector2i size, Vector3 offset, Quaternion rotation, Shape shape, ItemLocation location,
            AttackClass attackClasses, ItemUsage itemUsages, Protection protection, Material physicsMaterial,
            float mass, float healthDelta, float usageDeltaPerUsage, float attackStrength, float throwPower, float usage)
        {
            var entity = EntityFactory.Instance.CreateWith(name, messageProvider,
                systems: new[] { typeof(ItemSystem), typeof(ModelSystem), typeof(PhysicsSystem) });

            var item = entity.GetComponent<ItemComponent>();
            item.ImageLocation = imageLocation;
            item.Description = description;
            item.Size = size;
            item.Location = location;
            item.AttackClasses = attackClasses;
            item.ItemUsages = itemUsages;
            item.Protection = protection;
            item.HealthDelta = healthDelta;
            item.AttackStrength = attackStrength;
            item.ThrowPower = throwPower;
            item.Usage = usage;
            item.UsageDeltaPerUsage = usageDeltaPerUsage;
            item.Mass = mass;
            item.PhysicsMaterial = physicsMaterial;
            item.PositionOffset = offset;
            item.Rotation = rotation;
            item.ItemUsageHandler = new MazeItemUseHandler();

            var model = new ModelSceneObject(modelPath);
            model.Enabled = true;
            state.Scene.AddObject(model);
            entity.GetComponent<ModelComponent>().Model = model;

            var transform = entity.GetComponent<TransformComponent>();
            var physics = entity.GetComponent<PhysicsComponent> ();

            if (shape == null)
            {
                List<JVector> vertices = new List<JVector>();
                model.Model.Meshes[0].Vertices.ForEach(x => vertices.Add(x.ToJitterVector()));

                List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();

                for(int i = 0; i < model.Model.Meshes[0].Indices.Length; i+= 3)
                {
                    int i0 = model.Model.Meshes[0].Indices[i+0];
                    int i1 = model.Model.Meshes[0].Indices[i+1];
                    int i2 = model.Model.Meshes[0].Indices[i+2];

                    indices.Add(new TriangleVertexIndices(i0, i1, i2));
                }

                shape = new TriangleMeshShape(new Octree(vertices, indices));
            }

            var body = new RigidBody(shape);
            body.Position = transform.Position.ToJitterVector ();
            if (mass >= 0)
                body.Mass = mass;
            body.Material = physicsMaterial;
            body.AllowDeactivation = true;
            body.Tag = entity;

            state.PhysicsManager.World.AddBody(body);
            physics.RigidBody = body;
            physics.World = state.PhysicsManager.World;
            physics.PhysicsApplying = AffectedByPhysics.Orientation | AffectedByPhysics.Position;
            physics.RigidBody.IsStatic = false;
            physics.RigidBody.IsActive = false;
            physics.RigidBody.Position = transform.Position.ToJitterVector();
            model.Position = transform.Position;

            return item;
        }