summaryrefslogtreecommitdiff
path: root/python-pyglm.spec
blob: 0e4d141c6a2bd958afadf2978fa7b65a84e4e25e (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
%global _empty_manifest_terminate_build 0
Name:		python-PyGLM
Version:	2.7.0
Release:	1
Summary:	OpenGL Mathematics library for Python
License:	zlib/libpng license
URL:		https://github.com/Zuzu-Typ/PyGLM
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/4e/4c/ca1a71217c4ac5b0f9ef56681ebe9eae14b5bb0d3ac8bb58f392bad445a5/PyGLM-2.7.0.tar.gz


%description
[//]: # (generated using SlashBack 0.2.0)

# PyGLM  
## OpenGL Mathematics \(GLM\) library for Python  
**GLSL \+ Optional features \+ Python = PyGLM**  
**A mathematics library for graphics programming\.**  
  
**PyGLM** is a Python extension written in **C\+\+**\.   
By using [GLM by G\-Truc](https://glm.g-truc.net) under the hood, it manages to bring **glm's features** to Python\.    
Some features are unsupported \(such as most unstable extensions\)\.  
If you encounter any issues or want to request a feature, please create an issue on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\.  
  
**For a complete reference of the types and functions, please take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)**\.  
  
## Tiny Documentation  
### Why PyGLM?  
Besides the obvious \- being mostly compatible with **GLM** \- PyGLM offers a variety of features for **vector** and **matrix manipulation**\.  
It has a lot of possible use cases, including **3D\-Graphics** \(OpenGL, DirectX, \.\.\.\), **Physics** and more\.  
  
At the same time, it has **great performance**, usually being **a lot faster than numpy\!** \(see [end of page](#speed-comparison-to-numpy)\)  
\(*depending on the individual function*\)  
### Installation  
**PyGLM** supports **Windows**, **Linux**, **MacOS** and other operating systems with either x86 \(**32\-bit**\) or x64 \(**64\-bit**\) architecture,   
running **Python 3**\.5 or higher\. \(Prior versions of Python \- such as Python 2 \- were supported up to PyGLM version 0\.4\.8b1\)  
  
It can be installed from the [PyPI](https://pypi.python.org/pypi/PyGLM) using [pip](https://pip.pypa.io/en/stable/):  
``` batch
pip install PyGLM
# please make sure to install "PyGLM" and not "glm", which is a different module
 ```  
And finally imported and used:  
``` python
import glm
 ```  
### Using PyGLM  
PyGLM's syntax is very similar to the original GLM's syntax\.  
There is no need to import anything but **glm**, as it already contains the entire package\.  
  
For more information, take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)\.  
#### License requirements  
Please make sure to **include the license for GLM** in your project when you use PyGLM\!  
\(this is especially relevant for **binary distributions**, e\.g\. \*\.exe\)  
  
You can do so by copying the ``` COPYING ``` file \(or it's contents\) to your project\.  
#### Differences to glm  
Instead of using double colons \(**::**\) for namespaces, periods \(**\.**\) are used, so  
``` glm::vec2 ``` becomes ``` glm.vec2 ```\.  
  
PyGLM supports the [buffer protocol](https://docs.python.org/3/c-api/buffer.html), meaning its compitible to other objects that support the buffer protocol,  
such as ``` bytes ``` or ``` numpy.array ```   
\(for example you can convert a glm matrix to a numpy array and vice versa\)\.  
PyGLM is also capable of interpreting iterables \(such as tuples\) as vectors, so e\.g\. the following equasion is possible:  
``` python
result = glm.vec2(1) * (2, 3)
 ```  
*Note: This feature might not or only partially be available in PyGLM versions prior to 2\.0\.0*  
  
PyGLM doesn't support precision qualifiers\. All types use the default precision \(``` packed_highp ```\)\.  
  
If a glm function normally accepts ``` float ``` and ``` double ``` arguments, the higher precision \(``` double ```\) is used\.  
  
There is no way to set preprocessor definitions \(macros\)\.  
If \- for example \- you need to use the left handed coordinate system, you have to use **\*LH**, so  
``` glm.perspective ``` becomes ``` glm.perspectiveLH ```\.  
  
All types are initialized by default to avoid memory access violations\.  
\(i\.e\. the macro ``` GLM_FORCE_CTOR_INIT ``` is defined\)  
  
In case you need the size of a PyGLM datatype, you can use   
``` python
glm.sizeof(<type>)
 ```  
  
The function ``` glm.identity ``` requires a matrix type as it's argument\.  
  
The function ``` glm.frexp(x, exp) ``` returns a tuple ``` (m, e) ```, if the input arguments are numerical\.  
This function may issue a ``` UserWarning ```\. You can silence this warning using ``` glm.silence(1) ```\.  
  
The function ``` glm.value_ptr(x) ``` returns a ctypes pointer of the respective type\.  
I\.e\. if the datatype of ``` x ``` is ``` float ```, then a ``` c_float ``` pointer will be returned\.  
Likewise the reverse\-functions \(such as ``` make_vec2(ptr) ```\) will take a ctypes pointer as their argument  
and return \(in this case\) a 2 component vector of the pointers underlying type\.  
  
``` glm.silence(ID) ``` can be used to silence specific warnings\.  
Supplying an id of 0 will silence all warnings\.  
  
  
### FAQ  
#### How to pass the matrices generated by PyGLM to OpenGL functions?  
You will find an overview on the \[[Passing data to external libs](wiki/Passing-data-to-external-libs.md)\] page\.  
  
#### Types and functions are not available after installing from the PyPI using ``` pip install glm ```  
Most likely you've installed [glm](https://pypi.org/project/glm/), a JSON parser and not [PyGLM](https://pypi.org/project/PyGLM/) \(or a very early version of PyGLM\)\.&nbsp;&nbsp;  
The correct install command is:  
``` 
pip install PyGLM
 ```  
  
#### Why is *&lt;experimental extension name here&gt;* not supported?  
I prefer not to add too many experimental extensions to PyGLM, especially as they might change or be removed in the future and it is simply too much effort for me to keep up with all that\.&nbsp;&nbsp;  
If you **need a specific experimental extension**, feel free to **submit a feature request** on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\.&nbsp;&nbsp;  
I try adding them on a one\-by\-one basis\.  
  
#### Why are Python versions prior to 3\.5 no longer supported?  
Starting with version [0\.5\.0b1](https://github.com/Zuzu-Typ/PyGLM/releases/tag/0.5.0b1) I decided to use C\+\+ to build PyGLM, using [glm](https://glm.g-truc.net/) under the hood \- which requires C\+\+ 11 or upwards\.&nbsp;&nbsp;  
Only Python versions 3\.5\+ support C\+\+ 11, thus I was forced to stop supporting older versions\.&nbsp;&nbsp;  
The last version to support Python 2 and &lt;3\.5 is [0\.4\.8b1](https://github.com/Zuzu-Typ/PyGLM/releases/tag/0.4.8b1)\.  
  
### Short example  
``` Python
>>> import glm
>>> v = glm.vec3()
>>> v.x = 7
>>> print(v.xxy)
vec3(            7,            7,            0 )

>>> m = glm.mat4()
>>> print(m)
[            1 |            0 |            0 |            0 ]
[            0 |            1 |            0 |            0 ]
[            0 |            0 |            1 |            0 ]
[            0 |            0 |            0 |            1 ]

>>> v = glm.vec4(1, 2, 3, 4)
>>> print(v + (8, 7, 6, 5))
vec4(            9,            9,            9,            9 )
 ```  
  
### PyGLM in action  
Wanna see what PyGLM can do?  
Take a look at the [examples](https://github.com/Zuzu-Typ/LearnOpenGL-Python) from the popular LearnOpenGL tutorials by Joey De Vries running in Python using PyGLM\.  
![LearnOpenGL](https://raw.githubusercontent.com/Zuzu-Typ/PyGLM/master/LearnOpenGL.png)  
  
### Speed comparison to numpy  
The following is the output generated by [test/PyGLM vs Numpy\.py](https://github.com/Zuzu-Typ/PyGLM/blob/master/test/PyGLM%20vs%20NumPy.py)  
``` 
Evaluating performance of PyGLM compared to NumPy.

Running on platform 'win32'.

Python version:
3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]

Comparing the following module versions:
PyGLM (DEFAULT) version 2.5.2
 vs
NumPy version 1.21.3
________________________________________________________________________________

The following table shows information about a task to be achieved and the time
it took when using the given module. Lower time is better.
Each task is repeated ten times per module, only showing the best (i.e. lowest)
value.


+----------------------------------------+------------+------------+-----------+
| Description                            | PyGLM time | NumPy time |     ratio |
+----------------------------------------+------------+------------+-----------+
| 3 component vector creation            |            |            |           |
| (100,000 times)                        |        8ms |       21ms |     2.69x |
+----------------------------------------+------------+------------+-----------+
| 3 component vector creation with       |            |            |           |
| custom components                      |            |            |           |
| (50,000 times)                         |        8ms |       34ms |     4.32x |
+----------------------------------------+------------+------------+-----------+
| dot product                            |            |            |           |
| (50,000 times)                         |        4ms |       49ms |    10.93x |
+----------------------------------------+------------+------------+-----------+
| cross product                          |            |            |           |
| (25,000 times)                         |        2ms |      548ms |   234.34x |
+----------------------------------------+------------+------------+-----------+
| L2-Norm of 3 component vector          |            |            |           |
| (100,000 times)                        |        7ms |      310ms |    44.49x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix creation                    |            |            |           |
| (50,000 times)                         |        5ms |       11ms |     2.32x |
+----------------------------------------+------------+------------+-----------+
| 4x4 identity matrix creation           |            |            |           |
| (100,000 times)                        |        7ms |      176ms |    24.05x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix transposition               |            |            |           |
| (50,000 times)                         |        5ms |       32ms |     6.19x |
+----------------------------------------+------------+------------+-----------+
| 4x4 multiplicative inverse             |            |            |           |
| (50,000 times)                         |        4ms |     1925ms |   470.77x |
+----------------------------------------+------------+------------+-----------+
| 3 component vector addition            |            |            |           |
| (100,000 times)                        |        5ms |       38ms |     7.17x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix multiplication              |            |            |           |
| (100,000 times)                        |        7ms |       39ms |     5.36x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix x vector multiplication     |            |            |           |
| (100,000 times)                        |        6ms |      116ms |    20.01x |
+----------------------------------------+------------+------------+-----------+
| TOTAL                                  |      0.07s |      3.30s |    47.78x |
+----------------------------------------+------------+------------+-----------+
 ```


%package -n python3-PyGLM
Summary:	OpenGL Mathematics library for Python
Provides:	python-PyGLM
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
BuildRequires:	python3-cffi
BuildRequires:	gcc
BuildRequires:	gdb
%description -n python3-PyGLM
[//]: # (generated using SlashBack 0.2.0)

# PyGLM  
## OpenGL Mathematics \(GLM\) library for Python  
**GLSL \+ Optional features \+ Python = PyGLM**  
**A mathematics library for graphics programming\.**  
  
**PyGLM** is a Python extension written in **C\+\+**\.   
By using [GLM by G\-Truc](https://glm.g-truc.net) under the hood, it manages to bring **glm's features** to Python\.&nbsp;&nbsp;  
Some features are unsupported \(such as most unstable extensions\)\.  
If you encounter any issues or want to request a feature, please create an issue on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\.  
  
**For a complete reference of the types and functions, please take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)**\.  
  
## Tiny Documentation  
### Why PyGLM?  
Besides the obvious \- being mostly compatible with **GLM** \- PyGLM offers a variety of features for **vector** and **matrix manipulation**\.  
It has a lot of possible use cases, including **3D\-Graphics** \(OpenGL, DirectX, \.\.\.\), **Physics** and more\.  
  
At the same time, it has **great performance**, usually being **a lot faster than numpy\!** \(see [end of page](#speed-comparison-to-numpy)\)  
\(*depending on the individual function*\)  
### Installation  
**PyGLM** supports **Windows**, **Linux**, **MacOS** and other operating systems with either x86 \(**32\-bit**\) or x64 \(**64\-bit**\) architecture,   
running **Python 3**\.5 or higher\. \(Prior versions of Python \- such as Python 2 \- were supported up to PyGLM version 0\.4\.8b1\)  
  
It can be installed from the [PyPI](https://pypi.python.org/pypi/PyGLM) using [pip](https://pip.pypa.io/en/stable/):  
``` batch
pip install PyGLM
# please make sure to install "PyGLM" and not "glm", which is a different module
 ```  
And finally imported and used:  
``` python
import glm
 ```  
### Using PyGLM  
PyGLM's syntax is very similar to the original GLM's syntax\.  
There is no need to import anything but **glm**, as it already contains the entire package\.  
  
For more information, take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)\.  
#### License requirements  
Please make sure to **include the license for GLM** in your project when you use PyGLM\!  
\(this is especially relevant for **binary distributions**, e\.g\. \*\.exe\)  
  
You can do so by copying the ``` COPYING ``` file \(or it's contents\) to your project\.  
#### Differences to glm  
Instead of using double colons \(**::**\) for namespaces, periods \(**\.**\) are used, so  
``` glm::vec2 ``` becomes ``` glm.vec2 ```\.  
  
PyGLM supports the [buffer protocol](https://docs.python.org/3/c-api/buffer.html), meaning its compitible to other objects that support the buffer protocol,  
such as ``` bytes ``` or ``` numpy.array ```   
\(for example you can convert a glm matrix to a numpy array and vice versa\)\.  
PyGLM is also capable of interpreting iterables \(such as tuples\) as vectors, so e\.g\. the following equasion is possible:  
``` python
result = glm.vec2(1) * (2, 3)
 ```  
*Note: This feature might not or only partially be available in PyGLM versions prior to 2\.0\.0*  
  
PyGLM doesn't support precision qualifiers\. All types use the default precision \(``` packed_highp ```\)\.  
  
If a glm function normally accepts ``` float ``` and ``` double ``` arguments, the higher precision \(``` double ```\) is used\.  
  
There is no way to set preprocessor definitions \(macros\)\.  
If \- for example \- you need to use the left handed coordinate system, you have to use **\*LH**, so  
``` glm.perspective ``` becomes ``` glm.perspectiveLH ```\.  
  
All types are initialized by default to avoid memory access violations\.  
\(i\.e\. the macro ``` GLM_FORCE_CTOR_INIT ``` is defined\)  
  
In case you need the size of a PyGLM datatype, you can use   
``` python
glm.sizeof(<type>)
 ```  
  
The function ``` glm.identity ``` requires a matrix type as it's argument\.  
  
The function ``` glm.frexp(x, exp) ``` returns a tuple ``` (m, e) ```, if the input arguments are numerical\.  
This function may issue a ``` UserWarning ```\. You can silence this warning using ``` glm.silence(1) ```\.  
  
The function ``` glm.value_ptr(x) ``` returns a ctypes pointer of the respective type\.  
I\.e\. if the datatype of ``` x ``` is ``` float ```, then a ``` c_float ``` pointer will be returned\.  
Likewise the reverse\-functions \(such as ``` make_vec2(ptr) ```\) will take a ctypes pointer as their argument  
and return \(in this case\) a 2 component vector of the pointers underlying type\.  
  
``` glm.silence(ID) ``` can be used to silence specific warnings\.  
Supplying an id of 0 will silence all warnings\.  
  
  
### FAQ  
#### How to pass the matrices generated by PyGLM to OpenGL functions?  
You will find an overview on the \[[Passing data to external libs](wiki/Passing-data-to-external-libs.md)\] page\.  
  
#### Types and functions are not available after installing from the PyPI using ``` pip install glm ```  
Most likely you've installed [glm](https://pypi.org/project/glm/), a JSON parser and not [PyGLM](https://pypi.org/project/PyGLM/) \(or a very early version of PyGLM\)\.&nbsp;&nbsp;  
The correct install command is:  
``` 
pip install PyGLM
 ```  
  
#### Why is *&lt;experimental extension name here&gt;* not supported?  
I prefer not to add too many experimental extensions to PyGLM, especially as they might change or be removed in the future and it is simply too much effort for me to keep up with all that\.&nbsp;&nbsp;  
If you **need a specific experimental extension**, feel free to **submit a feature request** on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\.&nbsp;&nbsp;  
I try adding them on a one\-by\-one basis\.  
  
#### Why are Python versions prior to 3\.5 no longer supported?  
Starting with version [0\.5\.0b1](https://github.com/Zuzu-Typ/PyGLM/releases/tag/0.5.0b1) I decided to use C\+\+ to build PyGLM, using [glm](https://glm.g-truc.net/) under the hood \- which requires C\+\+ 11 or upwards\.&nbsp;&nbsp;  
Only Python versions 3\.5\+ support C\+\+ 11, thus I was forced to stop supporting older versions\.&nbsp;&nbsp;  
The last version to support Python 2 and &lt;3\.5 is [0\.4\.8b1](https://github.com/Zuzu-Typ/PyGLM/releases/tag/0.4.8b1)\.  
  
### Short example  
``` Python
>>> import glm
>>> v = glm.vec3()
>>> v.x = 7
>>> print(v.xxy)
vec3(            7,            7,            0 )

>>> m = glm.mat4()
>>> print(m)
[            1 |            0 |            0 |            0 ]
[            0 |            1 |            0 |            0 ]
[            0 |            0 |            1 |            0 ]
[            0 |            0 |            0 |            1 ]

>>> v = glm.vec4(1, 2, 3, 4)
>>> print(v + (8, 7, 6, 5))
vec4(            9,            9,            9,            9 )
 ```  
  
### PyGLM in action  
Wanna see what PyGLM can do?  
Take a look at the [examples](https://github.com/Zuzu-Typ/LearnOpenGL-Python) from the popular LearnOpenGL tutorials by Joey De Vries running in Python using PyGLM\.  
![LearnOpenGL](https://raw.githubusercontent.com/Zuzu-Typ/PyGLM/master/LearnOpenGL.png)  
  
### Speed comparison to numpy  
The following is the output generated by [test/PyGLM vs Numpy\.py](https://github.com/Zuzu-Typ/PyGLM/blob/master/test/PyGLM%20vs%20NumPy.py)  
``` 
Evaluating performance of PyGLM compared to NumPy.

Running on platform 'win32'.

Python version:
3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]

Comparing the following module versions:
PyGLM (DEFAULT) version 2.5.2
 vs
NumPy version 1.21.3
________________________________________________________________________________

The following table shows information about a task to be achieved and the time
it took when using the given module. Lower time is better.
Each task is repeated ten times per module, only showing the best (i.e. lowest)
value.


+----------------------------------------+------------+------------+-----------+
| Description                            | PyGLM time | NumPy time |     ratio |
+----------------------------------------+------------+------------+-----------+
| 3 component vector creation            |            |            |           |
| (100,000 times)                        |        8ms |       21ms |     2.69x |
+----------------------------------------+------------+------------+-----------+
| 3 component vector creation with       |            |            |           |
| custom components                      |            |            |           |
| (50,000 times)                         |        8ms |       34ms |     4.32x |
+----------------------------------------+------------+------------+-----------+
| dot product                            |            |            |           |
| (50,000 times)                         |        4ms |       49ms |    10.93x |
+----------------------------------------+------------+------------+-----------+
| cross product                          |            |            |           |
| (25,000 times)                         |        2ms |      548ms |   234.34x |
+----------------------------------------+------------+------------+-----------+
| L2-Norm of 3 component vector          |            |            |           |
| (100,000 times)                        |        7ms |      310ms |    44.49x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix creation                    |            |            |           |
| (50,000 times)                         |        5ms |       11ms |     2.32x |
+----------------------------------------+------------+------------+-----------+
| 4x4 identity matrix creation           |            |            |           |
| (100,000 times)                        |        7ms |      176ms |    24.05x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix transposition               |            |            |           |
| (50,000 times)                         |        5ms |       32ms |     6.19x |
+----------------------------------------+------------+------------+-----------+
| 4x4 multiplicative inverse             |            |            |           |
| (50,000 times)                         |        4ms |     1925ms |   470.77x |
+----------------------------------------+------------+------------+-----------+
| 3 component vector addition            |            |            |           |
| (100,000 times)                        |        5ms |       38ms |     7.17x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix multiplication              |            |            |           |
| (100,000 times)                        |        7ms |       39ms |     5.36x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix x vector multiplication     |            |            |           |
| (100,000 times)                        |        6ms |      116ms |    20.01x |
+----------------------------------------+------------+------------+-----------+
| TOTAL                                  |      0.07s |      3.30s |    47.78x |
+----------------------------------------+------------+------------+-----------+
 ```


%package help
Summary:	Development documents and examples for PyGLM
Provides:	python3-PyGLM-doc
%description help
[//]: # (generated using SlashBack 0.2.0)

# PyGLM  
## OpenGL Mathematics \(GLM\) library for Python  
**GLSL \+ Optional features \+ Python = PyGLM**  
**A mathematics library for graphics programming\.**  
  
**PyGLM** is a Python extension written in **C\+\+**\.   
By using [GLM by G\-Truc](https://glm.g-truc.net) under the hood, it manages to bring **glm's features** to Python\.&nbsp;&nbsp;  
Some features are unsupported \(such as most unstable extensions\)\.  
If you encounter any issues or want to request a feature, please create an issue on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\.  
  
**For a complete reference of the types and functions, please take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)**\.  
  
## Tiny Documentation  
### Why PyGLM?  
Besides the obvious \- being mostly compatible with **GLM** \- PyGLM offers a variety of features for **vector** and **matrix manipulation**\.  
It has a lot of possible use cases, including **3D\-Graphics** \(OpenGL, DirectX, \.\.\.\), **Physics** and more\.  
  
At the same time, it has **great performance**, usually being **a lot faster than numpy\!** \(see [end of page](#speed-comparison-to-numpy)\)  
\(*depending on the individual function*\)  
### Installation  
**PyGLM** supports **Windows**, **Linux**, **MacOS** and other operating systems with either x86 \(**32\-bit**\) or x64 \(**64\-bit**\) architecture,   
running **Python 3**\.5 or higher\. \(Prior versions of Python \- such as Python 2 \- were supported up to PyGLM version 0\.4\.8b1\)  
  
It can be installed from the [PyPI](https://pypi.python.org/pypi/PyGLM) using [pip](https://pip.pypa.io/en/stable/):  
``` batch
pip install PyGLM
# please make sure to install "PyGLM" and not "glm", which is a different module
 ```  
And finally imported and used:  
``` python
import glm
 ```  
### Using PyGLM  
PyGLM's syntax is very similar to the original GLM's syntax\.  
There is no need to import anything but **glm**, as it already contains the entire package\.  
  
For more information, take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)\.  
#### License requirements  
Please make sure to **include the license for GLM** in your project when you use PyGLM\!  
\(this is especially relevant for **binary distributions**, e\.g\. \*\.exe\)  
  
You can do so by copying the ``` COPYING ``` file \(or it's contents\) to your project\.  
#### Differences to glm  
Instead of using double colons \(**::**\) for namespaces, periods \(**\.**\) are used, so  
``` glm::vec2 ``` becomes ``` glm.vec2 ```\.  
  
PyGLM supports the [buffer protocol](https://docs.python.org/3/c-api/buffer.html), meaning its compitible to other objects that support the buffer protocol,  
such as ``` bytes ``` or ``` numpy.array ```   
\(for example you can convert a glm matrix to a numpy array and vice versa\)\.  
PyGLM is also capable of interpreting iterables \(such as tuples\) as vectors, so e\.g\. the following equasion is possible:  
``` python
result = glm.vec2(1) * (2, 3)
 ```  
*Note: This feature might not or only partially be available in PyGLM versions prior to 2\.0\.0*  
  
PyGLM doesn't support precision qualifiers\. All types use the default precision \(``` packed_highp ```\)\.  
  
If a glm function normally accepts ``` float ``` and ``` double ``` arguments, the higher precision \(``` double ```\) is used\.  
  
There is no way to set preprocessor definitions \(macros\)\.  
If \- for example \- you need to use the left handed coordinate system, you have to use **\*LH**, so  
``` glm.perspective ``` becomes ``` glm.perspectiveLH ```\.  
  
All types are initialized by default to avoid memory access violations\.  
\(i\.e\. the macro ``` GLM_FORCE_CTOR_INIT ``` is defined\)  
  
In case you need the size of a PyGLM datatype, you can use   
``` python
glm.sizeof(<type>)
 ```  
  
The function ``` glm.identity ``` requires a matrix type as it's argument\.  
  
The function ``` glm.frexp(x, exp) ``` returns a tuple ``` (m, e) ```, if the input arguments are numerical\.  
This function may issue a ``` UserWarning ```\. You can silence this warning using ``` glm.silence(1) ```\.  
  
The function ``` glm.value_ptr(x) ``` returns a ctypes pointer of the respective type\.  
I\.e\. if the datatype of ``` x ``` is ``` float ```, then a ``` c_float ``` pointer will be returned\.  
Likewise the reverse\-functions \(such as ``` make_vec2(ptr) ```\) will take a ctypes pointer as their argument  
and return \(in this case\) a 2 component vector of the pointers underlying type\.  
  
``` glm.silence(ID) ``` can be used to silence specific warnings\.  
Supplying an id of 0 will silence all warnings\.  
  
  
### FAQ  
#### How to pass the matrices generated by PyGLM to OpenGL functions?  
You will find an overview on the \[[Passing data to external libs](wiki/Passing-data-to-external-libs.md)\] page\.  
  
#### Types and functions are not available after installing from the PyPI using ``` pip install glm ```  
Most likely you've installed [glm](https://pypi.org/project/glm/), a JSON parser and not [PyGLM](https://pypi.org/project/PyGLM/) \(or a very early version of PyGLM\)\.&nbsp;&nbsp;  
The correct install command is:  
``` 
pip install PyGLM
 ```  
  
#### Why is *&lt;experimental extension name here&gt;* not supported?  
I prefer not to add too many experimental extensions to PyGLM, especially as they might change or be removed in the future and it is simply too much effort for me to keep up with all that\.&nbsp;&nbsp;  
If you **need a specific experimental extension**, feel free to **submit a feature request** on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\.&nbsp;&nbsp;  
I try adding them on a one\-by\-one basis\.  
  
#### Why are Python versions prior to 3\.5 no longer supported?  
Starting with version [0\.5\.0b1](https://github.com/Zuzu-Typ/PyGLM/releases/tag/0.5.0b1) I decided to use C\+\+ to build PyGLM, using [glm](https://glm.g-truc.net/) under the hood \- which requires C\+\+ 11 or upwards\.&nbsp;&nbsp;  
Only Python versions 3\.5\+ support C\+\+ 11, thus I was forced to stop supporting older versions\.&nbsp;&nbsp;  
The last version to support Python 2 and &lt;3\.5 is [0\.4\.8b1](https://github.com/Zuzu-Typ/PyGLM/releases/tag/0.4.8b1)\.  
  
### Short example  
``` Python
>>> import glm
>>> v = glm.vec3()
>>> v.x = 7
>>> print(v.xxy)
vec3(            7,            7,            0 )

>>> m = glm.mat4()
>>> print(m)
[            1 |            0 |            0 |            0 ]
[            0 |            1 |            0 |            0 ]
[            0 |            0 |            1 |            0 ]
[            0 |            0 |            0 |            1 ]

>>> v = glm.vec4(1, 2, 3, 4)
>>> print(v + (8, 7, 6, 5))
vec4(            9,            9,            9,            9 )
 ```  
  
### PyGLM in action  
Wanna see what PyGLM can do?  
Take a look at the [examples](https://github.com/Zuzu-Typ/LearnOpenGL-Python) from the popular LearnOpenGL tutorials by Joey De Vries running in Python using PyGLM\.  
![LearnOpenGL](https://raw.githubusercontent.com/Zuzu-Typ/PyGLM/master/LearnOpenGL.png)  
  
### Speed comparison to numpy  
The following is the output generated by [test/PyGLM vs Numpy\.py](https://github.com/Zuzu-Typ/PyGLM/blob/master/test/PyGLM%20vs%20NumPy.py)  
``` 
Evaluating performance of PyGLM compared to NumPy.

Running on platform 'win32'.

Python version:
3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]

Comparing the following module versions:
PyGLM (DEFAULT) version 2.5.2
 vs
NumPy version 1.21.3
________________________________________________________________________________

The following table shows information about a task to be achieved and the time
it took when using the given module. Lower time is better.
Each task is repeated ten times per module, only showing the best (i.e. lowest)
value.


+----------------------------------------+------------+------------+-----------+
| Description                            | PyGLM time | NumPy time |     ratio |
+----------------------------------------+------------+------------+-----------+
| 3 component vector creation            |            |            |           |
| (100,000 times)                        |        8ms |       21ms |     2.69x |
+----------------------------------------+------------+------------+-----------+
| 3 component vector creation with       |            |            |           |
| custom components                      |            |            |           |
| (50,000 times)                         |        8ms |       34ms |     4.32x |
+----------------------------------------+------------+------------+-----------+
| dot product                            |            |            |           |
| (50,000 times)                         |        4ms |       49ms |    10.93x |
+----------------------------------------+------------+------------+-----------+
| cross product                          |            |            |           |
| (25,000 times)                         |        2ms |      548ms |   234.34x |
+----------------------------------------+------------+------------+-----------+
| L2-Norm of 3 component vector          |            |            |           |
| (100,000 times)                        |        7ms |      310ms |    44.49x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix creation                    |            |            |           |
| (50,000 times)                         |        5ms |       11ms |     2.32x |
+----------------------------------------+------------+------------+-----------+
| 4x4 identity matrix creation           |            |            |           |
| (100,000 times)                        |        7ms |      176ms |    24.05x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix transposition               |            |            |           |
| (50,000 times)                         |        5ms |       32ms |     6.19x |
+----------------------------------------+------------+------------+-----------+
| 4x4 multiplicative inverse             |            |            |           |
| (50,000 times)                         |        4ms |     1925ms |   470.77x |
+----------------------------------------+------------+------------+-----------+
| 3 component vector addition            |            |            |           |
| (100,000 times)                        |        5ms |       38ms |     7.17x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix multiplication              |            |            |           |
| (100,000 times)                        |        7ms |       39ms |     5.36x |
+----------------------------------------+------------+------------+-----------+
| 4x4 matrix x vector multiplication     |            |            |           |
| (100,000 times)                        |        6ms |      116ms |    20.01x |
+----------------------------------------+------------+------------+-----------+
| TOTAL                                  |      0.07s |      3.30s |    47.78x |
+----------------------------------------+------------+------------+-----------+
 ```


%prep
%autosetup -n PyGLM-2.7.0

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-PyGLM -f filelist.lst
%dir %{python3_sitearch}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Mon Apr 10 2023 Python_Bot <Python_Bot@openeuler.org> - 2.7.0-1
- Package Spec generated