MCPcopy
hub / github.com/g3n/engine / RandomTangents

Method RandomTangents

math32/vector3.go:643–668  ·  view source on GitHub ↗

RandomTangents computes and returns two arbitrary tangents to the vector.

()

Source from the content-addressed store, hash-verified

641
642// RandomTangents computes and returns two arbitrary tangents to the vector.
643func (v *Vector3) RandomTangents() (*Vector3, *Vector3) {
644
645 t1 := NewVector3(0, 0, 0)
646 t2 := NewVector3(0, 0, 0)
647 length := v.Length()
648 if length > 0 {
649 n := NewVector3(v.X/length, v.Y/length, v.Z/length)
650 randVec := NewVector3(0, 0, 0)
651 if Abs(n.X) < 0.9 {
652 randVec.SetX(1)
653 t1.CrossVectors(n, randVec)
654 } else if Abs(n.Y) < 0.9 {
655 randVec.SetY(1)
656 t1.CrossVectors(n, randVec)
657 } else {
658 randVec.SetZ(1)
659 t1.CrossVectors(n, randVec)
660 }
661 t2.CrossVectors(n, t1)
662 } else {
663 t1.SetX(1)
664 t2.SetY(1)
665 }
666
667 return t1, t2
668}
669
670// TODO: implement similar methods for Vector2 and Vector4
671// AlmostEquals returns whether the vector is almost equal to another vector within the specified tolerance.

Callers 4

UpdateMethod · 0.80
UpdateMethod · 0.80

Calls 7

LengthMethod · 0.95
SetXMethod · 0.95
CrossVectorsMethod · 0.95
SetYMethod · 0.95
SetZMethod · 0.95
NewVector3Function · 0.85
AbsFunction · 0.85

Tested by

no test coverage detected