예제 #1
0
파일: BodyProperty.cs 프로젝트: nhaberl/PDI
        //=====================================================================

        /// <summary>
        /// This is overridden to allow cloning of a PDI object
        /// </summary>
        /// <returns>A clone of the object</returns>
        public override object Clone()
        {
            BodyProperty o = new BodyProperty();

            o.Clone(this);
            return(o);
        }
예제 #2
0
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(20, 10, 20);
            camera.Yaw      = MathHelper.Pi * -1f / 4;
            camera.Pitch    = MathHelper.Pi * 0.05f;
            var masks = new BodyProperty <ulong>();

            characters = new CharacterControllers(BufferPool);
            Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            var random = new Random(5);

            for (int i = 0; i < 8192; ++i)
            {
                ref var character = ref characters.AllocateCharacter(
                    Simulation.Bodies.Add(
                        BodyDescription.CreateDynamic(
                            new Vector3(250 * (float)random.NextDouble() - 125, 2, 250 * (float)random.NextDouble() - 125), new BodyInertia {
                    InverseMass = 1
                },
                            new CollidableDescription(Simulation.Shapes.Add(new Capsule(0.5f, 1f)), 0.1f),
                            new BodyActivityDescription(-1))),
                    out var characterIndex);

                character.CosMaximumSlope                 = .707f;
                character.LocalUp                         = Vector3.UnitY;
                character.MaximumHorizontalForce          = 10;
                character.MaximumVerticalForce            = 10;
                character.MinimumSupportContinuationDepth = -0.1f;
                character.MinimumSupportDepth             = -0.01f;
                character.TargetVelocity                  = new Vector2(4, 0);
                character.ViewDirection                   = new Vector3(0, 0, -1);
                character.JumpVelocity                    = 4;
            }
예제 #3
0
        public override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(-30, 8, -60);
            camera.Yaw      = MathHelper.Pi * 3f / 4;
            camera.Pitch    = 0;
            _bodyProperties = new BodyProperty <BodyProperty>(BufferPool);

            _events = new CollisionEvents <CollisionEventHandler>(new CollisionEventHandler(), BufferPool,
                                                                  ThreadDispatcher);
            _events.EventHandler.Pairs      = new QuickList <CollidablePair>(128, BufferPool);
            _events.EventHandler.Simulation = Simulation;


            _collisionGroups =
                new FeeSimNarrowPhaseCallbacks <CollisionEventHandler>
            {
                Events          = _events,
                CollisionGroups = _bodyProperties
            };
            Simulation = Simulation.Create(BufferPool, _collisionGroups,
                                           new DefaultPoseIntegratorCallbacks(BufferPool), timestepper: new CustomPositionLastTimestepper());

            var boxShape = new Box(1, 1, 1);

            boxShape.ComputeInertia(1, out _boxInertia);
            _boxIndex = Simulation.Shapes.Add(boxShape);

            CreateFloors();
        }
        public void SetBody(object value)
        {
            if (InstanceGetters.IsDisabledProcessing())
            {
                throw new InvalidOperationException("'SetBody(object)' can't be called while Prig framework is disabling processing. " +
                                                    "Confirm unintended calls for 'InstanceGetters.DisableProcessing().'");
            }

            BodyProperty.SetValue(BodyPropertyTarget, value, null);
        }
    // Start is called before the first frame update
    void Start()
    {
        // get useful classes
        tF = GetComponent <Transform>();
        dS = GameObject.Find("Setting").GetComponent <DisplaySetting>();
        bP = GetComponent <BodyProperty>();
        bO = GetComponent <BodyOrbit>();
        if (bO.centralBody != null)
        {
            cBM = bO.centralBody.GetComponent <BodyMotion>();
        }

        // set display size of body
        float d = (float)(bP.D * dS.scaleD);

        tF.localScale = new Vector3(d, d, d);
        MeshRenderer mr = GetComponent <MeshRenderer>();

        mr.material.color = Color.white;

        InitOrbit();

        /*
         * // set the initial position of body,
         * // initial position is relative to the central body
         * pos[0] = bO.R;
         * SetPosition();
         *
         * // set the initial velocity of revolution
         * // initial velocity if relative to the central body
         * double pi = Math.PI;
         * vel[1] = Math.Sin(pi * bO.angle / 180) * bO.V;
         * vel[2] = Math.Cos(pi * bO.angle / 180) * bO.V;
         */

        t0   = Time.time;
        minZ = bO.R;

        // init trajectory and line drawing setting
        if (trajEnable)
        {
            AddTrajectory();
            line               = gameObject.GetComponent <LineRenderer>();
            line.material      = new Material(Shader.Find("Sprites/Default"));
            line.positionCount = 0;
            line.startWidth    = (float)(dS.scaleD * bP.D * 1.05); // self 1.05 times;
            //line.startWidth = (float)(cBM.bP.D * dS.scaleD * 0.1); // 1/10 of central body size;
            line.endWidth      = 0.01f;
            line.startColor    = Color.red;
            line.endColor      = Color.red;
            line.useWorldSpace = true;
        }

        Debug.Log(this.name + " size=" + tF.localScale + " pos=" + tF.position);
    }
