diff options
| author | Bryan Galdrikian <[email protected]> | 2017-02-24 09:32:20 -0800 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2017-02-24 09:32:20 -0800 |
| commit | e1bf674c16e3c8472b29574159c789cd3f0c64e0 (patch) | |
| tree | 9f0cfce09c71a2c27ff19589fcad6cd83504477c /samples/SampleBase/blast/BlastFamilyBoxes.cpp | |
| parent | first commit (diff) | |
| download | archived-blast-e1bf674c16e3c8472b29574159c789cd3f0c64e0.tar.xz archived-blast-e1bf674c16e3c8472b29574159c789cd3f0c64e0.zip | |
Updating to [email protected] and [email protected] with a new directory structure.
NvBlast folder is gone, files have been moved to top level directory. README is changed to reflect this.
Diffstat (limited to 'samples/SampleBase/blast/BlastFamilyBoxes.cpp')
| -rw-r--r-- | samples/SampleBase/blast/BlastFamilyBoxes.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/samples/SampleBase/blast/BlastFamilyBoxes.cpp b/samples/SampleBase/blast/BlastFamilyBoxes.cpp new file mode 100644 index 0000000..e8b7b27 --- /dev/null +++ b/samples/SampleBase/blast/BlastFamilyBoxes.cpp @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. +* +* NVIDIA CORPORATION and its licensors retain all intellectual property +* and proprietary rights in and to this software, related documentation +* and any modifications thereto. Any use, reproduction, disclosure or +* distribution of this software and related documentation without an express +* license agreement from NVIDIA CORPORATION is strictly prohibited. +*/ + + +#include "BlastFamilyBoxes.h" +#include "NvBlastExtPxAsset.h" +#include "NvBlastExtPxActor.h" +#include "BlastAssetBoxes.h" +#include "Renderer.h" +#include "PhysXController.h" +#include "RenderUtils.h" +#include "PxRigidDynamic.h" + +using namespace physx; + + +BlastFamilyBoxes::BlastFamilyBoxes(PhysXController& physXController, ExtPxManager& pxManager, Renderer& renderer, const BlastAssetBoxes& blastAsset, const BlastAsset::ActorDesc& desc) + : BlastFamily(physXController, pxManager, blastAsset), m_renderer(renderer) +{ + // prepare renderables + IRenderMesh* boxRenderMesh = renderer.getPrimitiveRenderMesh(PrimitiveRenderMeshType::Box); + RenderMaterial* primitiveRenderMaterial = physXController.getPrimitiveRenderMaterial(); + + const ExtPxAsset* pxAsset = m_blastAsset.getPxAsset(); + const uint32_t chunkCount = pxAsset->getChunkCount(); + const ExtPxChunk* chunks = pxAsset->getChunks(); + const ExtPxSubchunk* subChunks = pxAsset->getSubchunks(); + m_chunkRenderables.resize(chunkCount); + for (uint32_t i = 0; i < chunkCount; i++) + { + Renderable* renderable = renderer.createRenderable(*boxRenderMesh, *primitiveRenderMaterial); + renderable->setHidden(true); + renderable->setScale(subChunks[chunks[i].firstSubchunkIndex].geometry.scale.scale); + m_chunkRenderables[i] = renderable; + } + + // initialize in position + initialize(desc); +} + +BlastFamilyBoxes::~BlastFamilyBoxes() +{ + for (uint32_t i = 0; i < m_chunkRenderables.size(); i++) + { + m_renderer.removeRenderable(m_chunkRenderables[i]); + } +} + +void BlastFamilyBoxes::onActorCreated(const ExtPxActor& actor) +{ + DirectX::XMFLOAT4 color = getRandomPastelColor(); + + const uint32_t* chunkIndices = actor.getChunkIndices(); + uint32_t chunkCount = actor.getChunkCount(); + for (uint32_t i = 0; i < chunkCount; i++) + { + const uint32_t chunkIndex = chunkIndices[i]; + m_chunkRenderables[chunkIndex]->setHidden(false); + m_chunkRenderables[chunkIndex]->setColor(color); + } +} + +void BlastFamilyBoxes::onActorUpdate(const ExtPxActor& actor) +{ + const ExtPxChunk* chunks = m_blastAsset.getPxAsset()->getChunks(); + const ExtPxSubchunk* subChunks = m_blastAsset.getPxAsset()->getSubchunks(); + const uint32_t* chunkIndices = actor.getChunkIndices(); + uint32_t chunkCount = actor.getChunkCount(); + for (uint32_t i = 0; i < chunkCount; i++) + { + const uint32_t chunkIndex = chunkIndices[i]; + m_chunkRenderables[chunkIndex]->setTransform(actor.getPhysXActor().getGlobalPose() * subChunks[chunks[chunkIndex].firstSubchunkIndex].transform); + } +} + +void BlastFamilyBoxes::onActorDestroyed(const ExtPxActor& actor) +{ + const uint32_t* chunkIndices = actor.getChunkIndices(); + uint32_t chunkCount = actor.getChunkCount(); + for (uint32_t i = 0; i < chunkCount; i++) + { + m_chunkRenderables[chunkIndices[i]]->setHidden(true); + } + +} |