コード例 #1
0
    public float GetAngleFromLocation(ViVector3 pos)
    {
        float deltaX = pos.x - Position.x;
        float deltaY = pos.y - Position.y;

        return(GetAngleFromDirection(deltaX, deltaY));
    }
コード例 #2
0
    public static float GetHorizontalDistance2(ViVector3 pos1, ViVector3 pos2)
    {
        float deltaX = pos1.x - pos2.x;
        float deltaY = pos1.y - pos2.y;

        return((deltaX * deltaX) + (deltaY * deltaY));
    }
コード例 #3
0
    public ViVector3 GetIntersectionPosByPerc(ViVector3 toPos, float perc)      //! fPerc = 0  Reach this, fPerc = 1 Reach From, fPerc < 0 behind self
    {
        float fDeltaX = toPos.x - Position.x;
        float fDeltaY = toPos.y - Position.y;

        return(new ViVector3(Position.x + fDeltaX * perc, Position.y + fDeltaY * perc, Position.z));
    }
コード例 #4
0
    TEntity GetNearst(Queue <TEntity> objs, ViVector3 center)
    {
        TEntity pkNearst = null;
        float   fMinDist = 100.0f;

        ViDebuger.AssertError(_deleIsInRange);
        ViDebuger.AssertError(_deleIsStateMatch);
        foreach (TEntity obj in objs)
        {
            ViDebuger.AssertError(obj);
            if (_Has(obj))
            {
                continue;
            }
            if (!_deleIsInRange(obj, center))
            {
                continue;
            }
            if (!_deleIsStateMatch(obj))
            {
                continue;
            }

            float fDist = obj.GetDistance(center);
            if (fMinDist > fDist)
            {
                fMinDist = fDist;
                pkNearst = obj;
            }
        }
        return(pkNearst);
    }
コード例 #5
0
    public float Aim(ViVector3 pos)
    {
        float angle = GetAngleFromLocation(pos);

        TurnAngle(angle);
        return(angle);
    }
コード例 #6
0
ファイル: ViRoute.cs プロジェクト: xubingyue/def
    public static float Distance(ViVector3 pos1, ViVector3 pos2)
    {
        float deltaX = pos1.x - pos2.x;
        float deltaY = pos1.y - pos2.y;

        return(ViMathDefine.Sqrt((deltaX * deltaX) + (deltaY * deltaY)));
    }
コード例 #7
0
    //
    public TEntity Next(float dir, ViVector3 center, Queue <TEntity> objs)
    {
        if (Max == 0)
        {
            return(null);
        }
        _OnDirCenterUpdated(dir, center);
        _Check(center);
        TEntity obj = GetNearst(objs, center);

        if (obj == null && !_objs.IsEmpty())
        {
            obj = _objs.GetFront(null).Obj;
            _objs.PopFront();
        }
        if (obj != null)
        {
            if (_objs.Count == Max)
            {
                _objs.PopFront();
            }
            _objs.PushBack(new ViRefPtr <TEntity>(obj));
        }
        return(obj);
    }