예제 #6
0
파일: VNote.cs 프로젝트: nhaberl/PDI
        /// <summary>
        /// The method can be called to clear all current property values from the vNote.  The version is left
        /// unchanged.
        /// </summary>
        public void ClearProperties()
        {
            uid            = null;
            summary        = null;
            body           = null;
            classification = null;
            categories     = null;
            dateCreated    = null;
            lastModified   = null;

            customProps = null;
        }
예제 #7
0
        public override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(0, 25, 100);
            camera.Yaw      = 0;
            camera.Pitch    = 0;

            var filters = new BodyProperty <SubgroupCollisionFilter>();

            Simulation = Simulation.Create(BufferPool, new SubgroupFilteredCallbacks()
            {
                CollisionFilters = filters
            }, new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));
        }
예제 #8
0
        public void Init()
        {
            bufferPool = new BufferPool();
            var collider = new BodyProperty <Collider>();

            simulation = Simulation.Create(bufferPool, new CarCallbacks {
                Collider = collider
            }, new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)));

            Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0f, 0f, 0f), new CollidableDescription(Simulation.Shapes.Add(new Box(30, 1, 30)), 0.04f)));
            threadDispatcher = new SimpleThreadDispatcher(Environment.ProcessorCount);
            (new Thread(PoolThread)).Start();
        }
예제 #9
0
        private static PropertyDeclarationSyntax CreateBodyProperty(BodyProperty property)
        {
            var propertyDeclaration = PropertyDeclaration(
                TypeGenerator.Create(property.Type), Identifier(property.Name))
                                      .AddAccessorListAccessors(CreateAccessDeclaration(SyntaxKind.GetAccessorDeclaration, property.GetBody, property.GetModifiers));

            if (property.SetBody != null)
            {
                propertyDeclaration =
                    propertyDeclaration.AddAccessorListAccessors(CreateAccessDeclaration(SyntaxKind.SetAccessorDeclaration, property.SetBody, property.SetModifiers));
            }

            return(propertyDeclaration);
        }
예제 #10
0
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(0, 9, -40);
            camera.Yaw      = MathHelper.Pi;
            camera.Pitch    = 0;
            var filters = new BodyProperty <SubgroupCollisionFilter>();

            Simulation = Simulation.Create(BufferPool, new SubgroupFilteredCallbacks {
                CollisionFilters = filters
            }, new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            int ragdollIndex = 0;
            var spacing      = new Vector3(1.7f, 1.8f, 0.5f);
            int width        = 4;
            int height       = 4;
            int length       = 44;
            var origin       = -0.5f * spacing * new Vector3(width - 1, 0, length - 1) + new Vector3(0, 5f, 0);

            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    for (int k = 0; k < length; ++k)
                    {
                        RagdollDemo.AddRagdoll(origin + spacing * new Vector3(i, j, k), Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), MathHelper.Pi * 0.05f), ragdollIndex++, filters, Simulation);
                    }
                }
            }

            var         tubeCenter      = new Vector3(0, 8, 0);
            const int   panelCount      = 20;
            const float tubeRadius      = 6;
            var         panelShape      = new Box((float)Math.PI * 2 * tubeRadius / panelCount, 1, 80);
            var         panelShapeIndex = Simulation.Shapes.Add(panelShape);
            var         builder         = new CompoundBuilder(BufferPool, Simulation.Shapes, panelCount + 1);

            for (int i = 0; i < panelCount; ++i)
            {
                var rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, i * MathHelper.TwoPi / panelCount);
                Quaternion.TransformUnitY(rotation, out var localUp);
                var position = localUp * tubeRadius;
                builder.AddForKinematic(panelShapeIndex, new RigidPose(position, rotation), 1);
            }
            builder.AddForKinematic(Simulation.Shapes.Add(new Box(1, 2, panelShape.Length)), new RigidPose(new Vector3(0, tubeRadius - 1, 0)), 0);
            builder.BuildKinematicCompound(out var children);
            var compound = new BigCompound(children, Simulation.Shapes, BufferPool);

            Simulation.Bodies.Add(BodyDescription.CreateKinematic(tubeCenter, new BodyVelocity(default, new Vector3(0, 0, .25f)), new CollidableDescription(Simulation.Shapes.Add(compound), 0.1f), new BodyActivityDescription()));
