Subversion Repository Public Repository

Divide-Dependencies

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// 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) 2018 NVIDIA Corporation. All rights reserved.



#ifndef TABLE_LOOKUP_H
#define TABLE_LOOKUP_H

namespace nvidia
{
namespace apex
{

// Stored Tables
const float custom[] =	{ 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f };
const float linear[] =	{ 1.00f, 0.90f, 0.80f, 0.70f, 0.60f, 0.50f, 0.40f, 0.30f, 0.20f, 0.10f, 0.00f };
const float steep[] =	{ 1.00f, 0.99f, 0.96f, 0.91f, 0.84f, 0.75f, 0.64f, 0.51f, 0.36f, 0.19f, 0.00f };
const float scurve[] =	{ 1.00f, 0.99f, 0.96f, 0.91f, 0.80f, 0.50f, 0.20f, 0.09f, 0.04f, 0.01f, 0.00f };

// Table sizes must be same for all stored tables
#define NUM_ELEMENTS(X) (sizeof(X)/sizeof(*(X)))
#define TABLE_SIZE NUM_ELEMENTS(custom)

// Stored Table enums
struct TableName
{
	enum Enum
	{
		CUSTOM = 0,
		LINEAR,
		STEEP,
		SCURVE,
	};
};

struct TableLookup
{
	float xVals[TABLE_SIZE];
	float yVals[TABLE_SIZE];
	float x1;
	float x2;
	float multiplier;

#ifdef __CUDACC__
	__device__ TableLookup() {}
#else
	TableLookup():
		x1(0),
		x2(0),
		multiplier(0)
	{
		zeroTable();
	}
#endif

	PX_CUDA_CALLABLE void zeroTable()
	{
		for (size_t i = 0; i < TABLE_SIZE; ++i)
		{
			xVals[i] = 0.0f;
			yVals[i] = 0.0f;
		}
	}

	PX_CUDA_CALLABLE void applyStoredTable(TableName::Enum tableName)
	{
		// build y values
		for (size_t i = 0; i < TABLE_SIZE; ++i)
		{
			if (tableName == TableName::LINEAR)
			{
				yVals[i] = linear[i];
			}
			else if (tableName == TableName::STEEP)
			{
				yVals[i] = steep[i];
			}
			else if (tableName == TableName::SCURVE)
			{
				yVals[i] = scurve[i];
			}
			else if (tableName == TableName::CUSTOM)
			{
				yVals[i] = custom[i];
			}
		}
	}

	PX_CUDA_CALLABLE void buildTable()
	{
		// build x values
		float interval = (x2 - x1) / (TABLE_SIZE - 1);
		for (size_t i = 0; i < TABLE_SIZE; ++i)
		{
			xVals[i] = x1 + i * interval;
		}

		// apply multipler to y values
		if (multiplier >= -1.0f && multiplier <= 1.0f)
		{
			for (size_t i = 0; i < TABLE_SIZE; ++i)
			{
				yVals[i] = yVals[i] * multiplier;
			}

			// offset = max y value in array
			float max = yVals[0];
			for (size_t i = 1; i < TABLE_SIZE; ++i)
			{
				if (yVals[i] > max)
				{
					max = yVals[i];
				}
			}

			// apply offset
			for (size_t i = 0; i < TABLE_SIZE; ++i)
			{
				yVals[i] = yVals[i] + (1.0f - max);
			}
		}
	}
	
	PX_CUDA_CALLABLE float lookupTableValue(float x) const
	{
		if (x <= xVals[0])
		{
			return yVals[0];
		}
		else if (x >= xVals[TABLE_SIZE-1])
		{
			return yVals[TABLE_SIZE-1];
		}
		else
		{
			// linear interpolation between x values
			float interval = (xVals[TABLE_SIZE-1] - xVals[0]) / (TABLE_SIZE - 1);
			uint32_t lerpPos = (uint32_t)((x - xVals[0]) / interval);
			float yDiff = yVals[lerpPos+1] - yVals[lerpPos];
			return yVals[lerpPos] + (x - xVals[lerpPos]) / interval * yDiff;
		}
	}
};

}
} // namespace nvidia::apex

#endif

Commits for Divide-Dependencies/physx/APEX_1.4/common/include/TableLookup.h

Diff revisions: vs.
Revision Author Commited Message
105 IonutCava picture IonutCava Tue 16 Apr, 2019 19:55:41 +0000

Forgot to actually add physx