This commit is contained in:
richard 2022-02-02 18:21:34 +00:00
parent ff84bdf2dd
commit 218d9a18f7
7 changed files with 84 additions and 145 deletions

View file

@ -1,4 +1,3 @@
#!/usr/bin/env python3
"""
Example converted to Python from:
@ -8,20 +7,9 @@ http://bedroomcoders.co.uk/raylib-fog/
"""
#
#<<<<<<< HEAD
#<<<<<<< HEAD
#<<<<<<< HEAD
from raylib import rl, ffi
#=======
#from raylib.dynamic import raylib as rl, ffi
#>>>>>>> ffe4403 (complete fog example)
#=======
#from raylib.static import rl, ffi
#>>>>>>> 10b63b9 (added shaders_texture_waves.py)
#=======
#from raylib.static import rl, ffi
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
import raylib as rl
from raylib.colors import *
import math
@ -31,7 +19,7 @@ from light_system import *
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE)
rl.InitWindow(1280, 768, b'Fog Test')
camera = ffi.new('struct Camera3D *', [
camera = rl.ffi.new('struct Camera3D *', [
[6, 2, 6],
[0, .5, 0],
[0, 1, 0],
@ -45,26 +33,20 @@ model3 = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
texture = rl.LoadTexture(b'resources/test.png')
model.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model2.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model3.materials[0].maps[rl.MAP_DIFFUSE].texture = texture
model.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
model2.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
model3.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
light = Light(LIGHT_POINT, [ 0, 4, 0 ], Vector3Zero(), WHITE)
lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], light)
#
#<<<<<<< HEAD
#<<<<<<< HEAD
fog_color = ffi.new('float[]', [0.2,0.2,1.0,1.0])
fog_color = rl.ffi.new('float[]', [0.2,0.2,1.0,1.0])
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.UNIFORM_VEC4);
#=======
#fog_color = [0.2, 0.2, 1.0, 1.0]
#>>>>>>> ffe4403 (complete fog example)
#=======
#fog_color = ffi.new('float[]', [0.2,0.2,1.0,1.0])
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
fogC = rl.GetShaderLocation(lightSystem.shader, b'fogColor')
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.UNIFORM_VEC4);
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
rl.SetShaderValue(lightSystem.shader, fogC, fog_color, rl.SHADER_UNIFORM_VEC4);
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
fogDensity = 0.12
@ -84,8 +66,8 @@ while not rl.WindowShouldClose():
lightSystem.update(camera.position)
model.transform = ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
model.transform = ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[0]
model.transform = rl.ffi.cast("Matrix *",MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
if rl.IsKeyDown(rl.KEY_UP):
fogDensity = min(fogDensity + 0.001, 1)
@ -93,21 +75,15 @@ while not rl.WindowShouldClose():
if rl.IsKeyDown(rl.KEY_DOWN):
fogDensity = max(fogDensity - 0.001, 0)
rl.SetShaderValue(lightSystem.shader, fogD, ffi.new('float[]', [fogDensity]), rl.UNIFORM_FLOAT)
rl.SetShaderValue(lightSystem.shader, fogD, rl.ffi.new('float[]', [fogDensity]), rl.SHADER_UNIFORM_FLOAT)
rl.BeginDrawing()
rl.ClearBackground([int(255 * i) for i in fog_color])
#<<<<<<< HEAD
#<<<<<<< HEAD
# if rl.IsKeyDown(rl.KEY_SPACE):
# rl.ClearBackground(BLACK)
#=======
#>>>>>>> ffe4403 (complete fog example)
#=======
if rl.IsKeyDown(rl.KEY_SPACE):
rl.ClearBackground(BLACK)
#>>>>>>> 1775ffc4b093c881ee44a8027b4143add066d738
rl.BeginMode3D(camera[0])
rl.DrawModel(model, [0] * 3, 1, WHITE)
@ -118,7 +94,8 @@ while not rl.WindowShouldClose():
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
rl.DrawGizmo([1000, 1000, 1000])
#Raylib removed this function
#rl.DrawGizmo([1000, 1000, 1000])
rl.EndMode3D()