Exemplo n.º 1
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;
                    }
                }
            }
        }