@@ -8,7 +8,7 @@ More about raylib can be found at its [repository](https://github.com/raisan5/ra
8
8
and/or [ website] ( https://www.raylib.com ) .
9
9
10
10
11
- ##features
11
+ ## features
12
12
* ** NO external dependencies** , all required libraries included with raylib.
13
13
* Multiple platforms supported: ** Window, MacOS, Android... and many more!**
14
14
* Hardware accelerated with OpenGL (** 1.1, 2.1, 3.3 or ES 2.0** )
@@ -48,18 +48,156 @@ More information on how to build raylib can be found in the [raylib wiki pages](
48
48
49
49
## raylib vs raylibpy
50
50
51
- Except for the naming conventions and data types (names and convertions), theres no
52
- significative differences between raylib and raylibpy. At the moment, only bytes
53
- are accepted as string arguments, no implicit convertion is made between integers and
54
- floats. Some of the refinements to be done are exposed below:
55
-
56
- | Expects or returns | Accepts/returns only | Will accept/return |
57
- | ------- | ------- | ------- |
58
- | ` const char * ` | ` bytes ` (ASCII) | ` str ` (unicode) |
59
- | ` const char ** ` | ` CharPtrPtr ` | ` List[str] ` |
60
- | ` int ` | ` int ` | ` float ` |
61
- | ` float ` | ` float ` | ` int ` |
62
- | ` int* ` as argument | ` IntPtr ` as argument | ` int ` as return, if omitted as argument |
63
- | ` Vector3 ` | ` Vector3 ` | ` Tuple[float, float, float] ` or ` List[float] ` |
64
- | ` Vector3 * ` | ` Vector3Ptr ` as ` byref(instance) ` | array, sequence or ` bytes ` |
51
+ ### Constant values
52
+
53
+ All C ` #define ` s and ` enum ` s got translated to Python 'constants'. Enums may, in the future,
54
+ be converted to Python [ enums] ( https://docs.python.org/3/library/enum.html ) , if
55
+ ` ctypes ` allows it.
56
+
57
+ ### Structures
58
+
59
+ #### In general
60
+
61
+ All structures inherit from ` ctypes.Structure ` class. Unlike functions, constructors require
62
+ the exact argument types, so ` int ` s can't be passed where ` float ` s are expected (although the
63
+ argument can be omitted):
64
+
65
+ ``` python
66
+ # ways of creating a Vector3 instance:
67
+ vec_a = Vector3()
68
+ vec_b = Vector3(0 ., 1 ., 0 .)
69
+ vec_c = Vector3.one()
70
+
71
+ # the following will raise an exception:
72
+ vec_d = Vector3(10 , 0 , 100 )
73
+ ```
74
+
75
+ All structures have ` __str__() ` implemented, so they have a very basic textual representation:
76
+ ``` python
77
+ # Define the camera to look into our 3d world
78
+ >> > camera = Camera()
79
+ >> > camera.position = Vector3(5 ., 4 ., 5 .)
80
+ >> > camera.target = Vector3(0 ., 2 ., 0 .)
81
+ >> > camera.up = Vector3(0 ., 1 ., 0 .)
82
+ >> > camera.fovy = 45.0
83
+ >> > camera.type = CAMERA_PERSPECTIVE
84
+ >> > camera
85
+ " (CAMERA3D: position: (5.0, 4.0, 5.0), target: (0.0, 2.0, 0.0), up: (0.0, 1.0, 0.0), fovy: 45.0°, type: PERSPECTIVE)"
86
+ ```
87
+ Not all information is exposed, though. Mesh objects, for example, exposes only the
88
+ vertex and triangle count attributes.
89
+
90
+
91
+ #### Vectors
92
+
93
+ Vector2, Vector3 and Vector4 support basic aritmetic operations: addiction, subtraction,
94
+ multiplication (incluiding scalar multiplication), division and modulo. Augmented
95
+ assignment is also supported; the right hand side operand can be any sequence of same
96
+ number of components:
97
+
98
+ ``` python
99
+ >> > vec_a = Vector3(3 ., 5 ., 7 .)
100
+ >> > vec_b = Vector3(4 ., 2 ., 0 .)
101
+ >> > vec_a * vec_b
102
+ " (12.0, 10.0, 0.0)"
103
+ >> > vec_a + (8 , 100 , - 1 )
104
+ " (11.0, 105.0, 6.0)"
105
+ >> > vec_a %= 2
106
+ >> > vec_a
107
+ " (1.0, 1.0, 1.0)"
108
+ ```
109
+
110
+ Vectors have also a feature that tries to emulate the GLSL vector swizzling, but
111
+ its done through subscription:
112
+ ``` python
113
+ >> > vec_a = Vector4(10.0 , 20.0 , 50.0 , 1.0 )
114
+ >> > # create a Vector2 from it:
115
+ ...
116
+ >> > vec_b = vec_a[' xy' ]
117
+ >> > vec_b
118
+ " (10.0, 20.0)"
119
+ >> > # create a Vector3 from it, setting 1.0 to the z axis:
120
+ ...
121
+ >> > vec_c = vec_b[' xy1' ]
122
+ >> > vec_c
123
+ " (10.0, 20.0, 0.0)"
124
+ >> > # another Vector2, perpendicular to vec_b:
125
+ ...
126
+ >> > vec_d = vec_b[' Yx' ]
127
+ >> > vec_d
128
+ " (-20.0, 10.0)"
129
+ >> > # a Vector4 from the y axis:
130
+ ...
131
+ >> > vec_e = vec_b[' yyyy' ]
132
+ >> > # vec_d with signs flipped:
133
+ ...
134
+ >> > vec_d[' XY' ]
135
+ " (20.0, -10.0)"
136
+ >> > # moving vec_a in the y axis by one:
137
+ ...
138
+ >> > vec_a += vec_a[' 0010' ]
139
+ ```
140
+ That's not all! Other component-wise operations (or tricks) can be made this way (note,
141
+ though that these operators apply in positional fashion):
142
+ ``` python
143
+ >> > vec_a = Vector3(- 10.0 , 20.5 , 15.840 )
144
+ >> > # divide all components by 2:
145
+ ...
146
+ >> > vec_a[' ///' ]
147
+ " (-5.0, 10.25, 7.920)"
148
+ >> >
149
+ >> >
150
+ >> > # multiply all components by 2:
151
+ ...
152
+ >> > vec_a[' ***' ]
153
+ " (-20.0, 41.0, 31.680)"
154
+ >> >
155
+ >> >
156
+ >> > # all components raised to the power of 2:
157
+ ...
158
+ >> > vec_a[' ^^^' ]
159
+ " (-1e-10, 7.779544182561597e+26, 1.0095364584490473e+19)"
160
+ >> >
161
+ >> >
162
+ >> > # inverse of all components (1/x):
163
+ ...
164
+ >> > vec_a[' ...' ]
165
+ " (-0.1, 0.04878048780487805, 0.06313131313131314)"
166
+ >> >
167
+ >> >
168
+ >> > # sign of components (-1 if < 0, 1 if > 0, 0 otherwise):
169
+ ...
170
+ >> > vec_a[' +++' ]
171
+ " (-1.0, 1.0, 1.0)"
172
+ >> >
173
+ >> >
174
+ >> > # nonzero components (1 if != 0, 0 otherwise):
175
+ ...
176
+ >> > vec_a[' ???' ]
177
+ " (1.0, 1.0, 1.0)"
178
+ >> >
179
+ >> >
180
+ >> > # the component of vec_a with largest value:
181
+ ...
182
+ >> > vec_a[' >>>' ]
183
+ " (15.840, 15.840, 15.840)"
184
+ >> >
185
+ >> >
186
+ >> > # the component of vec_a with smallest value:
187
+ ...
188
+ >> > vec_a[' <<<' ]
189
+ " (-10.0, -10.0, -10.0)"
190
+ >> >
191
+ >> >
192
+ >> > # component values rounded:
193
+ ...
194
+ >> > vec_a[' ###' ]
195
+ " (-10.0, 20.0, 15.0)"
196
+ >> >
197
+ >> >
198
+ >> > # fractional part of component values:
199
+ ...
200
+ >> > vec_a[' %% %' ]
201
+ " (0.0, 0.5, 0.840)"
202
+ ```
65
203
0 commit comments