예제 #11
0
파일: VNote.cs 프로젝트: nhaberl/PDI
        /// <summary>
        /// This is overridden to allow copying of the additional properties
        /// </summary>
        /// <param name="p">The PDI object from which the settings are to be copied</param>
        protected override void Clone(PDIObject p)
        {
            VNote o = (VNote)p;

            this.ClearProperties();

            dateCreated    = (DateCreatedProperty)o.DateCreated.Clone();
            lastModified   = (LastModifiedProperty)o.LastModified.Clone();
            summary        = (SummaryProperty)o.Summary.Clone();
            body           = (BodyProperty)o.Body.Clone();
            classification = (ClassificationProperty)o.Classification.Clone();
            categories     = (CategoriesProperty)o.Categories.Clone();
            uid            = (UniqueIdProperty)o.UniqueId.Clone();

            this.CustomProperties.CloneRange(o.CustomProperties);
        }
예제 #12
0
        public WalkerDemo()
        {
            var masks     = new BodyProperty <ulong>();
            var callbacks = new Demos.Demos.RagdollCallbacks {
                Masks = masks
            };

            Simulation = Simulation.Create(BufferPool, callbacks);
            Simulation.PoseIntegrator.Gravity = new Vector3(0, -9.8f, 0);

            FixedTimeScale = 1; // TODO: Statistics doesn't work without this because ElapsedMilliseconds is only computed then

            Objects.Add(new World());
            Objects.Add(new Quadruped());
            Objects.Add(new DemoEngine.Objects.Controls());
            Objects.Add(new DemoEngine.Objects.Statistics(this));
        }
예제 #13
0
파일: Bepu.cs 프로젝트: parapoohda/testBepu
        internal void Initialize(ContentArchive content, Camera camera)
        {
            ThreadDispatcher = new SimpleThreadDispatcher(Environment.ProcessorCount);
            BufferPool       = new BufferPool();
            camera.Position  = new Vector3(20, 10, 20);
            camera.Yaw       = MathF.PI;
            camera.Pitch     = 0;
            characterCTs     = new CharacterControllers(BufferPool);

            var collider = new BodyProperty <Collider>();

            Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characterCTs), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));
            //Simulation = Simulation.Create(BufferPool, new MolCallbacks { Collider = collider, Characters= characterCTs }, new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)));
            CreateCharacter(characterCTs, new Vector3(0, 2, -4), 1);
            CreateCharacter(characterCTs, new Vector3(0, 3, -2), 2);
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(200, 1, 200)), 0.1f)));
        }
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(20, 10, 20);
            camera.Yaw      = MathF.PI;
            camera.Pitch    = 0;
            bufferPool      = new BufferPool();
            var collider = new BodyProperty <Collider>();

            //characters = new CharacterControllers(BufferPool);
            characs = new CharacterControllers(BufferPool);
            //Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));
            Simulation = Simulation.Create(BufferPool, new MolCallbacks(characs, collider), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)));
            character  = new PlayerCharacter(1, 1, "noname", 1, this, new Vector3(0f, 3f, 0f));
            AddPlayerCharacter(character);
            //Prevent the character from falling into the void.
            //Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(200, 1, 200)), 0.1f)));
            Simulation.Statics.Add(new StaticDescription(new System.Numerics.Vector3(0, -2f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(200, 1, 200)), 0.4f)));
        }
