| 73 | } |
| 74 | |
| 75 | bool MorphController::Update(double applicationTime) |
| 76 | { |
| 77 | // The key interpolation uses linear interpolation. To get higher-order |
| 78 | // interpolation, you need to provide a more sophisticated key (Bezier |
| 79 | // cubic or TCB spline, for example). |
| 80 | |
| 81 | if (!Controller::Update(applicationTime)) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | // Get access to the vertex buffer to store the blended targets. |
| 87 | auto visual = static_cast<Visual*>(mObject); |
| 88 | auto const& vbuffer = visual->GetVertexBuffer(); |
| 89 | VertexFormat vformat = vbuffer->GetFormat(); |
| 90 | |
| 91 | // Initialize the 3-tuple positions (x,y,z) to zero for accumulation. |
| 92 | uint32_t numVertices = vbuffer->GetNumElements(); |
| 93 | char* combination = vbuffer->GetData(); |
| 94 | size_t vertexSize = static_cast<size_t>(vformat.GetVertexSize()); |
| 95 | for (uint32_t i = 0; i < numVertices; ++i) |
| 96 | { |
| 97 | Vector3<float>& vertex = *reinterpret_cast<Vector3<float>*>(combination); |
| 98 | vertex = { 0.0f, 0.0f, 0.0f }; |
| 99 | combination += vertexSize; |
| 100 | } |
| 101 | |
| 102 | // Look up the bounding keys. |
| 103 | float ctrlTime = static_cast<float>(GetControlTime(applicationTime)); |
| 104 | float normTime; |
| 105 | size_t key0, key1; |
| 106 | GetKeyInfo(ctrlTime, normTime, key0, key1); |
| 107 | float oneMinusNormTime = 1.0f - normTime; |
| 108 | |
| 109 | // Compute the weighted combination. |
| 110 | float const* weights0 = &mWeights[key0 * mNumTargets]; |
| 111 | float const* weights1 = &mWeights[key1 * mNumTargets]; |
| 112 | Vector3<float> const* vertices = mVertices.data(); |
| 113 | for (size_t n = 0; n < mNumTargets; ++n) |
| 114 | { |
| 115 | float w = oneMinusNormTime * weights0[n] + normTime * weights1[n]; |
| 116 | combination = vbuffer->GetData(); |
| 117 | for (size_t m = 0; m < mNumVertices; ++m) |
| 118 | { |
| 119 | Vector3<float>& position = *reinterpret_cast<Vector3<float>*>(combination); |
| 120 | position += w * (*vertices++); |
| 121 | // += w * mVertices[m + mNumTargets * n]; |
| 122 | combination += vertexSize; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | visual->UpdateModelBound(); |
| 127 | visual->UpdateModelNormals(); |
| 128 | mPostUpdate(vbuffer); |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | void MorphController::SetObject(ControlledObject* object) |
nothing calls this directly
no test coverage detected