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

Function zSort

renderer/renderer.go:279–298  ·  view source on GitHub ↗

zSort sorts a list of graphic materials based on the user-specified render order then based on their Z position relative to the camera, back to front.

(grmats []*graphic.GraphicMaterial)

Source from the content-addressed store, hash-verified

277// zSort sorts a list of graphic materials based on the user-specified render order
278// then based on their Z position relative to the camera, back to front.
279func zSort(grmats []*graphic.GraphicMaterial) {
280
281 sort.Slice(grmats, func(i, j int) bool {
282 gr1 := grmats[i].IGraphic().GetGraphic()
283 gr2 := grmats[j].IGraphic().GetGraphic()
284 // Check for user-supplied render order
285 rO1 := gr1.RenderOrder()
286 rO2 := gr2.RenderOrder()
287 if rO1 != rO2 {
288 return rO1 < rO2
289 }
290 mvm1 := gr1.ModelViewMatrix()
291 mvm2 := gr2.ModelViewMatrix()
292 g1pos := gr1.Position()
293 g2pos := gr2.Position()
294 g1pos.ApplyMatrix4(mvm1)
295 g2pos.ApplyMatrix4(mvm2)
296 return g1pos.Z < g2pos.Z
297 })
298}
299
300// renderGraphicMaterial renders the specified graphic material.
301func (r *Renderer) renderGraphicMaterial(grmat *graphic.GraphicMaterial) error {

Callers 1

RenderMethod · 0.85

Calls 6

IGraphicMethod · 0.80
RenderOrderMethod · 0.80
ModelViewMatrixMethod · 0.80
GetGraphicMethod · 0.65
PositionMethod · 0.65
ApplyMatrix4Method · 0.45

Tested by

no test coverage detected