예제 #15
0
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(-5f, 5.5f, 5f);
            camera.Yaw      = MathHelper.Pi / 4;
            camera.Pitch    = MathHelper.Pi * 0.15f;

            var filters = new BodyProperty <DeformableCollisionFilter>();

            Simulation = Simulation.Create(BufferPool, new DeformableCallbacks {
                Filters = filters
            }, new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            var   meshContent = content.Load <MeshContent>("Content\\newt.obj");
            float cellSize    = 0.1f;

            DumbTetrahedralizer.Tetrahedralize(meshContent.Triangles, cellSize, BufferPool,
                                               out var vertices, out var vertexSpatialIndices, out var cellVertexIndices, out var tetrahedraVertexIndices);
            var weldSpringiness   = new SpringSettings(30f, 0);
            var volumeSpringiness = new SpringSettings(30f, 1);

            for (int i = 0; i < 5; ++i)
            {
                NewtDemo.CreateDeformable(Simulation, new Vector3(i * 3, 5 + i * 1.5f, 0), Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathF.PI * (i * 0.55f)), 1f, cellSize, weldSpringiness, volumeSpringiness, i, filters, ref vertices, ref vertexSpatialIndices, ref cellVertexIndices, ref tetrahedraVertexIndices);
            }

            BufferPool.Return(ref vertices);
            vertexSpatialIndices.Dispose(BufferPool);
            BufferPool.Return(ref cellVertexIndices);
            BufferPool.Return(ref tetrahedraVertexIndices);

            Simulation.Bodies.Add(BodyDescription.CreateConvexDynamic(new Vector3(0, 100, -.5f), 10, Simulation.Shapes, new Sphere(5)));

            Simulation.Statics.Add(new StaticDescription(new Vector3(0, -0.5f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(1500, 1, 1500)), 0.1f)));
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, -1.5f, 0), new CollidableDescription(Simulation.Shapes.Add(new Sphere(3)), 0.1f)));

            var bulletShape = new Sphere(0.5f);

            bulletShape.ComputeInertia(.25f, out var bulletInertia);
            bulletDescription = BodyDescription.CreateDynamic(RigidPose.Identity, bulletInertia, new CollidableDescription(Simulation.Shapes.Add(bulletShape), 1f), new BodyActivityDescription(0.01f));

            DemoMeshHelper.LoadModel(content, BufferPool, "Content\\newt.obj", new Vector3(20), out var mesh);
            Simulation.Statics.Add(new StaticDescription(new Vector3(200, 0.5f, 120), Quaternion.CreateFromAxisAngle(Vector3.UnitY, -3 * MathHelper.PiOver4), new CollidableDescription(Simulation.Shapes.Add(mesh), 0.1f)));
        }
예제 #16
0
        private void CreateFloors()
        {
            var floorShape      = new Box(200, 1, 10);
            var floorShapeIndex = Simulation.Shapes.Add(floorShape);

            var position = new Vector3(0, -0.5f, -NumberOfFloors * floorShape.HalfLength);

            _floorReferences = new List <BodyReference>(NumberOfFloors);
            var offset = new Vector3(0, 0, floorShape.Length);

            for (var i = 0; i < NumberOfFloors; i++)
            {
                var floorIndex = CreateFloor(position, floorShapeIndex);
                position += offset;
                var     floorReference      = new BodyReference(floorIndex, Simulation.Bodies);
                ref var floorBodyProperties = ref _bodyProperties.Allocate(floorIndex);

                var floorCollisionGroup = new CollisionGroup(0b1);
                floorBodyProperties = new BodyProperty {
                    Filter = floorCollisionGroup, Friction = 1f
                };
                _floorReferences.Add(floorReference);
            }
예제 #17
0
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(-32f, 20.5f, 61f);
            camera.Yaw      = MathHelper.Pi * 0.3f;
            camera.Pitch    = MathHelper.Pi * -0.05f;

            filters    = new BodyProperty <SubgroupCollisionFilter>(BufferPool);
            Simulation = Simulation.Create(BufferPool, new SubgroupFilteredCallbacks()
            {
                CollisionFilters = filters
            }, new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            Simulation.Statics.Add(new StaticDescription(new Vector3(0, -0.5f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(1500, 1, 1500)), 0.1f)));
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 10, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(70, 20, 80)), 0.1f)));
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 7.5f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(80, 15, 90)), 0.1f)));
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 5, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(90, 10, 100)), 0.1f)));
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 2.5f, 0), new CollidableDescription(Simulation.Shapes.Add(new Box(100, 5, 110)), 0.1f)));

            //High fidelity simulation isn't super important on this one.
            Simulation.Solver.IterationCount = 2;

            DemoMeshHelper.LoadModel(content, BufferPool, "Content\\newt.obj", new Vector3(30), out var mesh);
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 20, 0), Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0), new CollidableDescription(Simulation.Shapes.Add(mesh), 0.1f)));
        }
예제 #18
0
 set => SetValue(BodyProperty, value);
