| 1 | // |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions |
| 4 | // are met: |
| 5 | // * Redistributions of source code must retain the above copyright |
| 6 | // notice, this list of conditions and the following disclaimer. |
| 7 | // * Redistributions in binary form must reproduce the above copyright |
| 8 | // notice, this list of conditions and the following disclaimer in the |
| 9 | // documentation and/or other materials provided with the distribution. |
| 10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
| 11 | // contributors may be used to endorse or promote products derived |
| 12 | // from this software without specific prior written permission. |
| 13 | // |
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
| 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | // |
| 26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
| 27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 29 | |
| 30 | #ifndef PX_VEHICLE_UTILSTELEMETRY_H |
| 31 | #define PX_VEHICLE_UTILSTELEMETRY_H |
| 32 | /** \addtogroup vehicle |
| 33 | @{ |
| 34 | */ |
| 35 | |
| 36 | #include "vehicle/PxVehicleSDK.h" |
| 37 | #include "foundation/PxSimpleTypes.h" |
| 38 | #include "foundation/PxVec3.h" |
| 39 | |
| 40 | #if !PX_DOXYGEN |
| 41 | namespace physx |
| 42 | { |
| 43 | #endif |
| 44 | |
| 45 | #if PX_DEBUG_VEHICLE_ON |
| 46 | |
| 47 | class PxVehicleGraphDesc |
| 48 | { |
| 49 | |
| 50 | friend class PxVehicleGraph; |
| 51 | |
| 52 | PxVehicleGraphDesc(); |
| 53 | |
| 54 | /** |
| 55 | \brief x-coord of graph centre. |
| 56 | <b>Range:</b> (0,1)<br> |
| 57 | */ |
| 58 | PxReal mPosX; |
| 59 | |
| 60 | /** |
| 61 | \brief y-coord of graph centre. |
| 62 | <b>Range:</b> (0,1)<br> |
| 63 | */ |
| 64 | PxReal mPosY; |
| 65 | |
| 66 | /** |
| 67 | \brief x-extents of graph (from mPosX-0.5f*mSizeX to mPosX+0.5f*mSizeX). |
| 68 | <b>Range:</b> (0,1)<br> |
| 69 | */ |
| 70 | PxReal mSizeX; |
| 71 | |
| 72 | /** |
| 73 | \brief y-extents of graph (from mPosY-0.5f*mSizeY to mPosY+0.5f*mSizeY). |
| 74 | <b>Range:</b> (0,1)<br> |
| 75 | */ |
| 76 | PxReal mSizeY; |
| 77 | |
| 78 | /** |
| 79 | \brief Background color of graph. |
| 80 | */ |
| 81 | PxVec3 mBackgroundColor; |
| 82 | |
| 83 | /** |
| 84 | \brief Alpha value of background color. |
| 85 | */ |
| 86 | PxReal mAlpha; |
| 87 | |
| 88 | private: |
| 89 | |
| 90 | bool isValid() const; |
| 91 | }; |
| 92 | |
| 93 | struct PxVehicleGraphChannelDesc |
| 94 | { |
| 95 | public: |
| 96 | |
| 97 | friend class PxVehicleGraph; |
| 98 | |
| 99 | PxVehicleGraphChannelDesc(); |
| 100 | |
| 101 | /** |
| 102 | \brief Data values less than mMinY will be clamped at mMinY. |
| 103 | */ |
| 104 | PxReal mMinY; |
| 105 | |
| 106 | /** |
| 107 | \brief Data values greater than mMaxY will be clamped at mMaxY. |
| 108 | */ |
| 109 | PxReal mMaxY; |
| 110 | |
| 111 | /** |
| 112 | \brief Data values greater than mMidY will be drawn with color mColorHigh. |
| 113 | Data values less than mMidY will be drawn with color mColorLow. |
| 114 | */ |
| 115 | PxReal mMidY; |
| 116 | |
| 117 | /** |
| 118 | \brief Color used to render data values lower than mMidY. |
| 119 | */ |
| 120 | PxVec3 mColorLow; |
| 121 | |
| 122 | /** |
| 123 | \brief Color used to render data values greater than mMidY. |
| 124 | */ |
| 125 | PxVec3 mColorHigh; |
| 126 | |
| 127 | /** |
| 128 | \brief String to describe data channel. |
| 129 | */ |
| 130 | char* mTitle; |
| 131 | |
| 132 | private: |
| 133 | |
| 134 | bool isValid() const; |
| 135 | }; |
| 136 | |
| 137 | struct PxVehicleWheelGraphChannel |
| 138 | { |
| 139 | enum Enum |
| 140 | { |
| 141 | eJOUNCE=0, |
| 142 | eSUSPFORCE, |
| 143 | eTIRELOAD, |
| 144 | eNORMALIZED_TIRELOAD, |
| 145 | eWHEEL_OMEGA, |
| 146 | eTIRE_FRICTION, |
| 147 | eTIRE_LONG_SLIP, |
| 148 | eNORM_TIRE_LONG_FORCE, |
| 149 | eTIRE_LAT_SLIP, |
| 150 | eNORM_TIRE_LAT_FORCE, |
| 151 | eNORM_TIRE_ALIGNING_MOMENT, |
| 152 | eMAX_NB_WHEEL_CHANNELS |
| 153 | }; |
| 154 | }; |
| 155 | |
| 156 | struct PxVehicleDriveGraphChannel |
| 157 | { |
| 158 | enum Enum |
| 159 | { |
| 160 | eENGINE_REVS=0, |
| 161 | eENGINE_DRIVE_TORQUE, |
| 162 | eCLUTCH_SLIP, |
| 163 | eACCEL_CONTROL, //TANK_ACCEL |
| 164 | eBRAKE_CONTROL, //TANK_BRAKE_LEFT |
| 165 | eHANDBRAKE_CONTROL, //TANK_BRAKE_RIGHT |
| 166 | eSTEER_LEFT_CONTROL, //TANK_THRUST_LEFT |
| 167 | eSTEER_RIGHT_CONTROL, //TANK_THRUST_RIGHT |
| 168 | eGEAR_RATIO, |
| 169 | eMAX_NB_DRIVE_CHANNELS |
| 170 | }; |
| 171 | }; |
| 172 | |
| 173 | struct PxVehicleGraphType |
| 174 | { |
| 175 | enum Enum |
| 176 | { |
| 177 | eWHEEL=0, |
| 178 | eDRIVE |
| 179 | }; |
| 180 | }; |
| 181 | |
| 182 | |
| 183 | class PxVehicleGraph |
| 184 | { |
| 185 | public: |
| 186 | |
| 187 | friend class PxVehicleTelemetryData; |
| 188 | friend class PxVehicleUpdate; |
| 189 | |
| 190 | enum |
| 191 | { |
| 192 | eMAX_NB_SAMPLES=256 |
| 193 | }; |
| 194 | |
| 195 | enum |
| 196 | { |
| 197 | eMAX_NB_TITLE_CHARS=256 |
| 198 | }; |
| 199 | |
| 200 | enum |
| 201 | { |
| 202 | eMAX_NB_CHANNELS=12 |
| 203 | }; |
| 204 | |
| 205 | /** |
| 206 | \brief Setup a graph from a descriptor. |
| 207 | */ |
| 208 | void setup(const PxVehicleGraphDesc& desc, const PxVehicleGraphType::Enum graphType); |
| 209 | |
| 210 | /** |
| 211 | \brief Clear all data recorded in a graph. |
| 212 | */ |
| 213 | void clearRecordedChannelData(); |
| 214 | |
| 215 | /** |
| 216 | \brief Get the color of the graph background. Used for rendering a graph. |
| 217 | */ |
| 218 | const PxVec3& getBackgroundColor() const {return mBackgroundColor;} |
| 219 | |
| 220 | /** |
| 221 | \brief Get the alpha transparency of the color of the graph background. Used for rendering a graph. |
| 222 | */ |
| 223 | PxReal getBackgroundAlpha() const {return mBackgroundAlpha;} |
| 224 | |
| 225 | /** |
| 226 | \brief Get the coordinates of the graph background. Used for rendering a graph |
| 227 | |
| 228 | \param[out] xMin is the x-coord of the lower-left corner |
| 229 | \param[out] yMin is the y-coord of the lower-left corner |
| 230 | \param[out] xMax is the x-coord of the upper-right corner |
| 231 | \param[out] yMax is the y-coord of the upper-right corner |
| 232 | */ |
| 233 | void getBackgroundCoords(PxReal& xMin, PxReal& yMin, PxReal& xMax, PxReal& yMax) const {xMin = mBackgroundMinX;xMax = mBackgroundMaxX;yMin = mBackgroundMinY;yMax = mBackgroundMaxY;} |
| 234 | |
| 235 | /** |
| 236 | \brief Compute the coordinates of the graph data of a specific graph channel. |
| 237 | |
| 238 | \param[out] xy is an array of graph sample coordinates stored in order x0,y0,x1,y1,x2,y2...xn,yn. |
| 239 | \param[out] colors stores the color of each point on the graph. |
| 240 | \param[out] title is the title of the graph. |
| 241 | */ |
| 242 | void computeGraphChannel(const PxU32 channel, PxReal* xy, PxVec3* colors, char* title) const; |
| 243 | |
| 244 | /** |
| 245 | \brief Return the latest value stored in the specified graph channel |
| 246 | */ |
| 247 | PxF32 getLatestValue(const PxU32 channel) const ; |
| 248 | |
| 249 | /** |
| 250 | \brief Get the raw data of a specific graph channel. |
| 251 | |
| 252 | \param[in] channel is the ID of the graph channel to get data from. |
| 253 | \param[out] values is the buffer to write the data to. Minimum required size is eMAX_NB_SAMPLES. |
| 254 | */ |
| 255 | void getRawData(const PxU32 channel, PxReal* values) const; |
| 256 | |
| 257 | private: |
| 258 | |
| 259 | //Min and max of each sample. |
| 260 | PxReal mChannelMinY[eMAX_NB_CHANNELS]; |
| 261 | PxReal mChannelMaxY[eMAX_NB_CHANNELS]; |
| 262 | //Discriminate between high and low values with different colors. |
| 263 | PxReal mChannelMidY[eMAX_NB_CHANNELS]; |
| 264 | //Different colors for values than midY and less than midY. |
| 265 | PxVec3 mChannelColorLow[eMAX_NB_CHANNELS]; |
| 266 | PxVec3 mChannelColorHigh[eMAX_NB_CHANNELS]; |
| 267 | //Title of graph |
| 268 | char mChannelTitle[eMAX_NB_CHANNELS][eMAX_NB_TITLE_CHARS]; |
| 269 | //Graph data. |
| 270 | PxReal mChannelSamples[eMAX_NB_CHANNELS][eMAX_NB_SAMPLES]; |
| 271 | |
| 272 | //Background color,alpha,coords |
| 273 | PxVec3 mBackgroundColor; |
| 274 | PxReal mBackgroundAlpha; |
| 275 | PxReal mBackgroundMinX; |
| 276 | PxReal mBackgroundMaxX; |
| 277 | PxReal mBackgroundMinY; |
| 278 | PxReal mBackgroundMaxY; |
| 279 | |
| 280 | PxU32 mSampleTide; |
| 281 | |
| 282 | PxU32 mNbChannels; |
| 283 | |
| 284 | PxU32 mPad[2]; |
| 285 | |
| 286 | |
| 287 | void setup |
| 288 | (const PxF32 graphSizeX, const PxF32 graphSizeY, |
| 289 | const PxF32 engineGraphPosX, const PxF32 engineGraphPosY, |
| 290 | const PxF32* const wheelGraphPosX, const PxF32* const wheelGraphPosY, |
| 291 | const PxVec3& backgroundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow); |
| 292 | |
| 293 | void updateTimeSlice(const PxReal* const samples); |
| 294 | |
| 295 | void setChannel(PxVehicleGraphChannelDesc& desc, const PxU32 channel); |
| 296 | |
| 297 | void setupEngineGraph |
| 298 | (const PxF32 sizeX, const PxF32 sizeY, const PxF32 posX, const PxF32 posY, |
| 299 | const PxVec3& backgoundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow); |
| 300 | |
| 301 | void setupWheelGraph |
| 302 | (const PxF32 sizeX, const PxF32 sizeY, const PxF32 posX, const PxF32 posY, |
| 303 | const PxVec3& backgoundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow); |
| 304 | |
| 305 | PxVehicleGraph(); |
| 306 | ~PxVehicleGraph(); |
| 307 | }; |
| 308 | PX_COMPILE_TIME_ASSERT(PxU32(PxVehicleGraph::eMAX_NB_CHANNELS) >= PxU32(PxVehicleWheelGraphChannel::eMAX_NB_WHEEL_CHANNELS) && PxU32(PxVehicleGraph::eMAX_NB_CHANNELS) >= PxU32(PxVehicleDriveGraphChannel::eMAX_NB_DRIVE_CHANNELS)); |
| 309 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleGraph) & 15)); |
| 310 | |
| 311 | class PxVehicleTelemetryData |
| 312 | { |
| 313 | public: |
| 314 | |
| 315 | friend class PxVehicleUpdate; |
| 316 | |
| 317 | /** |
| 318 | \brief Allocate a PxVehicleNWTelemetryData instance for a vehicle with nbWheels |
| 319 | @see PxVehicleNWTelemetryDataFree |
| 320 | */ |
| 321 | static PxVehicleTelemetryData* allocate(const PxU32 nbWheels); |
| 322 | |
| 323 | /** |
| 324 | \brief Free a PxVehicleNWTelemetryData instance for a vehicle. |
| 325 | @see PxVehicleNWTelemetryDataAllocate |
| 326 | */ |
| 327 | void free(); |
| 328 | |
| 329 | /** |
| 330 | \brief Set up all the graphs so that they are ready to record data. |
| 331 | */ |
| 332 | void setup |
| 333 | (const PxReal graphSizeX, const PxReal graphSizeY, |
| 334 | const PxReal engineGraphPosX, const PxReal engineGraphPosY, |
| 335 | const PxReal* const wheelGraphPosX, const PxReal* const wheelGraphPosY, |
| 336 | const PxVec3& backGroundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow); |
| 337 | |
| 338 | /** |
| 339 | \brief Clear the graphs of recorded data. |
| 340 | */ |
| 341 | void clear(); |
| 342 | |
| 343 | /** |
| 344 | \brief Get the graph data for the engine |
| 345 | */ |
| 346 | const PxVehicleGraph& getEngineGraph() const {return *mEngineGraph;} |
| 347 | |
| 348 | /** |
| 349 | \brief Get the number of wheel graphs |
| 350 | */ |
| 351 | PxU32 getNbWheelGraphs() const {return mNbActiveWheels;} |
| 352 | |
| 353 | /** |
| 354 | \brief Get the graph data for the kth wheel |
| 355 | */ |
| 356 | const PxVehicleGraph& getWheelGraph(const PxU32 k) const {return mWheelGraphs[k];} |
| 357 | |
| 358 | /** |
| 359 | \brief Get the array of tire force application points so they can be rendered |
| 360 | */ |
| 361 | const PxVec3* getTireforceAppPoints() const {return mTireforceAppPoints;} |
| 362 | |
| 363 | /** |
| 364 | \brief Get the array of susp force application points so they can be rendered |
| 365 | */ |
| 366 | const PxVec3* getSuspforceAppPoints() const {return mSuspforceAppPoints;} |
| 367 | |
| 368 | private: |
| 369 | |
| 370 | /** |
| 371 | \brief Graph data for engine. |
| 372 | Used for storing single timeslices of debug data for engine graph. |
| 373 | @see PxVehicleGraph |
| 374 | */ |
| 375 | PxVehicleGraph* mEngineGraph; |
| 376 | |
| 377 | /** |
| 378 | \brief Graph data for each wheel. |
| 379 | Used for storing single timeslices of debug data for wheel graphs. |
| 380 | @see PxVehicleGraph |
| 381 | */ |
| 382 | PxVehicleGraph* mWheelGraphs; |
| 383 | |
| 384 | /** |
| 385 | \brief Application point of tire forces. |
| 386 | */ |
| 387 | PxVec3* mTireforceAppPoints; |
| 388 | |
| 389 | /** |
| 390 | \brief Application point of susp forces. |
| 391 | */ |
| 392 | PxVec3* mSuspforceAppPoints; |
| 393 | |
| 394 | /** |
| 395 | \brief Total number of active wheels |
| 396 | */ |
| 397 | PxU32 mNbActiveWheels; |
| 398 | |
| 399 | PxU32 mPad[3]; |
| 400 | |
| 401 | private: |
| 402 | |
| 403 | PxVehicleTelemetryData(){} |
| 404 | ~PxVehicleTelemetryData(){} |
| 405 | }; |
| 406 | |
| 407 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleTelemetryData) & 15)); |
| 408 | |
| 409 | #endif //PX_DEBUG_VEHICLE_ON |
| 410 | |
| 411 | //#endif // PX_DEBUG_VEHICLE_ON |
| 412 | |
| 413 | #if !PX_DOXYGEN |
| 414 | } // namespace physx |
| 415 | #endif |
| 416 | |
| 417 | /** @} */ |
| 418 | #endif //PX_VEHICLE_UTILSTELEMETRY_H |
| 419 | |