// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2019 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 "vehicle/PxVehicleUtilTelemetry.h" #include "PsFoundation.h" #include "PsUtilities.h" #include "stdio.h" #include "CmPhysXCommon.h" namespace physx { #if PX_DEBUG_VEHICLE_ON PxVehicleGraphDesc::PxVehicleGraphDesc() : mPosX(PX_MAX_F32), mPosY(PX_MAX_F32), mSizeX(PX_MAX_F32), mSizeY(PX_MAX_F32), mBackgroundColor(PxVec3(PX_MAX_F32,PX_MAX_F32,PX_MAX_F32)), mAlpha(PX_MAX_F32) { } bool PxVehicleGraphDesc::isValid() const { PX_CHECK_AND_RETURN_VAL(mPosX != PX_MAX_F32, "PxVehicleGraphDesc.mPosX must be initialised", false); PX_CHECK_AND_RETURN_VAL(mPosY != PX_MAX_F32, "PxVehicleGraphDesc.mPosY must be initialised", false); PX_CHECK_AND_RETURN_VAL(mSizeX != PX_MAX_F32, "PxVehicleGraphDesc.mSizeX must be initialised", false); PX_CHECK_AND_RETURN_VAL(mSizeY != PX_MAX_F32, "PxVehicleGraphDesc.mSizeY must be initialised", false); PX_CHECK_AND_RETURN_VAL(mBackgroundColor.x != PX_MAX_F32 && mBackgroundColor.y != PX_MAX_F32 && mBackgroundColor.z != PX_MAX_F32, "PxVehicleGraphDesc.mBackgroundColor must be initialised", false); PX_CHECK_AND_RETURN_VAL(mAlpha != PX_MAX_F32, "PxVehicleGraphDesc.mAlpha must be initialised", false); return true; } PxVehicleGraphChannelDesc::PxVehicleGraphChannelDesc() : mMinY(PX_MAX_F32), mMaxY(PX_MAX_F32), mMidY(PX_MAX_F32), mColorLow(PxVec3(PX_MAX_F32,PX_MAX_F32,PX_MAX_F32)), mColorHigh(PxVec3(PX_MAX_F32,PX_MAX_F32,PX_MAX_F32)), mTitle(NULL) { } bool PxVehicleGraphChannelDesc::isValid() const { PX_CHECK_AND_RETURN_VAL(mMinY != PX_MAX_F32, "PxVehicleGraphChannelDesc.mMinY must be initialised", false); PX_CHECK_AND_RETURN_VAL(mMaxY != PX_MAX_F32, "PxVehicleGraphChannelDesc.mMaxY must be initialised", false); PX_CHECK_AND_RETURN_VAL(mMidY != PX_MAX_F32, "PxVehicleGraphChannelDesc.mMidY must be initialised", false); PX_CHECK_AND_RETURN_VAL(mColorLow.x != PX_MAX_F32 && mColorLow.y != PX_MAX_F32 && mColorLow.z != PX_MAX_F32, "PxVehicleGraphChannelDesc.mColorLow must be initialised", false); PX_CHECK_AND_RETURN_VAL(mColorHigh.x != PX_MAX_F32 && mColorHigh.y != PX_MAX_F32 && mColorHigh.z != PX_MAX_F32, "PxVehicleGraphChannelDesc.mColorHigh must be initialised", false); PX_CHECK_AND_RETURN_VAL(mTitle, "PxVehicleGraphChannelDesc.mTitle must be initialised", false); return true; } PxVehicleGraph::PxVehicleGraph() { mBackgroundMinX=0; mBackgroundMaxX=0; mBackgroundMinY=0; mBackgroundMaxY=0; mSampleTide=0; mBackgroundColor=PxVec3(255.f,255.f,255.f); mBackgroundAlpha=1.0f; for(PxU32 i=0;i= size_t(PxVehicleDriveGraphChannel::eMAX_NB_DRIVE_CHANNELS) && size_t(PxVehicleGraph::eMAX_NB_CHANNELS) >= size_t(PxVehicleWheelGraphChannel::eMAX_NB_WHEEL_CHANNELS)); } PxVehicleGraph::~PxVehicleGraph() { } void PxVehicleGraph::setup(const PxVehicleGraphDesc& desc, const PxVehicleGraphType::Enum graphType) { mBackgroundMinX = (desc.mPosX - 0.5f*desc.mSizeX); mBackgroundMaxX = (desc.mPosX + 0.5f*desc.mSizeX); mBackgroundMinY = (desc.mPosY - 0.5f*desc.mSizeY); mBackgroundMaxY = (desc.mPosY + 0.5f*desc.mSizeY); mBackgroundColor=desc.mBackgroundColor; mBackgroundAlpha=desc.mAlpha; mNbChannels = (PxVehicleGraphType::eWHEEL==graphType) ? PxU32(PxVehicleWheelGraphChannel::eMAX_NB_WHEEL_CHANNELS) : PxU32(PxVehicleDriveGraphChannel::eMAX_NB_DRIVE_CHANNELS); } void PxVehicleGraph::setChannel(PxVehicleGraphChannelDesc& desc, const PxU32 channel) { PX_ASSERT(channel(PX_ALLOC(size, "PxVehicleNWTelemetryData")); //Patch up the pointers. PxU8* ptr = reinterpret_cast(vehTelData) + sizeof(PxVehicleTelemetryData); vehTelData->mEngineGraph = reinterpret_cast(ptr); new(vehTelData->mEngineGraph) PxVehicleGraph(); ptr += sizeof(PxVehicleGraph); vehTelData->mWheelGraphs = reinterpret_cast(ptr); for(PxU32 i=0;imWheelGraphs[i]) PxVehicleGraph(); } ptr += sizeof(PxVehicleGraph)*numWheels; vehTelData->mSuspforceAppPoints = reinterpret_cast(ptr); ptr += sizeof(PxVec3)*numWheels; vehTelData->mTireforceAppPoints = reinterpret_cast(ptr); ptr += sizeof(PxVec3)*numWheels; //Set the number of wheels in each structure that needs it. vehTelData->mNbActiveWheels=numWheels; //Finished. return vehTelData; } void PxVehicleTelemetryData::free() { PX_FREE(this); } void physx::PxVehicleTelemetryData::setup (const PxF32 graphSizeX, const PxF32 graphSizeY, const PxF32 engineGraphPosX, const PxF32 engineGraphPosY, const PxF32* const wheelGraphPosX, const PxF32* const wheelGraphPosY, const PxVec3& backgroundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow) { mEngineGraph->setupEngineGraph (graphSizeX, graphSizeY, engineGraphPosX, engineGraphPosY, backgroundColor, lineColorHigh, lineColorLow); const PxU32 numActiveWheels=mNbActiveWheels; for(PxU32 k=0;kclearRecordedChannelData(); const PxU32 numActiveWheels=mNbActiveWheels; for(PxU32 k=0;k