// This code contains NVIDIA Confidential Information and is disclosed to you // under a form of NVIDIA software license agreement provided separately to you. // // Notice // NVIDIA Corporation and its licensors retain all intellectual property and // proprietary rights in and to this software and 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. // // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. // // Information and code furnished is believed to be accurate and reliable. // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such // information or for any infringement of patents or other rights of third parties that may // result from its use. No license is granted by implication or otherwise under any patent // or patent rights of NVIDIA Corporation. Details are subject to change without notice. // This code supersedes and replaces all information previously supplied. // NVIDIA Corporation products are not authorized for use as critical // components in life support devices or systems without express written approval of // NVIDIA Corporation. // // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. #include "SamplePreprocessor.h" #include "SampleHelloWorld.h" #include "SampleUtils.h" #include "SampleConsole.h" #include "RendererMemoryMacros.h" #include "RenderMeshActor.h" #include "PxPhysics.h" #include "PxScene.h" #include "PxRigidDynamic.h" #include "PxShape.h" #include "PxPhysicsAPI.h" #include "RenderBoxActor.h" #include #include #include #include #include using namespace SampleRenderer; using namespace SampleFramework; REGISTER_SAMPLE(SampleHelloWorld, "SampleHelloWorld") /////////////////////////////////////////////////////////////////////////////// SampleHelloWorld::SampleHelloWorld(PhysXSampleApplication& app) : PhysXSample(app) { } SampleHelloWorld::~SampleHelloWorld() { } void SampleHelloWorld::onTickPreRender(float dtime) { PhysXSample::onTickPreRender(dtime); } void SampleHelloWorld::onTickPostRender(float dtime) { PhysXSample::onTickPostRender(dtime); } void SampleHelloWorld::customizeSceneDesc(PxSceneDesc& sceneDesc) { sceneDesc.flags |= PxSceneFlag::eREQUIRE_RW_LOCK; } void SampleHelloWorld::newMesh(const RAWMesh& data) { } static void gValue(Console* console, const char* text, void* userData) { if(!text) { console->out("Usage: value "); return; } const float val = (float)::atof(text); shdfnd::printFormatted("value: %f\n", val); } static void gExport(Console* console, const char* text, void* userData) { if(!text) { console->out("Usage: export "); return; } } static void gImport(Console* console, const char* text, void* userData) { if(!text) { console->out("Usage: import "); return; } } void SampleHelloWorld::onInit() { if(getConsole()) { getConsole()->addCmd("value", gValue); getConsole()->addCmd("export", gExport); getConsole()->addCmd("import", gImport); } PhysXSample::onInit(); mApplication.setMouseCursorHiding(true); mApplication.setMouseCursorRecentering(true); mCameraController.init(PxVec3(0.0f, 10.0f, 0.0f), PxVec3(0.0f, 0.0f, 0.0f)); mCameraController.setMouseSensitivity(0.5f); } void SampleHelloWorld::collectInputEvents(std::vector& inputEvents) { PhysXSample::collectInputEvents(inputEvents); getApplication().getPlatform()->getSampleUserInput()->unregisterInputEvent(CAMERA_SPEED_INCREASE); getApplication().getPlatform()->getSampleUserInput()->unregisterInputEvent(CAMERA_SPEED_DECREASE); //touch events TOUCH_INPUT_EVENT_DEF(SPAWN_DEBUG_OBJECT, "Throw Object", ABUTTON_5, IBUTTON_5); } void SampleHelloWorld::helpRender(PxU32 x, PxU32 y, PxU8 textAlpha) { Renderer* renderer = getRenderer(); const PxU32 yInc = 18; const PxReal scale = 0.5f; const PxReal shadowOffset = 6.0f; const RendererColor textColor(255, 255, 255, textAlpha); const bool isMouseSupported = getApplication().getPlatform()->getSampleUserInput()->mouseSupported(); const bool isPadSupported = getApplication().getPlatform()->getSampleUserInput()->gamepadSupported(); const char* msg; if (isMouseSupported && isPadSupported) renderer->print(x, y += yInc, "Use mouse or right stick to rotate", scale, shadowOffset, textColor); else if (isMouseSupported) renderer->print(x, y += yInc, "Use mouse to rotate", scale, shadowOffset, textColor); else if (isPadSupported) renderer->print(x, y += yInc, "Use right stick to rotate", scale, shadowOffset, textColor); if (isPadSupported) renderer->print(x, y += yInc, "Use left stick to move",scale, shadowOffset, textColor); msg = mApplication.inputMoveInfoMsg("Press "," to move", CAMERA_MOVE_FORWARD,CAMERA_MOVE_BACKWARD, CAMERA_MOVE_LEFT, CAMERA_MOVE_RIGHT); if(msg) renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor); msg = mApplication.inputInfoMsg("Press "," to move fast", CAMERA_SHIFT_SPEED, -1); if(msg) renderer->print(x, y += yInc, msg, scale, shadowOffset, textColor); msg = mApplication.inputInfoMsg("Press "," to throw an object", SPAWN_DEBUG_OBJECT, -1); if(msg) renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor); } void SampleHelloWorld::descriptionRender(PxU32 x, PxU32 y, PxU8 textAlpha) { bool print=(textAlpha!=0.0f); if(print) { Renderer* renderer = getRenderer(); const PxU32 yInc = 18; const PxReal scale = 0.5f; const PxReal shadowOffset = 6.0f; const RendererColor textColor(255, 255, 255, textAlpha); char line1[256]="This sample demonstrates how to set up and simulate a PhysX"; char line2[256]="scene. Further, it illustrates the creation, simulation and"; char line3[256]="collision of simple dynamic objects."; renderer->print(x, y+=yInc, line1, scale, shadowOffset, textColor); renderer->print(x, y+=yInc, line2, scale, shadowOffset, textColor); renderer->print(x, y+=yInc, line3, scale, shadowOffset, textColor); } } PxU32 SampleHelloWorld::getDebugObjectTypes() const { return DEBUG_OBJECT_BOX | DEBUG_OBJECT_SPHERE | DEBUG_OBJECT_CAPSULE | DEBUG_OBJECT_CONVEX; }