Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Public Attributes | List of all members
VSphere Struct Reference

Classes

struct  RotateInfo
 

Public Member Functions

 VSphere (SkV2 center, SkScalar radius)
 
bool contains (SkV2 v) const
 
SkV2 pinLoc (SkV2 p) const
 
SkV3 computeUnitV3 (SkV2 v) const
 
RotateInfo computeRotationInfo (SkV2 a, SkV2 b) const
 
SkM44 computeRotation (SkV2 a, SkV2 b) const
 

Public Attributes

SkV2 fCenter
 
SkScalar fRadius
 

Detailed Description

Definition at line 19 of file 3DSlide.cpp.

Constructor & Destructor Documentation

◆ VSphere()

VSphere::VSphere ( SkV2  center,
SkScalar  radius 
)
inline

Definition at line 23 of file 3DSlide.cpp.

23: fCenter(center), fRadius(radius) {}
static SkScalar center(float pos0, float pos1)
SkScalar fRadius
Definition: 3DSlide.cpp:21
SkV2 fCenter
Definition: 3DSlide.cpp:20

Member Function Documentation

◆ computeRotation()

SkM44 VSphere::computeRotation ( SkV2  a,
SkV2  b 
) const
inline

Definition at line 65 of file 3DSlide.cpp.

65 {
66 auto [axis, angle] = this->computeRotationInfo(a, b);
67 return SkM44::Rotate(axis, angle);
68 }
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition: SkM44.h:239
static bool b
RotateInfo computeRotationInfo(SkV2 a, SkV2 b) const
Definition: 3DSlide.cpp:53

◆ computeRotationInfo()

RotateInfo VSphere::computeRotationInfo ( SkV2  a,
SkV2  b 
) const
inline

Definition at line 53 of file 3DSlide.cpp.

53 {
54 SkV3 u = this->computeUnitV3(a);
55 SkV3 v = this->computeUnitV3(b);
56 SkV3 axis = u.cross(v);
57 SkScalar length = axis.length();
58
60 return {axis * (1.0f / length), std::acos(u.dot(v))};
61 }
62 return {{0, 0, 0}, 0};
63 }
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
float SkScalar
Definition: extension.cpp:12
size_t length
Definition: SkM44.h:56
SkV3 cross(const SkV3 &v) const
Definition: SkM44.h:91
SkScalar dot(const SkV3 &v) const
Definition: SkM44.h:90
SkScalar length() const
Definition: SkM44.h:88
SkV3 computeUnitV3(SkV2 v) const
Definition: 3DSlide.cpp:37

◆ computeUnitV3()

SkV3 VSphere::computeUnitV3 ( SkV2  v) const
inline

Definition at line 37 of file 3DSlide.cpp.

37 {
38 v = (v - fCenter) * (1 / fRadius);
39 SkScalar len2 = v.lengthSquared();
40 if (len2 > 1) {
41 v = v.normalize();
42 len2 = 1;
43 }
44 SkScalar z = SkScalarSqrt(1 - len2);
45 return {v.x, v.y, z};
46 }
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
SkV2 normalize() const
Definition: SkM44.h:50
float x
Definition: SkM44.h:20
SkScalar lengthSquared() const
Definition: SkM44.h:45
float y
Definition: SkM44.h:20

◆ contains()

bool VSphere::contains ( SkV2  v) const
inline

Definition at line 25 of file 3DSlide.cpp.

25 {
26 return (v - fCenter).length() <= fRadius;
27 }

◆ pinLoc()

SkV2 VSphere::pinLoc ( SkV2  p) const
inline

Definition at line 29 of file 3DSlide.cpp.

29 {
30 auto v = p - fCenter;
31 if (v.length() > fRadius) {
32 v *= (fRadius / v.length());
33 }
34 return fCenter + v;
35 }

Member Data Documentation

◆ fCenter

SkV2 VSphere::fCenter

Definition at line 20 of file 3DSlide.cpp.

◆ fRadius

SkScalar VSphere::fRadius

Definition at line 21 of file 3DSlide.cpp.


The documentation for this struct was generated from the following file: