New examples from @chriscamacho (#23)
* complete fog example as both fog and basic lighting need the light system it made sense to seperate it out, there are a few functions from raymath int rlmath.py * added shaders custom uniform * added shaders_texture_waves.py * added shaders_texture_drawing.py * bug fix - unwanted transparent effect! * complete fog example as both fog and basic lighting need the light system it made sense to seperate it out, there are a few functions from raymath int rlmath.py * added shaders custom uniform * added shaders_texture_waves.py * initial commit still WIP * updated raylib * undo all changes in this branch except for the example updates * remove local raylib-c Co-authored-by: codifies <nospam@antispam.com>
Before Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 403 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 95 KiB |
|
@ -1,196 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - PBR material
|
||||
*
|
||||
* This example has been created using raylib 1.8 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#define RLIGHTS_IMPLEMENTATION
|
||||
#include "rlights.h"
|
||||
|
||||
#define CUBEMAP_SIZE 512 # Cubemap texture size
|
||||
#define IRRADIANCE_SIZE 32 # Irradiance texture size
|
||||
#define PREFILTERED_SIZE 256 # Prefiltered HDR environment texture size
|
||||
#define BRDF_SIZE 512 # BRDF LUT texture size
|
||||
|
||||
# PBR material loading
|
||||
static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
|
||||
int main()
|
||||
[
|
||||
# Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800
|
||||
int screenHeight = 450
|
||||
|
||||
SetConfigFlags(FLAG_MSAA_4X_HINT) # Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - pbr material")
|
||||
|
||||
# Define the camera to look into our 3d world
|
||||
Camera camera = [[ 4.0, 4.0, 4.0 ], [ 0.0, 0.5f, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ]
|
||||
|
||||
# Load model and PBR material
|
||||
Model model = LoadModel("resources/pbr/trooper.obj")
|
||||
MeshTangents(&model.mesh)
|
||||
model.material = LoadMaterialPBR((Color)[ 255, 255, 255, 255 ], 1.0, 1.0)
|
||||
|
||||
# Define lights attributes
|
||||
# NOTE: Shader is passed to every light on creation to define shader bindings internally
|
||||
Light lights[MAX_LIGHTS] = [
|
||||
CreateLight(LIGHT_POINT, (Vector3)[ LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0 ], (Vector3)[ 0.0, 0.0, 0.0 ], (Color)[ 255, 0, 0, 255 ], model.material.shader),
|
||||
CreateLight(LIGHT_POINT, (Vector3)[ 0.0, LIGHT_HEIGHT, LIGHT_DISTANCE ], (Vector3)[ 0.0, 0.0, 0.0 ], (Color)[ 0, 255, 0, 255 ], model.material.shader),
|
||||
CreateLight(LIGHT_POINT, (Vector3)[ -LIGHT_DISTANCE, LIGHT_HEIGHT, 0.0 ], (Vector3)[ 0.0, 0.0, 0.0 ], (Color)[ 0, 0, 255, 255 ], model.material.shader),
|
||||
CreateLight(LIGHT_DIRECTIONAL, (Vector3)[ 0.0, LIGHT_HEIGHT*2.0, -LIGHT_DISTANCE ], (Vector3)[ 0.0, 0.0, 0.0 ], (Color)[ 255, 0, 255, 255 ], model.material.shader)
|
||||
]
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL) # Set an orbital camera mode
|
||||
|
||||
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# Main game loop
|
||||
while (!WindowShouldClose()) # Detect window close button or ESC key
|
||||
[
|
||||
# Update
|
||||
#----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera) # Update camera
|
||||
|
||||
# Send to material PBR shader camera view position
|
||||
float cameraPos[3] = [ camera.position.x, camera.position.y, camera.position.z ]
|
||||
SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, 3)
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
BeginMode3D(camera)
|
||||
|
||||
DrawModel(model, Vector3Zero(), 1.0, WHITE)
|
||||
|
||||
DrawGrid(10, 1.0)
|
||||
|
||||
EndMode3D()
|
||||
|
||||
DrawFPS(10, 10)
|
||||
|
||||
EndDrawing()
|
||||
#----------------------------------------------------------------------------------
|
||||
]
|
||||
|
||||
# De-Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
UnloadModel(model) # Unload skybox model
|
||||
|
||||
CloseWindow() # Close window and OpenGL context
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
return 0
|
||||
]
|
||||
|
||||
# Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps)
|
||||
# NOTE: PBR shader is loaded inside this function
|
||||
static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
[
|
||||
Material mat = [ 0 ] # NOTE: All maps textures are set to [ 0 ]
|
||||
|
||||
#define PATH_PBR_VS "resources/shaders/pbr.vs" # Path to physically based rendering vertex shader
|
||||
#define PATH_PBR_FS "resources/shaders/pbr.fs" # Path to physically based rendering fragment shader
|
||||
|
||||
mat.shader = LoadShader(PATH_PBR_VS, PATH_PBR_FS)
|
||||
|
||||
# Get required locations points for PBR material
|
||||
# NOTE: Those location names must be available and used in the shader code
|
||||
mat.shader.locs[LOC_MAP_ALBEDO] = GetShaderLocation(mat.shader, "albedo.sampler")
|
||||
mat.shader.locs[LOC_MAP_METALNESS] = GetShaderLocation(mat.shader, "metalness.sampler")
|
||||
mat.shader.locs[LOC_MAP_NORMAL] = GetShaderLocation(mat.shader, "normals.sampler")
|
||||
mat.shader.locs[LOC_MAP_ROUGHNESS] = GetShaderLocation(mat.shader, "roughness.sampler")
|
||||
mat.shader.locs[LOC_MAP_OCCLUSION] = GetShaderLocation(mat.shader, "occlusion.sampler")
|
||||
#mat.shader.locs[LOC_MAP_EMISSION] = GetShaderLocation(mat.shader, "emission.sampler")
|
||||
#mat.shader.locs[LOC_MAP_HEIGHT] = GetShaderLocation(mat.shader, "height.sampler")
|
||||
mat.shader.locs[LOC_MAP_IRRADIANCE] = GetShaderLocation(mat.shader, "irradianceMap")
|
||||
mat.shader.locs[LOC_MAP_PREFILTER] = GetShaderLocation(mat.shader, "prefilterMap")
|
||||
mat.shader.locs[LOC_MAP_BRDF] = GetShaderLocation(mat.shader, "brdfLUT")
|
||||
|
||||
# Set view matrix location
|
||||
mat.shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(mat.shader, "matModel")
|
||||
mat.shader.locs[LOC_MATRIX_VIEW] = GetShaderLocation(mat.shader, "view")
|
||||
mat.shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(mat.shader, "viewPos")
|
||||
|
||||
# Set PBR standard maps
|
||||
mat.maps[MAP_ALBEDO].texture = LoadTexture("resources/pbr/trooper_albedo.png")
|
||||
mat.maps[MAP_NORMAL].texture = LoadTexture("resources/pbr/trooper_normals.png")
|
||||
mat.maps[MAP_METALNESS].texture = LoadTexture("resources/pbr/trooper_metalness.png")
|
||||
mat.maps[MAP_ROUGHNESS].texture = LoadTexture("resources/pbr/trooper_roughness.png")
|
||||
mat.maps[MAP_OCCLUSION].texture = LoadTexture("resources/pbr/trooper_ao.png")
|
||||
|
||||
# Set environment maps
|
||||
#define PATH_CUBEMAP_VS "resources/shaders/cubemap.vs" # Path to equirectangular to cubemap vertex shader
|
||||
#define PATH_CUBEMAP_FS "resources/shaders/cubemap.fs" # Path to equirectangular to cubemap fragment shader
|
||||
#define PATH_SKYBOX_VS "resources/shaders/skybox.vs" # Path to skybox vertex shader
|
||||
#define PATH_IRRADIANCE_FS "resources/shaders/irradiance.fs" # Path to irradiance (GI) calculation fragment shader
|
||||
#define PATH_PREFILTER_FS "resources/shaders/prefilter.fs" # Path to reflection prefilter calculation fragment shader
|
||||
#define PATH_BRDF_VS "resources/shaders/brdf.vs" # Path to bidirectional reflectance distribution function vertex shader
|
||||
#define PATH_BRDF_FS "resources/shaders/brdf.fs" # Path to bidirectional reflectance distribution function fragment shader
|
||||
|
||||
Shader shdrCubemap = LoadShader(PATH_CUBEMAP_VS, PATH_CUBEMAP_FS)
|
||||
Shader shdrIrradiance = LoadShader(PATH_SKYBOX_VS, PATH_IRRADIANCE_FS)
|
||||
Shader shdrPrefilter = LoadShader(PATH_SKYBOX_VS, PATH_PREFILTER_FS)
|
||||
Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS)
|
||||
|
||||
# Setup required shader locations
|
||||
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1])[ 0 ], 1)
|
||||
SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1])[ 0 ], 1)
|
||||
SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1])[ 0 ], 1)
|
||||
|
||||
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr")
|
||||
Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE)
|
||||
mat.maps[MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE)
|
||||
mat.maps[MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE)
|
||||
mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, cubemap, BRDF_SIZE)
|
||||
UnloadTexture(cubemap)
|
||||
UnloadTexture(texHDR)
|
||||
|
||||
# Unload already used shaders (to create specific textures)
|
||||
UnloadShader(shdrCubemap)
|
||||
UnloadShader(shdrIrradiance)
|
||||
UnloadShader(shdrPrefilter)
|
||||
UnloadShader(shdrBRDF)
|
||||
|
||||
# Set textures filtering for better quality
|
||||
SetTextureFilter(mat.maps[MAP_ALBEDO].texture, FILTER_BILINEAR)
|
||||
SetTextureFilter(mat.maps[MAP_NORMAL].texture, FILTER_BILINEAR)
|
||||
SetTextureFilter(mat.maps[MAP_METALNESS].texture, FILTER_BILINEAR)
|
||||
SetTextureFilter(mat.maps[MAP_ROUGHNESS].texture, FILTER_BILINEAR)
|
||||
SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR)
|
||||
|
||||
# Enable sample usage in shader for assigned textures
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1])[ 1 ], 1)
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1])[ 1 ], 1)
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1])[ 1 ], 1)
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1])[ 1 ], 1)
|
||||
SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1])[ 1 ], 1)
|
||||
|
||||
int renderModeLoc = GetShaderLocation(mat.shader, "renderMode")
|
||||
SetShaderValuei(mat.shader, renderModeLoc, (int[1])[ 0 ], 1)
|
||||
|
||||
# Set up material properties color
|
||||
mat.maps[MAP_ALBEDO].color = albedo
|
||||
mat.maps[MAP_NORMAL].color = (Color)[ 128, 128, 255, 255 ]
|
||||
mat.maps[MAP_METALNESS].value = metalness
|
||||
mat.maps[MAP_ROUGHNESS].value = roughness
|
||||
mat.maps[MAP_OCCLUSION].value = 1.0
|
||||
mat.maps[MAP_EMISSION].value = 0.5f
|
||||
mat.maps[MAP_HEIGHT].value = 0.5f
|
||||
|
||||
return mat
|
||||
]
|
Before Width: | Height: | Size: 317 KiB |
|
@ -1,113 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib example - procedural mesh generation
|
||||
*
|
||||
* This example has been created using raylib 1.8 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2017 Ramon Santamaria (Ray San)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#define NUM_MODELS 7 # We generate 7 parametric 3d shapes
|
||||
|
||||
int main()
|
||||
[
|
||||
# Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800
|
||||
int screenHeight = 450
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation")
|
||||
|
||||
# We generate a checked image for texturing
|
||||
Image checked = GenImageChecked(2, 2, 1, 1, RED, GREEN)
|
||||
Texture2D texture = LoadTextureFromImage(checked)
|
||||
UnloadImage(checked)
|
||||
|
||||
Model models[NUM_MODELS]
|
||||
|
||||
models[0] = LoadModelFromMesh(GenMeshPlane(2, 2, 5, 5))
|
||||
models[1] = LoadModelFromMesh(GenMeshCube(2.0, 1.0, 2.0))
|
||||
models[2] = LoadModelFromMesh(GenMeshSphere(2, 32, 32))
|
||||
models[3] = LoadModelFromMesh(GenMeshHemiSphere(2, 16, 16))
|
||||
models[4] = LoadModelFromMesh(GenMeshCylinder(1, 2, 16))
|
||||
models[5] = LoadModelFromMesh(GenMeshTorus(0.25f, 4.0, 16, 32))
|
||||
models[6] = LoadModelFromMesh(GenMeshKnot(1.0, 2.0, 16, 128))
|
||||
|
||||
# Set checked texture as default diffuse component for all models material
|
||||
for (int i = 0 i < NUM_MODELS i++) models[i].material.maps[MAP_DIFFUSE].texture = texture
|
||||
|
||||
# Define the camera to look into our 3d world
|
||||
Camera camera = [[ 5.0, 5.0, 5.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ]
|
||||
|
||||
# Model drawing position
|
||||
Vector3 position = [ 0.0, 0.0, 0.0 ]
|
||||
|
||||
int currentModel = 0
|
||||
|
||||
SetCameraMode(camera, CAMERA_ORBITAL) # Set a orbital camera mode
|
||||
|
||||
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# Main game loop
|
||||
while (!WindowShouldClose()) # Detect window close button or ESC key
|
||||
[
|
||||
# Update
|
||||
#----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera) # Update internal camera and our camera
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
[
|
||||
currentModel = (currentModel + 1)%NUM_MODELS # Cycle between the textures
|
||||
]
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
BeginMode3D(camera)
|
||||
|
||||
DrawModel(models[currentModel], position, 1.0, WHITE)
|
||||
|
||||
DrawGrid(10, 1.0)
|
||||
|
||||
EndMode3D()
|
||||
|
||||
DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f))
|
||||
DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f))
|
||||
DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, BLUE)
|
||||
|
||||
switch(currentModel)
|
||||
[
|
||||
case 0: DrawText("PLANE", 680, 10, 20, DARKBLUE) break
|
||||
case 1: DrawText("CUBE", 680, 10, 20, DARKBLUE) break
|
||||
case 2: DrawText("SPHERE", 680, 10, 20, DARKBLUE) break
|
||||
case 3: DrawText("HEMISPHERE", 640, 10, 20, DARKBLUE) break
|
||||
case 4: DrawText("CYLINDER", 680, 10, 20, DARKBLUE) break
|
||||
case 5: DrawText("TORUS", 680, 10, 20, DARKBLUE) break
|
||||
case 6: DrawText("KNOT", 680, 10, 20, DARKBLUE) break
|
||||
default: break
|
||||
]
|
||||
|
||||
EndDrawing()
|
||||
#----------------------------------------------------------------------------------
|
||||
]
|
||||
|
||||
# De-Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# Unload models data (GPU VRAM)
|
||||
for (int i = 0 i < NUM_MODELS i++) UnloadModel(models[i])
|
||||
|
||||
CloseWindow() # Close window and OpenGL context
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
return 0
|
||||
]
|
Before Width: | Height: | Size: 27 KiB |
|
@ -1,201 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh
|
||||
*
|
||||
* This example has been created using raylib 1.7 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
* Example contributed by Joel Davis (@joeld42)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#define FLT_MAX 3.40282347E+38F # Maximum value of a float, defined in <float.h>
|
||||
|
||||
int main()
|
||||
[
|
||||
# Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800
|
||||
int screenHeight = 450
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking")
|
||||
|
||||
# Define the camera to look into our 3d world
|
||||
Camera camera
|
||||
camera.position = (Vector3)[ 20.0, 20.0, 20.0 ] # Camera position
|
||||
camera.target = (Vector3)[ 0.0, 8.0, 0.0 ] # Camera looking at point
|
||||
camera.up = (Vector3)[ 0.0, 1.6f, 0.0 ] # Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0 # Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE # Camera mode type
|
||||
|
||||
Ray ray # Picking ray
|
||||
|
||||
Model tower = LoadModel("resources/models/turret.obj") # Load OBJ model
|
||||
Texture2D texture = LoadTexture("resources/models/turret_diffuse.png") # Load model texture
|
||||
tower.material.maps[MAP_DIFFUSE].texture = texture # Set model diffuse texture
|
||||
|
||||
Vector3 towerPos = [ 0.0, 0.0, 0.0 ] # Set model position
|
||||
BoundingBox towerBBox = MeshBoundingBox(tower.mesh) # Get mesh bounding box
|
||||
bool hitMeshBBox = false
|
||||
bool hitTriangle = false
|
||||
|
||||
# Test triangle
|
||||
Vector3 ta = (Vector3)[ -25.0, 0.5, 0.0 ]
|
||||
Vector3 tb = (Vector3)[ -4.0, 2.5, 1.0 ]
|
||||
Vector3 tc = (Vector3)[ -8.0, 6.5, 0.0 ]
|
||||
|
||||
Vector3 bary = [ 0.0, 0.0, 0.0 ]
|
||||
|
||||
SetCameraMode(camera, CAMERA_FREE) # Set a free camera mode
|
||||
|
||||
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||
#--------------------------------------------------------------------------------------
|
||||
# Main game loop
|
||||
while (!WindowShouldClose()) # Detect window close button or ESC key
|
||||
[
|
||||
# Update
|
||||
#----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera) # Update camera
|
||||
|
||||
# Display information about closest hit
|
||||
RayHitInfo nearestHit
|
||||
char *hitObjectName = "None"
|
||||
nearestHit.distance = FLT_MAX
|
||||
nearestHit.hit = false
|
||||
Color cursorColor = WHITE
|
||||
|
||||
# Get ray and test against ground, triangle, and mesh
|
||||
ray = GetMouseRay(GetMousePosition(), camera)
|
||||
|
||||
# Check ray collision aginst ground plane
|
||||
RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0)
|
||||
|
||||
if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance))
|
||||
[
|
||||
nearestHit = groundHitInfo
|
||||
cursorColor = GREEN
|
||||
hitObjectName = "Ground"
|
||||
]
|
||||
|
||||
# Check ray collision against test triangle
|
||||
RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc)
|
||||
|
||||
if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance))
|
||||
[
|
||||
nearestHit = triHitInfo
|
||||
cursorColor = PURPLE
|
||||
hitObjectName = "Triangle"
|
||||
|
||||
bary = Vector3Barycenter(nearestHit.position, ta, tb, tc)
|
||||
hitTriangle = true
|
||||
]
|
||||
else hitTriangle = false
|
||||
|
||||
RayHitInfo meshHitInfo
|
||||
|
||||
# Check ray collision against bounding box first, before trying the full ray-mesh test
|
||||
if (CheckCollisionRayBox(ray, towerBBox))
|
||||
[
|
||||
hitMeshBBox = true
|
||||
|
||||
# Check ray collision against model
|
||||
# NOTE: It considers model.transform matrix!
|
||||
meshHitInfo = GetCollisionRayModel(ray, &tower)
|
||||
|
||||
if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance))
|
||||
[
|
||||
nearestHit = meshHitInfo
|
||||
cursorColor = ORANGE
|
||||
hitObjectName = "Mesh"
|
||||
]
|
||||
|
||||
] hitMeshBBox = false
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
BeginMode3D(camera)
|
||||
|
||||
# Draw the tower
|
||||
# WARNING: If scale is different than 1.0,
|
||||
# not considered by GetCollisionRayModel()
|
||||
DrawModel(tower, towerPos, 1.0, WHITE)
|
||||
|
||||
# Draw the test triangle
|
||||
DrawLine3D(ta, tb, PURPLE)
|
||||
DrawLine3D(tb, tc, PURPLE)
|
||||
DrawLine3D(tc, ta, PURPLE)
|
||||
|
||||
# Draw the mesh bbox if we hit it
|
||||
if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME)
|
||||
|
||||
# If we hit something, draw the cursor at the hit point
|
||||
if (nearestHit.hit)
|
||||
[
|
||||
DrawCube(nearestHit.position, 0.3, 0.3, 0.3, cursorColor)
|
||||
DrawCubeWires(nearestHit.position, 0.3, 0.3, 0.3, RED)
|
||||
|
||||
Vector3 normalEnd
|
||||
normalEnd.x = nearestHit.position.x + nearestHit.normal.x
|
||||
normalEnd.y = nearestHit.position.y + nearestHit.normal.y
|
||||
normalEnd.z = nearestHit.position.z + nearestHit.normal.z
|
||||
|
||||
DrawLine3D(nearestHit.position, normalEnd, RED)
|
||||
]
|
||||
|
||||
DrawRay(ray, MAROON)
|
||||
|
||||
DrawGrid(10, 10.0)
|
||||
|
||||
EndMode3D()
|
||||
|
||||
# Draw some debug GUI text
|
||||
DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK)
|
||||
|
||||
if (nearestHit.hit)
|
||||
[
|
||||
int ypos = 70
|
||||
|
||||
DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK)
|
||||
|
||||
DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f",
|
||||
nearestHit.position.x,
|
||||
nearestHit.position.y,
|
||||
nearestHit.position.z), 10, ypos + 15, 10, BLACK)
|
||||
|
||||
DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f",
|
||||
nearestHit.normal.x,
|
||||
nearestHit.normal.y,
|
||||
nearestHit.normal.z), 10, ypos + 30, 10, BLACK)
|
||||
|
||||
if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK)
|
||||
]
|
||||
|
||||
DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY)
|
||||
|
||||
DrawText("(c) Turret 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY)
|
||||
|
||||
DrawFPS(10, 10)
|
||||
|
||||
EndDrawing()
|
||||
#----------------------------------------------------------------------------------
|
||||
]
|
||||
|
||||
# De-Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
UnloadModel(tower) # Unload model
|
||||
UnloadTexture(texture) # Unload texture
|
||||
|
||||
CloseWindow() # Close window and OpenGL context
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
return 0
|
||||
]
|
Before Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 260 KiB |
|
@ -20,15 +20,17 @@ InitWindow(screenWidth, screenHeight, b"raylib [models] example - obj model load
|
|||
|
||||
# Define the camera to look into our 3d world
|
||||
camera = ffi.new("struct Camera3D *")
|
||||
camera.position = [ 50.0, 50.0, 50.0 ] # Camera position
|
||||
camera.position = [ 5.0, 5.0, 5.0 ] # Camera position
|
||||
camera.target = [ 0.0, 2.5, 0.0 ] # Camera looking at point
|
||||
camera.up = [ 0.0, 1.0, 0.0 ] # Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0 # Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE # Camera mode type
|
||||
|
||||
model = LoadModel(b"resources/models/monkey/monkey4.gltf") # Load OBJ model
|
||||
texture = LoadTexture(b"resources/models/castle_diffuse.png") # Load model texture
|
||||
#model.materials.maps[MAP_DIFFUSE].texture = texture # Set map diffuse texture
|
||||
rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL)
|
||||
|
||||
model = LoadModel(b"resources/models/house.obj") # Load OBJ model
|
||||
texture = LoadTexture(b"resources/models/house_diffuse.png") # Load model texture
|
||||
model.materials.maps[MAP_DIFFUSE].texture = texture # Set map diffuse texture
|
||||
position = [ 0.0, 0.0, 0.0 ] # Set model position
|
||||
|
||||
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||
|
@ -40,7 +42,7 @@ while not WindowShouldClose(): # Detect window close button or ESC key
|
|||
#----------------------------------------------------------------------------------
|
||||
#...
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
rl.UpdateCamera(camera);
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Show the difference between perspective and orthographic projection
|
||||
*
|
||||
* This program is heavily based on the geometric objects example
|
||||
*
|
||||
* This example has been created using raylib 1.9.7 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2018 Max Danielsson & Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
#define FOVY_PERSPECTIVE 45.0
|
||||
#define WIDTH_ORTHOGRAPHIC 10.0
|
||||
|
||||
int main()
|
||||
[
|
||||
# Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800
|
||||
int screenHeight = 450
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
||||
|
||||
# Define the camera to look into our 3d world
|
||||
Camera camera = [[ 0.0, 10.0, 10.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE ]
|
||||
|
||||
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# Main game loop
|
||||
while (!WindowShouldClose()) # Detect window close button or ESC key
|
||||
[
|
||||
# Update
|
||||
#----------------------------------------------------------------------------------
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
[
|
||||
if (camera.type == CAMERA_PERSPECTIVE)
|
||||
[
|
||||
camera.fovy = WIDTH_ORTHOGRAPHIC
|
||||
camera.type = CAMERA_ORTHOGRAPHIC
|
||||
]
|
||||
else
|
||||
[
|
||||
camera.fovy = FOVY_PERSPECTIVE
|
||||
camera.type = CAMERA_PERSPECTIVE
|
||||
]
|
||||
]
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
BeginMode3D(camera)
|
||||
|
||||
DrawCube((Vector3)[-4.0, 0.0, 2.0], 2.0, 5.0, 2.0, RED)
|
||||
DrawCubeWires((Vector3)[-4.0, 0.0, 2.0], 2.0, 5.0, 2.0, GOLD)
|
||||
DrawCubeWires((Vector3)[-4.0, 0.0, -2.0], 3.0, 6.0, 2.0, MAROON)
|
||||
|
||||
DrawSphere((Vector3)[-1.0, 0.0, -2.0], 1.0, GREEN)
|
||||
DrawSphereWires((Vector3)[1.0, 0.0, 2.0], 2.0, 16, 16, LIME)
|
||||
|
||||
DrawCylinder((Vector3)[4.0, 0.0, -2.0], 1.0, 2.0, 3.0, 4, SKYBLUE)
|
||||
DrawCylinderWires((Vector3)[4.0, 0.0, -2.0], 1.0, 2.0, 3.0, 4, DARKBLUE)
|
||||
DrawCylinderWires((Vector3)[4.5f, -1.0, 2.0], 1.0, 1.0, 2.0, 6, BROWN)
|
||||
|
||||
DrawCylinder((Vector3)[1.0, 0.0, -4.0], 0.0, 1.5f, 3.0, 8, GOLD)
|
||||
DrawCylinderWires((Vector3)[1.0, 0.0, -4.0], 0.0, 1.5f, 3.0, 8, PINK)
|
||||
|
||||
DrawGrid(10, 1.0) # Draw a grid
|
||||
|
||||
EndMode3D()
|
||||
|
||||
DrawText("Press Spacebar to switch camera type", 10, GetScreenHeight() - 30, 20, DARKGRAY)
|
||||
|
||||
if (camera.type == CAMERA_ORTHOGRAPHIC) DrawText("ORTHOGRAPHIC", 10, 40, 20, BLACK)
|
||||
else if (camera.type == CAMERA_PERSPECTIVE) DrawText("PERSPECTIVE", 10, 40, 20, BLACK)
|
||||
|
||||
DrawFPS(10, 10)
|
||||
|
||||
EndDrawing()
|
||||
#----------------------------------------------------------------------------------
|
||||
]
|
||||
|
||||
# De-Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
CloseWindow() # Close window and OpenGL context
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
return 0
|
||||
]
|
Before Width: | Height: | Size: 32 KiB |
|
@ -1,90 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Skybox loading and drawing
|
||||
*
|
||||
* This example has been created using raylib 1.8 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
int main()
|
||||
[
|
||||
# Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
int screenWidth = 800
|
||||
int screenHeight = 450
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing")
|
||||
|
||||
# Define the camera to look into our 3d world
|
||||
Camera camera = [[ 1.0, 1.0, 1.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ]
|
||||
|
||||
# Load skybox model
|
||||
Mesh cube = GenMeshCube(1.0, 1.0, 1.0)
|
||||
Model skybox = LoadModelFromMesh(cube)
|
||||
|
||||
# Load skybox shader and set required locations
|
||||
# NOTE: Some locations are automatically set at shader loading
|
||||
skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs")
|
||||
SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1])[ MAP_CUBEMAP ], 1)
|
||||
|
||||
# Load cubemap shader and setup required shader locations
|
||||
Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs")
|
||||
SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1])[ 0 ], 1)
|
||||
|
||||
# Load HDR panorama (sphere) texture
|
||||
Texture2D texHDR = LoadTexture("resources/dresden_square.hdr")
|
||||
|
||||
# Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
|
||||
# NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping
|
||||
skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512)
|
||||
|
||||
UnloadTexture(texHDR) # Texture not required anymore, cubemap already generated
|
||||
UnloadShader(shdrCubemap) # Unload cubemap generation shader, not required anymore
|
||||
|
||||
SetCameraMode(camera, CAMERA_FIRST_PERSON) # Set a first person camera mode
|
||||
|
||||
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# Main game loop
|
||||
while (!WindowShouldClose()) # Detect window close button or ESC key
|
||||
[
|
||||
# Update
|
||||
#----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera) # Update camera
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
BeginMode3D(camera)
|
||||
|
||||
DrawModel(skybox, (Vector3)[0, 0, 0], 1.0, WHITE)
|
||||
|
||||
DrawGrid(10, 1.0)
|
||||
|
||||
EndMode3D()
|
||||
|
||||
DrawFPS(10, 10)
|
||||
|
||||
EndDrawing()
|
||||
#----------------------------------------------------------------------------------
|
||||
]
|
||||
|
||||
# De-Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
UnloadModel(skybox) # Unload skybox model (and textures)
|
||||
|
||||
CloseWindow() # Close window and OpenGL context
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
return 0
|
||||
]
|
Before Width: | Height: | Size: 417 KiB |
|
@ -37,7 +37,7 @@ rl.SetShaderValue(
|
|||
|
||||
texHDR = rl.LoadTexture(b'resources/dresden_square.hdr')
|
||||
|
||||
skybox.materials[0].maps[rl.MAP_CUBEMAP].texture = rl.GenTextureCubemap(shdrCubemap, texHDR, 512);
|
||||
skybox.materials[0].maps[rl.MAP_CUBEMAP].texture = rl.GenTextureCubemap(shdrCubemap, texHDR, 512, rl.UNCOMPRESSED_R32G32B32);
|
||||
|
||||
rl.UnloadTexture(texHDR)
|
||||
rl.UnloadShader(shdrCubemap)
|
||||
|
|
|
@ -1,199 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Plane rotations (yaw, pitch, roll)
|
||||
*
|
||||
* This example has been created using raylib 1.8 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Example based on Berni work on Raspberry Pi:
|
||||
* http:#forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order
|
||||
*
|
||||
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
|
||||
# Draw angle gauge controls
|
||||
void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color)
|
||||
|
||||
#----------------------------------------------------------------------------------
|
||||
# Main entry point
|
||||
#----------------------------------------------------------------------------------
|
||||
int main()
|
||||
[
|
||||
# Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800
|
||||
const int screenHeight = 450
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)")
|
||||
|
||||
Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png")
|
||||
Texture2D texBackground = LoadTexture("resources/background.png")
|
||||
Texture2D texPitch = LoadTexture("resources/pitch.png")
|
||||
Texture2D texPlane = LoadTexture("resources/plane.png")
|
||||
|
||||
RenderTexture2D framebuffer = LoadRenderTexture(192, 192)
|
||||
|
||||
# Model loading
|
||||
Model model = LoadModel("resources/plane.obj") # Load OBJ model
|
||||
model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png") # Set map diffuse texture
|
||||
|
||||
GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture)
|
||||
|
||||
Camera camera = [ 0 ]
|
||||
camera.position = (Vector3)[ 0.0, 60.0, -120.0 ]# Camera position perspective
|
||||
camera.target = (Vector3)[ 0.0, 12.0, 0.0 ] # Camera looking at point
|
||||
camera.up = (Vector3)[ 0.0, 1.0, 0.0 ] # Camera up vector (rotation towards target)
|
||||
camera.fovy = 30.0 # Camera field-of-view Y
|
||||
camera.type = CAMERA_PERSPECTIVE # Camera type
|
||||
|
||||
float pitch = 0.0
|
||||
float roll = 0.0
|
||||
float yaw = 0.0
|
||||
|
||||
SetTargetFPS(60)
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
while (!WindowShouldClose()) # Detect window close button or ESC key
|
||||
[
|
||||
# Update
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Plane roll (x-axis) controls
|
||||
if (IsKeyDown(KEY_LEFT)) roll += 1.0
|
||||
else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0
|
||||
else
|
||||
[
|
||||
if (roll > 0.0) roll -= 0.5f
|
||||
else if (roll < 0.0) roll += 0.5f
|
||||
]
|
||||
|
||||
# Plane yaw (y-axis) controls
|
||||
if (IsKeyDown(KEY_S)) yaw += 1.0
|
||||
else if (IsKeyDown(KEY_A)) yaw -= 1.0
|
||||
else
|
||||
[
|
||||
if (yaw > 0.0) yaw -= 0.5f
|
||||
else if (yaw < 0.0) yaw += 0.5f
|
||||
]
|
||||
|
||||
# Plane pitch (z-axis) controls
|
||||
if (IsKeyDown(KEY_DOWN)) pitch += 0.6f
|
||||
else if (IsKeyDown(KEY_UP)) pitch -= 0.6f
|
||||
else
|
||||
[
|
||||
if (pitch > 0.3f) pitch -= 0.3f
|
||||
else if (pitch < -0.3f) pitch += 0.3f
|
||||
]
|
||||
|
||||
# Wraps the phase of an angle to fit between -180 and +180 degrees
|
||||
int pitchOffset = pitch
|
||||
while (pitchOffset > 180) pitchOffset -= 360
|
||||
while (pitchOffset < -180) pitchOffset += 360
|
||||
pitchOffset *= 10
|
||||
|
||||
Matrix transform = MatrixIdentity()
|
||||
|
||||
transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll))
|
||||
transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch))
|
||||
transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw))
|
||||
|
||||
model.transform = transform
|
||||
#----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
#----------------------------------------------------------------------------------
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
# Draw framebuffer texture (Ahrs Display)
|
||||
int centerX = framebuffer.texture.width/2
|
||||
int centerY = framebuffer.texture.height/2
|
||||
float scaleFactor = 0.5f
|
||||
|
||||
BeginTextureMode(framebuffer)
|
||||
|
||||
BeginBlendMode(BLEND_ALPHA)
|
||||
|
||||
DrawTexturePro(texBackground, (Rectangle)[ 0, 0, texBackground.width, texBackground.height ],
|
||||
(Rectangle)[ centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor],
|
||||
(Vector2)[ texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor ], roll, WHITE)
|
||||
|
||||
DrawTexturePro(texPitch, (Rectangle)[ 0, 0, texPitch.width, texPitch.height ],
|
||||
(Rectangle)[ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor ],
|
||||
(Vector2)[ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor ], roll, WHITE)
|
||||
|
||||
DrawTexturePro(texPlane, (Rectangle)[ 0, 0, texPlane.width, texPlane.height ],
|
||||
(Rectangle)[ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor ],
|
||||
(Vector2)[ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor ], 0, WHITE)
|
||||
|
||||
EndBlendMode()
|
||||
|
||||
EndTextureMode()
|
||||
|
||||
# Draw 3D model (recomended to draw 3D always before 2D)
|
||||
BeginMode3D(camera)
|
||||
|
||||
DrawModel(model, (Vector3)[ 0, 6.0, 0 ], 1.0, WHITE) # Draw 3d model with texture
|
||||
DrawGrid(10, 10.0)
|
||||
|
||||
EndMode3D()
|
||||
|
||||
# Draw 2D GUI stuff
|
||||
DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED)
|
||||
DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN)
|
||||
DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE)
|
||||
|
||||
DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f))
|
||||
DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f))
|
||||
DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY)
|
||||
DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 390, 10, DARKGRAY)
|
||||
DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY)
|
||||
|
||||
# Draw framebuffer texture
|
||||
DrawTextureRec(framebuffer.texture, (Rectangle)[ 0, 0, framebuffer.texture.width, -framebuffer.texture.height ],
|
||||
(Vector2)[ screenWidth - framebuffer.texture.width - 20, 20 ], Fade(WHITE, 0.8f))
|
||||
|
||||
DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY)
|
||||
|
||||
EndDrawing()
|
||||
#----------------------------------------------------------------------------------
|
||||
]
|
||||
|
||||
# De-Initialization
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# Unload all loaded data
|
||||
UnloadModel(model)
|
||||
|
||||
UnloadRenderTexture(framebuffer)
|
||||
|
||||
UnloadTexture(texAngleGauge)
|
||||
UnloadTexture(texBackground)
|
||||
UnloadTexture(texPitch)
|
||||
UnloadTexture(texPlane)
|
||||
|
||||
CloseWindow() # Close window and OpenGL context
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
return 0
|
||||
]
|
||||
|
||||
# Draw angle gauge controls
|
||||
void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[], Color color)
|
||||
[
|
||||
Rectangle srcRec = [ 0, 0, angleGauge.width, angleGauge.height ]
|
||||
Rectangle dstRec = [ x, y, angleGauge.width, angleGauge.height ]
|
||||
Vector2 origin = [ angleGauge.width/2, angleGauge.height/2]
|
||||
int textSize = 20
|
||||
|
||||
DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color)
|
||||
|
||||
DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY)
|
||||
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY)
|
||||
]
|
Before Width: | Height: | Size: 180 KiB |