예제 #19
0
 public void Update(Simulation simulation, BodyProperty <TankDemoBodyProperties> bodyProperties, Random random, long frameIndex, in Vector2 playAreaMin, in Vector2 playAreaMax, int aiIndex, ref QuickList <AITank> aiTanks, ref int projectileCount)
        public unsafe override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(20, 10, 20);
            camera.Yaw      = MathF.PI;
            camera.Pitch    = 0;
            var masks = new BodyProperty <ulong>();

            characters = new CharacterControllers(BufferPool);
            Simulation = Simulation.Create(BufferPool, new CharacterNarrowphaseCallbacks(characters), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            CreateCharacter(new Vector3(0, 2, -4));

            //Create a bunch of legos to hurt your feet on.
            var random  = new Random(5);
            var origin  = new Vector3(-3f, 0.5f, 0);
            var spacing = new Vector3(0.5f, 0, -0.5f);

            for (int i = 0; i < 12; ++i)
            {
                for (int j = 0; j < 12; ++j)
                {
                    var position    = origin + new Vector3(i, 0, j) * spacing;
                    var orientation = Quaternion.CreateFromAxisAngle(Vector3.Normalize(new Vector3(0.0001f) + new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())), 10 * (float)random.NextDouble());
                    var shape       = new Box(0.1f + 0.3f * (float)random.NextDouble(), 0.1f + 0.3f * (float)random.NextDouble(), 0.1f + 0.3f * (float)random.NextDouble());
                    var collidable  = new CollidableDescription(Simulation.Shapes.Add(shape), 0.1f);
                    shape.ComputeInertia(1, out var inertia);
                    var choice = (i + j) % 3;
                    switch (choice)
                    {
                    case 0:
                        Simulation.Bodies.Add(BodyDescription.CreateDynamic(new RigidPose(position, orientation), inertia, collidable, new BodyActivityDescription(0.01f)));
                        break;

                    case 1:
                        Simulation.Bodies.Add(BodyDescription.CreateKinematic(new RigidPose(position, orientation), collidable, new BodyActivityDescription(0.01f)));
                        break;

                    case 2:
                        Simulation.Statics.Add(new StaticDescription(position, orientation, collidable));
                        break;
                    }
                }
            }

            //Add some spinning fans to get slapped by.
            var bladeDescription     = BodyDescription.CreateConvexDynamic(new Vector3(), 3, Simulation.Shapes, new Box(10, 0.2f, 2));
            var bladeBaseDescription = BodyDescription.CreateConvexKinematic(new Vector3(), Simulation.Shapes, new Box(0.2f, 1, 0.2f));

            for (int i = 0; i < 3; ++i)
            {
                bladeBaseDescription.Pose.Position = new Vector3(-22, 1, i * 11);
                bladeDescription.Pose.Position     = new Vector3(-22, 1.7f, i * 11);
                var baseHandle  = Simulation.Bodies.Add(bladeBaseDescription);
                var bladeHandle = Simulation.Bodies.Add(bladeDescription);
                Simulation.Solver.Add(baseHandle, bladeHandle,
                                      new Hinge
                {
                    LocalHingeAxisA = Vector3.UnitY,
                    LocalHingeAxisB = Vector3.UnitY,
                    LocalOffsetA    = new Vector3(0, 0.7f, 0),
                    LocalOffsetB    = new Vector3(0, 0, 0),
                    SpringSettings  = new SpringSettings(30, 1)
                });
                Simulation.Solver.Add(baseHandle, bladeHandle,
                                      new AngularAxisMotor
                {
                    LocalAxisA     = Vector3.UnitY,
                    TargetVelocity = (i + 1) * (i + 1) * (i + 1) * (i + 1) * 0.2f,
                    Settings       = new MotorSettings(5 * (i + 1), 0.0001f)
                });
            }

            //Include a giant newt to test character-newt behavior and to ensure thematic consistency.
            MeshDemo.LoadModel(content, BufferPool, @"Content\newt.obj", new Vector3(15, 15, 15), out var newtMesh);
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0.5f, 0), new CollidableDescription(Simulation.Shapes.Add(newtMesh), 0.1f)));

            //Give the newt a tongue, I guess.
            var tongueBase = Simulation.Bodies.Add(BodyDescription.CreateKinematic(new Vector3(0, 8.4f, 24), default, default));
 public MolCallbacks(CharacterControllers characters, BodyProperty <Collider> Collider)
 {
     this.Characters = characters;
     this.Collider   = Collider;
 }
