| 39 | } |
| 40 | |
| 41 | void PointController::SetObject(ControlledObject* object) |
| 42 | { |
| 43 | mPointLinearSpeed.clear(); |
| 44 | mPointAngularSpeed.clear(); |
| 45 | mPointLinearAxis.clear(); |
| 46 | mPointAngularAxis.clear(); |
| 47 | |
| 48 | auto visual = dynamic_cast<Visual*>(object); |
| 49 | LogAssert(visual != nullptr, "Object is not of type Visual."); |
| 50 | |
| 51 | auto const& ibuffer = visual->GetIndexBuffer(); |
| 52 | uint32_t primitiveType = ibuffer->GetPrimitiveType(); |
| 53 | LogAssert(primitiveType == IP_POLYPOINT, "Geometric primitive must be points."); |
| 54 | |
| 55 | // The vertex buffer for a Visual controlled by a PointController must |
| 56 | // have 3-tuple or 4-tuple float-valued position that occurs at the |
| 57 | // beginning (offset 0) of the vertex structure. |
| 58 | auto const& vbuffer = visual->GetVertexBuffer(); |
| 59 | VertexFormat vformat = vbuffer->GetFormat(); |
| 60 | int32_t index = vformat.GetIndex(VASemantic::POSITION, 0); |
| 61 | LogAssert(index >= 0, "Vertex format does not have VASemantic::POSITION."); |
| 62 | |
| 63 | uint32_t type = vformat.GetType(index); |
| 64 | LogAssert(type == DF_R32G32B32_FLOAT || type == DF_R32G32B32A32_FLOAT, "Invalid position type."); |
| 65 | |
| 66 | uint32_t offset = vformat.GetOffset(index); |
| 67 | LogAssert(offset == 0, "Position offset must be 0."); |
| 68 | |
| 69 | // If the vertex buffer for a Visual controlled by a PointController has |
| 70 | // normal vectors, they must be 3-tuple or 4-tuple float-valued that |
| 71 | // occurs at an offset >= sizeof(Vector3<float>>). |
| 72 | index = vformat.GetIndex(VASemantic::NORMAL, 0); |
| 73 | if (index >= 0) |
| 74 | { |
| 75 | type = vformat.GetType(index); |
| 76 | LogAssert(type == DF_R32G32B32_FLOAT || type == DF_R32G32B32A32_FLOAT, "Invalid normal type."); |
| 77 | } |
| 78 | |
| 79 | size_t numPoints = static_cast<size_t>(vbuffer->GetNumElements()); |
| 80 | mPointLinearSpeed.resize(numPoints); |
| 81 | mPointAngularSpeed.resize(numPoints); |
| 82 | mPointLinearAxis.resize(numPoints); |
| 83 | mPointAngularAxis.resize(numPoints); |
| 84 | for (size_t i = 0; i < numPoints; ++i) |
| 85 | { |
| 86 | mPointLinearSpeed[i] = 0.0f; |
| 87 | mPointAngularSpeed[i] = 0.0f; |
| 88 | mPointLinearAxis[i] = Vector3<float>::Unit(2); |
| 89 | mPointAngularAxis[i] = Vector3<float>::Unit(2); |
| 90 | } |
| 91 | |
| 92 | Controller::SetObject(object); |
| 93 | } |
| 94 | |
| 95 | void PointController::UpdateSystemMotion(float ctrlTime) |
| 96 | { |
nothing calls this directly
no test coverage detected