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

Method SetFromCamera

experimental/collision/raycaster.go:134–146  ·  view source on GitHub ↗

SetRaycaster sets the specified raycaster with this camera position in world coordinates pointing to the direction defined by the specified coordinates unprojected using this camera.

(cam *camera.Camera, sx, sy float32)

Source from the content-addressed store, hash-verified

132// SetRaycaster sets the specified raycaster with this camera position in world coordinates
133// pointing to the direction defined by the specified coordinates unprojected using this camera.
134func (rc *Raycaster) SetFromCamera(cam *camera.Camera, sx, sy float32) error { // TODO maybe use ICamera
135
136 var origin, direction math32.Vector3
137 matrixWorld := cam.MatrixWorld()
138 origin.SetFromMatrixPosition(&matrixWorld)
139 direction.Set(sx, sy, 0.5)
140
141 unproj := cam.Unproject(&direction) // unproj = direction after this point TODO improve clarity
142 unproj.Sub(&origin).Normalize()
143 rc.Set(&origin, &direction)
144 cam.ViewMatrix(&rc.ViewMatrix) // Update the view matrix of the raycaster
145 return nil
146}
147
148// RaycastSprite checks intersections between the raycaster and the specified sprite
149// and if any found appends it to the specified intersects array.

Callers

nothing calls this directly

Calls 8

SetFromMatrixPositionMethod · 0.95
SetMethod · 0.95
MatrixWorldMethod · 0.80
UnprojectMethod · 0.80
ViewMatrixMethod · 0.65
NormalizeMethod · 0.45
SubMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected