Skip to content

Commit 6e4f8df

Browse files
committedDec 31, 2019
first commit
0 parents  commit 6e4f8df

10 files changed

+154
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
bin/*

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libs/prlib"]
2+
path = libs/prlib
3+
url = https://github.com/Ushio/prlib

‎README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Cone TightFit AABB
2+
3+
Thanks
4+
http://iquilezles.org/www/articles/diskbbox/diskbbox.htm
5+
6+
```
7+
8+
git submodule update --init
9+
premake5 vs2019
10+
11+
```
12+
13+
## demo
14+
![image](demo.gif)
15+
![image](idea.png)
16+
![image](form.png)
17+
18+
<!--
19+
a=\begin{pmatrix} x_{ T } \\ y_{ T } \\ z_{ T } \end{pmatrix}=P_{ 1 }-P_{ 0 }\\ \overrightarrow { x } =\begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix},\overrightarrow { y } =\begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix},\overrightarrow { z } =\begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix}\\ \overrightarrow { x } \times a=\begin{pmatrix} y_{ 1 }z_{ 2 }-z_{ 1 }y_{ 2 } \\ z_{ 1 }x_{ 2 }-x_{ 1 }z_{ 2 } \\ x_{ 1 }y_{ 2 }-y_{ 1 }x_{ 2 } \end{pmatrix}=\begin{pmatrix} 0z_{ 2 }-0y_{ 2 } \\ 0x_{ 2 }-1z_{ 2 } \\ 1y_{ 2 }-0x_{ 2 } \end{pmatrix}=\begin{pmatrix} 0 \\ -z_{ T } \\ y_{ T } \end{pmatrix}\\ \left\| \overrightarrow { x } \times a \right\| =\sqrt { { z_{ T } }^{ 2 }+{ y_{ T } }^{ 2 } } \\ \left\| \overrightarrow { x } \times \frac { a }{ \left\| a \right\| } \right\| =\frac { 1 }{ \left\| a \right\| } \sqrt { { z_{ T } }^{ 2 }+{ y_{ T } }^{ 2 } } =\sqrt { \frac { 1 }{ { \left\| a \right\| }^{ 2 } } \left( { z_{ T } }^{ 2 }+{ y_{ T } }^{ 2 } \right) } \\ \\ { x_{ T } }^{ 2 }+{ y_{ T } }^{ 2 }+{ z_{ T } }^{ 2 }={ \left\| a \right\| }^{ 2 }\\ { y_{ T } }^{ 2 }+{ z_{ T } }^{ 2 }={ \left\| a \right\| }^{ 2 }-{ x_{ T } }^{ 2 }\\ \left\| \overrightarrow { x } \times \frac { a }{ \left\| a \right\| } \right\| =\sqrt { \frac { 1 }{ { \left\| a \right\| }^{ 2 } } \left( { \left\| a \right\| }^{ 2 }-{ x_{ T } }^{ 2 } \right) } =\sqrt { 1-\frac { { x_{ T } }^{ 2 } }{ { \left\| a \right\| }^{ 2 } } } \\ \\ \overrightarrow { y } \times a=\begin{pmatrix} y_{ 1 }z_{ 2 }-z_{ 1 }y_{ 2 } \\ z_{ 1 }x_{ 2 }-x_{ 1 }z_{ 2 } \\ x_{ 1 }y_{ 2 }-y_{ 1 }x_{ 2 } \end{pmatrix}=\begin{pmatrix} 1z_{ 2 }-0y_{ 2 } \\ 0x_{ 2 }-0z_{ 2 } \\ 0y_{ 2 }-1x_{ 2 } \end{pmatrix}=\begin{pmatrix} z_{ T } \\ 0 \\ -x_{ T } \end{pmatrix}\\ \left\| \overrightarrow { y } \times a \right\| =\sqrt { { z_{ T } }^{ 2 }+{ x_{ T } }^{ 2 } } \\ \left\| \overrightarrow { y } \times \frac { a }{ \left\| a \right\| } \right\| =\frac { 1 }{ \left\| a \right\| } \sqrt { { z_{ T } }^{ 2 }+{ x_{ T } }^{ 2 } } =\sqrt { \frac { 1 }{ { \left\| a \right\| }^{ 2 } } \left( { z_{ T } }^{ 2 }+{ x_{ T } }^{ 2 } \right) } \\ =\sqrt { \frac { 1 }{ { \left\| a \right\| }^{ 2 } } \left( { \left\| a \right\| }^{ 2 }-{ y_{ T } }^{ 2 } \right) } =\sqrt { 1-\frac { { y_{ T } }^{ 2 } }{ { \left\| a \right\| }^{ 2 } } } \\ \\ \overrightarrow { z } \times a=\begin{pmatrix} y_{ 1 }z_{ 2 }-z_{ 1 }y_{ 2 } \\ z_{ 1 }x_{ 2 }-x_{ 1 }z_{ 2 } \\ x_{ 1 }y_{ 2 }-y_{ 1 }x_{ 2 } \end{pmatrix}=\begin{pmatrix} 0z_{ 2 }-1y_{ 2 } \\ 1x_{ 2 }-0z_{ 2 } \\ 0y_{ 2 }-0x_{ 2 } \end{pmatrix}=\begin{pmatrix} -y_{ T } \\ x_{ T } \\ 0 \end{pmatrix}\\ \left\| \overrightarrow { z } \times \frac { a }{ \left\| a \right\| } \right\| =\frac { 1 }{ \left\| a \right\| } \sqrt { { x_{ T } }^{ 2 }+{ y_{ T } }^{ 2 } } =\sqrt { \frac { 1 }{ { \left\| a \right\| }^{ 2 } } \left( { x_{ T } }^{ 2 }+{ y_{ T } }^{ 2 } \right) } \\ =\sqrt { \frac { 1 }{ { \left\| a \right\| }^{ 2 } } \left( { \left\| a \right\| }^{ 2 }-{ z_{ T } }^{ 2 } \right) } =\sqrt { 1-\frac { { z_{ T } }^{ 2 } }{ { \left\| a \right\| }^{ 2 } } } \\ \overrightarrow { e } =\begin{pmatrix} \sqrt { 1-\frac { { x_{ T } }^{ 2 } }{ a\cdot a } } \\ \sqrt { 1-\frac { { y_{ T } }^{ 2 } }{ a\cdot a } } \\ \sqrt { 1-\frac { { z_{ T } }^{ 2 } }{ a\cdot a } } \end{pmatrix}\\
20+
21+
-->
22+
23+
24+
25+

‎demo.gif

1.22 MB
Loading

‎form.png

121 KB
Loading

‎idea.png

87.1 KB
Loading

‎libs/prlib

Submodule prlib added at 0bedd46

‎main.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "pr.hpp"
2+
#include <iostream>
3+
#include <memory>
4+
5+
int main() {
6+
using namespace pr;
7+
8+
Config config;
9+
config.ScreenWidth = 1920;
10+
config.ScreenHeight = 1080;
11+
config.SwapInterval = 1;
12+
Initialize(config);
13+
14+
Camera3D camera;
15+
camera.origin = { 4, 8, 8 };
16+
camera.lookat = { 0, 0, 0 };
17+
camera.zUp = false;
18+
19+
double e = GetElapsedTime();
20+
21+
glm::vec3 p0 = { -2, 2, -3 };
22+
glm::vec3 p1 = { 2, 5, 1 };
23+
float r0 = 0.5f;
24+
float r1 = 1.0f;
25+
26+
while (pr::NextFrame() == false) {
27+
if (IsImGuiUsingMouse() == false) {
28+
UpdateCameraBlenderLike(&camera);
29+
}
30+
31+
ClearBackground(0.1f, 0.1f, 0.1f, 1);
32+
33+
BeginCamera(camera);
34+
35+
PushGraphicState();
36+
37+
DrawGrid(GridAxis::XZ, 1.0f, 10, { 128, 128, 128 });
38+
DrawXYZAxis(1.0f);
39+
40+
DrawTube(p0, p1, r0, r1, {255, 255, 0}, 32);
41+
42+
glm::vec3 a = p1 - p0;
43+
glm::vec3 e = glm::sqrt(
44+
glm::max(
45+
glm::vec3(1.0f) - a * a / glm::dot(a, a),
46+
glm::vec3(0.0f)
47+
)
48+
);
49+
50+
glm::vec3 lower = glm::min(p0 - e * r0, p1 - e * r1);
51+
glm::vec3 upper = glm::max(p0 + e * r0, p1 + e * r1);
52+
DrawAABB(lower, upper, {255, 255, 255}, 2);
53+
54+
ManipulatePosition(camera, &p0, 0.5f);
55+
ManipulatePosition(camera, &p1, 0.5f);
56+
57+
PopGraphicState();
58+
EndCamera();
59+
60+
BeginImGui();
61+
62+
ImGui::SetNextWindowSize({ 500, 800 }, ImGuiCond_Once);
63+
ImGui::Begin("Panel");
64+
ImGui::Text("fps = %f", GetFrameRate());
65+
ImGui::SliderFloat("perspective", &camera.perspective, 0, 1);
66+
ImGui::SliderFloat("r1", &r0, 0, 1);
67+
ImGui::SliderFloat("r2", &r1, 0, 1);
68+
69+
ImGui::End();
70+
71+
EndImGui();
72+
}
73+
74+
pr::CleanUp();
75+
}

‎premake5.exe

1.3 MB
Binary file not shown.

‎premake5.lua

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
include "libs/PrLib"
2+
3+
workspace "ConeTightFitAABB"
4+
location "build"
5+
configurations { "Debug", "Release" }
6+
startproject "main"
7+
8+
architecture "x86_64"
9+
10+
externalproject "prlib"
11+
location "libs/PrLib/build"
12+
kind "StaticLib"
13+
language "C++"
14+
15+
project "main"
16+
kind "ConsoleApp"
17+
language "C++"
18+
targetdir "bin/"
19+
systemversion "latest"
20+
flags { "MultiProcessorCompile", "NoPCH" }
21+
22+
-- Src
23+
files { "main.cpp" }
24+
25+
-- prlib
26+
-- setup command
27+
-- git submodule add https://github.com/Ushio/prlib libs/prlib
28+
-- premake5 vs2017
29+
dependson { "prlib" }
30+
includedirs { "libs/prlib/src" }
31+
libdirs { "libs/prlib/bin" }
32+
filter {"Debug"}
33+
links { "prlib_d" }
34+
filter {"Release"}
35+
links { "prlib" }
36+
filter{}
37+
38+
symbols "On"
39+
40+
filter {"Debug"}
41+
runtime "Debug"
42+
targetname ("Main_Debug")
43+
optimize "Off"
44+
filter {"Release"}
45+
runtime "Release"
46+
targetname ("Main")
47+
optimize "Full"
48+
filter{}

0 commit comments

Comments
 (0)
Please sign in to comment.