RenderSetup sets up the rendering of the sprite.
(gs *gls.GLS, rinfo *core.RenderInfo)
| 57 | |
| 58 | // RenderSetup sets up the rendering of the sprite. |
| 59 | func (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 | } |
nothing calls this directly
no test coverage detected