RavEngine
Loading...
Searching...
No Matches
SnippetUtils.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26
27#include "foundation/Px.h"
28#include "foundation/PxSimpleTypes.h"
29
30namespace physx
31{
32 namespace SnippetUtils
33 {
35
36 void setRotX(PxMat33& m, PxReal angle);
37 void setRotY(PxMat33& m, PxReal angle);
38 void setRotZ(PxMat33& m, PxReal angle);
39
40 PxQuat getRotXQuat(float angle);
41 PxQuat getRotYQuat(float angle);
42 PxQuat getRotZQuat(float angle);
43
45
47 {
48 public:
49 BasicRandom(PxU32 seed=0) : mRnd(seed) {}
50 ~BasicRandom() {}
51
52 PX_FORCE_INLINE void setSeed(PxU32 seed) { mRnd = seed; }
53 PX_FORCE_INLINE PxU32 getCurrentValue() const { return mRnd; }
54 PxU32 randomize() { mRnd = mRnd * 2147001325 + 715136305; return mRnd; }
55
56 PX_FORCE_INLINE PxU32 rand() { return randomize() & 0xffff; }
57 PX_FORCE_INLINE PxU32 rand32() { return randomize() & 0xffffffff; }
58
59 PxF32 rand(PxF32 a, PxF32 b)
60 {
61 const PxF32 r = rand32()/(static_cast<PxF32>(0xffffffff));
62 return r*(b-a) + a;
63 }
64
65 PxI32 rand(PxI32 a, PxI32 b)
66 {
67 return a + static_cast<PxI32>(rand32()%(b-a));
68 }
69
70 PxF32 randomFloat()
71 {
72 return rand()/(static_cast<PxF32>(0xffff)) - 0.5f;
73 }
74 PxF32 randomFloat32()
75 {
76 return rand32()/(static_cast<PxF32>(0xffffffff)) - 0.5f;
77 }
78
79 PxF32 randomFloat32(PxReal a, PxReal b) { return rand32()/PxF32(0xffffffff)*(b-a)+a; }
80 void unitRandomPt(physx::PxVec3& v);
81 void unitRandomQuat(physx::PxQuat& v);
82
83 PxVec3 unitRandomPt();
84 PxQuat unitRandomQuat();
85 private:
86 PxU32 mRnd;
87 };
88
90
91 PxU32 Bunny_getNbVerts();
92 PxU32 Bunny_getNbFaces();
93 const PxVec3* Bunny_getVerts();
94 const PxU32* Bunny_getFaces();
95
97
98 /* Increment the specified location. Return the incremented value. */
99 PxI32 atomicIncrement(volatile PxI32* val);
100
101 /* Decrement the specified location. Return the decremented value. */
102 PxI32 atomicDecrement(volatile PxI32* val);
103
104 //******************************************************************************//
105
106 /* Return the number of physical cores (does not include hyper-threaded cores), returns 0 on failure. */
107 PxU32 getNbPhysicalCores();
108
109 //******************************************************************************//
110
111 /* Return the id of a thread. */
112 PxU32 getThreadId();
113
114 //******************************************************************************//
115
116 /* Return the current time */
117 PxU64 getCurrentTimeCounterValue();
118
119 /* Convert to milliseconds an elapsed time computed from the difference of the times returned from two calls to getCurrentTimeCounterValue. */
120 PxReal getElapsedTimeInMilliseconds(const PxU64 elapsedTime);
121
122 /* Convert to microseconds an elapsed time computed from the difference of the times returned from two calls to getCurrentTimeCounterValue. */
123 PxReal getElapsedTimeInMicroSeconds(const PxU64 elapsedTime);
124
125 //******************************************************************************//
126
127 struct Sync;
128
129 /* Create a sync object. Returns a unique handle to the sync object so that it may be addressed through syncWait etc. */
130 Sync* syncCreate();
131
132 /* Wait indefinitely until the specified sync object is signaled. */
133 void syncWait(Sync* sync);
134
135 /* Signal the specified synchronization object, waking all threads waiting on it. */
136 void syncSet(Sync* sync);
137
139 void syncReset(Sync* sync);
140
141 /* Release the specified sync object so that it may be reused with syncCreate. */
142 void syncRelease(Sync* sync);
143
144 //******************************************************************************//
145
146 struct Thread;
147
148 /* Prototype of callback passed to threadCreate. */
149 typedef void (*ThreadEntryPoint)(void*);
150
151 /* Create a thread object and return a unique handle to the thread object so that it may be addressed through threadStart etc.
152 entryPoint implements ThreadEntryPoint and data will be passed as a function argument, POSIX-style. */
153 Thread* threadCreate(ThreadEntryPoint entryPoint, void* data);
154
155 /* Cleanly shut down the specified thread. Called in the context of the spawned thread. */
156 void threadQuit(Thread* thread);
157
158 /* Stop the specified thread. Signals the spawned thread that it should stop, so the
159 thread should check regularly. */
160 void threadSignalQuit(Thread* thread);
161
162 /* Wait for the specified thread to stop. Should be called in the context of the spawning
163 thread. Returns false if the thread has not been started.*/
164 bool threadWaitForQuit(Thread* thread);
165
166 /* Check whether the thread is signalled to quit. Called in the context of the
167 spawned thread. */
168 bool threadQuitIsSignalled(Thread* thread);
169
170 /* Release the specified thread object so that it may be reused with threadCreate. */
171 void threadRelease(Thread* thread);
172
173 //******************************************************************************//
174
175 struct Mutex;
176
177 /* Create a mutex object and return a unique handle to the mutex object so that it may be addressed through mutexLock etc. */
178 Mutex* mutexCreate();
179
180 /* Acquire (lock) the specified mutex. If the mutex is already locked by another thread, this method blocks until the mutex is unlocked.*/
181 void mutexLock(Mutex* mutex);
182
183 /* Release (unlock) the specified mutex, the calling thread must have previously called lock() or method will error. */
184 void mutexUnlock(Mutex* mutex);
185
186 /* Release the specified mutex so that it may be reused with mutexCreate. */
187 void mutexRelease(Mutex* mutex);
188 }
189}
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:50
3 Element vector class.
Definition PxVec3.h:50
Definition SnippetUtils.h:47
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition SnippetUtils.cpp:279
Definition SnippetUtils.cpp:195
Definition SnippetUtils.cpp:226