MCPcopy
hub / github.com/EngoEngine/engo / makeModelMatrix

Method makeModelMatrix

common/render_shaders_default.go:323–343  ·  view source on GitHub ↗
(ren *RenderComponent, space *SpaceComponent)

Source from the content-addressed store, hash-verified

321}
322
323func (s *basicShader) makeModelMatrix(ren *RenderComponent, space *SpaceComponent) *engo.Matrix {
324 // Instead of creating a new model matrix every time, we instead store a global one as a struct member
325 // and just reset it for every sprite. This prevents us from allocating a bunch of new Matrix instances in memory
326 // ultimately saving on GC activity.
327 // When a negative scale is used, we just want to flip the sprite, so this
328 // makes up for the translation that happens on the openGL side.
329 transX := space.Position.X
330 transY := space.Position.Y
331 if ren.Scale.X < 0 {
332 transX -= ren.Drawable.Width() * ren.Scale.X
333 }
334 if ren.Scale.Y < 0 {
335 transY -= ren.Drawable.Height() * ren.Scale.Y
336 }
337 s.modelMatrix.Identity().Scale(engo.GetGlobalScale().X, engo.GetGlobalScale().Y).Translate(transX, transY)
338 if space.Rotation != 0 {
339 s.modelMatrix.Rotate(space.Rotation)
340 }
341 s.modelMatrix.Scale(ren.Scale.X, ren.Scale.Y)
342 return s.modelMatrix
343}
344
345func (s *basicShader) generateBufferContent(ren *RenderComponent, space *SpaceComponent, buffer []float32) bool {
346 // We shouldn't use SpaceComponent to get width/height, because this usually already contains the Scale (which

Callers 1

generateBufferContentMethod · 0.95

Calls 7

GetGlobalScaleFunction · 0.92
TranslateMethod · 0.80
ScaleMethod · 0.80
IdentityMethod · 0.80
RotateMethod · 0.80
WidthMethod · 0.65
HeightMethod · 0.65

Tested by

no test coverage detected