Пример #1
0
        public void GetWheelTransform(int unitIndex, int axleIndex, int axleSide, ref Vector3 position, ref Quaternion rotation)
        {
            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    double forward = 0;
                    double left    = 0;
                    double up      = 0;

                    double rollRightRad = 0;
                    double pitchDownRad = 0;
                    double yawLeftRad   = 0;



                    VS_Vehicle.GetTireWorldPosition(VsVehicleHandle, unitIndex, axleIndex, axleSide, ref forward, ref left, ref up);
                    VS_Vehicle.GetTireWorldOrientation(VsVehicleHandle, unitIndex, axleIndex, axleSide, ref rollRightRad, ref pitchDownRad, ref yawLeftRad);

                    position = VsUnityLib.VSToUnityVector(forward, left, up);
                    rotation = VsUnityLib.VSToUnityRotation(rollRightRad, pitchDownRad, yawLeftRad);

                    //Log(rollRightRad + "," + pitchDownRad + "," + yawLeftRad);
                    //CarSim_UnityLib.SetUnityTransformFromSolverValues(wheelGameObject, (float)forward, (float)left, (float)up, (float)rollRightRad, (float)pitchDownRad, (float)yawLeftRad);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Sets a import index to a variable when it is reset.
 /// </summary>
 protected override void OnResetVehicle()
 {
     _importIndex = VS_Vehicle.Import_GetOrAdd(VsVehicleSolver.VsVehicleHandle, this.Name, _value, true);
     if (_importIndex < 0)
     {
         LogError($"Unable to locate VS Solver import {Name}.");
     }
 }
Пример #3
0
        public Vector3 GetUnitWorldPosition(int unitIndex)
        {
            double forward = 0, left = 0, up = 0;

            VS_Vehicle.GetWorldPosition(VsVehicleHandle, unitIndex, ref forward, ref left, ref up);
            Vector3 worldLocation = VsUnityLib.VSToUnityVector(forward, left, up);

            return(worldLocation);
        }
Пример #4
0
        public Quaternion GetUnitWorldOrientation(int unitIndex)
        {
            double rollRightRad = 0, pitchDownRad = 0, yawLeftRad = 0;

            VS_Vehicle.GetWorldOrientation(VsVehicleHandle, unitIndex, ref rollRightRad, ref pitchDownRad, ref yawLeftRad);

            Quaternion worldRotation = VsUnityLib.VSToUnityRotation(rollRightRad, pitchDownRad, yawLeftRad);

            return(worldRotation);
        }
Пример #5
0
        private void Integrate(float delta)
        {
            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    double throttle = UserThrottle * VehicleData.MaxThrottle;
                    double brakePedalForceNewtons = UserBrake * VehicleData.MaxBrakePedalForceNewtons;
                    double steerLeftDeg           = SteeringWheelAngleLeftDeg;

                    VS_Vehicle.SetDriverThrottle(VsVehicleHandle, throttle);
                    VS_Vehicle.SetDriverBrakePedalNewtons(VsVehicleHandle, brakePedalForceNewtons);
                    VS_Vehicle.SetDriverSteerLeftDegrees(VsVehicleHandle, steerLeftDeg);

                    int integrateResult = VS_Vehicle.Integrate(VsVehicleHandle, delta);


                    if (!VS_Vehicle.IsOk(VsVehicleHandle))
                    {
                        if (this.VehicleData.AutoResetSolver)
                        {
                            VehicleSolver.ResetVsVehicle();
                        }
                    }
                    else
                    {
                        double forward = 0;
                        double left    = 0;
                        double up      = 0;

                        double rollRightRad = 0;
                        double pitchDownRad = 0;
                        double yawLeftRad   = 0;

                        VS_Vehicle.GetWorldPosition(VsVehicleHandle, 0, ref forward, ref left, ref up);
                        VS_Vehicle.GetWorldOrientation(VsVehicleHandle, 0, ref rollRightRad, ref pitchDownRad, ref yawLeftRad);

                        //Log((180/Math.PI*rollRightRad) + "," + (180 / Math.PI * pitchDownRad) + "," + (180 / Math.PI * yawLeftRad));
                        //Log(forward + "," + left + "," + up);

                        VsUnityLib.SetUnityTransformFromSolverValues(this.gameObject, (float)forward, (float)left, (float)up, (float)rollRightRad, (float)pitchDownRad, (float)yawLeftRad);

                        //Todo temporary change. more precise
                        this.transform.position += this.transform.forward * BodyOffset;
                    }
                }
            }
        }
Пример #6
0
        public void SyncVsVehicleLocOri()
        {
            var wpos = this.gameObject.transform.position;
            var wrot = this.gameObject.transform.rotation;

            double forward = 0, left = 0, up = 0;

            VsUnityLib.UnityToVSVector(wpos, ref forward, ref left, ref up);
            double roll = 0, pitch = 0, yaw = 0;

            wrot.UnityToVSRotation(ref roll, ref pitch, ref yaw);
            VS_Vehicle.SetWorldPosition(VsVehicleHandle, forward, left, up);
            VS_Vehicle.SetWorldOrientation(VsVehicleHandle, roll, pitch, yaw);
        }
Пример #7
0
        public float GetAxleOffsetForward(int unitIndex, int axleIndex)
        {
            float retOffset = 0;  // The offset of the axle in centimeters.

            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    retOffset = (float)VS_Vehicle.GetAxleOffsetForward(VsVehicleHandle, unitIndex, (ulong)axleIndex);
                }
            }
            return(retOffset);
        }
Пример #8
0
        public float GetDualTireWidth(int unitIndex, int axleIndex)
        {
            float retDualWidth = 0;

            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    retDualWidth = (float)VS_Vehicle.GetDualWidth(VsVehicleHandle, unitIndex, (ulong)axleIndex);
                }
            }

            return(retDualWidth);
        }
Пример #9
0
        public float GetAxleTrack(int unitIndex, int axleIndex)
        {
            float retTrack = 0; // The track width of the axle in centimeters.

            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    retTrack = (float)VS_Vehicle.GetAxleTrack(VsVehicleHandle, unitIndex, (ulong)axleIndex);
                }
            }

            return(retTrack);
        }
Пример #10
0
        public int GetNumAxles(int unitIndex)
        {
            int retNumAxles = 0;

            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    retNumAxles = (int)VS_Vehicle.GetNumAxles(VsVehicleHandle, unitIndex);
                }
            }

            return(retNumAxles);
        }
Пример #11
0
        public float GetWheelRotation(int unitIndex, int axleIndex, int axleSide)
        {
            float rotation = 0;

            if (IntPtr.Zero != VsVehicleHandle)
            {
                Check(VS_Vehicle.IsValidVehicle(VsVehicleHandle));

                if (VS_Vehicle.IsOk(VsVehicleHandle))
                {
                    double rotPitchForward = 0;

                    VS_Vehicle.GetTireSolverRotation(VsVehicleHandle, unitIndex, axleIndex, axleSide, ref rotPitchForward);
                    rotation = (float)rotPitchForward * 180 / Mathf.PI;
                }
            }
            return(rotation);
        }