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

Method Rotate

camera/orbit_control.go:142–168  ·  view source on GitHub ↗

Rotate rotates the camera around the target by the specified angles.

(thetaDelta, phiDelta float32)

Source from the content-addressed store, hash-verified

140
141// Rotate rotates the camera around the target by the specified angles.
142func (oc *OrbitControl) Rotate(thetaDelta, phiDelta float32) {
143
144 const EPS = 0.0001
145
146 // Compute direction vector from target to camera
147 tcam := oc.cam.Position()
148 tcam.Sub(&oc.target)
149
150 // Calculate angles based on current camera position plus deltas
151 radius := tcam.Length()
152 theta := math32.Atan2(tcam.X, tcam.Z) + thetaDelta
153 phi := math32.Acos(tcam.Y/radius) + phiDelta
154
155 // Restrict phi and theta to be between desired limits
156 phi = math32.Clamp(phi, oc.MinPolarAngle, oc.MaxPolarAngle)
157 phi = math32.Clamp(phi, EPS, math32.Pi-EPS)
158 theta = math32.Clamp(theta, oc.MinAzimuthAngle, oc.MaxAzimuthAngle)
159
160 // Calculate new cartesian coordinates
161 tcam.X = radius * math32.Sin(phi) * math32.Sin(theta)
162 tcam.Y = radius * math32.Cos(phi)
163 tcam.Z = radius * math32.Sin(phi) * math32.Cos(theta)
164
165 // Update camera position and orientation
166 oc.cam.SetPositionVec(oc.target.Clone().Add(&tcam))
167 oc.cam.LookAt(&oc.target, &oc.up)
168}
169
170// Zoom moves the camera closer or farther from the target the specified amount
171// and also updates the camera's orthographic size to match.

Callers 2

onCursorMethod · 0.95
onKeyMethod · 0.95

Calls 12

Atan2Function · 0.92
AcosFunction · 0.92
ClampFunction · 0.92
SinFunction · 0.92
CosFunction · 0.92
SetPositionVecMethod · 0.80
PositionMethod · 0.65
CloneMethod · 0.65
SubMethod · 0.45
LengthMethod · 0.45
AddMethod · 0.45
LookAtMethod · 0.45

Tested by

no test coverage detected