Skip to content

Commit 069e3dd

Browse files
committed
Added example.
1 parent da0bb9e commit 069e3dd

File tree

6 files changed

+4172
-1
lines changed

6 files changed

+4172
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $(TARGET): src/raylib.f90 src/raylib_util.f90
2121
$(FC) $(FFLAGS) -c src/raylib_util.f90
2222
$(AR) $(ARFLAGS) $(TARGET) raylib.o raylib_camera.o raylib_math.o raylib_util.o
2323

24-
examples: camera castle cubes flags fly keys map window
24+
examples: camera castle cubes flags fly keys map truck window
2525

2626
camera: $(TARGET) examples/camera.f90
2727
$(FC) $(FFLAGS) $(LDFLAGS) -o camera examples/camera.f90 $(TARGET) $(LDLIBS)
@@ -44,6 +44,9 @@ keys: $(TARGET) examples/keys.f90
4444
map: $(TARGET) examples/map.f90
4545
$(FC) $(FFLAGS) $(LDFLAGS) -o map examples/map.f90 $(TARGET) $(LDLIBS)
4646

47+
truck: $(TARGET) examples/truck.f90
48+
$(FC) $(FFLAGS) $(LDFLAGS) -o truck examples/truck.f90 $(TARGET) $(LDLIBS)
49+
4750
window: $(TARGET) examples/window.f90
4851
$(FC) $(FFLAGS) $(LDFLAGS) -o window examples/window.f90 $(TARGET) $(LDLIBS)
4952

@@ -58,4 +61,5 @@ clean:
5861
if [ -e fly ]; then rm fly; fi
5962
if [ -e keys ]; then rm keys; fi
6063
if [ -e map ]; then rm map; fi
64+
if [ -e truck ]; then rm truck; fi
6165
if [ -e window ]; then rm window; fi

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ More examples can be found in `examples/`:
100100
* **fly** renders a 3-D scene, with keyboard and mouse controls.
101101
* **keys** demonstrates keyboard input.
102102
* **map** renders a height map.
103+
* **truck** rotates a 3-D model loaded from file.
103104
* **window** opens a window with raylib.
104105

105106
Build all examples with:

examples/truck.f90

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
! truck.f90
2+
!
3+
! Example program that rotates a 3-D model loaded from file.
4+
! Model (CC0) source: https://kenney.nl/assets/car-kit
5+
!
6+
! Author: Philipp Engel
7+
! Licence: ISC
8+
program main
9+
use, intrinsic :: iso_c_binding
10+
use :: raylib
11+
use :: raylib_math
12+
implicit none (type, external)
13+
14+
integer, parameter :: SCREEN_WIDTH = 800
15+
integer, parameter :: SCREEN_HEIGHT = 450
16+
17+
real :: angle
18+
type(camera3d_type) :: camera
19+
type(model_type) :: model
20+
type(vector3_type) :: position
21+
type(vector3_type) :: rotation
22+
type(vector3_type) :: scale
23+
24+
call init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'Fortran + raylib' // c_null_char)
25+
call set_target_fps(60)
26+
call disable_cursor()
27+
28+
! Define camera to look into our 3-D world.
29+
camera%position = vector3_type(50.0, 50.0, 50.0)
30+
camera%target = vector3_type(0.0, 0.0, 0.0)
31+
camera%up = vector3_type(0.0, 1.0, 0.0)
32+
camera%fov_y = 45.0
33+
camera%projection = CAMERA_PERSPECTIVE
34+
35+
model = load_model('share/truck.obj' // c_null_char)
36+
37+
angle = 0.0
38+
rotation = vector3_type(0.0, 1.0, 0.0)
39+
scale = vector3_type(15.0, 15.0, 15.0)
40+
41+
do while (.not. window_should_close())
42+
call update_camera(camera, CAMERA_FIRST_PERSON)
43+
44+
angle = modulo(angle + 0.1, 360.0)
45+
46+
call begin_drawing()
47+
call clear_background(RAYWHITE)
48+
49+
call begin_mode3d(camera)
50+
call draw_model_ex(model, position, rotation, angle, scale, WHITE)
51+
call draw_grid(20, 10.0)
52+
call end_mode3d()
53+
54+
call draw_fps(10, 10)
55+
call end_drawing()
56+
end do
57+
58+
call unload_model(model)
59+
call close_window()
60+
end program main

fpm.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ name = "keys"
4646
source-dir = "examples"
4747
main = "keys.f90"
4848

49+
[[executable]]
50+
name = "map"
51+
source-dir = "examples"
52+
main = "map.f90"
53+
54+
[[executable]]
55+
name = "truck"
56+
source-dir = "examples"
57+
main = "truck.f90"
58+
4959
[[executable]]
5060
name = "window"
5161
source-dir = "examples"

share/truck.mtl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Created by Kenney (www.kenney.nl)
2+
3+
newmtl plastic
4+
Kd 0.3764706 0.3764706 0.3764706
5+
6+
newmtl carTire
7+
Kd 0.2392156 0.2392156 0.2392156
8+
9+
newmtl paintGreen
10+
Kd 0.246796 0.8867924 0.5275686
11+
12+
newmtl lightFront
13+
Kd 0.9607843 0.7254902 0.2588235
14+
15+
newmtl _defaultMat
16+
Kd 1 1 1
17+
18+
newmtl lightBack
19+
Kd 1 0.3490196 0.2274509
20+
21+
newmtl window
22+
Kd 0.9372549 0.9372549 0.9372549
23+
24+
newmtl wheelInside
25+
Kd 0.7960573 0.8047704 0.8396226

0 commit comments

Comments
 (0)