Пример #1
0
    public override void PostSceneInsertionSetup()
    {
        if (wheels.Count > 0)
        {
            IntPtr   wheelSimData   = PhysXLib.CreateWheelSimData(wheels.Count);
            IntPtr[] suspensions    = new IntPtr[wheels.Count];
            IntPtr   wheelPositions = PhysXLib.CreateVectorArray();

            for (int i = 0; i < wheels.Count; i++)
            {
                suspensions[i] = wheels[i].SetupInitialProperties();
                PhysXLib.AddVectorToArray(wheelPositions, new PhysXVec3(transform.InverseTransformPoint(wheels[i].worldWheelCentre)));
            }

            PhysXLib.SetSuspensionSprungMasses(suspensions, wheels.Count, wheelPositions, new PhysXVec3(Vector3.zero), mass);

            for (int i = 0; i < wheels.Count; i++)
            {
                //Debug.Log(vehicleId);
                wheels[i].SetupSimData(this, wheelSimData, i, vehicleId);
            }

            vehicle = PhysXLib.CreateVehicleFromRigidBody(physXBody, wheelSimData);

            for (int i = 0; i < wheels.Count; i++)
            {
                wheels[i].SetVehicle(vehicle);
            }
        }

        physXCOMPosition.FromVector(centreOfMass);
        // PhysXVec3 position = new PhysXVec3(centreOfMass);
        // PhysXQuat rotation = new PhysXQuat(Quaternion.identity);

        IntPtr oldCentre = PhysXLib.GetCentreOfMass(physXBody);

        IntPtr newCentre = PhysXLib.CreateTransform(physXCOMPosition, physXCOMRotation);

        PhysXLib.SetRigidBodyMassPose(physXBody, newCentre);

        if (vehicle != IntPtr.Zero)
        {
            PhysXLib.UpdateVehicleCentreOfMass(oldCentre, newCentre, vehicle);
        }

        if (GetComponentInChildren <CollisionSoftener>() != null)
        {
            Debug.Log("made ghost body");
            ghostBody     = PhysXLib.CreateGhostRigidBody(physXBody, ghostBlend);
            _ghostEnabled = true;
        }
    }
Пример #2
0
    public virtual void Setup()
    {
        physXPosition.FromVector(transform.position);
        physXRotation.FromQuaternion(transform.rotation);
        IntPtr physXTransform = PhysXLib.CreateTransform(physXPosition, physXRotation);

        _position = transform.position;
        _rotation = transform.rotation;
        physXBody = PhysXLib.CreateStaticRigidBody(physXTransform);

        PhysXCollider[] colliders = GetComponentsInChildren <PhysXCollider>(true);

        foreach (PhysXCollider collider in colliders)
        {
            collider.Setup(this, 0);
        }
    }
Пример #3
0
    public override void Setup()
    {
        physXPosition.FromVector(transform.position);
        physXRotation.FromQuaternion(transform.rotation);
        IntPtr physXTransform = PhysXLib.CreateTransform(physXPosition, physXRotation);

        _position = transform.position;
        _rotation = transform.rotation;
        physXBody = PhysXLib.CreateDynamicRigidBody(physXTransform);

        // PhysXLib.RegisterCollisionEnterCallback(ProcessCollisionEnterEvents, physXDynamicRigidBody);
        // PhysXLib.RegisterCollisionStayCallback(ProcessCollisionStayEvents, physXDynamicRigidBody);
        // PhysXLib.RegisterCollisionExitCallback(ProcessCollisionExitEvents, physXDynamicRigidBody);

        PhysXLib.SetRigidBodyFlag(physXBody, PhysXLib.PhysXRigidBodyFlag.eKINEMATIC, kinematic);
        if (kinematic)
        {
            PhysXLib.SetRigidBodyDominanceGroup(physXBody, 1);
        }

        PhysXLib.SetRigidBodyMaxDepenetrationVelocity(physXBody, Physics.defaultMaxDepenetrationVelocity);
        PhysXLib.SetRigidBodyMaxLinearVelocity(physXBody, maxVelocity);

        wheels = new List <PhysXWheelCollider>(GetComponentsInChildren <PhysXWheelCollider>(true));
        PhysXCollider[] colliders = GetComponentsInChildren <PhysXCollider>(true);

        if (wheels.Count > 0)
        {
            vehicleId = currentVehicleId;
            currentVehicleId++;
        }

        foreach (PhysXCollider collider in colliders)
        {
            collider.Setup(this, vehicleId);
        }
        //Debug.Log(vehicleId);

        PhysXLib.SetRigidBodyMassAndInertia(physXBody, mass, new PhysXVec3(Vector3.zero));
        PhysXLib.SetRigidBodyDamping(physXBody, linearDamping, angularDamping);
    }
Пример #4
0
    // Start is called before the first frame update
    public virtual void Setup(PhysXBody attachedRigidBody, uint vehicleId)
    {
        this.attachedRigidBody = attachedRigidBody as PhysXRigidBody;
        Transform bodyParent = attachedRigidBody.transform;

        PhysXVec3 position = new PhysXVec3(bodyParent.InverseTransformPoint(transform.TransformPoint(offset)));
        PhysXQuat rotation = new PhysXQuat(transform.rotation * Quaternion.Inverse(bodyParent.rotation));

        IntPtr localTransform = PhysXLib.CreateTransform(position, rotation);

        PhysXLib.SetShapeLocalTransform(shape, localTransform);

        PhysXLib.SetShapeSimulationFlag(shape, !trigger);
        PhysXLib.SetShapeSceneQueryFlag(shape, !trigger);
        PhysXLib.SetShapeTriggerFlag(shape, trigger);

        PhysXLib.CollisionEvent collisionEventFlags = attachedRigidBody.collisionEventFlags;
        PhysXLib.SetCollisionFilterData(shape, (UInt32)ownLayers, (UInt32)collisionLayers, (UInt32)collisionEventFlags, vehicleId);
        PhysXLib.SetQueryFilterData(shape, (UInt32)ownLayers, 0, 0, vehicleId);
        shapeNum = attachedRigidBody.AddCollider(this);
    }