It's a 2D rotation, but working the similar way I think.
Hope this helps.
*EDIT* Sorry, this code is not correct...
I'll modify it.
But at least you can use it for testing.. lol
*EDIT2* It's working properly now I think.
The COS(da+la) is used instead of angle comparison.
It choose the smaller angle when diff > limit, in order to avoid the jumpping.
Hope this helps.
Type face Global faces:TList = New TList Field x:Float Field y:Float Field rot:Float = 0 Field radius:Float = 50 Field anglimit:Float = 45 Method render() SetColor(80, 80, 80) DrawOval(x - radius / 2, y - radius / 2, radius, radius) SetColor(255, 0, 0) DrawLine(x, y, Cos(rot) * radius * 1.5 + x, Sin(rot) * radius * 1.5 + y) SetColor(0, 0, 255) DrawLine(x, y, Cos(rot + anglimit) * radius * 1.2 + x, Sin(rot + anglimit) * radius * 1.2 + y) DrawLine(x, y, Cos(rot - anglimit) * radius * 1.2 + x, Sin(rot - anglimit) * radius * 1.2 + y) End Method Method New() faces.AddFirst(Self) End Method End Type Function faceeach(f1:face, f2:face) Local ca:Float = f1.rot Local ta:Float = ATan2(f2.y - f1.y, f2.x - f1.x) Local la:Float = f1.anglimit Local da:Float = ta - ca Local dif:Float = Abs(da) - la If dif > 0 Then Local da1:Float = Cos(da + la) Local da2:Float = Cos(da - la) If da1 >= da2 Then f1.rot = ta + la Else f1.rot = ta - la End If EndIf End Function Graphics(640, 480) Local f1:face = New face Local f2:face = New face While Not KeyHit(KEY_ESCAPE) If MouseDown(1) f1.x = MouseX() f1.y = MouseY() End If If MouseDown(2) f2.x = MouseX() f2.y = MouseY() End If faceeach(f1, f2) faceeach(f2, f1) Flip Cls For Local f:face = EachIn face.faces f.render() Next Wend
*EDIT* Sorry, this code is not correct...
I'll modify it.
But at least you can use it for testing.. lol
*EDIT2* It's working properly now I think.
The COS(da+la) is used instead of angle comparison.
It choose the smaller angle when diff > limit, in order to avoid the jumpping.