Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 35c25fa

Browse files
author
Jorge A. Gomes
committed
added rl5 (binding generator rewrite) working examples
1 parent ccd91d3 commit 35c25fa

9 files changed

+647
-0
lines changed

‎examples/models_animation.py‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
import sys
3+
import os
4+
from ctypes import byref
5+
from raylibpy import *
6+
7+
def main():
8+
9+
screenWidth = 800
10+
screenHeight = 450
11+
12+
init_window(screenWidth, screenHeight, "raylib [models] example - model animation")
13+
camera = Camera(0)
14+
camera.position = Vector3(10.0, 10.0, 10.0)
15+
camera.target = Vector3(0.0, 0.0, 0.0)
16+
camera.up = Vector3(0.0, 1.0, 0.0)
17+
camera.fovy = 45.0
18+
camera.projection = CAMERA_PERSPECTIVE
19+
20+
model = load_model("resources/models/iqm/guy.iqm")
21+
texture = load_texture("resources/models/iqm/guytex.png")
22+
set_material_texture(byref(model.materials[0]), MATERIAL_MAP_ALBEDO, texture)
23+
24+
position = Vector3(0.0, 0.0, 0.0)
25+
26+
anims = load_model_animations("resources/models/iqm/guyanim.iqm", 0)
27+
animsCount = len(anims)
28+
animFrameCounter = 0
29+
30+
disable_cursor()
31+
32+
set_target_fps(60)
33+
34+
while not window_should_close():
35+
update_camera(byref(camera), CAMERA_FIRST_PERSON)
36+
37+
if is_key_down(KEY_SPACE):
38+
animFrameCounter += 1
39+
update_model_animation(model, anims[0], animFrameCounter)
40+
41+
if animFrameCounter >= anims[0].frame_count:
42+
animFrameCounter = 0
43+
44+
with drawing():
45+
46+
clear_background(RAYWHITE)
47+
48+
with mode3d(camera):
49+
draw_model_ex(model, position, Vector3(1.0, 0.0, 0.0), -90.0, Vector3(1.0, 1.0, 1.0), WHITE)
50+
draw_grid(10, 1.0)
51+
52+
# end_mode3d()
53+
54+
draw_text("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, MAROON)
55+
draw_text("(c) Guy IQM 3D model by @culacant", screenWidth - 200, screenHeight - 20, 10, GRAY)
56+
57+
# end_drawing()
58+
59+
unload_texture(texture)
60+
unload_model_animations(anims, animsCount)
61+
unload_model(model)
62+
63+
close_window()
64+
65+
return 0
66+
67+
68+
if __name__ == "__main__":
69+
if len(sys.argv) >= 2 and isinstance(sys.argv[1], str):
70+
os.chdir(sys.argv[1])
71+
print("Working dir:", os.getcwd())
72+
sys.exit(main())

‎examples/models_billboard.py‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
import sys
3+
import os
4+
from ctypes import byref
5+
from raylibpy import *
6+
# import raymath.h
7+
8+
def main():
9+
screenWidth = 800
10+
screenHeight = 450
11+
12+
init_window(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
13+
14+
camera = Camera()
15+
camera.position = Vector3(5.0, 4.0, 5.0)
16+
camera.target = Vector3(0.0, 2.0, 0.0)
17+
camera.up = Vector3(0.0, 1.0, 0.0)
18+
camera.fovy = 45.0
19+
camera.projection = CAMERA_PERSPECTIVE
20+
21+
bill = load_texture("resources/billboard.png")
22+
billPositionStatic = Vector3(0.0, 2.0, 0.0)
23+
billPositionRotating = Vector3(1.0, 2.0, 1.0)
24+
25+
source = Rectangle(0.0, 0.0, bill.width, bill.height)
26+
billUp = Vector3(0.0, 1.0, 0.0)
27+
rotateOrigin = Vector2()
28+
distanceStatic = None
29+
distanceRotating = None
30+
rotation = 0.0
31+
32+
set_target_fps(60)
33+
34+
while not window_should_close():
35+
update_camera(byref(camera), CAMERA_ORBITAL)
36+
37+
rotation += 0.4
38+
distanceStatic = camera.position.distance(billPositionStatic)
39+
distanceRotating = camera.position.distance(billPositionRotating)
40+
41+
with drawing():
42+
clear_background(RAYWHITE)
43+
44+
with mode3d(camera):
45+
46+
draw_grid(10, 1.0)
47+
48+
if distanceStatic > distanceRotating:
49+
draw_billboard(camera, bill, billPositionStatic, 2.0, WHITE)
50+
draw_billboard_pro(camera, bill, source, billPositionRotating, billUp, Vector2(1.0, 1.0), rotateOrigin, rotation, WHITE)
51+
else:
52+
draw_billboard_pro(camera, bill, source, billPositionRotating, billUp, Vector2(1.0, 1.0), rotateOrigin, rotation, WHITE)
53+
draw_billboard(camera, bill, billPositionStatic, 2.0, WHITE)
54+
55+
# end_mode3d()
56+
57+
draw_fps(10, 10)
58+
59+
# end_drawing()
60+
61+
unload_texture(bill)
62+
close_window()
63+
64+
return 0
65+
66+
67+
if __name__ == "__main__":
68+
if len(sys.argv) >= 2 and isinstance(sys.argv[1], str):
69+
os.chdir(sys.argv[1])
70+
print("Working dir:", os.getcwd())
71+
sys.exit(main())

‎examples/models_box_collisions.py‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
import sys
3+
import os
4+
from ctypes import byref
5+
from raylibpy import *
6+
7+
def main():
8+
screenWidth = 800
9+
screenHeight = 450
10+
11+
init_window(screenWidth, screenHeight, "raylib [models] example - box collisions")
12+
13+
camera = Camera((0.0, 10.0, 10.0), (0.0, 0.0, 0.0), (0.0, 1.0, 0.0), 45.0, 0)
14+
15+
playerPosition = Vector3(0.0, 1.0, 2.0)
16+
playerSize = Vector3(1.0, 2.0, 1.0)
17+
playerColor = GREEN
18+
19+
enemyBoxPos = Vector3(-4.0, 1.0, 0.0)
20+
enemyBoxSize = Vector3(2.0, 2.0, 2.0)
21+
enemySpherePos = Vector3(4.0, 0.0, 0.0)
22+
enemySphereSize = 1.5
23+
24+
collision = False
25+
26+
set_target_fps(60)
27+
28+
while not window_should_close():
29+
30+
if is_key_down(KEY_RIGHT):
31+
playerPosition.x += 0.2
32+
elif is_key_down(KEY_LEFT):
33+
playerPosition.x -= 0.2
34+
elif is_key_down(KEY_DOWN):
35+
playerPosition.z += 0.2
36+
elif is_key_down(KEY_UP):
37+
playerPosition.z -= 0.2
38+
39+
collision = False
40+
41+
if check_collision_boxes(
42+
BoundingBox(
43+
Vector3(playerPosition.x - playerSize.x / 2, playerPosition.y - playerSize.y / 2, playerPosition.z - playerSize.z / 2),
44+
Vector3(playerPosition.x + playerSize.x / 2, playerPosition.y + playerSize.y / 2, playerPosition.z + playerSize.z / 2)),
45+
BoundingBox(
46+
Vector3(enemyBoxPos.x - enemyBoxSize.x / 2, enemyBoxPos.y - enemyBoxSize.y / 2, enemyBoxPos.z - enemyBoxSize.z / 2),
47+
Vector3(enemyBoxPos.x + enemyBoxSize.x / 2, enemyBoxPos.y + enemyBoxSize.y / 2, enemyBoxPos.z + enemyBoxSize.z / 2))):
48+
collision = True
49+
50+
if check_collision_box_sphere(
51+
BoundingBox(
52+
Vector3(playerPosition.x - playerSize.x / 2, playerPosition.y - playerSize.y / 2, playerPosition.z - playerSize.z / 2),
53+
Vector3(playerPosition.x + playerSize.x / 2, playerPosition.y + playerSize.y / 2, playerPosition.z + playerSize.z / 2)), enemySpherePos, enemySphereSize):
54+
collision = True
55+
56+
if collision:
57+
playerColor = RED
58+
else:
59+
playerColor = GREEN
60+
61+
with drawing():
62+
clear_background(RAYWHITE)
63+
64+
with mode3d(camera):
65+
draw_cube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY)
66+
draw_cube_wires(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, DARKGRAY)
67+
draw_sphere(enemySpherePos, enemySphereSize, GRAY)
68+
draw_sphere_wires(enemySpherePos, enemySphereSize, 16, 16, DARKGRAY)
69+
draw_cube_v(playerPosition, playerSize, playerColor)
70+
draw_grid(10, 1.0)
71+
# end_mode3d()
72+
73+
draw_text("Move player with cursors to collide", 220, 40, 20, GRAY)
74+
draw_fps(10, 10)
75+
76+
# end_drawing()
77+
78+
close_window()
79+
80+
return 0
81+
82+
83+
if __name__ == "__main__":
84+
if len(sys.argv) >= 2 and isinstance(sys.argv[1], str):
85+
os.chdir(sys.argv[1])
86+
print("Working dir:", os.getcwd())
87+
sys.exit(main())

‎examples/models_cubicmap.py‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
import sys
3+
import os
4+
from ctypes import byref
5+
from raylibpy import *
6+
7+
def main():
8+
"""Transpiled function."""
9+
screenWidth = 800
10+
screenHeight = 450
11+
init_window(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
12+
13+
camera = Camera()
14+
camera.position = Vector3(16.0, 14.0, 16.0)
15+
camera.target = Vector3(0.0, 0.0, 0.0)
16+
camera.up = Vector3(0.0, 1.0, 0.0)
17+
camera.fovy = 45.0
18+
camera.projection = CAMERA_PERSPECTIVE
19+
20+
image = load_image("resources/cubicmap.png")
21+
cubicmap = load_texture_from_image(image)
22+
mesh = gen_mesh_cubicmap(image, Vector3(1.0, 1.0, 1.0))
23+
model = load_model_from_mesh(mesh)
24+
texture = load_texture("resources/cubicmap_atlas.png")
25+
26+
model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture
27+
mapPosition = Vector3(-16.0, 0.0, -8.0)
28+
29+
unload_image(image)
30+
31+
set_target_fps(60)
32+
33+
while not window_should_close():
34+
update_camera(camera.byref, CAMERA_ORBITAL)
35+
36+
with drawing():
37+
clear_background(RAYWHITE)
38+
39+
with mode3d(camera):
40+
draw_model(model, mapPosition, 1.0, WHITE)
41+
# end_mode3d()
42+
43+
draw_texture_ex(cubicmap, Vector2(screenWidth - cubicmap.width * 4.0 - 20, 20.0), 0.0, 4.0, WHITE)
44+
draw_rectangle_lines(screenWidth - cubicmap.width * 4 - 20, 20, cubicmap.width * 4, cubicmap.height * 4, GREEN)
45+
draw_text("cubicmap image used to", 658, 90, 10, GRAY)
46+
draw_text("generate map 3d model", 658, 104, 10, GRAY)
47+
draw_fps(10, 10)
48+
49+
# end_drawing()
50+
51+
unload_texture(cubicmap)
52+
unload_texture(texture)
53+
unload_model(model)
54+
55+
close_window()
56+
57+
return 0
58+
59+
60+
if __name__ == "__main__":
61+
if len(sys.argv) >= 2 and isinstance(sys.argv[1], str):
62+
os.chdir(sys.argv[1])
63+
print("Working dir:", os.getcwd())
64+
sys.exit(main())

‎examples/models_geometric_shapes.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import sys
3+
import os
4+
from ctypes import byref
5+
from raylibpy import *
6+
7+
def main():
8+
9+
screenWidth = 800
10+
screenHeight = 450
11+
12+
init_window(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
13+
14+
camera = Camera()
15+
camera.position = Vector3(0.0, 10.0, 10.0)
16+
camera.target = Vector3(0.0, 0.0, 0.0)
17+
camera.up = Vector3(0.0, 1.0, 0.0)
18+
camera.fovy = 45.0
19+
camera.projection = CAMERA_PERSPECTIVE
20+
21+
set_target_fps(60)
22+
23+
while not window_should_close():
24+
with drawing():
25+
clear_background(RAYWHITE)
26+
27+
with mode3d(camera):
28+
draw_cube(Vector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, RED)
29+
draw_cube_wires(Vector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, GOLD)
30+
draw_cube_wires(Vector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, MAROON)
31+
draw_sphere(Vector3(-1.0, 0.0, -2.0), 1.0, GREEN)
32+
draw_sphere_wires(Vector3(1.0, 0.0, 2.0), 2.0, 16, 16, LIME)
33+
draw_cylinder(Vector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, SKYBLUE)
34+
draw_cylinder_wires(Vector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, DARKBLUE)
35+
draw_cylinder_wires(Vector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, BROWN)
36+
draw_cylinder(Vector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, GOLD)
37+
draw_cylinder_wires(Vector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, PINK)
38+
draw_capsule(Vector3(-3.0, 1.5, -4.0), Vector3(-4.0, -1.0, -4.0), 1.2, 8, 8, VIOLET)
39+
draw_capsule_wires(Vector3(-3.0, 1.5, -4.0), Vector3(-4.0, -1.0, -4.0), 1.2, 8, 8, PURPLE)
40+
draw_grid(10, 1.0)
41+
42+
# end_mode3d()
43+
44+
draw_fps(10, 10)
45+
46+
# end_drawing()
47+
48+
close_window()
49+
return 0
50+
51+
52+
if __name__ == "__main__":
53+
if len(sys.argv) >= 2 and isinstance(sys.argv[1], str):
54+
os.chdir(sys.argv[1])
55+
print("Working dir:", os.getcwd())
56+
sys.exit(main())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /