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

Method RenderSetup

graphic/sprite.go:59–94  ·  view source on GitHub ↗

RenderSetup sets up the rendering of the sprite.

(gs *gls.GLS, rinfo *core.RenderInfo)

Source from the content-addressed store, hash-verified

57
58// RenderSetup sets up the rendering of the sprite.
59func (s *Sprite) RenderSetup(gs *gls.GLS, rinfo *core.RenderInfo) {
60
61 // Calculates model view matrix
62 mw := s.MatrixWorld()
63 var mvm math32.Matrix4
64 mvm.MultiplyMatrices(&rinfo.ViewMatrix, &mw)
65
66 // Decomposes model view matrix
67 var position math32.Vector3
68 var quaternion math32.Quaternion
69 var scale math32.Vector3
70 mvm.Decompose(&position, &quaternion, &scale)
71
72 // Removes any rotation in X and Y axes and compose new model view matrix
73 rotation := s.Rotation()
74 actualScale := s.Scale()
75 if actualScale.X >= 0 {
76 rotation.Y = 0
77 } else {
78 rotation.Y = math32.Pi
79 }
80 if actualScale.Y >= 0 {
81 rotation.X = 0
82 } else {
83 rotation.X = math32.Pi
84 }
85 quaternion.SetFromEuler(&rotation)
86 var mvmNew math32.Matrix4
87 mvmNew.Compose(&position, &quaternion, &scale)
88
89 // Calculates final MVP and updates uniform
90 var mvpm math32.Matrix4
91 mvpm.MultiplyMatrices(&rinfo.ProjMatrix, &mvmNew)
92 location := s.uniMVPM.Location(gs)
93 gs.UniformMatrix4fv(location, 1, false, &mvpm[0])
94}

Callers

nothing calls this directly

Calls 9

MultiplyMatricesMethod · 0.95
DecomposeMethod · 0.95
SetFromEulerMethod · 0.95
ComposeMethod · 0.95
MatrixWorldMethod · 0.80
LocationMethod · 0.80
RotationMethod · 0.65
ScaleMethod · 0.65
UniformMatrix4fvMethod · 0.45

Tested by

no test coverage detected