Last active
December 14, 2015 01:59
-
-
Save attrition/5010589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array<Vector3>^ ParticleReadData::GetPositionBuffer() | |
{ | |
// get array of vectors, treat them as array of floats | |
const PxVec3* p1 = this->UnmanagedPointer->positionBuffer.ptr(); | |
float* p = (float*)p1; | |
if (p1 == NULL) | |
return nullptr; | |
int n = this->UnmanagedPointer->numValidParticles; | |
// manually create new array of Vector3 taking into account stride of 8 | |
array<Vector3>^ arr = gcnew array<Vector3>(n); | |
pin_ptr<Vector3> arrPin = &arr[0]; | |
int size = sizeof(Vector3); | |
// copy one vector of memory worth from source array into output managed array | |
for (int i = 0; i < n; i++) | |
{ | |
int next = i * 8; // records are 8 floats apart | |
memcpy_s(arrPin + i, size, p + next, size); | |
} | |
return arr; | |
//return Util::AsManagedArray<Vector3>((void*)p, n); // old block copy | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment