Merge pull request #86 from sDos280/master
adding example and making examples look neater
This commit is contained in:
commit
d4278968b5
4 changed files with 133 additions and 83 deletions
|
@ -30,7 +30,6 @@
|
||||||
|
|
||||||
import raylib as rl
|
import raylib as rl
|
||||||
|
|
||||||
|
|
||||||
from raylib.colors import *
|
from raylib.colors import *
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
@ -43,12 +42,13 @@ from rlmath import *
|
||||||
# lighting system
|
# lighting system
|
||||||
from light_system import *
|
from light_system import *
|
||||||
|
|
||||||
#// Initialization
|
# Initialization
|
||||||
#//--------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
screenWidth = 1200;
|
screenWidth = 1200
|
||||||
screenHeight = 720;
|
screenHeight = 720
|
||||||
|
|
||||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT| rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(
|
||||||
|
rl.FLAG_MSAA_4X_HINT | rl.FLAG_WINDOW_RESIZABLE); # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
rl.InitWindow(screenWidth, screenHeight, b"raylib [shaders] example - basic lighting")
|
||||||
|
|
||||||
camera = rl.ffi.new('struct Camera3D *', [
|
camera = rl.ffi.new('struct Camera3D *', [
|
||||||
|
@ -59,22 +59,22 @@ camera = rl.ffi.new('struct Camera3D *', [
|
||||||
rl.CAMERA_PERSPECTIVE
|
rl.CAMERA_PERSPECTIVE
|
||||||
])
|
])
|
||||||
|
|
||||||
#// Load models
|
# Load models
|
||||||
modelA = rl.LoadModelFromMesh(rl.GenMeshTorus(0.4, 1.0, 16, 32))
|
modelA = rl.LoadModelFromMesh(rl.GenMeshTorus(0.4, 1.0, 16, 32))
|
||||||
modelB = rl.LoadModelFromMesh(rl.GenMeshCube(1.0, 1.0, 1.0))
|
modelB = rl.LoadModelFromMesh(rl.GenMeshCube(1.0, 1.0, 1.0))
|
||||||
modelC = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
|
modelC = rl.LoadModelFromMesh(rl.GenMeshSphere(0.5, 32, 32))
|
||||||
|
|
||||||
#// Load models texture
|
# Load models texture
|
||||||
texture = rl.LoadTexture(b"resources/texel_checker.png")
|
texture = rl.LoadTexture(b"resources/texel_checker.png")
|
||||||
|
|
||||||
#// Assign texture to default model material
|
# Assign texture to default model material
|
||||||
modelA.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
modelA.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
modelB.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
modelB.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
modelC.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
modelC.materials[0].maps[rl.MATERIAL_MAP_ALBEDO].texture = texture
|
||||||
|
|
||||||
angle = 6.282;
|
angle = 6.282
|
||||||
|
|
||||||
#// Using 4 point lights, white, red, green and blue
|
# Using 4 point lights, white, red, green and blue
|
||||||
|
|
||||||
lights0 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), WHITE)
|
lights0 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), WHITE)
|
||||||
lights1 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), RED)
|
lights1 = Light(LIGHT_POINT, [4, 2, 4], Vector3Zero(), RED)
|
||||||
|
@ -85,7 +85,7 @@ lightSystem = LightSystem([ 0.2, 0.2, 0.2, 1.0 ], lights0, lights1, lights2, lig
|
||||||
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
|
fogD = rl.GetShaderLocation(lightSystem.shader, b'FogDensity')
|
||||||
fogDensity = 0.0
|
fogDensity = 0.0
|
||||||
|
|
||||||
#// All models use the same shader - which lights them
|
# All models use the same shader - which lights them
|
||||||
modelA.materials[0].shader = lightSystem.shader
|
modelA.materials[0].shader = lightSystem.shader
|
||||||
modelB.materials[0].shader = lightSystem.shader
|
modelB.materials[0].shader = lightSystem.shader
|
||||||
modelC.materials[0].shader = lightSystem.shader
|
modelC.materials[0].shader = lightSystem.shader
|
||||||
|
@ -93,20 +93,20 @@ modelC.materials[0].shader = lightSystem.shader
|
||||||
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) # Set an orbital camera mode
|
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) # Set an orbital camera mode
|
||||||
|
|
||||||
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
rl.SetTargetFPS(60) # // Set our game to run at 60 frames-per-second
|
||||||
#//--------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#// Main game loop
|
# Main game loop
|
||||||
while not rl.WindowShouldClose(): #// Detect window close button or ESC key
|
while not rl.WindowShouldClose(): # Detect window close button or ESC key
|
||||||
#// Update
|
# Update
|
||||||
#//----------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------
|
||||||
if rl.IsKeyPressed(rl.KEY_W): lights0.enabled = not lights0.enabled
|
if rl.IsKeyPressed(rl.KEY_W): lights0.enabled = not lights0.enabled
|
||||||
if rl.IsKeyPressed(rl.KEY_R): lights1.enabled = not lights1.enabled
|
if rl.IsKeyPressed(rl.KEY_R): lights1.enabled = not lights1.enabled
|
||||||
if rl.IsKeyPressed(rl.KEY_G): lights2.enabled = not lights2.enabled
|
if rl.IsKeyPressed(rl.KEY_G): lights2.enabled = not lights2.enabled
|
||||||
if rl.IsKeyPressed(rl.KEY_B): lights3.enabled = not lights3.enabled
|
if rl.IsKeyPressed(rl.KEY_B): lights3.enabled = not lights3.enabled
|
||||||
|
|
||||||
rl.UpdateCamera(camera) #// Update camera
|
rl.UpdateCamera(camera) # Update camera
|
||||||
|
|
||||||
#// Make the lights do differing orbits
|
# Make the lights do differing orbits
|
||||||
angle -= 0.02
|
angle -= 0.02
|
||||||
lights0.position.x = math.cos(angle) * 4.0
|
lights0.position.x = math.cos(angle) * 4.0
|
||||||
lights0.position.z = math.sin(angle) * 4.0
|
lights0.position.z = math.sin(angle) * 4.0
|
||||||
|
@ -117,15 +117,14 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
lights3.position.y = math.cos(-angle * 0.35) * 4.0
|
lights3.position.y = math.cos(-angle * 0.35) * 4.0
|
||||||
lights3.position.z = math.sin(-angle * 0.35) * 4.0
|
lights3.position.z = math.sin(-angle * 0.35) * 4.0
|
||||||
|
|
||||||
#// Update the light shader with the camera view position
|
# Update the light shader with the camera view position
|
||||||
|
|
||||||
lightSystem.update(camera.position)
|
lightSystem.update(camera.position)
|
||||||
|
|
||||||
|
|
||||||
# ffi.cast('wchar_t', x)
|
# ffi.cast('wchar_t', x)
|
||||||
# modelA.transform = ffi.cast('Matrix *', MatrixRotateY(angle*1.7))[0]
|
# modelA.transform = ffi.cast('Matrix *', MatrixRotateY(angle*1.7))[0]
|
||||||
# modelA.transform = MatrixRotateY(angle*1.7)
|
# modelA.transform = MatrixRotateY(angle*1.7)
|
||||||
#// Rotate the torus
|
# Rotate the torus
|
||||||
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
|
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)[0])[0]
|
||||||
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
|
# modelA.transform = MatrixMultiply(modelA.transform, MatrixRotateZ(0.012)[0])[0]
|
||||||
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
modelA.transform = rl.ffi.cast('Matrix *', MatrixMultiply(modelA.transform, MatrixRotateX(-0.025)))[0]
|
||||||
|
@ -134,26 +133,24 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
if (rl.IsKeyPressed(rl.KEY_F)):
|
if (rl.IsKeyPressed(rl.KEY_F)):
|
||||||
rl.ToggleFullscreen()
|
rl.ToggleFullscreen()
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#//----------------------------------------------------------------------------------
|
# Draw
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
#// Draw
|
|
||||||
#//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(RAYWHITE)
|
rl.ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
rl.BeginMode3D(camera[0])
|
rl.BeginMode3D(camera[0])
|
||||||
|
|
||||||
#// Draw the three models
|
# Draw the three models
|
||||||
rl.DrawModel(modelA, [0, 0, 0], 1.0, WHITE)
|
rl.DrawModel(modelA, [0, 0, 0], 1.0, WHITE)
|
||||||
rl.DrawModel(modelB, [-1.6, 0, 0], 1.0, WHITE)
|
rl.DrawModel(modelB, [-1.6, 0, 0], 1.0, WHITE)
|
||||||
rl.DrawModel(modelC, [1.6, 0, 0], 1.0, WHITE)
|
rl.DrawModel(modelC, [1.6, 0, 0], 1.0, WHITE)
|
||||||
|
|
||||||
#// Draw markers to show where the lights are
|
# Draw markers to show where the lights are
|
||||||
lightSystem.draw()
|
lightSystem.draw()
|
||||||
|
|
||||||
|
|
||||||
rl.DrawGrid(10, 1.0)
|
rl.DrawGrid(10, 1.0)
|
||||||
|
|
||||||
rl.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
@ -163,17 +160,17 @@ while not rl.WindowShouldClose(): #// Detect window close button or E
|
||||||
rl.DrawText(b"Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY)
|
rl.DrawText(b"Keys RGB & W toggle lights", 10, 30, 20, DARKGRAY)
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
#//----------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
#// De-Initialization
|
# De-Initialization
|
||||||
#//--------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
rl.UnloadModel(modelA) # // Unload the modelA
|
rl.UnloadModel(modelA) # Unload the modelA
|
||||||
rl.UnloadModel(modelB) # // Unload the modelB
|
rl.UnloadModel(modelB) # Unload the modelB
|
||||||
rl.UnloadModel(modelC) # // Unload the modelC
|
rl.UnloadModel(modelC) # Unload the modelC
|
||||||
|
|
||||||
rl.UnloadTexture(texture) #// Unload the texture
|
rl.UnloadTexture(texture) # Unload the texture
|
||||||
|
|
||||||
rl.UnloadShader(lightSystem.shader)
|
rl.UnloadShader(lightSystem.shader)
|
||||||
|
|
||||||
rl.CloseWindow() #// Close window and OpenGL context
|
rl.CloseWindow() # Close window and OpenGL context
|
||||||
|
|
|
@ -65,7 +65,6 @@ while not rl.WindowShouldClose():
|
||||||
|
|
||||||
lightSystem.update(camera.position)
|
lightSystem.update(camera.position)
|
||||||
|
|
||||||
|
|
||||||
model.transform = rl.ffi.cast("Matrix *", MatrixMultiply(model.transform, MatrixRotateX(-0.025)))[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]
|
model.transform = rl.ffi.cast("Matrix *", MatrixMultiply(model.transform, MatrixRotateZ(0.012)))[0]
|
||||||
|
|
||||||
|
@ -84,7 +83,6 @@ while not rl.WindowShouldClose():
|
||||||
if rl.IsKeyDown(rl.KEY_SPACE):
|
if rl.IsKeyDown(rl.KEY_SPACE):
|
||||||
rl.ClearBackground(BLACK)
|
rl.ClearBackground(BLACK)
|
||||||
|
|
||||||
|
|
||||||
rl.BeginMode3D(camera[0])
|
rl.BeginMode3D(camera[0])
|
||||||
rl.DrawModel(model, [0] * 3, 1, WHITE)
|
rl.DrawModel(model, [0] * 3, 1, WHITE)
|
||||||
rl.DrawModel(model2, [-2.6, 0, 0], 1, WHITE)
|
rl.DrawModel(model2, [-2.6, 0, 0], 1, WHITE)
|
||||||
|
@ -93,7 +91,6 @@ while not rl.WindowShouldClose():
|
||||||
for i in range(-20, 20, 2):
|
for i in range(-20, 20, 2):
|
||||||
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
|
rl.DrawModel(model, [i, 0, 2], 1, WHITE)
|
||||||
|
|
||||||
|
|
||||||
# Raylib removed this function
|
# Raylib removed this function
|
||||||
# rl.DrawGizmo([1000, 1000, 1000])
|
# rl.DrawGizmo([1000, 1000, 1000])
|
||||||
|
|
||||||
|
@ -110,4 +107,3 @@ rl.UnloadModel(model3)
|
||||||
rl.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
rl.UnloadShader(lightSystem.shader)
|
rl.UnloadShader(lightSystem.shader)
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
|
|
||||||
|
|
61
examples/shapes/shapes_lines_bezier.py
Normal file
61
examples/shapes/shapes_lines_bezier.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
"""
|
||||||
|
|
||||||
|
raylib [shapes] example - Lines Bezier
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pyray import *
|
||||||
|
from raylib.colors import (
|
||||||
|
RAYWHITE,
|
||||||
|
GRAY,
|
||||||
|
RED
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
# Program main entry point
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
def main():
|
||||||
|
# Initialization
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
screenWidth = 800
|
||||||
|
screenHeight = 450
|
||||||
|
|
||||||
|
set_config_flags(ConfigFlags.FLAG_MSAA_4X_HINT)
|
||||||
|
init_window(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
|
||||||
|
|
||||||
|
start = Vector2(0, 0)
|
||||||
|
end = Vector2(screenWidth, screenHeight)
|
||||||
|
|
||||||
|
set_target_fps(60) # Set our game to run at 60 frames-per-second
|
||||||
|
# -------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Main game loop
|
||||||
|
while not window_should_close(): # Detect window close button or ESC key
|
||||||
|
# Update
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
if is_mouse_button_down(MouseButton.MOUSE_BUTTON_LEFT): start = get_mouse_position()
|
||||||
|
if is_mouse_button_down(MouseButton.MOUSE_BUTTON_RIGHT): end = get_mouse_position()
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Draw
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
begin_drawing()
|
||||||
|
|
||||||
|
clear_background(RAYWHITE)
|
||||||
|
|
||||||
|
draw_text("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY)
|
||||||
|
|
||||||
|
draw_line_bezier(start, end, 2.0, RED)
|
||||||
|
|
||||||
|
end_drawing()
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# De-Initialization
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
close_window() # Close window and OpenGL context
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# execute the main function
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -5,9 +5,7 @@ screenHeight = 450
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, b"raylib [textures] example - image loading")
|
InitWindow(screenWidth, screenHeight, b"raylib [textures] example - image loading")
|
||||||
|
|
||||||
|
image = LoadImage(b"resources/raylib_logo.png")
|
||||||
|
|
||||||
image = LoadImage(b"resources/raylib_logo.jpg")
|
|
||||||
texture = LoadTextureFromImage(image)
|
texture = LoadTextureFromImage(image)
|
||||||
|
|
||||||
UnloadImage(image)
|
UnloadImage(image)
|
||||||
|
@ -24,8 +22,6 @@ while not WindowShouldClose():
|
||||||
|
|
||||||
EndDrawing()
|
EndDrawing()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UnloadTexture(texture)
|
UnloadTexture(texture)
|
||||||
|
|
||||||
CloseWindow()
|
CloseWindow()
|
||||||
|
|
Reference in a new issue