Skip to content

Commit

Permalink
Various updates and additions
Browse files Browse the repository at this point in the history
  • Loading branch information
overdev committed Aug 9, 2018
1 parent fc50259 commit 6538379
Show file tree
Hide file tree
Showing 65 changed files with 59,664 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*.pyc
build/
dist/
_unused
test.py
templates/
libraylib_shared_no9patch.dll
libraylib_shared_pre9patch.dll
*.egg-info/
*.egg
*.py[cod]
Expand Down
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2018 Jorge A. Gomes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added MANIFEST.in
Empty file.
168 changes: 153 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ More about raylib can be found at its [repository](https://github.com/raisan5/ra
and/or [website](https://www.raylib.com).


##features
## features
* **NO external dependencies**, all required libraries included with raylib.
* Multiple platforms supported: **Window, MacOS, Android... and many more!**
* Hardware accelerated with OpenGL (**1.1, 2.1, 3.3 or ES 2.0**)
Expand Down Expand Up @@ -48,18 +48,156 @@ More information on how to build raylib can be found in the [raylib wiki pages](

## raylib vs raylibpy

Except for the naming conventions and data types (names and convertions), theres no
significative differences between raylib and raylibpy. At the moment, only bytes
are accepted as string arguments, no implicit convertion is made between integers and
floats. Some of the refinements to be done are exposed below:

| Expects or returns | Accepts/returns only | Will accept/return |
| ------- | ------- | ------- |
| `const char *` | `bytes` (ASCII) | `str` (unicode) |
| `const char **` | `CharPtrPtr` | `List[str]` |
| `int` | `int` | `float` |
| `float` | `float` | `int` |
| `int*` as argument | `IntPtr` as argument | `int` as return, if omitted as argument |
| `Vector3` | `Vector3` | `Tuple[float, float, float]` or `List[float]` |
| `Vector3 *` | `Vector3Ptr` as `byref(instance)` | array, sequence or `bytes` |
### Constant values

All C `#define`s and `enum`s got translated to Python 'constants'. Enums may, in the future,
be converted to Python [enums](https://docs.python.org/3/library/enum.html), if
`ctypes` allows it.

### Structures

#### In general

All structures inherit from `ctypes.Structure` class. Unlike functions, constructors require
the exact argument types, so `int`s can't be passed where `float`s are expected (although the
argument can be omitted):

```python
# ways of creating a Vector3 instance:
vec_a = Vector3()
vec_b = Vector3(0., 1., 0.)
vec_c = Vector3.one()

# the following will raise an exception:
vec_d = Vector3(10, 0, 100)
```

All structures have `__str__()` implemented, so they have a very basic textual representation:
```python
# Define the camera to look into our 3d world
>>> camera = Camera()
>>> camera.position = Vector3(5., 4., 5.)
>>> camera.target = Vector3(0., 2., 0.)
>>> camera.up = Vector3(0., 1., 0.)
>>> camera.fovy = 45.0
>>> camera.type = CAMERA_PERSPECTIVE
>>> camera
"(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)"
```
Not all information is exposed, though. Mesh objects, for example, exposes only the
vertex and triangle count attributes.


#### Vectors

Vector2, Vector3 and Vector4 support basic aritmetic operations: addiction, subtraction,
multiplication (incluiding scalar multiplication), division and modulo. Augmented
assignment is also supported; the right hand side operand can be any sequence of same
number of components:

```python
>>> vec_a = Vector3(3., 5., 7.)
>>> vec_b = Vector3(4., 2., 0.)
>>> vec_a * vec_b
"(12.0, 10.0, 0.0)"
>>> vec_a + (8, 100, -1)
"(11.0, 105.0, 6.0)"
>>> vec_a %= 2
>>> vec_a
"(1.0, 1.0, 1.0)"
```

Vectors have also a feature that tries to emulate the GLSL vector swizzling, but
its done through subscription:
```python
>>> vec_a = Vector4(10.0, 20.0, 50.0, 1.0)
>>> # create a Vector2 from it:
...
>>> vec_b = vec_a['xy']
>>> vec_b
"(10.0, 20.0)"
>>> # create a Vector3 from it, setting 1.0 to the z axis:
...
>>> vec_c = vec_b['xy1']
>>> vec_c
"(10.0, 20.0, 0.0)"
>>> # another Vector2, perpendicular to vec_b:
...
>>> vec_d = vec_b['Yx']
>>> vec_d
"(-20.0, 10.0)"
>>> # a Vector4 from the y axis:
...
>>> vec_e = vec_b['yyyy']
>>> # vec_d with signs flipped:
...
>>> vec_d['XY']
"(20.0, -10.0)"
>>> # moving vec_a in the y axis by one:
...
>>> vec_a += vec_a['0010']
```
That's not all! Other component-wise operations (or tricks) can be made this way (note,
though that these operators apply in positional fashion):
```python
>>> vec_a = Vector3(-10.0, 20.5, 15.840)
>>> # divide all components by 2:
...
>>> vec_a['///']
"(-5.0, 10.25, 7.920)"
>>>
>>>
>>> # multiply all components by 2:
...
>>> vec_a['***']
"(-20.0, 41.0, 31.680)"
>>>
>>>
>>> # all components raised to the power of 2:
...
>>> vec_a['^^^']
"(-1e-10, 7.779544182561597e+26, 1.0095364584490473e+19)"
>>>
>>>
>>> # inverse of all components (1/x):
...
>>> vec_a['...']
"(-0.1, 0.04878048780487805, 0.06313131313131314)"
>>>
>>>
>>> # sign of components (-1 if < 0, 1 if > 0, 0 otherwise):
...
>>> vec_a['+++']
"(-1.0, 1.0, 1.0)"
>>>
>>>
>>> # nonzero components (1 if != 0, 0 otherwise):
...
>>> vec_a['???']
"(1.0, 1.0, 1.0)"
>>>
>>>
>>> # the component of vec_a with largest value:
...
>>> vec_a['>>>']
"(15.840, 15.840, 15.840)"
>>>
>>>
>>> # the component of vec_a with smallest value:
...
>>> vec_a['<<<']
"(-10.0, -10.0, -10.0)"
>>>
>>>
>>> # component values rounded:
...
>>> vec_a['###']
"(-10.0, 20.0, 15.0)"
>>>
>>>
>>> # fractional part of component values:
...
>>> vec_a['%%%']
"(0.0, 0.5, 0.840)"
```

Empty file added examples/__init__.py
Empty file.
Empty file added examples/core/__init__.py
Empty file.
19 changes: 10 additions & 9 deletions examples/core/core_basic_window.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# core_basic_window.py
import raylibpy as rl

from raylibpy import *


def main():

rl.init_window(800, 450, "raylib [core] example - basic window")
init_window(800, 450, "raylib [core] example - basic window")

rl.set_target_fps(60)
set_target_fps(60)

while not rl.window_should_close():
while not window_should_close():

rl.begin_drawing()
rl.clear_background(rl.RAYWHITE)
rl.draw_text("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
rl.end_drawing()
begin_drawing()
clear_background(RAYWHITE)
draw_text("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY)
end_drawing()

rl.close_window()
close_window()


if __name__ == '__main__':
Expand Down
8 changes: 5 additions & 3 deletions examples/core/core_color_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ def main():
color_rects: List[Rectangle] = []

for i in range(21):
y, x = divmod(i, 7)
rect = Rectangle(
20 + 100 * (i % 7) + 10 * (i % 7),
60 + 100 * (i / 7) + 10 * (i / 7),
20 + 110 * x,
60 + 110 * y,
100,
100
)
print(rect)
color_rects.append(rect)

selected: List[bool] = [False for i in range(21)]
mouse_point: Vector2.zero()
mouse_point: Vector2

set_target_fps(60)

Expand Down
4 changes: 2 additions & 2 deletions examples/core/core_input_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def main():
if is_key_down(KEY_RIGHT):
ball_position.x += 2.0
if is_key_down(KEY_LEFT):
ball_position.x += 2.0
ball_position.x -= 2.0
if is_key_down(KEY_UP):
ball_position.y += 2.0
ball_position.y -= 2.0
if is_key_down(KEY_DOWN):
ball_position.y += 2.0

Expand Down
Binary file added examples/core/resources/ps3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/core/resources/xbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/models/models_billboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def main() -> int:
camera.fovy = 45.0
camera.type = CAMERA_PERSPECTIVE

print(camera)


bill: Texture2D = load_texture("resources/billboard.png")
bill_position = Vector3(0., 2., 0.)
Expand Down
Binary file added examples/models/resources/angle_gauge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/models/resources/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/models/resources/billboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/models/resources/cubicmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/models/resources/cubicmap_atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/models/resources/dresden_square.hdr
Binary file not shown.
Binary file added examples/models/resources/heightmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6538379

Please sign in to comment.