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