bool ParticleEmitter::spawnParticle(ParticleData& data, PxU32& num, const PxU32 max, const PxVec3& position, const PxVec3& velocity) { PX_ASSERT(PxI32(max) - PxI32(num) <= PxI32(data.maxParticles) - PxI32(data.numParticles)); if(num >= max) return false; data.positions[data.numParticles] = position; data.velocities[data.numParticles] = velocity; data.numParticles++; num++; return true; }
static PxU32 addToStringTable(physx::shdfnd::Array<char>& stringTable, const char* str) { if(!str) return 0xffffffff; PxI32 length = PxI32(stringTable.size()); const char* table = stringTable.begin(); const char* start = table; while(length) { if(strcmp(table, str)==0) return PxU32(table - start); const char* saved = table; while(*table++); length -= PxU32(table - saved); PX_ASSERT(length>=0); } const PxU32 offset = stringTable.size(); while(*str) stringTable.pushBack(*str++); stringTable.pushBack(0); return offset; }
bool PhysXHeightfield::LoadHeightfield(const char* filename) { mHeightfield.height = 2049; mHeightfield.width = 2049; float yScale = 0.001f; // A height for each vertex std::vector<unsigned char> in( mHeightfield.width * mHeightfield.height ); // Open the file. std::ifstream inFile; inFile.open(filename, std::ios_base::binary); if(inFile) { // Read the RAW bytes. inFile.read((char*)&in[0], (std::streamsize)in.size()); // Done with file. inFile.close(); } else { return false; } mHeightfield.data = new PxHeightFieldSample[(mHeightfield.height*mHeightfield.width)]; // Copy the array data into a float array and scale it. /*for(int i = 0; i < mHeightfield.width * mHeightfield.height; ++i) { PxI32 h = PxI32(heightmap[y+x*hfSize]/heightScale); PX_ASSERT(h<=0xffff); samples[x+y*hfSize].height = (PxI16)(h); samples[x+y*hfSize].setTessFlag(); samples[x+y*hfSize].materialIndex0=1; samples[x+y*hfSize].materialIndex1=1; PxHeightFieldSample* currentSample = 0; currentSample->height = (in[i] / 255.0f); currentSample->materialIndex0 = 0; currentSample->materialIndex1 = 0; currentSample->clearTessFlag(); mHeightfield.data[i] = *currentSample; }*/ for(PxU32 x = 0; x < mHeightfield.width; x++) for(PxU32 y = 0; y < mHeightfield.height; y++) { float n = float(in[y+x*mHeightfield.height]); float no = float(n / 255.0); PxI32 h = PxI32(no * yScale); PX_ASSERT(h<=0xffff); mHeightfield.data[x+y*mHeightfield.height].height = (PxI16)(h); mHeightfield.data[x+y*mHeightfield.height].setTessFlag(); mHeightfield.data[x+y*mHeightfield.height].materialIndex0=1; mHeightfield.data[x+y*mHeightfield.height].materialIndex1=1; } return true; }
void RTree::refitAllStaticTree(CallbackRefit& cb, PxBounds3* retBounds) { PxU8* treeNodes8 = PX_IS_X64 ? CAST_U8(get64BitBasePage()) : CAST_U8((mFlags & IS_DYNAMIC) ? NULL : mPages); // since pages are ordered we can scan back to front and the hierarchy will be updated for (PxI32 iPage = PxI32(mTotalPages)-1; iPage>=0; iPage--) { RTreePage& page = mPages[iPage]; for (PxU32 j = 0; j < RTREE_PAGE_SIZE; j++) { if (page.isEmpty(j)) continue; if (page.isLeaf(j)) { Vec3V childMn, childMx; cb.recomputeBounds(page.ptrs[j]-1, childMn, childMx); // compute the bound around triangles PxVec3 mn3, mx3; V3StoreU(childMn, mn3); V3StoreU(childMx, mx3); page.minx[j] = mn3.x; page.miny[j] = mn3.y; page.minz[j] = mn3.z; page.maxx[j] = mx3.x; page.maxy[j] = mx3.y; page.maxz[j] = mx3.z; } else { const RTreePage* child = (const RTreePage*)(treeNodes8 + page.ptrs[j]); PX_COMPILE_TIME_ASSERT(RTREE_PAGE_SIZE == 4); bool first = true; for (PxU32 k = 0; k < RTREE_PAGE_SIZE; k++) { if (child->isEmpty(k)) continue; if (first) { page.minx[j] = child->minx[k]; page.miny[j] = child->miny[k]; page.minz[j] = child->minz[k]; page.maxx[j] = child->maxx[k]; page.maxy[j] = child->maxy[k]; page.maxz[j] = child->maxz[k]; first = false; } else { page.minx[j] = PxMin(page.minx[j], child->minx[k]); page.miny[j] = PxMin(page.miny[j], child->miny[k]); page.minz[j] = PxMin(page.minz[j], child->minz[k]); page.maxx[j] = PxMax(page.maxx[j], child->maxx[k]); page.maxy[j] = PxMax(page.maxy[j], child->maxy[k]); page.maxz[j] = PxMax(page.maxz[j], child->maxz[k]); } } } } } if (retBounds) { RTreeNodeQ bound1; for (PxU32 ii = 0; ii<mNumRootPages; ii++) { mPages[ii].computeBounds(bound1); if (ii == 0) { retBounds->minimum = PxVec3(bound1.minx, bound1.miny, bound1.minz); retBounds->maximum = PxVec3(bound1.maxx, bound1.maxy, bound1.maxz); } else { retBounds->minimum = retBounds->minimum.minimum(PxVec3(bound1.minx, bound1.miny, bound1.minz)); retBounds->maximum = retBounds->maximum.maximum(PxVec3(bound1.maxx, bound1.maxy, bound1.maxz)); } } } #ifdef PX_CHECKED validate(&cb); #endif }