From 1433aa8e40f13dd0911051e0515a04f93325d774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Mon, 3 Mar 2025 00:30:34 +0300 Subject: [PATCH] aabb drawing for debug --- data/scripts/game.lua | 14 +++++++------- data/scripts/types/aabb.lua | 32 +++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/data/scripts/game.lua b/data/scripts/game.lua index 164da4a..96f4782 100644 --- a/data/scripts/game.lua +++ b/data/scripts/game.lua @@ -2,12 +2,12 @@ util = require "util" local player = require "classes.player" local Vector3 = require "types.vector3" local List = require "types.list" --- local AABB = require "types.aabb" +local AABB = require "types.aabb" --- local test_aabb = AABB.new( --- Vector3(-1, -1, -1), --- Vector3(1, 1, 1) --- ) +local test_aabb = AABB.new( + Vector3(-1, -1, -1), + Vector3(1, 2, 1) +) local Obj = require "classes.obj" @@ -91,12 +91,12 @@ function game_tick() texture = "images/measure001a.png", texture_region = { x = 0, y = 0, w = 512, h = 512 }, } - draw_quad(util.merge(q, params)) + -- draw_quad(util.merge(q, params)) cube.position.y = math.sin(ctx.frame_number * 0.05) -- cube.position.z = math.cos(ctx.frame_number * 0.01) cube.rotation.x = cube.rotation.x + 0.01 cube.rotation.z = cube.rotation.z + 0.01 cube:draw() - -- test_aabb:draw() + test_aabb:draw() end diff --git a/data/scripts/types/aabb.lua b/data/scripts/types/aabb.lua index 2add9b3..b3b2c44 100644 --- a/data/scripts/types/aabb.lua +++ b/data/scripts/types/aabb.lua @@ -6,6 +6,13 @@ local AABB = { max = Vector3(), } +local RED = { + r = 255, + g = 0, + b = 0, + a = 255, +} + setmetatable(AABB, AABB) AABB.__index = AABB @@ -29,10 +36,29 @@ function AABB:draw() draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.min.y, self.min.z)} draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.min.y, self.max.z)} draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.min.y, self.max.z)} + draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.max.x, self.min.y, self.min.z)} + -- bottom rectangle diagonal + draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.min.y, self.max.z), color = RED} + -- top rectangle + draw_line_3d{start = Vector3(self.min.x, self.max.y, self.min.z), finish = Vector3(self.max.x, self.max.y, self.min.z)} + draw_line_3d{start = Vector3(self.min.x, self.max.y, self.min.z), finish = Vector3(self.min.x, self.max.y, self.max.z)} + draw_line_3d{start = Vector3(self.max.x, self.max.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.max.z)} + draw_line_3d{start = Vector3(self.max.x, self.max.y, self.max.z), finish = Vector3(self.max.x, self.max.y, self.min.z)} + -- top rectangle diagonal + draw_line_3d{start = Vector3(self.max.x, self.max.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.min.z), color = RED} + -- hull + draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.max.y, self.min.z)} + draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.max.y, self.min.z), color = RED} + + draw_line_3d{start = Vector3(self.max.x, self.min.y, self.min.z), finish = Vector3(self.max.x, self.max.y, self.min.z)} + draw_line_3d{start = Vector3(self.max.x, self.min.y, self.min.z), finish = Vector3(self.max.x, self.max.y, self.max.z), color = RED} + + draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.max.x, self.max.y, self.max.z)} + draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.max.z), color = RED} + + draw_line_3d{start = Vector3(self.min.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.max.z)} + draw_line_3d{start = Vector3(self.min.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.min.z), color = RED} - -- draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.min.y, self.min.z)} - -- draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.max.y, self.min.z)} - -- draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.min.y, self.max.z)} end return AABB