Beispiel #1
0
        public void ProjectVector(SBSVector3 v, SBSVector3 o)
        {
            float d = SBSVector3.Dot(normal, v);

            o.x = v.x - d * normal.x;
            o.y = v.y - d * normal.y;
            o.z = v.z - d * normal.z;
        }
Beispiel #2
0
        public void ProjectPoint(SBSVector3 p, SBSVector3 o)
        {
            float d = SBSVector3.Dot(normal, p) + distance;

            o.x = p.x - d * normal.x;
            o.y = p.y - d * normal.y;
            o.z = p.z - d * normal.z;
        }
Beispiel #3
0
        public void ReflectVector(SBSVector3 v, SBSVector3 o)
        {
            float _2d = 2.0f * SBSVector3.Dot(normal, v);

            o.x = v.x - _2d * normal.x;
            o.y = v.y - _2d * normal.y;
            o.z = v.z - _2d * normal.z;
        }
Beispiel #4
0
        public void ReflectPoint(SBSVector3 p, SBSVector3 o)
        {
            float _2d = 2.0f * (SBSVector3.Dot(normal, p) + distance);

            o.x = p.x - _2d * normal.x;
            o.y = p.y - _2d * normal.y;
            o.z = p.z - _2d * normal.z;
        }
Beispiel #5
0
    void Update()
    {
        foreach (Checkpoint checkpoint in checkpoints)
        {
            if (null == checkpoint || !checkpoint.enabled)
            {
                continue;
            }

            LevelObject   chkPtLvlObj = checkpoint.GetComponent <LevelObject>();
            LevelObject[] gameObjects = LevelRoot.Instance.Query(chkPtLvlObj.Bounds, checkpoint.layersMask);

            foreach (LevelObject levelObj in gameObjects)
            {
                if (!levelObj.IsMovable)
                {
                    continue;
                }

                SBSVector3 prevLocalPt = chkPtLvlObj.WorldToLocal.MultiplyPoint3x4(((MovableLevelObject)levelObj).PrevLocalToWorld.position);
                SBSVector3 localPt = chkPtLvlObj.WorldToLocal.MultiplyPoint3x4(levelObj.LocalToWorld.position);
                float      prevDist = 0.0f, dist = 0.0f;

                switch (checkpoint.type)
                {
                case Checkpoint.Type.Cylindrical:
                    prevLocalPt -= (SBSVector3)checkpoint.upVector * SBSVector3.Dot(checkpoint.upVector, prevLocalPt);
                    localPt     -= (SBSVector3)checkpoint.upVector * SBSVector3.Dot(checkpoint.upVector, localPt);
                    prevDist     = prevLocalPt.magnitude;
                    dist         = localPt.magnitude;
                    break;

                case Checkpoint.Type.Spherical:
                    prevDist = prevLocalPt.magnitude;
                    dist     = localPt.magnitude;
                    break;
                }

                if (prevDist > checkpoint.radius && dist <= checkpoint.radius)
                {
                    Debug.Log(levelObj.name + " has entered checkpoint " + checkpoint.name);
                    levelObj.SendMessage("OnCheckpointEnter", checkpoint, SendMessageOptions.DontRequireReceiver);
                }

                if (prevDist <= checkpoint.radius && dist > checkpoint.radius)
                {
                    Debug.Log(levelObj.name + " has exited checkpoint " + checkpoint.name);
                    levelObj.SendMessage("OnCheckpointExit", checkpoint, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }
Beispiel #6
0
    public void WorldToToken(SBSVector3 worldPos, out float longitudinal, out float trasversal)
    {
        switch (type)
        {
        case TokenType.Cross:
        case TokenType.Rect:
            SBSVector3 localPos = matInvWorld.MultiplyPoint3x4(worldPos);
            longitudinal = SBSVector3.Dot(localPos, SBSVector3.forward) / lengthOrRadius;
            trasversal   = SBSVector3.Dot(localPos, SBSVector3.right) * 2.0f / width;
            break;

        case TokenType.Curve:
            SBSVector3 c  = this.Center,
                       p0 = matWorld.position - c,
                       p1 = worldPos - c;

            p0.DecrementBy(SBSVector3.Dot(p0, SBSVector3.up) * SBSVector3.up);
            p1.DecrementBy(SBSVector3.Dot(p1, SBSVector3.up) * SBSVector3.up);

            float sign  = SBSMath.Sign(SBSVector3.Dot(SBSVector3.Cross(p0, p1), SBSVector3.up));
            float angle = SBSVector3.Angle(p0, p1);

            longitudinal = angle / arcAngle;
            if (sign == curveDir)
            {
                longitudinal *= -1.0f;
            }
            trasversal = (p1.magnitude - lengthOrRadius) * 2.0f * curveDir / width;
            break;

        default:
            longitudinal = 0.0f;
            trasversal   = 0.0f;
            break;
        }
    }
Beispiel #7
0
 public SBSVector3 ProjectVector(SBSVector3 v)
 {
     return(v - SBSVector3.Dot(normal, v) * normal);
 }
Beispiel #8
0
 public SBSVector3 ProjectPoint(SBSVector3 p)
 {
     return(p - (SBSVector3.Dot(normal, p) + distance) * normal);
 }
Beispiel #9
0
 public SBSVector3 ReflectVector(SBSVector3 v)
 {
     return(v - (2.0f * SBSVector3.Dot(normal, v)) * normal);
 }
Beispiel #10
0
 public SBSVector3 ReflectPoint(SBSVector3 p)
 {
     return(p - (2.0f * (SBSVector3.Dot(normal, p) + distance)) * normal);
 }
Beispiel #11
0
 public float GetDistanceToPoint(SBSVector3 p)
 {
     return(SBSVector3.Dot(normal, p) + distance);
 }
Beispiel #12
0
 public void Set3Points(SBSVector3 p0, SBSVector3 p1, SBSVector3 p2)
 {
     normal   = SBSVector3.Cross(p1 - p0, p2 - p0);
     distance = -SBSVector3.Dot(normal, p0);
 }
Beispiel #13
0
 public void SetNormalAndPoint(SBSVector3 _normal, SBSVector3 point)
 {
     normal   = _normal;
     distance = -SBSVector3.Dot(_normal, point);
 }
Beispiel #14
0
 public SBSPlane(SBSVector3 p0, SBSVector3 p1, SBSVector3 p2)
 {
     normal   = SBSVector3.Cross(p1 - p0, p2 - p0);
     distance = -SBSVector3.Dot(normal, p0);
 }
Beispiel #15
0
 public SBSPlane(SBSVector3 _normal, SBSVector3 point)
 {
     normal   = _normal;
     distance = -SBSVector3.Dot(_normal, point);
 }
Beispiel #16
0
 public static float Angle(SBSVector3 v0, SBSVector3 v1)
 {
     return(SBSMath.Acos(SBSVector3.Dot(v0.normalized, v1.normalized)) * SBSMath.ToDegrees);
 }