예제 #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
파일: SoftBody.cs 프로젝트: tpb3d/TPB3D
 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;
        }