KiCad PCB EDA Suite
Loading...
Searching...
No Matches
3d_fastmath.cpp
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright (C) 2016 Mario Luzeiro <
[email protected]
>
5
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, you may find one here:
19
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20
* or you may search the http://www.gnu.org website for the version 2 license,
21
* or you may write to the Free Software Foundation, Inc.,
22
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23
*/
24
31
#include "
3d_fastmath.h
"
32
33
34
// Fast Float Random Numbers
35
// a small and fast implementation for random float numbers in the range [-1,1]
36
// References : Posted by dominik.ries[AT]gmail[DOT]com
37
// http://www.musicdsp.org/showone.php?id=273
38
39
40
// set the initial seed to whatever you like
41
static
int
s_randSeed
= 1;
42
43
// fast rand float, using full 32bit precision
44
// returns in the range [-1, 1] (not confirmed)
45
float
Fast_RandFloat
()
46
{
47
s_randSeed
*= 16807;
48
49
return
(
float
)
s_randSeed
* 4.6566129e-010f;
50
}
51
52
53
// Fast rand, as described here:
54
// http://wiki.osdev.org/Random_Number_Generator
55
56
static
unsigned
long
int
s_nextRandSeed
= 1;
57
58
int
Fast_rand
(
void
)
// RAND_MAX assumed to be 32767
59
{
60
s_nextRandSeed
=
s_nextRandSeed
* 1103515245 + 12345;
61
62
return
(
unsigned
int
)(
s_nextRandSeed
>> 16) & 0x7FFF;
63
}
64
65
void
Fast_srand
(
unsigned
int
seed )
66
{
67
s_nextRandSeed
= seed;
68
}
Fast_RandFloat
float Fast_RandFloat()
Definition:
3d_fastmath.cpp:45
s_randSeed
static int s_randSeed
Definition:
3d_fastmath.cpp:41
Fast_rand
int Fast_rand(void)
Definition:
3d_fastmath.cpp:58
s_nextRandSeed
static unsigned long int s_nextRandSeed
Definition:
3d_fastmath.cpp:56
Fast_srand
void Fast_srand(unsigned int seed)
Definition:
3d_fastmath.cpp:65
3d_fastmath.h
Defines math related functions.
src
3d-viewer
3d_fastmath.cpp
Generated on Sun Dec 22 2024 00:05:17 for KiCad PCB EDA Suite by
1.9.6