예제 #22
0
        public override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(0, 5, 10);
            camera.Yaw      = 0;
            camera.Pitch    = 0;

            var properties = new BodyProperty <CarBodyProperties>();

            Simulation = Simulation.Create(BufferPool, new CarCallbacks()
            {
                Properties = properties
            }, new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            var builder = new CompoundBuilder(BufferPool, Simulation.Shapes, 2);

            builder.Add(new Box(1.85f, 0.7f, 4.73f), RigidPose.Identity, 10);
            builder.Add(new Box(1.85f, 0.6f, 2.5f), new RigidPose(new Vector3(0, 0.65f, -0.35f)), 0.5f);
            builder.BuildDynamicCompound(out var children, out var bodyInertia, out _);
            builder.Dispose();
            var bodyShape      = new Compound(children);
            var bodyShapeIndex = Simulation.Shapes.Add(bodyShape);
            var wheelShape     = new Cylinder(0.4f, .18f);

            wheelShape.ComputeInertia(0.25f, out var wheelInertia);
            var wheelShapeIndex = Simulation.Shapes.Add(wheelShape);

            const float x      = 0.9f;
            const float y      = -0.1f;
            const float frontZ = 1.7f;
            const float backZ  = -1.7f;

            playerController = new SimpleCarController(SimpleCar.Create(Simulation, properties, new RigidPose(new Vector3(0, 10, 0), Quaternion.Identity), bodyShapeIndex, bodyInertia, 0.5f, wheelShapeIndex, wheelInertia, 2f,
                                                                        new Vector3(-x, y, frontZ), new Vector3(x, y, frontZ), new Vector3(-x, y, backZ), new Vector3(x, y, backZ), new Vector3(0, -1, 0), 0.25f,
                                                                        new SpringSettings(5f, 0.7f), Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathF.PI * 0.5f)),
                                                       forwardSpeed: 75, forwardForce: 6, zoomMultiplier: 2, backwardSpeed: 30, backwardForce: 4, idleForce: 0.25f, brakeForce: 7, steeringSpeed: 1.5f, maximumSteeringAngle: MathF.PI * 0.23f);

            //Create a bunch of AI cars to race against.
            const int aiCount = 384;

            BufferPool.Take(aiCount, out aiControllers);


            const int   planeWidth      = 257;
            const float scale           = 3;
            Vector2     terrainPosition = new Vector2(1 - planeWidth, 1 - planeWidth) * scale * 0.5f;

            raceTrack = new RaceTrack {
                QuadrantRadius = (planeWidth - 32) * scale * 0.25f, Center = default
            };
            var random = new Random(5);

            //Add some building-ish landmarks in the middle of each of the four racetrack quadrants.
            for (int i = 0; i < 4; ++i)
            {
                var landmarkCenter = new Vector3((i & 1) * raceTrack.QuadrantRadius * 2 - raceTrack.QuadrantRadius, -20, (i & 2) * raceTrack.QuadrantRadius - raceTrack.QuadrantRadius);
                var landmarkMin    = landmarkCenter - new Vector3(raceTrack.QuadrantRadius * 0.5f, 0, raceTrack.QuadrantRadius * 0.5f);
                var landmarkSpan   = new Vector3(raceTrack.QuadrantRadius, 0, raceTrack.QuadrantRadius);
                for (int j = 0; j < 25; ++j)
                {
                    var buildingShape = new Box(10 + (float)random.NextDouble() * 10, 20 + (float)random.NextDouble() * 20, 10 + (float)random.NextDouble() * 10);
                    Simulation.Statics.Add(new StaticDescription(
                                               new Vector3(0, buildingShape.HalfHeight, 0) + landmarkMin + landmarkSpan * new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()),
                                               Quaternion.CreateFromAxisAngle(Vector3.UnitY, (float)random.NextDouble() * MathF.PI),
                                               new CollidableDescription(Simulation.Shapes.Add(buildingShape), 0.1f)));
                }
            }

            Vector3 min  = new Vector3(-planeWidth * scale * 0.45f, 10, -planeWidth * scale * 0.45f);
            Vector3 span = new Vector3(planeWidth * scale * 0.9f, 15, planeWidth * scale * 0.9f);

            for (int i = 0; i < aiCount; ++i)
            {
                //The AI cars are very similar, except... we handicap them a little to make the player good about themselves.
                var position    = min + span * new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
                var orientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)random.NextDouble() * MathF.PI * 2);
                aiControllers[i].Controller = new SimpleCarController(SimpleCar.Create(Simulation, properties, new RigidPose(position, orientation), bodyShapeIndex, bodyInertia, 0.5f, wheelShapeIndex, wheelInertia, 2f,
                                                                                       new Vector3(-x, y, frontZ), new Vector3(x, y, frontZ), new Vector3(-x, y, backZ), new Vector3(x, y, backZ), new Vector3(0, -1, 0), 0.25f,
                                                                                       new SpringSettings(5, 0.7f), Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathF.PI * 0.5f)),
                                                                      forwardSpeed: 50, forwardForce: 5, zoomMultiplier: 2, backwardSpeed: 10, backwardForce: 4, idleForce: 0.25f, brakeForce: 7, steeringSpeed: 1.5f, maximumSteeringAngle: MathF.PI * 0.23f);
                aiControllers[i].LaneOffset = (float)random.NextDouble() * 20 - 10;
            }


            DemoMeshHelper.CreateDeformedPlane(planeWidth, planeWidth,
                                               (int vX, int vY) =>
            {
                var octave0         = (MathF.Sin((vX + 5f) * 0.05f) + MathF.Sin((vY + 11) * 0.05f)) * 1.8f;
                var octave1         = (MathF.Sin((vX + 17) * 0.15f) + MathF.Sin((vY + 19) * 0.15f)) * 0.9f;
                var octave2         = (MathF.Sin((vX + 37) * 0.35f) + MathF.Sin((vY + 93) * 0.35f)) * 0.4f;
                var octave3         = (MathF.Sin((vX + 53) * 0.65f) + MathF.Sin((vY + 47) * 0.65f)) * 0.2f;
                var octave4         = (MathF.Sin((vX + 67) * 1.50f) + MathF.Sin((vY + 13) * 1.5f)) * 0.125f;
                var distanceToEdge  = planeWidth / 2 - Math.Max(Math.Abs(vX - planeWidth / 2), Math.Abs(vY - planeWidth / 2));
                var edgeRamp        = 25f / (distanceToEdge + 1);
                var terrainHeight   = octave0 + octave1 + octave2 + octave3 + octave4;
                var vertexPosition  = new Vector2(vX * scale, vY * scale) + terrainPosition;
                var distanceToTrack = raceTrack.GetDistance(vertexPosition);
                var trackWeight     = MathF.Min(1f, 3f / (distanceToTrack * 0.1f + 1f));
                var height          = trackWeight * -10f + terrainHeight * (1 - trackWeight);
                return(new Vector3(vertexPosition.X, height + edgeRamp, vertexPosition.Y));
            }, new Vector3(1, 1, 1), BufferPool, out var planeMesh);
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, -15, 0), Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), MathF.PI / 2),
                                                         new CollidableDescription(Simulation.Shapes.Add(planeMesh), 0.1f)));
        }
