Esempio n. 1
0
        private void RegisterSkid(VehicleWheel wheel, Vector3 pos)
        {
            if (pos == Vector3.Zero)
            {
                return;
            }

            CurrentSkid skid = null;

            foreach (CurrentSkid cskid in _currentSkids)
            {
                if (cskid.Wheel == wheel)
                {
                    skid = cskid; break;
                }
            }
            if (skid == null)
            {
                skid = new CurrentSkid {
                    Wheel = wheel, StartPosition = pos, EndPosition = pos, StartTime = GameEngine.TotalSeconds
                };
                _currentSkids.Add(skid);
            }
            else
            {
                skid.IsActive    = true;
                skid.EndPosition = pos;
            }
        }
Esempio n. 2
0
        private void AddToBuffer(CurrentSkid skid)
        {
            int p1, p2;

            float thickness = 0.13f;
            float length    = _vehicle.Chassis.Speed * 0.2f;

            Vector3 direction = skid.EndPosition - skid.StartPosition;

            direction.Normalize();

            Vector3 normal = Vector3.Cross(direction, Vector3.UnitY);

            normal.Normalize();

            _vertices[_firstFreeVert].Position          = skid.StartPosition - normal * thickness;
            _vertices[_firstFreeVert].TextureCoordinate = new Vector2(0, 1);

            _firstFreeVert++;
            p1 = _firstFreeVert;
            _vertices[_firstFreeVert].Position          = skid.EndPosition - normal * thickness;
            _vertices[_firstFreeVert].TextureCoordinate = new Vector2(length, 1);

            _firstFreeVert++;
            p2 = _firstFreeVert;
            _vertices[_firstFreeVert].Position          = skid.StartPosition + normal * thickness;
            _vertices[_firstFreeVert].TextureCoordinate = Vector2.Zero;

            _firstFreeVert++;
            _vertices[_firstFreeVert] = _vertices[p2];
            _firstFreeVert++;
            _vertices[_firstFreeVert] = _vertices[p1];
            _firstFreeVert++;
            _vertices[_firstFreeVert].Position          = skid.EndPosition + normal * thickness;
            _vertices[_firstFreeVert].TextureCoordinate = new Vector2(length, 0);

            _firstFreeVert = (_firstFreeVert + 1) % _vertices.Length;

            if (_texture == null)
            {
            }
            _skids[_skidPtr] = _texture; // ?? _defaultTexture;
            _skidPtr         = (_skidPtr + 1) % _maxSkids;
        }
Esempio n. 3
0
        private void Update()
        {
            if (Enabled)
            {
                if (!Helpers.HasTimePassed(0.5f, _vehicle.LastRunOverPedTime))
                {
                    foreach (var wheel in _vehicle.Chassis.Wheels)
                    {
                        if (!wheel.IsRear)
                        {
                            RegisterSkid(wheel, wheel.ContactPoint);
                        }
                    }
                    SetTexture(_bloodTexture);
                }
                else
                {
                    if (_usingBloodTexture)
                    {
                        _usingBloodTexture = false;
                        SetTexture(_defaultTexture);
                    }

                    foreach (var wheel in _vehicle.Chassis.Wheels)
                    {
                        if (wheel.IsSkiddingLat || wheel.IsSkiddingLng)
                        {
                            RegisterSkid(wheel, wheel.ContactPoint);
                        }
                    }
                }
            }

            for (int i = 0; i < _currentSkids.Count; i++)
            {
                CurrentSkid skid = _currentSkids[i];
                if (!skid.IsActive)
                {
                    _currentSkids.RemoveAt(i);
                    i--;
                    AddToBuffer(skid);
                }
                else if (Helpers.HasTimePassed(SKID_TIME, _currentSkids[i].StartTime))
                {
                    AddToBuffer(skid);
                    skid.StartPosition = skid.EndPosition;
                    skid.StartTime     = GameEngine.TotalSeconds;
                }
            }

            int nbrTempSkids = 0;

            for (int i = 0; i < _currentSkids.Count; i++)
            {
                if (_currentSkids[i].IsActive && !Helpers.HasTimePassed(SKID_TIME, _currentSkids[i].StartTime))
                {
                    //temp
                    _currentSkids[i].EndPosition = _currentSkids[i].Wheel.ContactPoint;
                    AddToBuffer(_currentSkids[i]);
                    nbrTempSkids++;
                }
            }

            AddNewParticlesToVertexBuffer();

            _firstFreeVert -= 6 * nbrTempSkids;
            if (_firstFreeVert < 0)
            {
                _firstFreeVert = _vertices.Length - (-_firstFreeVert);
            }
            _firstNewVert = _firstFreeVert;
            _skidPtr     -= 1 * nbrTempSkids;
            if (_skidPtr < 0)
            {
                _skidPtr = _maxSkids - (-_skidPtr);
            }
        }