Unproject transforms the specified position from camera projected coordinates to world coordinates.
(v *math32.Vector3)
| 289 | |
| 290 | // Unproject transforms the specified position from camera projected coordinates to world coordinates. |
| 291 | func (c *Camera) Unproject(v *math32.Vector3) *math32.Vector3 { |
| 292 | |
| 293 | // Get inverted camera view matrix |
| 294 | invViewMat := c.MatrixWorld() |
| 295 | |
| 296 | // Get inverted camera projection matrix |
| 297 | var invProjMat math32.Matrix4 |
| 298 | c.ProjMatrix(&invProjMat) |
| 299 | err := invProjMat.GetInverse(&invProjMat) |
| 300 | if err != nil { |
| 301 | panic("Camera.Unproject: Couldn't invert matrix") |
| 302 | } |
| 303 | |
| 304 | // Apply invViewMat * invProjMat to the provided vector |
| 305 | v.ApplyProjection(invViewMat.Multiply(&invProjMat)) |
| 306 | return v |
| 307 | } |
no test coverage detected