Pan pans the camera and target the specified amount on the plane perpendicular to the viewing direction.
(deltaX, deltaY float32)
| 187 | |
| 188 | // Pan pans the camera and target the specified amount on the plane perpendicular to the viewing direction. |
| 189 | func (oc *OrbitControl) Pan(deltaX, deltaY float32) { |
| 190 | |
| 191 | // Compute direction vector from camera to target |
| 192 | position := oc.cam.Position() |
| 193 | vdir := oc.target.Clone().Sub(&position) |
| 194 | |
| 195 | // Conversion constant between an on-screen cursor delta and its projection on the target plane |
| 196 | c := 2 * vdir.Length() * math32.Tan((oc.cam.Fov()/2.0)*math32.Pi/180.0) / oc.winSize() |
| 197 | |
| 198 | // Calculate pan components, scale by the converted offsets and combine them |
| 199 | var pan, panX, panY math32.Vector3 |
| 200 | panX.CrossVectors(&oc.up, vdir).Normalize() |
| 201 | panY.CrossVectors(vdir, &panX).Normalize() |
| 202 | panY.MultiplyScalar(c * deltaY) |
| 203 | panX.MultiplyScalar(c * deltaX) |
| 204 | pan.AddVectors(&panX, &panY) |
| 205 | |
| 206 | // Add pan offset to camera and target |
| 207 | oc.cam.SetPositionVec(position.Add(&pan)) |
| 208 | oc.target.Add(&pan) |
| 209 | } |
| 210 | |
| 211 | // onMouse is called when an OnMouseDown/OnMouseUp event is received. |
| 212 | func (oc *OrbitControl) onMouse(evname string, ev interface{}) { |
no test coverage detected