Exemple #1
0
 public static void LocalToWorldRect(ref SkidmarkRect localRect, ref SkidmarkRect worldRect, Transform t)
 {
     worldRect.position      = t.TransformPoint(localRect.position);
     worldRect.normal        = t.TransformDirection(localRect.normal);
     worldRect.tangent       = t.TransformDirection(localRect.tangent);
     worldRect.positionLeft  = t.TransformPoint(localRect.positionLeft);
     worldRect.positionRight = t.TransformPoint(localRect.positionRight);
 }
Exemple #2
0
 public static void WorldToLocalRect(ref SkidmarkRect worldRect, ref SkidmarkRect localRect, Transform t)
 {
     localRect.position      = t.InverseTransformPoint(worldRect.position);
     localRect.normal        = t.InverseTransformDirection(worldRect.normal);
     localRect.tangent       = t.InverseTransformDirection(worldRect.tangent);
     localRect.positionLeft  = t.InverseTransformPoint(worldRect.positionLeft);
     localRect.positionRight = t.InverseTransformPoint(worldRect.positionRight);
 }
Exemple #3
0
        public void Update(int surfaceMapIndex, float newIntensity, float albedoIntensity, float normalIntensity,
                           Vector3 velocity, float dt)
        {
            _isGrounded    = _targetWheelComponent.IsGrounded;
            _prevIntensity = _intensity;

            _surfaceMapIndex = surfaceMapIndex;
            _albedoIntensity = albedoIntensity;
            _normalIntensity = normalIntensity;

            if (newIntensity < _lowerIntensityThreshold || !_isGrounded)
            {
                _intensity       = 0;
                _wasGroundedFlag = false;
                return;
            }

            _intensity = Mathf.SmoothDamp(_intensity, newIntensity, ref _intensityVelocity, _smoothing);

            // Calculate skidmark intensity on hard surfaces (asphalt, concrete, etc.)
            if (surfaceMapIndex >= 0)
            {
                // Get current position
                Vector3 currentPosition =
                    _skidObject.transform.InverseTransformPoint(
                        _targetWheelComponent.wheelController.wheelHit.groundPoint);
                currentPosition += _targetWheelComponent.wheelController.wheelHit.normal * _groundOffset;
                currentPosition += velocity * (dt * 0.5f);

                // Check distance
                float sqrDistance = (currentPosition - _previousRect.position).sqrMagnitude;
                if (sqrDistance < _minSqrDistance)
                {
                    return;
                }


                bool startAnew = _isGrounded && !_wasGroundedFlag || _intensity > 0 && _prevIntensity <= 0 ||
                                 surfaceMapIndex != _prevSurfaceMapIndex;

                // Initial triangle, can not use data from previous
                if (_isInitial || startAnew)
                {
                    Transform controllerTransform = _targetWheelComponent.ControllerTransform;
                    _currentRect.position = currentPosition;
                    _currentRect.normal   = _targetWheelComponent.wheelController.wheelHit.normal;
                    Vector3 right = controllerTransform.right;
                    _currentRect.positionLeft =
                        currentPosition - right * (_markWidth * 0.5f);
                    _currentRect.positionRight =
                        currentPosition + right * (_markWidth * 0.5f);

                    _direction           = controllerTransform.forward;
                    _xDirection          = -right;
                    _currentRect.tangent = new Vector4(_xDirection.x, _xDirection.y, _xDirection.y, 1f);

                    _previousRect    = _currentRect;
                    _wasGroundedFlag = true;

                    _isInitial = false;
                }
                // Use data from previous triangle to calculate geometry
                else
                {
                    _currentRect.position = currentPosition;
                    _currentRect.normal   = _targetWheelComponent.wheelController.wheelHit.normal;
                    _direction            = _currentRect.position - _previousRect.position;
                    _xDirection           = Vector3.Cross(_direction, _targetWheelComponent.wheelController.wheelHit.normal)
                                            .normalized;

                    _color.a = _intensity;
                    _currentRect.positionLeft  = currentPosition + _xDirection * (_markWidth * 0.5f);
                    _currentRect.positionRight = currentPosition - _xDirection * (_markWidth * 0.5f);
                    _currentRect.tangent       = new Vector4(_xDirection.x, _xDirection.y, _xDirection.z, 1f);
                }

                GenerateRectGeometry();

                _previousRect = _currentRect;
            }

            _prevSurfaceMapIndex = surfaceMapIndex;
        }