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

Function NewPositionChannel

animation/channel.go:117–152  ·  view source on GitHub ↗
(node core.INode)

Source from the content-addressed store, hash-verified

115type PositionChannel NodeChannel
116
117func NewPositionChannel(node core.INode) *PositionChannel {
118
119 pc := new(PositionChannel)
120 pc.target = node
121 pc.updateInterpAction = func() {
122 // Get node
123 node := pc.target.GetNode()
124 // Update interpolation function
125 switch pc.interpType {
126 case STEP:
127 pc.interpAction = func(idx int, k float32) {
128 var v math32.Vector3
129 pc.values.GetVector3(idx*3, &v)
130 node.SetPositionVec(&v)
131 }
132 case LINEAR:
133 pc.interpAction = func(idx int, k float32) {
134 var v1, v2 math32.Vector3
135 pc.values.GetVector3(idx*3, &v1)
136 pc.values.GetVector3((idx+1)*3, &v2)
137 v1.Lerp(&v2, k)
138 node.SetPositionVec(&v1)
139 }
140 case CUBICSPLINE: // TODO
141 pc.interpAction = func(idx int, k float32) {
142 var v1, v2 math32.Vector3
143 pc.values.GetVector3(idx*3, &v1)
144 pc.values.GetVector3((idx+1)*3, &v2)
145 v1.Lerp(&v2, k)
146 node.SetPositionVec(&v1)
147 }
148 }
149 }
150 pc.SetInterpolationType(LINEAR)
151 return pc
152}
153
154// RotationChannel is the animation channel for a node's rotation.
155type RotationChannel NodeChannel

Callers 1

LoadAnimationMethod · 0.92

Calls 5

LerpMethod · 0.95
GetVector3Method · 0.80
SetPositionVecMethod · 0.80
GetNodeMethod · 0.65
SetInterpolationTypeMethod · 0.65

Tested by

no test coverage detected