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)
| 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. |
| 279 | func 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. |
| 301 | func (r *Renderer) renderGraphicMaterial(grmat *graphic.GraphicMaterial) error { |
no test coverage detected