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

Method Update

common/camera.go:120–174  ·  view source on GitHub ↗

Update updates the camera. lLong tasks are attempted to update incrementally in batches.

(dt float32)

Source from the content-addressed store, hash-verified

118
119// Update updates the camera. lLong tasks are attempted to update incrementally in batches.
120func (cam *CameraSystem) Update(dt float32) {
121 for axis, longTask := range cam.longTasks {
122 if !longTask.Incremental {
123 longTask.Incremental = true
124 longTask.value = longTask.Value
125
126 switch axis {
127 case XAxis:
128 longTask.Value -= cam.x
129 case YAxis:
130 longTask.Value -= cam.y
131 case ZAxis:
132 longTask.Value -= cam.z
133 case Angle:
134 longTask.Value -= cam.angle
135 }
136 }
137
138 // Set speed if needed
139 if longTask.speed == 0 {
140 longTask.speed = longTask.Value / float32(longTask.Duration.Seconds())
141 }
142
143 cam.moveAxis(axis, longTask.speed*dt)
144
145 longTask.Duration -= time.Duration(dt * float32(time.Second))
146 if longTask.Duration <= time.Duration(0) {
147
148 // it enforces that the last call will have the exactly position set by `Value` when `incremental = false`.
149 if longTask.value != 0 {
150 cam.moveAxisTo(axis, longTask.value)
151 }
152
153 delete(cam.longTasks, axis)
154 }
155 }
156
157 if cam.tracking.BasicEntity == nil {
158 return
159 }
160
161 if cam.tracking.SpaceComponent == nil {
162 log.Println("Should be tracking", cam.tracking.BasicEntity.ID(), "but SpaceComponent is nil")
163 cam.tracking.BasicEntity = nil
164 return
165 }
166
167 cam.centerCam(cam.tracking.SpaceComponent.Position.X+cam.tracking.SpaceComponent.Width/2,
168 cam.tracking.SpaceComponent.Position.Y+cam.tracking.SpaceComponent.Height/2,
169 cam.z,
170 )
171 if cam.trackRotation {
172 cam.rotateTo(cam.tracking.SpaceComponent.Rotation)
173 }
174}
175
176// FollowEntity sets the camera to follow the entity with BasicEntity basic
177// and SpaceComponent space.

Callers

nothing calls this directly

Calls 5

moveAxisMethod · 0.95
moveAxisToMethod · 0.95
centerCamMethod · 0.95
rotateToMethod · 0.95
IDMethod · 0.80

Tested by

no test coverage detected