コード例 #8
0
 public bool Update(float deltaTime, out ViVector3 moved)
 {
     moved = ViVector3.ZERO;
     while (deltaTime > _iterSpan)
     {
         deltaTime -= _iterSpan;
         ViVector3 iterMoved;
         bool      result = _Update(_iterSpan, out iterMoved);
         moved += iterMoved;
         if (result == false)
         {
             return(false);
         }
     }
     if (deltaTime > 0)
     {
         ViVector3 iterMoved;
         bool      result = _Update(deltaTime, out iterMoved);
         moved += iterMoved;
         if (result == false)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #9
0
ファイル: ViRoute.cs プロジェクト: xubingyue/def
    //
    bool _UpdateDistance(float distance)
    {
        if (_nextNode == null)
        {
            return(false);
        }
        ViVector3 nextPos   = _nextNode._pos;
        float     distRight = Distance(_currentPos, nextPos);

        if (distRight > distance)
        {
            _currentPos += _dir * distance;
        }
        else
        {
            float newDistance = distance - distRight;
            _currentPos = nextPos;
            _prePos     = nextPos;
            if (ViRouteNode.HasEvent(_nextNode._eventId))
            {
                _endCallbackList.Invoke(_nextNode._eventId);
            }
            S_Nodes.Delete(_nodes.GetHead());
            _nextNode = _LerpToNextNode();
            if (_nextNode != null)
            {
                _UpdateDistance(newDistance);
            }
            else
            {
                _ClearState();
            }
        }
        return(true);
    }
コード例 #10
0
ファイル: ViArea.cs プロジェクト: xubingyue/def
    public void SetDir(float dir)
    {
        ViVector3 kDir = ViVector3.ZERO;

        ViGeographicObject.GetRotate(dir, ref kDir.x, ref kDir.y);
        _rotRect.Dir = kDir;
    }
コード例 #11
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public static ViVector3 Lerp(ViVector3 from, ViVector3 to, float t)
    {
        ViVector3 v = from;

        v += (to - from) * t;
        return(v);
    }
コード例 #12
0
    static public ViQuaternion FromAxisAngle(ViVector3 axis, float radians)
    {
        axis.Normalize();
        ViVector3 scaledAxis = axis * (float)Math.Sin(radians * 0.5f);

        return(new ViQuaternion(scaledAxis.x, scaledAxis.y, scaledAxis.z, (float)Math.Cos(radians * 0.5f)));
    }
コード例 #13
0
ファイル: ViRoute.cs プロジェクト: xubingyue/def
    public void Append(ViVector3 pos, UInt32 eventId)
    {
        ViDoubleLinkNode2 <ViRouteNode> node = S_Nodes.New();

        node.Data._eventId = eventId;
        node.Data._pos     = pos;
        _nodes.PushBack(node);
    }
コード例 #14
0
ファイル: ViRoute.cs プロジェクト: xubingyue/def
    //
    public void Append(ViVector3 pos)
    {
        ViDoubleLinkNode2 <ViRouteNode> node = S_Nodes.New();

        node.Data._eventId = ViRouteNode.NULL_EVENT;
        node.Data._pos     = pos;
        _nodes.PushBack(node);
    }
コード例 #15
0
ファイル: ViTrackMotor.cs プロジェクト: xubingyue/def
    public override void _Update(float deltaTime, ViVector3 target)
    {
        ViVector3 dir = target - Translate;

        dir.Normalize();
        _velocity  = dir * _speed;
        _direction = dir;
    }
コード例 #16
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
 public static ViVector3 ClampMagnitude(ViVector3 vector, float maxLength)
 {
     if (vector.sqrMagnitude > (maxLength * maxLength))
     {
         return((ViVector3)(vector.normalized * maxLength));
     }
     return(vector);
 }
コード例 #17
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public static float Distance(ViVector3 a, ViVector3 b)
    {
        float deltaX = a.x - b.x;
        float deltaY = a.y - b.y;
        float deltaZ = a.z - b.z;

        return(ViMathDefine.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)));
    }
