Example #1
1
 public CarFacade()
 {
 model = new CarModel();
 engine = new CarEngine();
 body = new CarBody();
 accessories = new CarAccessories();
 }
 public CarFacade()
 {
     carModel       = new CarModel();
     carEngine      = new CarEngine();
     carBody        = new CarBody();
     carAccessories = new CarAccessories();
 }
Example #3
0
    public float HeadAngle(CarBody body)
    {
        var left = -body.transform.right;
        var head = transform.forward;

        return(Vector3.Angle(left, head));
    }
Example #4
0
        public async Task <IActionResult> PutCarBody(string id, CarBody carBody)
        {
            if (id != carBody.BodyId)
            {
                return(BadRequest());
            }

            _context.Entry(carBody).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarBodyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
    public float GetSensorDistance(CarBody body)
    {
        float      dis;
        RaycastHit hit;
        bool       hitSomething;

        Color col = Color.green;

        hitSomething = Physics.Raycast(transform.position, transform.forward, out hit, body.maxLookDistance);



        if (hitSomething)
        {
            dis = hit.distance;
            col = Color.yellow;
            if (hit.distance < body.safeDistance)
            {
                col = Color.red;
            }
        }
        else
        {
            dis = body.maxLookDistance;
        }

        Debug.DrawRay(transform.position, transform.forward * dis, col);

        return(dis);
    }
Example #6
0
        public async Task <ActionResult <CarBody> > PostCarBody(CarBody carBody)
        {
            _context.carbody.Add(carBody);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCarBody", new { id = carBody.BodyId }, carBody));
        }
Example #7
0
 public CarFacade()
 {
     _model       = new CarModel();
     _engine      = new CarEngine();
     _body        = new CarBody();
     _accessories = new CarAccessories();
 }
    private void Awake()
    {
        rb = GetComponent <Rigidbody>();
        CarAI ai = GetComponent <CarAI>();

        if (ai != null)
        {
            AIEnabled = true;
        }
        CustomizerCar cc = GetComponent <CustomizerCar>();

        if (cc != null)
        {
            customizerCar = true;
        }
        dataHolder = FindObjectOfType <CarDataHolder>();
        if (!AIEnabled)
        {
            body   = dataHolder.body;
            engine = dataHolder.engine;
            aero   = dataHolder.aero;
            tire   = dataHolder.tire;
        }
        Setup();

        defaultDownForce = downwardForce;
    }
Example #9
0
    private Vector3 CalculateCorrectionTorque()
    {
        var correctionTorque = CarBody.CalculateRequiredTorqueForRotation(castedOrientation, Time.fixedDeltaTime, maxCorrectionTorque);

        correctionTorque -= up * Vector3.Dot(correctionTorque, up);
        return(correctionTorque);
    }
Example #10
0
 public CarFacade()
 {
     model       = new CarModel();
     engine      = new CarEngine();
     body        = new CarBody();
     accessories = new CarAccessories();
 }
        public IResult Update(CarBody carBody)
        {
            var carBodyToUpdate = _carBodyDal.Get(c => c.CarBodyId == carBody.CarBodyId);

            carBodyToUpdate.CarBodyName = carBody.CarBodyName;
            _carBodyDal.Update(carBodyToUpdate);
            return(new SuccessResult());
        }
Example #12
0
    public float Scan(CarBody body)
    {
        var qe = transform.localEulerAngles;

        qe.y += body.scanRateUpdate;
        transform.localEulerAngles = qe;
        scanDistance = GetScanDistance(body);

        return(scanDistance);
    }
        public IResult Delete(CarBody carBody)
        {
            var carBodyToDelete = _carBodyDal.Get(c => c.CarBodyId == carBody.CarBodyId);

            if (carBodyToDelete.CarBodyId > 0)
            {
                return(new SuccessResult(Messages.CarBodyDeleted));
            }
            return(new ErrorResult(Messages.CarBodyNotFound));
        }
Example #14
0
    void FixedUpdate()
    {
        vehicleBounds = transform.GetTotalBounds(Space.World);

        CalculateOrientationFromSurroundings();

        if (control)
        {
            if (Input.GetKey(KeyCode.W))
            {
                gas = 1;
            }
            else if (Input.GetKey(KeyCode.S))
            {
                gas = -1;
            }
            else
            {
                gas = 0;
            }

            if (Input.GetKey(KeyCode.D))
            {
                steer = 1;
            }
            else if (Input.GetKey(KeyCode.A))
            {
                steer = -1;
            }
            else
            {
                steer = 0;
            }
        }

        float currentForwardVelocity = Vector3.Dot(CarBody.velocity, forward);

        if (gas > float.Epsilon || gas < -float.Epsilon)
        {
            CarBody.AddForce(PhysicsHelpers.CalculateRequiredForceForSpeed(CarBody.mass, currentForwardVelocity, Mathf.Clamp(currentForwardVelocity + gas * acceleration, -maxSpeed, maxSpeed)) * forward, ForceMode.Force);
        }

        float handlingMultiplier = handlingCurve.Evaluate(Mathf.Abs(currentForwardVelocity) / maxSpeed);

        if (steer > float.Epsilon || steer < -float.Epsilon)
        {
            forward = Quaternion.AngleAxis(steer * maxTurnRate * handlingMultiplier * Mathf.Sign(currentForwardVelocity), up) * forward;
        }

        ApplyFloatation();
        ApplyOrientator();

        ApplyFriction();
    }
Example #15
0
        public JsonResult CreateCarBody(CarBodyViewModel carBodyViewModel)
        {
            try
            {
                var data = Db.ModelYear.FirstOrDefault(my => my.Year == carBodyViewModel.Year && my.ModelId == carBodyViewModel.ModelId);
                if (data == null)
                {
                    data = new ModelYear
                    {
                        Year    = carBodyViewModel.Year,
                        ModelId = carBodyViewModel.ModelId
                    };
                    Db.ModelYear.Add(data);
                }

                List <object> front = new List <object>
                {
                    new { tire_width = new List <object> {
                              int.Parse(carBodyViewModel.Width)
                          }, tire_aspect_ratio = new List <object> {
                              int.Parse(carBodyViewModel.Height)
                          }, rim_diameter = new List <object> {
                              int.Parse(carBodyViewModel.Radius)
                          } }
                };
                var frontjs = new List <object> {
                    new { front = front }
                };
                var wheel = new List <object> {
                    new { wheel = frontjs }
                };
                var javaScriptSerializer = new
                                           System.Web.Script.Serialization.JavaScriptSerializer();
                string jsonWheel = javaScriptSerializer.Serialize(wheel);

                var carBody = new CarBody
                {
                    Name        = carBodyViewModel.Name,
                    ModelYearId = data.Id,
                    Wheels      = jsonWheel,
                    Description = carBodyViewModel.Description
                };
                Db.CarBody.Add(carBody);
                Db.SaveChanges();
                return(Json(new { Result = "OK", Record = carBodyViewModel }));
            }
            catch (Exception ex)
            {
                Response.StatusCode = 400;
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #16
0
        public IActionResult Update(CarBody carBody)
        {
            var result = _carBodyservice.Update(carBody);

            if (result.Success)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }
Example #17
0
        private static void Main(string[] args)
        {
            CarModel       model       = new CarModel();
            CarEngine      engine      = new CarEngine();
            CarBody        body        = new CarBody();
            CarAccessories accessories = new CarAccessories();

            Console.WriteLine("******** Creating a Car **********\n");
            model.SetModel();
            engine.SetEngine();
            body.SetBody();
            accessories.SetAccessories();

            Console.WriteLine("\n******** Car creation complete **********");
        }
Example #18
0
    private void ApplyFriction()
    {
        float currentHorVelocity         = Vector3.Dot(CarBody.velocity, right);
        float velocityFrictionMultiplier = frictionCurve.Evaluate(currentHorVelocity / maxSpeed);

        float forceToStop = PhysicsHelpers.CalculateRequiredForceForSpeed(CarBody.mass, currentHorVelocity, 0);

        CarBody.AddForce(right * forceToStop * velocityFrictionMultiplier, ForceMode.Force);

        Vector3 correctionTorque         = CarBody.CalculateRequiredTorqueForRotation(castedOrientation, Time.fixedDeltaTime, maxCorrectionTorque);
        float   maxTorque                = 20;
        float   correctionTorqueAmount   = Vector3.Dot(correctionTorque, up);
        float   torqueFrictionMultiplier = frictionCurve.Evaluate(correctionTorqueAmount / maxTorque);

        CarBody.AddTorque(up * correctionTorqueAmount, ForceMode.Force);
    }
Example #19
0
        /// <summary>
        /// Получить кузов.
        /// </summary>
        /// <returns>Кузов.</returns>
        public override BodyMachineBase GetBody()
        {
            var carBody = new CarBody();

            LifePoints     += carBody.LifePoints + _koef;
            ArmorPoints    += carBody.ArmorPoints + _koef;
            MaxArmorPoints += carBody.MaxArmorPoints + _koef;
            MaxLifePoints  += carBody.MaxLifePoints + _koef;

            if (ArmorResistance == 0)
            {
                ArmorResistance += carBody.ArmorResistance;
            }
            else
            {
                ArmorResistance = (ArmorResistance + carBody.ArmorResistance) / 2;
            }

            return(carBody);
        }
Example #20
0
    private Vector3 CalculateFloatingForce()
    {
        float vehicleSizeOnUpAxis = Mathf.Abs(Vector3.Dot(vehicleBounds.extents, up));

        float      groundCastDistance = vehicleSizeOnUpAxis + minGroundDistance * 5;
        RaycastHit hitInfo;
        float      groundDistance = float.MaxValue;
        bool       rayHitGround   = Physics.Raycast(vehicleBounds.center, -up, out hitInfo, groundCastDistance, groundMask);

        if (rayHitGround)
        {
            groundDistance = hitInfo.distance - vehicleSizeOnUpAxis;
        }

        float groundOffset = minGroundDistance - groundDistance;

        float antigravityMultiplier = 1;

        if (groundOffset < -float.Epsilon)
        {
            antigravityMultiplier = antigravityFalloffCurve.Evaluate(Mathf.Max(antigravityFalloffDistance - Mathf.Abs(groundOffset), 0) / antigravityFalloffDistance);
        }
        Vector3 antigravityForce = CarBody.CalculateAntiGravityForce() * antigravityMultiplier;

        Vector3 floatingForce = Vector3.zero;

        if (groundDistance < float.MaxValue) //If the ground is within range
        {
            //Thanks to @bmabsout for a much better and more stable floatation method
            //based on pid but just the p and the d
            groundedPosition = hitInfo.point + up * minGroundDistance;
            Vector3 err          = up * Vector3.Dot(up, groundedPosition - CarBody.position);
            Vector3 proportional = Kp * err;
            Vector3 derivative   = Kd * (err - prevErr);
            floatingForce = proportional + derivative;
            prevErr       = err;
        }

        return(antigravityForce + floatingForce);
    }
Example #21
0
 public void CreateCompleteCar()
 {
     CarModel.SetModel();
     CarBody.SetBody();
     CarAcessories.SetAcessories();
 }
Example #22
0
 public CarFacade()
 {
     CarModel      = new CarModel();
     CarBody       = new CarBody();
     CarAcessories = new CarAcessories();
 }
Example #23
0
 public static bool Update(CarBody CarBody)
 {
     return(WebApi <bool> .PutAsync(controllerName, CarBody, "Put").Result);
 }
Example #24
0
 public static int Insert(CarBody CarBody)
 {
     return(WebApi <int> .PostAsync(controllerName, CarBody, "SinglePost").Result);
 }
 public IResult Add(CarBody carBody)
 {
     _carBodyDal.Add(carBody);
     return(new SuccessResult(Messages.CarBodyAdded));
 }
Example #26
0
 public float GetScanDistance(CarBody body)
 {
     return(scanner.GetSensorDistance(body));
 }
Example #27
0
    private void ApplyFloatation()
    {
        Vector3 expectedFloatingForce = CalculateFloatingForce();

        CarBody.AddForce(expectedFloatingForce, ForceMode.Force);
    }
Example #28
0
    private void ApplyOrientator()
    {
        Vector3 correctionTorque = CalculateCorrectionTorque();

        CarBody.AddTorque(correctionTorque, ForceMode.Force);
    }