diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /APEX_1.4/samples_v2/SampleParticlesImpactParticles | |
| download | physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip | |
Initial commit:
PhysX 3.4.0 Update @ 21294896
APEX 1.4.0 Update @ 21275617
[CL 21300167]
Diffstat (limited to 'APEX_1.4/samples_v2/SampleParticlesImpactParticles')
5 files changed, 306 insertions, 0 deletions
diff --git a/APEX_1.4/samples_v2/SampleParticlesImpactParticles/Main.cpp b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/Main.cpp new file mode 100644 index 00000000..2dda1416 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/Main.cpp @@ -0,0 +1,51 @@ +#include "Utils.h" + +#include <DirectXMath.h> +#include "XInput.h" +#include "DXUTMisc.h" +#include "DXUTCamera.h" + + +#include "ApexController.h" +#include "ApexRenderer.h" +#include "CommonUIController.h" +#include "SampleUIController.h" +#include "SampleSceneController.h" + +#include "SampleManager.h" + +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) +{ + PX_UNUSED(hInstance); + PX_UNUSED(hPrevInstance); + PX_UNUSED(lpCmdLine); + PX_UNUSED(nCmdShow); + +// Enable run-time memory check for debug builds. +#if defined(DEBUG) | defined(_DEBUG) + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); + AllocConsole(); +#endif + + SampleManager* sampleManager = new SampleManager(L"APEX Particles Sample: Impact Particles"); + + CFirstPersonCamera camera; + + auto apexController = ApexController(PxDefaultSimulationFilterShader, &camera); + auto apexRender = ApexRenderer(&camera, apexController); + auto sceneController = SampleSceneController(&camera, apexController); + auto commonUiController = CommonUIController(&camera, &apexRender, &apexController); + auto sampleUIController = SampleUIController(&sceneController, &commonUiController); + + sampleManager->addControllerToFront(&apexController); + sampleManager->addControllerToFront(&apexRender); + sampleManager->addControllerToFront(&sceneController); + sampleManager->addControllerToFront(&sampleUIController); + sampleManager->addControllerToFront(&commonUiController); + + int result = sampleManager->run(); + + delete sampleManager; + + return result; +} diff --git a/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleSceneController.cpp b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleSceneController.cpp new file mode 100644 index 00000000..6e8d3adb --- /dev/null +++ b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleSceneController.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 "SampleSceneController.h" +#include "ApexRenderer.h" // for matrix conversion +#include <DirectXMath.h> +#include "XInput.h" +#include "DXUTMisc.h" +#pragma warning(push) +#pragma warning(disable : 4481) // Suppress "nonstandard extension used" warning +#include "DXUTCamera.h" +#pragma warning(pop) + +#include "PxPhysicsAPI.h" +#include "PxMath.h" + +#include "ApexResourceCallback.h" +#include "PhysXPrimitive.h" + +#include "ImpactEmitterAsset.h" +#include "ImpactEmitterActor.h" + +using namespace physx; + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +SampleSceneController::SampleSceneController(CFirstPersonCamera* camera, ApexController& apex) + : mApex(apex), mCamera(camera) +{ +} + +SampleSceneController::~SampleSceneController() +{ +} + +void SampleSceneController::onSampleStart() +{ + // setup camera + DirectX::XMVECTORF32 lookAtPt = { 0, 2, 0, 0 }; + DirectX::XMVECTORF32 eyePt = { 0, 5, 10, 0 }; + mCamera->SetViewParams(eyePt, lookAtPt); + mCamera->SetRotateButtons(false, false, true, false); + mCamera->SetEnablePositionMovement(true); + + // spawn mesh emitter + mAsset = (nvidia::apex::ImpactEmitterAsset *)mApex.getApexSDK()->getNamedResourceProvider()->getResource(IMPACT_EMITTER_AUTHORING_TYPE_NAME, "testImpactEmitter"); + NvParameterized::Interface *defaultActorDesc = mAsset->getDefaultActorDesc(); + NvParameterized::setParamTransform(*defaultActorDesc, "InitialPose", PxTransform(PxIdentity)); + mActor = (ImpactEmitterActor *)mAsset->createApexActor(*defaultActorDesc, *(mApex.getApexScene())); + +} + + +void SampleSceneController::fire(float mouseX, float mouseY) +{ + PxVec3 eyePos, pickDir; + mApex.getEyePoseAndPickDir(mouseX, mouseY, eyePos, pickDir); + + if (pickDir.normalize() <= 0) + { + return; + } + + PxHitFlags outputFlags; + outputFlags |= PxHitFlag::ePOSITION; + outputFlags |= PxHitFlag::eDISTANCE; + PxRaycastBuffer rcBuffer; + bool collision = false; + + PxScene* scene = mApex.getApexScene()->getPhysXScene(); + scene->lockRead(__FILE__, __LINE__); + collision = scene->raycast(eyePos, pickDir, 1e6, rcBuffer, outputFlags); + scene->unlockRead(); + + uint32_t surfType = mAsset->querySetID("meshParticleEvent"); + + mActor->registerImpact(rcBuffer.block.position, pickDir, rcBuffer.block.normal, surfType); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + diff --git a/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleSceneController.h b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleSceneController.h new file mode 100644 index 00000000..ef84613c --- /dev/null +++ b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleSceneController.h @@ -0,0 +1,54 @@ +/* +* 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. +*/ + +#ifndef SCENE_CONTROLLER_H +#define SCENE_CONTROLLER_H + +#include "ApexController.h" +#include "SampleManager.h" +#include "PxPhysicsAPI.h" + +class CFirstPersonCamera; + +namespace nvidia +{ + namespace apex + { + class ImpactEmitterActor; + class ImpactEmitterAsset; + } +} + +using namespace physx; +using namespace nvidia; + + +class SampleSceneController : public ISampleController +{ +public: + SampleSceneController(CFirstPersonCamera* camera, ApexController& apex); + virtual ~SampleSceneController(); + + virtual void onSampleStart(); + + // commands + void fire(float mouseX, float mouseY); + +private: + SampleSceneController& operator= (SampleSceneController&); + + ApexController& mApex; + CFirstPersonCamera* mCamera; + + nvidia::apex::ImpactEmitterActor* mActor; + nvidia::apex::ImpactEmitterAsset* mAsset; +}; + +#endif
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleUIController.cpp b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleUIController.cpp new file mode 100644 index 00000000..2448f65a --- /dev/null +++ b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleUIController.cpp @@ -0,0 +1,70 @@ +/* +* 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 "SampleUIController.h" +#include "SampleSceneController.h" +#include "CommonUIController.h" + +SampleUIController::SampleUIController(SampleSceneController* s, CommonUIController* c) : mScene(s), mCommonUIController(c) +{ +} + +void SampleUIController::onInitialize() +{ + TwBar* sampleBar = TwNewBar("Sample"); + PX_UNUSED(sampleBar); + TwDefine("Sample color='19 25 59' alpha=128 text=light size='200 150' iconified=false valueswidth=150 position='12 480' label='Select Asset'"); + + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_POSITION); + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_VELOCITY); + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_COLLISION_NORMAL); + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_BOUNDS); + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_GRID); + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_BROADPHASE_BOUNDS); + mCommonUIController->addPhysXDebugRenderParam(PxVisualizationParameter::ePARTICLE_SYSTEM_MAX_MOTION_DISTANCE); + + mCommonUIController->addApexDebugRenderParam("VISUALIZE_TURBULENCE_FS_VELOCITY", "TurbulenceFS", 1.0f, "TurbulenceFS velocities"); + mCommonUIController->addApexDebugRenderParam("VISUALIZE_TURBULENCE_FS_BBOX", "TurbulenceFS", 1.0f, "TurbulenceFS BBOX"); + mCommonUIController->addApexDebugRenderParam("VISUALIZE_TURBULENCE_FS_ACTOR_NAME", "TurbulenceFS", 1.0f, "TurbulenceFS name"); + mCommonUIController->addApexDebugRenderParam("VISUALIZE_TURBULENCE_FS_VELOCITY_FIELD", "TurbulenceFS", 1.0f, "TurbulenceFS velocity field"); + mCommonUIController->addApexDebugRenderParam("VISUALIZE_TURBULENCE_FS_STREAMLINES", "TurbulenceFS", 1.0f, "TurbulenceFS streamlines"); + mCommonUIController->addApexDebugRenderParam("VISUALIZE_IOFX_ACTOR", "Iofx", 1.0f, "IOFX actor"); + mCommonUIController->addApexDebugRenderParam("apexEmitterParameters.VISUALIZE_APEX_EMITTER_ACTOR", "Emitter", 1.0f, "Emitter actor"); + + mCommonUIController->addHintLine("Impact - LMB"); +} + +LRESULT SampleUIController::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + PX_UNUSED(hWnd); + PX_UNUSED(wParam); + PX_UNUSED(lParam); + + if (uMsg == WM_LBUTTONDOWN) + { + short mouseX = (short)LOWORD(lParam); + short mouseY = (short)HIWORD(lParam); + mScene->fire(mouseX / static_cast<float>(mWidth), mouseY / static_cast<float>(mHeight)); + } + + return 1; +} + +void SampleUIController::BackBufferResized(ID3D11Device* pDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc) +{ + PX_UNUSED(pDevice); + + mWidth = pBackBufferSurfaceDesc->Width; + mHeight = pBackBufferSurfaceDesc->Height; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// UI Callbacks +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleUIController.h b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleUIController.h new file mode 100644 index 00000000..93fe5bbf --- /dev/null +++ b/APEX_1.4/samples_v2/SampleParticlesImpactParticles/SampleUIController.h @@ -0,0 +1,39 @@ +/* +* 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. +*/ + +#ifndef SAMPLE_UI_CONTROLLER_H +#define SAMPLE_UI_CONTROLLER_H + +#include "SampleManager.h" +#include <DirectXMath.h> +#include "AntTweakBar.h" + +class SampleSceneController; +class CommonUIController; + +class SampleUIController : public ISampleController +{ + public: + SampleUIController(SampleSceneController* s, CommonUIController* c); + + virtual void onInitialize(); + virtual LRESULT MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + virtual void BackBufferResized(ID3D11Device* pDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc); + + private: + SampleSceneController* mScene; + CommonUIController* mCommonUIController; + TwBar* mSettingsBar; + + UINT mWidth; + UINT mHeight; +}; + +#endif
\ No newline at end of file |