예제 #23
0
        public override void Initialize(ContentArchive content, Camera camera)
        {
            camera.Position = new Vector3(0, 5, 10);
            camera.Yaw      = 0;
            camera.Pitch    = 0;

            bodyProperties = new BodyProperty <TankDemoBodyProperties>();
            Simulation     = Simulation.Create(BufferPool, new TankCallbacks()
            {
                Properties = bodyProperties
            }, new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)));

            var builder = new CompoundBuilder(BufferPool, Simulation.Shapes, 2);

            builder.Add(new Box(1.85f, 0.7f, 4.73f), RigidPose.Identity, 10);
            builder.Add(new Box(1.85f, 0.6f, 2.5f), new RigidPose(new Vector3(0, 0.65f, -0.35f)), 0.5f);
            builder.BuildDynamicCompound(out var children, out var bodyInertia, out _);
            builder.Dispose();
            var bodyShape      = new Compound(children);
            var bodyShapeIndex = Simulation.Shapes.Add(bodyShape);
            var wheelShape     = new Cylinder(0.4f, .18f);

            wheelShape.ComputeInertia(0.25f, out var wheelInertia);
            var wheelShapeIndex = Simulation.Shapes.Add(wheelShape);

            var projectileShape = new Sphere(0.1f);

            projectileShape.ComputeInertia(0.2f, out var projectileInertia);
            var tankDescription = new TankDescription
            {
                Body         = TankPartDescription.Create(10, new Box(4f, 1, 5), RigidPose.Identity, 0.5f, Simulation.Shapes),
                Turret       = TankPartDescription.Create(1, new Box(1.5f, 0.7f, 2f), new RigidPose(new Vector3(0, 0.85f, 0.4f)), 0.5f, Simulation.Shapes),
                Barrel       = TankPartDescription.Create(0.5f, new Box(0.2f, 0.2f, 3f), new RigidPose(new Vector3(0, 0.85f, 0.4f - 1f - 1.5f)), 0.5f, Simulation.Shapes),
                TurretAnchor = new Vector3(0f, 0.5f, 0.4f),
                BarrelAnchor = new Vector3(0, 0.5f + 0.35f, 0.4f - 1f),
                TurretBasis  = Quaternion.Identity,
                TurretServo  = new ServoSettings(1f, 0f, 40f),
                TurretSpring = new SpringSettings(10f, 1f),
                BarrelServo  = new ServoSettings(1f, 0f, 40f),
                BarrelSpring = new SpringSettings(10f, 1f),

                ProjectileShape            = Simulation.Shapes.Add(projectileShape),
                ProjectileSpeed            = 100f,
                BarrelLocalProjectileSpawn = new Vector3(0, 0, -1.5f),
                ProjectileInertia          = projectileInertia,

                LeftTreadOffset    = new Vector3(-1.9f, 0f, 0),
                RightTreadOffset   = new Vector3(1.9f, 0f, 0),
                SuspensionLength   = 1f,
                SuspensionSettings = new SpringSettings(2.5f, 1.5f),
                WheelShape         = wheelShapeIndex,
                WheelInertia       = wheelInertia,
                WheelFriction      = 2f,
                TreadSpacing       = 1f,
                WheelCountPerTread = 5,
                WheelOrientation   = QuaternionEx.CreateFromAxisAngle(Vector3.UnitZ, MathF.PI * -0.5f),
            };

            playerController = new TankController(Tank.Create(Simulation, bodyProperties, BufferPool, new RigidPose(new Vector3(0, 10, 0), Quaternion.Identity), tankDescription), 20, 5, 2, 1, 3.5f);


            const int   planeWidth          = 257;
            const float terrainScale        = 3;
            const float inverseTerrainScale = 1f / terrainScale;
            var         terrainPosition     = new Vector2(1 - planeWidth, 1 - planeWidth) * terrainScale * 0.5f;

            random = new Random(5);

            //Add some building-ish landmarks.
            var landmarkMin  = new Vector3(planeWidth * terrainScale * -0.45f, 0, planeWidth * terrainScale * -0.45f);
            var landmarkMax  = new Vector3(planeWidth * terrainScale * 0.45f, 0, planeWidth * terrainScale * 0.45f);
            var landmarkSpan = landmarkMax - landmarkMin;

            for (int j = 0; j < 25; ++j)
            {
                var buildingShape = new Box(10 + (float)random.NextDouble() * 10, 20 + (float)random.NextDouble() * 20, 10 + (float)random.NextDouble() * 10);
                var position      = landmarkMin + landmarkSpan * new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
                Simulation.Statics.Add(new StaticDescription(
                                           new Vector3(0, buildingShape.HalfHeight - 4f + GetHeightForPosition(position.X, position.Z, planeWidth, inverseTerrainScale, terrainPosition), 0) + position,
                                           QuaternionEx.CreateFromAxisAngle(Vector3.UnitY, (float)random.NextDouble() * MathF.PI),
                                           new CollidableDescription(Simulation.Shapes.Add(buildingShape), 0.1f)));
            }

            DemoMeshHelper.CreateDeformedPlane(planeWidth, planeWidth,
                                               (int vX, int vY) =>
            {
                var position2D = new Vector2(vX, vY) * terrainScale + terrainPosition;
                return(new Vector3(position2D.X, GetHeightForPosition(position2D.X, position2D.Y, planeWidth, inverseTerrainScale, terrainPosition), position2D.Y));
            }, new Vector3(1, 1, 1), BufferPool, out var planeMesh);
            Simulation.Statics.Add(new StaticDescription(new Vector3(0, 0, 0),
                                                         new CollidableDescription(Simulation.Shapes.Add(planeMesh), 0.1f)));

            explosions = new QuickList <Explosion>(32, BufferPool);

            //Create the AI tanks.
            const int aiTankCount = 100;

            aiTanks     = new QuickList <AITank>(aiTankCount, BufferPool);
            playAreaMin = new Vector2(landmarkMin.X, landmarkMin.Z);
            playAreaMax = new Vector2(landmarkMax.X, landmarkMax.Z);
            var playAreaSpan = playAreaMax - playAreaMin;

            for (int i = 0; i < aiTankCount; ++i)
            {
                var horizontalPosition = playAreaMin + new Vector2((float)random.NextDouble(), (float)random.NextDouble()) * playAreaSpan;
                aiTanks.AllocateUnsafely() = new AITank
                {
                    Controller = new TankController(
                        Tank.Create(Simulation, bodyProperties, BufferPool, new RigidPose(
                                        new Vector3(horizontalPosition.X, 10, horizontalPosition.Y),
                                        QuaternionEx.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)random.NextDouble() * 0.1f)),
                                    tankDescription), 20, 5, 2, 1, 3.5f),
                    HitPoints = 5
                };
            }
        }
예제 #24
0
        //=====================================================================

        /// <summary>
        /// This is overridden to allow cloning of a PDI object
        /// </summary>
        /// <returns>A clone of the object</returns>
        public override object Clone()
        {
            BodyProperty o = new BodyProperty();
            o.Clone(this);
            return o;
        }
예제 #25
0
 get => (View)GetValue(BodyProperty); set => SetValue(BodyProperty, value);