コード例 #18
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public static float Distance2(ViVector3 a, ViVector3 b)
    {
        float deltaX = a.x - b.x;
        float deltaY = a.y - b.y;
        float deltaZ = a.z - b.z;

        return((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
    }
コード例 #19
0
ファイル: ViArea.cs プロジェクト: xubingyue/def
    public override bool InArea(ViVector3 pos, float range)
    {
        ViDebuger.AssertWarning(_dirLeftAngle <= _dirRightAngle);
        float deltaX = pos.x - _center.x;
        float deltaY = pos.y - _center.y;
        float dir    = ViMath2D.GetAngle(deltaX, deltaY);

        return((ViMath2D.Length2(_center.x, _center.y, pos.x, pos.y) < (_radius2 + range * range)) && (_dirLeftAngle <= dir && dir < _dirRightAngle));
    }
コード例 #20
0
 public override void OnUpdate(UInt8 channel, ViIStream IS, ViEntity entity)
 {
     if (MatchChannel(channel))
     {
         ViVector3 oldValue = _value;
         IS.Read(out _value);
         OnUpdateInvoke(oldValue);
     }
 }
コード例 #21
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public static ViVector3 Cross(ViVector3 v1, ViVector3 v2)
    {
        ViVector3 result;

        result.x = (v1.y * v2.z) - (v1.z * v2.y);
        result.y = (v1.z * v2.x) - (v1.x * v2.z);
        result.z = (v1.x * v2.y) - (v1.y * v2.x);
        return(result);
    }
コード例 #22
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public static ViVector3 Normalize(ViVector3 value)
    {
        float num = Magnitude(value);

        if (num > 1E-05f)
        {
            return((ViVector3)(value / num));
        }
        return(ZERO);
    }
コード例 #23
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public override bool Equals(object other)
    {
        if (!(other is ViVector3))
        {
            return(false);
        }
        ViVector3 vector = (ViVector3)other;

        return((this.x.Equals(vector.x) && this.y.Equals(vector.y)) && this.z.Equals(vector.z));
    }
コード例 #24
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
 public static void PrintTo(this ViVector3 value, ref string strValue)
 {
     strValue += "(";
     strValue += value.x;
     strValue += ", ";
     strValue += value.y;
     strValue += ", ";
     strValue += value.z;
     strValue += ")";
 }
コード例 #25
0
ファイル: ViVector3.cs プロジェクト: xubingyue/def
    public static ViVector3 Project(ViVector3 vector, ViVector3 onNormal)
    {
        float num = Dot(onNormal, onNormal);

        if (num < float.Epsilon)
        {
            return(ZERO);
        }
        return((ViVector3)((onNormal * Dot(vector, onNormal)) / num));
    }
コード例 #26
0
ファイル: ViPlaneMotor.cs プロジェクト: xubingyue/def
    public override void _Update(float deltaTime, ViVector3 target)
    {
        ViVector3 diffDir = target - Translate;

        diffDir.Normalize();
        if (_direction == diffDir)
        {
            _velocity = _direction * _speed;
        }
        else
        {
            ViVector3 rotateAxis = ViVector3.Cross(_direction, diffDir);
            rotateAxis.Normalize();
            const float STABLE = 0.0001f;
            // 计算公式与变量定义
            // V 线速度
            // W 角速度
            // A 侧向加速度
            // R 运动半径
            // W = V/R;
            // A = (V*V)/R = W*W*R = V*W;
            float angleDiff        = ViVector3.Angle(diffDir, _direction);
            float destW            = 4.0f * Math.Abs((angleDiff + STABLE) / (_duration + STABLE));
            float destA            = destW * Speed;
            float destLateralAngle = (float)Math.Atan2(destA, _gravity);
            //
            _rollSpd = 3.0f * (destLateralAngle - _lateralAngle + STABLE) / (_duration + STABLE);
            if (destLateralAngle > _lateralAngle)
            {
                _lateralAngle = ViMathDefine.MoveTowards(_lateralAngle, destLateralAngle, _rollSpd * deltaTime);
            }
            else
            {
                _lateralAngle = destLateralAngle;
            }
            float currentA   = (float)Math.Tan(_lateralAngle) * _gravity;
            float currentW   = currentA / Speed;
            float deltaAngle = currentW * deltaTime;
            //
            ViQuaternion rotateQuat = ViQuaternion.FromAxisAngle(rotateAxis, deltaAngle);
            ViVector3    newDir     = rotateQuat * _direction;
            newDir.Normalize();
            _velocity = (newDir + _direction) * _speed * 0.5f;
            if (ViVector3.Dot(ViVector3.Cross(_direction, newDir), ViVector3.Cross(newDir, diffDir)) < 0.0f)            // 插值抖动
            {
                _lateralSign = 0.0f;
                _direction   = diffDir;
            }
            else
            {
                _direction   = newDir;
                _lateralSign = (rotateAxis.z > 0.0f) ? 1.0f : -1.0f;
            }
        }
    }
コード例 #27
0
 public float GetDistance2()
 {
     if (_target0 != null && _target1 != null)
     {
         return(ViVector3.Distance2(_target0.Value, _target1.Value));
     }
     else
     {
         return(0.0f);
     }
 }
コード例 #28
0
 public bool IsIn()
 {
     if (_target0 != null && _target1 != null)
     {
         return(ViVector3.Distance2(_target0.Value, _target1.Value) < _range2);
     }
     else
     {
         return(false);
     }
 }
コード例 #29
0
 private void _UpdateInside()
 {
     ViDebuger.AssertError(_target0 != null && _target1 != null);
     if (ViVector3.Distance2(_target0.Value, _target1.Value) > _range2)
     {
         _listWaitingOutor.PushBack(_node);
         if (_delegateOut != null)
         {
             _delegateOut();
         }
     }
 }
コード例 #30
0
 //
 private void _Update()
 {
     ViDebuger.AssertError(_target0 != null && _target1 != null);
     if (ViVector3.Distance2(_target0.Value, _target1.Value) < _range2)
     {
         _node.Detach();
         if (_delegate != null)
         {
             _delegate();
         }
     }
 }