~evantj/hare-raylib

3 files changed, 68 insertions(+), 0 deletions(-)

M .gitignore
A examples/heightmap/main.ha
A resources/heightmap.png
M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
demo
heightmap

A examples/heightmap/main.ha => examples/heightmap/main.ha +67 -0
@@ 0,0 1,67 @@
use raylib;

export fn main() void = {
	let screen_width = 800;
	let screen_height = 450;

	raylib::InitWindow(screen_width, screen_height, "raylib [models] example - heightmap loading and drawing");

	let camera = raylib::Camera {
		position = raylib::Vector3 {
			x = 18.0,
			y = 18.0,
			z = 18.0,
		},
		target = raylib::Vector3 {
			x = 0.0,
			y = 0.0,
			z = 0.0,

		},
		up = raylib::Vector3 {
			x = 0.0,
			y = 1.0,
			z = 0.0,

		},
		fovy = 45.0,
		projection = raylib::CameraProjection::CAMERA_PERSPECTIVE,
	};

	let image = raylib::LoadImage("resources/heightmap.png");
	defer raylib::UnloadImage(image);
	let texture = raylib::LoadTextureFromImage(image);
	defer raylib::UnloadTexture(texture);

	let mesh = raylib::GenMeshHeightmap(image, raylib::Vector3 {x = 16.0, y = 8.0, z = 16.0});
	let model = raylib::LoadModelFromMesh(mesh);
	defer raylib::UnloadModel(model);

	model.materials[0].maps[raylib::MaterialMapIndex::MATERIAL_MAP_ALBEDO].texture = texture;

	let mapPosition = raylib::Vector3 {
		x = -8.0,
		y = 0.0,
		z = -8.0,
	};

	raylib::SetCameraMode(camera, raylib::CameraMode::CAMERA_ORBITAL);

	raylib::SetTargetFPS(60);

	for (!raylib::WindowShouldClose()) {
		screen_width = raylib::GetScreenWidth();
		screen_height = raylib::GetScreenHeight();
		raylib::UpdateCamera(&camera);
		raylib::BeginDrawing();
		raylib::ClearBackground(raylib::RAYWHITE);
		raylib::BeginMode3D(camera);
		raylib::DrawModel(model, mapPosition, 1.0, raylib::RED);
		raylib::DrawGrid(20, 1.0);
		raylib::EndMode3D();
		raylib::DrawTexture(texture, screen_width - texture.width - 20, 20, raylib::WHITE);
		raylib::DrawRectangleLines(screen_width - texture.width - 20, 20, texture.width, texture.height, raylib::GREEN);
		raylib::DrawFPS(10, 10);
		raylib::EndDrawing();
	};
};

A resources/heightmap.png => resources/heightmap.png +0 -0