heightmap example
This commit is contained in:
parent
ad8d4f06d1
commit
2335c5275f
3 changed files with 77 additions and 85 deletions
|
@ -1,82 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [models] example - Heightmap 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) 2015 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
#include "raylib.h"
|
|
||||||
|
|
||||||
int main()
|
|
||||||
[
|
|
||||||
# Initialization
|
|
||||||
#--------------------------------------------------------------------------------------
|
|
||||||
int screenWidth = 800
|
|
||||||
int screenHeight = 450
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
|
||||||
|
|
||||||
# Define our custom camera to look into our 3d world
|
|
||||||
Camera camera = [[ 18.0, 16.0, 18.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ]
|
|
||||||
|
|
||||||
Image image = LoadImage("resources/heightmap.png") # Load heightmap image (RAM)
|
|
||||||
Texture2D texture = LoadTextureFromImage(image) # Convert image to texture (VRAM)
|
|
||||||
|
|
||||||
Mesh mesh = GenMeshHeightmap(image, (Vector3)[ 16, 8, 16 ]) # Generate heightmap mesh (RAM and VRAM)
|
|
||||||
Model model = LoadModelFromMesh(mesh) # Load model from generated mesh
|
|
||||||
|
|
||||||
model.material.maps[MAP_DIFFUSE].texture = texture # Set map diffuse texture
|
|
||||||
Vector3 mapPosition = [ -8.0, 0.0, -8.0 ] # Define model position
|
|
||||||
|
|
||||||
UnloadImage(image) # Unload heightmap image from RAM, already uploaded to VRAM
|
|
||||||
|
|
||||||
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
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Draw
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
BeginDrawing()
|
|
||||||
|
|
||||||
ClearBackground(RAYWHITE)
|
|
||||||
|
|
||||||
BeginMode3D(camera)
|
|
||||||
|
|
||||||
DrawModel(model, mapPosition, 1.0, RED)
|
|
||||||
|
|
||||||
DrawGrid(20, 1.0)
|
|
||||||
|
|
||||||
EndMode3D()
|
|
||||||
|
|
||||||
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE)
|
|
||||||
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN)
|
|
||||||
|
|
||||||
DrawFPS(10, 10)
|
|
||||||
|
|
||||||
EndDrawing()
|
|
||||||
#----------------------------------------------------------------------------------
|
|
||||||
]
|
|
||||||
|
|
||||||
# De-Initialization
|
|
||||||
#--------------------------------------------------------------------------------------
|
|
||||||
UnloadTexture(texture) # Unload texture
|
|
||||||
UnloadModel(model) # Unload model
|
|
||||||
|
|
||||||
CloseWindow() # Close window and OpenGL context
|
|
||||||
#--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return 0
|
|
||||||
]
|
|
77
examples/models/models_heightmap.py
Normal file
77
examples/models/models_heightmap.py
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
# /*******************************************************************************************
|
||||||
|
# *
|
||||||
|
# * raylib [models] example - Heightmap 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) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
# *
|
||||||
|
# ********************************************************************************************/
|
||||||
|
|
||||||
|
from raylib import *
|
||||||
|
|
||||||
|
# Initialization
|
||||||
|
#--------------------------------------------------------------------------------------
|
||||||
|
screenWidth = 800
|
||||||
|
screenHeight = 450
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, b"raylib [models] example - heightmap loading and drawing")
|
||||||
|
|
||||||
|
# Define our custom camera to look into our 3d world
|
||||||
|
camera = ffi.new("struct Camera3D *", [[ 18.0, 16.0, 18.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ])
|
||||||
|
|
||||||
|
image = LoadImage(b"resources/heightmap.png") # Load heightmap image (RAM)
|
||||||
|
texture = LoadTextureFromImage(image) # Convert image to texture (VRAM)
|
||||||
|
|
||||||
|
mesh = GenMeshHeightmap(image, ( 16, 8, 16 )) # Generate heightmap mesh (RAM and VRAM)
|
||||||
|
model = LoadModelFromMesh(mesh) # Load model from generated mesh
|
||||||
|
|
||||||
|
model.materials[0].maps[MAP_DIFFUSE].texture = texture # Set map diffuse texture
|
||||||
|
mapPosition = ( -8.0, 0.0, -8.0 ) # Define model position
|
||||||
|
|
||||||
|
UnloadImage(image) # Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
SetCameraMode(camera[0], CAMERA_ORBITAL) # Set an orbital camera mode
|
||||||
|
|
||||||
|
SetTargetFPS(60) # Set our game to run at 60 frames-per-second
|
||||||
|
#--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Main game loop
|
||||||
|
while not WindowShouldClose(): # Detect window close button or ESC key
|
||||||
|
# Update
|
||||||
|
#----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(camera) # Update camera
|
||||||
|
#----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Draw
|
||||||
|
#----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing()
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE)
|
||||||
|
|
||||||
|
BeginMode3D(camera[0])
|
||||||
|
|
||||||
|
DrawModel(model, mapPosition, 1.0, RED)
|
||||||
|
|
||||||
|
DrawGrid(20, 1.0)
|
||||||
|
|
||||||
|
EndMode3D()
|
||||||
|
|
||||||
|
DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE)
|
||||||
|
DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN)
|
||||||
|
|
||||||
|
DrawFPS(10, 10)
|
||||||
|
|
||||||
|
EndDrawing()
|
||||||
|
#----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# De-Initialization
|
||||||
|
#--------------------------------------------------------------------------------------
|
||||||
|
UnloadTexture(texture) # Unload texture
|
||||||
|
UnloadModel(model) # Unload model
|
||||||
|
|
||||||
|
CloseWindow() # Close window and OpenGL context
|
||||||
|
#--------------------------------------------------------------------------------------
|
||||||
|
|
3
test.py
3
test.py
|
@ -8,9 +8,6 @@ SetTargetFPS(60)
|
||||||
|
|
||||||
camera = ffi.new("struct Camera3D *", [[ 18.0, 16.0, 18.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ])
|
camera = ffi.new("struct Camera3D *", [[ 18.0, 16.0, 18.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], 45.0, 0 ])
|
||||||
|
|
||||||
# (( 18.0, 16.0, 18.0 ), ( 0.0, 0.0, 0.0 ), ( 0.0, 1.0, 0.0 ), 45.0, 0 )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
image = LoadImage(b"resources/heightmap.png") # Load heightmap image (RAM)
|
image = LoadImage(b"resources/heightmap.png") # Load heightmap image (RAM)
|
||||||
texture = LoadTextureFromImage(image) # Convert image to texture (VRAM)
|
texture = LoadTextureFromImage(image) # Convert image to texture (VRAM)
|
||||||
|
|
Reference in a new issue