DynMatrix.h 936 B

12345678910111213141516171819202122232425262728293031
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2022 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. JPH_NAMESPACE_BEGIN
  6. /// Dynamic resizable matrix class
  7. class [[nodiscard]] DynMatrix
  8. {
  9. public:
  10. /// Constructor
  11. DynMatrix(const DynMatrix &) = default;
  12. DynMatrix(uint inRows, uint inCols) : mRows(inRows), mCols(inCols) { mElements.resize(inRows * inCols); }
  13. /// Access an element
  14. float operator () (uint inRow, uint inCol) const { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; }
  15. float & operator () (uint inRow, uint inCol) { JPH_ASSERT(inRow < mRows && inCol < mCols); return mElements[inRow * mCols + inCol]; }
  16. /// Get dimensions
  17. uint GetCols() const { return mCols; }
  18. uint GetRows() const { return mRows; }
  19. private:
  20. uint mRows;
  21. uint mCols;
  22. Array<float> mElements;
  23. };
  24. JPH_NAMESPACE_END