Commit a743ae3f authored by DALAB\sjtud's avatar DALAB\sjtud
Browse files

initialize

parent 9814ef6b
cmake_minimum_required(VERSION 3.1)
project(CA)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
option(LIBIGL_USE_STATIC_LIBRARY "Use libigl as static library" OFF)
option(LIBIGL_WITH_ANTTWEAKBAR "Use AntTweakBar" OFF)
option(LIBIGL_WITH_CGAL "Use CGAL" OFF)
option(LIBIGL_WITH_COMISO "Use CoMiso" OFF)
option(LIBIGL_WITH_CORK "Use Cork" OFF)
option(LIBIGL_WITH_EMBREE "Use Embree" OFF)
option(LIBIGL_WITH_LIM "Use LIM" OFF)
option(LIBIGL_WITH_MATLAB "Use Matlab" OFF)
option(LIBIGL_WITH_MOSEK "Use MOSEK" OFF)
option(LIBIGL_WITH_OPENGL "Use OpenGL" ON)
option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON)
option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON)
option(LIBIGL_WITH_PNG "Use PNG" OFF)
option(LIBIGL_WITH_PYTHON "Use Python" OFF)
option(LIBIGL_WITH_TETGEN "Use Tetgen" OFF)
option(LIBIGL_WITH_TRIANGLE "Use Triangle" OFF)
option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON)
option(LIBIGL_WITH_XML "Use XML" OFF)
if (NOT LIBIGL_FOUND)
find_package(LIBIGL REQUIRED QUIET)
endif()
# add_subdirectory(0_dummy)
# add_subdirectory(1-0_earth)
# add_subdirectory(1-1_cannonball)
# add_subdirectory(1-2_spring)
# add_subdirectory(2-1_bead)
# add_subdirectory(2-2_pendulum)
# add_subdirectory(3_cloth)
# add_subdirectory(4-1_spinning)
# add_subdirectory(4-2_collision)
add_subdirectory(5_fluid)
\ No newline at end of file
# Computer Animation 2022 - Exercise
## Overview
Code framework for course exercise.
## Installation
Install **Git** and build system **Cmake**. For windows user, MSVC need to be installed.
### Note for linux users
Many linux distributions do not include `gcc` and the basic development tools in their default installation. On Ubuntu, you need to install the following packages:
```
sudo apt-get install build-essential libx11-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libxrandr-dev libxi-dev libxmu-dev libblas-dev libxinerama-dev libxcursor-dev
```
### Build
Clone this repo (together with the submodule `libigl`):
```
git clone --recursive http://dalab.se.sjtu.edu.cn/gitlab/courses/ca-framework-2022.git
# if you forget clone submodule at first place
git submodule update --init --recursive
```
Run the following commands inside the relevant subfolder to setup the build folder:
```
mkdir build
cd build
cmake ..
```
Compile and run the executable, e.g. Ubuntu:
```
make && ./0_dummy/0_dummy
```
### For Windows
Cmake will generate Microsft visual studio project. Click the `*.sln` file to open the project and build.
## Exercise Handin
**You only need to handin the directory containing the modified executable**. For example (homework 0), you only need to compress folder *0_dummy* and submit the compressed file. *Please don't include any build file, only the source code and related resource file*.
```
zip NAME_ID_0_dummy.zip 0_dummy/*
```
Rename your compressed file following the rule *`NAME_ID_XXX`*.
## FAQ
* Command `cmake ../` stuck at `Cloning into 'eigen'...` or other cloning.
This may caused by problem of accessing github. Please first try use [SJTU VPN](!https://net.sjtu.edu.cn/wlfw/VPN.htm) and compile.
~~Also, some repos are available on our own server, such as *Eigen*. The download info of libigl dependencies is located at file `libigl/cmake/LibiglDownloadExternal.cmake`. For example, you can change the link at line 70 to `http://dalab.se.sjtu.edu.cn/gitlab/xiaoyuwei/eigen.git` use eigen mirror repo at DALAB server.~~
~~glfw (http://dalab.se.sjtu.edu.cn/gitlab/xiaoyuwei/glfw.git) and imgui (http://dalab.se.sjtu.edu.cn/gitlab/xiaoyuwei/imgui.git) are also available on our server.~~
* The menu bar isn't rendered correctly in Release mode using VS2019.
Solution 1: Use Debug mode.
Solution 2: Remove `ImGuiWindowFlags_AlwaysAutoResize` flag used in `ImGui::Begin()` and comment out `ImGui::SetNextWindowSizeConstraints()` in `include/Gui.cpp`. See [#1669](https://github.com/libigl/libigl/issues/1669) for more details.
----
The main part of this framework refers to physical-based simulation course at ETH Zurich.
# - Try to find the LIBIGL library
# Once done this will define
#
# LIBIGL_FOUND - system has LIBIGL
# LIBIGL_INCLUDE_DIR - **the** LIBIGL include directory
if(LIBIGL_FOUND)
return()
endif()
find_path(LIBIGL_INCLUDE_DIR igl/readOBJ.h
HINTS
ENV LIBIGL
ENV LIBIGLROOT
ENV LIBIGL_ROOT
ENV LIBIGL_DIR
PATHS
${CMAKE_SOURCE_DIR}/../..
${CMAKE_SOURCE_DIR}/..
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/libigl
${CMAKE_SOURCE_DIR}/../libigl
${CMAKE_SOURCE_DIR}/../../libigl
${CMAKE_SOURCE_DIR}/../../lib/libigl
${CMAKE_SOURCE_DIR}/lib/libigl
${CMAKE_SOURCE_DIR}/../lib/libigl
/usr
/usr/local
/usr/local/igl/libigl
PATH_SUFFIXES include
)
message(${LIBIGL_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBIGL
"\nlibigl not found --- You can download it using:\n\tgit clone --recursive https://github.com/libigl/libigl.git ${CMAKE_SOURCE_DIR}/../libigl"
LIBIGL_INCLUDE_DIR)
mark_as_advanced(LIBIGL_INCLUDE_DIR)
list(APPEND CMAKE_MODULE_PATH "${LIBIGL_INCLUDE_DIR}/../cmake")
message(${CMAKE_MODULE_PATH})
include(libigl)
OFF
# cube.off
# A cube
8 12 0
-1 -1 -1
1 -1 -1
-1 1 -1
1 1 -1
-1 -1 1
1 -1 1
-1 1 1
1 1 1
3 0 2 1
3 2 3 1
3 1 3 5
3 3 7 5
3 2 6 3
3 6 7 3
3 5 7 4
3 7 6 4
3 4 6 0
3 6 2 0
3 4 0 1
3 4 1 5
\ No newline at end of file
OFF
# cube.off
# A cube
8 24 0
-1 -1 -1
1 -1 -1
-1 1 -1
1 1 -1
-1 -1 1
1 -1 1
-1 1 1
1 1 1
3 0 2 1
3 2 3 1
3 1 3 5
3 3 7 5
3 2 6 3
3 6 7 3
3 5 7 4
3 7 6 4
3 4 6 0
3 6 2 0
3 4 0 1
3 4 1 5
3 0 3 1
3 2 3 0
3 1 7 5
3 3 7 1
3 2 7 3
3 6 7 2
3 5 7 6
3 6 4 5
3 4 6 2
3 4 2 0
3 5 0 1
3 4 0 5
\ No newline at end of file
OFF
# cube.off
# A cube
8 12 0
-1 -1 -1
1 -1 -1
-1 1 -1
1 1 -1
-1 -1 1
1 -1 1
-1 1 1
1 1 1
3 0 2 1
3 2 3 1
3 2 6 3
3 6 7 3
3 5 7 4
3 7 6 4
3 1 7 5
3 3 7 1
#3 2 7 3
#3 6 7 2
3 4 6 2
3 4 2 0
3 5 0 1
3 4 0 5
\ No newline at end of file
OFF
# cube.off
# A cube
8 12 0
-1 -0.1 -1
1 -0.1 -1
-1 0.1 -1
1 0.1 -1
-1 -0.1 1
1 -0.1 1
-1 0.1 1
1 0.1 1
3 0 2 1
3 2 3 1
3 1 3 5
3 3 7 5
3 2 6 3
3 6 7 3
3 5 7 4
3 7 6 4
3 4 6 0
3 6 2 0
3 4 0 1
3 4 1 5
\ No newline at end of file
OFF
482 960 0
0 19.7371 -0
-0 19.3578 -3.85051
-0.751198 19.3578 -3.77653
-1.47353 19.3578 -3.55741
-2.13923 19.3578 -3.20159
-2.72272 19.3578 -2.72272
-3.20159 19.3578 -2.13923
-3.55741 19.3578 -1.47353
-3.77653 19.3578 -0.751197
-3.85051 19.3578 1e-06
-3.77653 19.3578 0.751199
-3.55741 19.3578 1.47353
-3.20158 19.3578 2.13923
-2.72272 19.3578 2.72273
-2.13923 19.3578 3.20159
-1.47353 19.3578 3.55741
-0.751195 19.3578 3.77653
4e-06 19.3578 3.85051
0.751202 19.3578 3.77653
1.47353 19.3578 3.55741
2.13924 19.3578 3.20158
2.72273 19.3578 2.72272
3.20159 19.3578 2.13923
3.55741 19.3578 1.47352
3.77653 19.3578 0.751192
3.85051 19.3578 -6e-06
3.77653 19.3578 -0.751204
3.55741 19.3578 -1.47353
3.20158 19.3578 -2.13924
2.72272 19.3578 -2.72273
2.13922 19.3578 -3.20159
1.47352 19.3578 -3.55741
0.75119 19.3578 -3.77653
-0 18.2347 -7.55305
-1.47353 18.2347 -7.40792
-2.89043 18.2347 -6.97811
-4.19625 18.2347 -6.28014
-5.34082 18.2347 -5.34082
-6.28014 18.2347 -4.19625
-6.97811 18.2347 -2.89043
-7.40792 18.2347 -1.47353
-7.55305 18.2347 2e-06
-7.40792 18.2347 1.47353
-6.97811 18.2347 2.89043
-6.28013 18.2347 4.19626
-5.34081 18.2347 5.34082
-4.19625 18.2347 6.28014
-2.89042 18.2347 6.97811
-1.47352 18.2347 7.40793
7e-06 18.2347 7.55305
1.47353 18.2347 7.40792
2.89044 18.2347 6.97811
4.19626 18.2347 6.28013
5.34082 18.2347 5.34081
6.28014 18.2347 4.19624
6.97812 18.2347 2.89042
7.40793 18.2347 1.47352
7.55305 18.2347 -1.2e-05
7.40792 18.2347 -1.47354
6.97811 18.2347 -2.89044
6.28013 18.2347 -4.19626
5.34081 18.2347 -5.34083
4.19624 18.2347 -6.28014
2.89041 18.2347 -6.97812
1.47351 18.2347 -7.40793
-0 16.4108 -10.9653
-2.13923 16.4108 -10.7546
-4.19625 16.4108 -10.1306
-6.09201 16.4108 -9.11734
-7.75366 16.4108 -7.75366
-9.11734 16.4108 -6.09201
-10.1306 16.4108 -4.19625
-10.7546 16.4108 -2.13923
-10.9653 16.4108 4e-06
-10.7546 16.4108 2.13924
-10.1306 16.4108 4.19626
-9.11734 16.4108 6.09202
-7.75366 16.4108 7.75367
-6.09201 16.4108 9.11735
-4.19624 16.4108 10.1307
-2.13922 16.4108 10.7546
1.1e-05 16.4108 10.9653
2.13924 16.4108 10.7546
4.19626 16.4108 10.1306
6.09202 16.4108 9.11733
7.75367 16.4108 7.75365
9.11735 16.4108 6.092
10.1307 16.4108 4.19624
10.7546 16.4108 2.13921
10.9653 16.4108 -1.8e-05
10.7546 16.4108 -2.13925
10.1306 16.4108 -4.19627
9.11733 16.4108 -6.09203
7.75365 16.4108 -7.75368
6.09199 16.4108 -9.11735
4.19623 16.4108 -10.1307
2.13921 16.4108 -10.7546
-1e-06 13.9562 -13.9562
-2.72272 13.9562 -13.6881
-5.34082 13.9562 -12.8939
-7.75366 13.9562 -11.6042
-9.86854 13.9562 -9.86854
-11.6042 13.9562 -7.75366
-12.8939 13.9562 -5.34081
-13.6881 13.9562 -2.72272
-13.9562 13.9562 5e-06
-13.6881 13.9562 2.72273
-12.8939 13.9562 5.34082
-11.6042 13.9562 7.75367
-9.86853 13.9562 9.86855
-7.75365 13.9562 11.6042
-5.34081 13.9562 12.8939
-2.72271 13.9562 13.6881
1.3e-05 13.9562 13.9562
2.72274 13.9562 13.6881
5.34083 13.9562 12.8939
7.75368 13.9562 11.6042
9.86855 13.9562 9.86853
11.6042 13.9562 7.75365
12.8939 13.9562 5.3408
13.6881 13.9562 2.7227
13.9562 13.9562 -2.2e-05
13.6881 13.9562 -2.72275
12.8939 13.9562 -5.34084
11.6042 13.9562 -7.75368
9.86852 13.9562 -9.86856
7.75364 13.9562 -11.6042
5.34079 13.9562 -12.8939
2.72269 13.9562 -13.6881
-1e-06 10.9653 -16.4108
-3.20159 10.9653 -16.0955
-6.28013 10.9653 -15.1616
-9.11734 10.9653 -13.6451
-11.6042 10.9653 -11.6042
-13.6451 10.9653 -9.11734
-15.1616 10.9653 -6.28013
-16.0955 10.9653 -3.20158
-16.4108 10.9653 5e-06
-16.0955 10.9653 3.20159
-15.1616 10.9653 6.28014
-13.6451 10.9653 9.11735
-11.6042 10.9653 11.6042
-9.11733 10.9653 13.6451
-6.28012 10.9653 15.1616
-3.20157 10.9653 16.0955
1.6e-05 10.9653 16.4108
3.2016 10.9653 16.0955
6.28015 10.9653 15.1616
9.11736 10.9653 13.6451
11.6042 10.9653 11.6042
13.6451 10.9653 9.11732
15.1616 10.9653 6.28011
16.0955 10.9653 3.20156
16.4108 10.9653 -2.6e-05
16.0954 10.9653 -3.20161
15.1616 10.9653 -6.28016
13.6451 10.9653 -9.11737
11.6042 10.9653 -11.6042
9.11732 10.9653 -13.6451
6.2801 10.9653 -15.1616
3.20155 10.9653 -16.0955
-1e-06 7.55305 -18.2347
-3.55741 7.55305 -17.8843
-6.97811 7.55305 -16.8467
-10.1306 7.55305 -15.1616
-12.8939 7.55305 -12.8939
-15.1616 7.55305 -10.1306
-16.8467 7.55305 -6.97811
-17.8843 7.55305 -3.55741
-18.2347 7.55305 6e-06
-17.8843 7.55305 3.55742
-16.8466 7.55305 6.97812
-15.1616 7.55305 10.1307
-12.8939 7.55305 12.8939
-10.1306 7.55305 15.1616
-6.9781 7.55305 16.8467
-3.55739 7.55305 17.8843
1.8e-05 7.55305 18.2347
3.55743 7.55305 17.8843
6.97813 7.55305 16.8466
10.1307 7.55305 15.1616
12.8939 7.55305 12.8939
15.1616 7.55305 10.1306
16.8467 7.55305 6.97809
17.8843 7.55305 3.55738
18.2347 7.55305 -2.9e-05
17.8843 7.55305 -3.55744
16.8466 7.55305 -6.97814
15.1616 7.55305 -10.1307
12.8938 7.55305 -12.8939
10.1306 7.55305 -15.1616
6.97808 7.55305 -16.8467
3.55737 7.55305 -17.8843
-1e-06 3.85051 -19.3578
-3.77653 3.85051 -18.9859
-7.40792 3.85051 -17.8843
-10.7546 3.85051 -16.0955
-13.6881 3.85051 -13.6881
-16.0955 3.85051 -10.7546
-17.8843 3.85051 -7.40792
-18.9859 3.85051 -3.77652
-19.3578 3.85051 6e-06
-18.9859 3.85051 3.77653
-17.8843 3.85051 7.40793
-16.0954 3.85051 10.7546
-13.688 3.85051 13.6881
-10.7546 3.85051 16.0955
-7.40791 3.85051 17.8843
-3.77651 3.85051 18.9859
1.9e-05 3.85051 19.3578
3.77655 3.85051 18.9859
7.40794 3.85051 17.8843
10.7547 3.85051 16.0954
13.6881 3.85051 13.688
16.0955 3.85051 10.7546
17.8843 3.85051 7.4079
18.9859 3.85051 3.7765
19.3578 3.85051 -3.1e-05
18.9859 3.85051 -3.77656
17.8843 3.85051 -7.40796
16.0954 3.85051 -10.7547
13.688 3.85051 -13.6881
10.7546 3.85051 -16.0955
7.40789 3.85051 -17.8843
3.77648 3.85051 -18.9859
-1e-06 1e-06 -19.7371
-3.85051 1e-06 -19.3578
-7.55305 1e-06 -18.2347
-10.9653 1e-06 -16.4108
-13.9562 1e-06 -13.9562
-16.4108 1e-06 -10.9653
-18.2347 1e-06 -7.55305
-19.3578 1e-06 -3.85051
-19.7371 1e-06 6e-06
-19.3578 1e-06 3.85052
-18.2347 1e-06 7.55306
-16.4108 1e-06 10.9653
-13.9562 1e-06 13.9562
-10.9653 1e-06 16.4108
-7.55304 1e-06 18.2347
-3.8505 1e-06 19.3578
1.9e-05 1e-06 19.7371
3.85053 1e-06 19.3578
7.55307 1e-06 18.2347
10.9654 1e-06 16.4108
13.9562 1e-06 13.9562
16.4108 1e-06 10.9653
18.2347 1e-06 7.55303
19.3578 1e-06 3.85048
19.7371 1e-06 -3.2e-05
19.3578 1e-06 -3.85055
18.2347 1e-06 -7.55308
16.4108 1e-06 -10.9654
13.9562 1e-06 -13.9562
10.9653 1e-06 -16.4108
7.55302 1e-06 -18.2347
3.85047 1e-06 -19.3578
-1e-06 -3.85051 -19.3578
-3.77653 -3.85051 -18.9859
-7.40792 -3.85051 -17.8843
-10.7546 -3.85051 -16.0955
-13.6881 -3.85051 -13.6881
-16.0955 -3.85051 -10.7546
-17.8843 -3.85051 -7.40792
-18.9859 -3.85051 -3.77652
-19.3578 -3.85051 6e-06
-18.9859 -3.85051 3.77654
-17.8843 -3.85051 7.40793
-16.0954 -3.85051 10.7546
-13.688 -3.85051 13.6881
-10.7546 -3.85051 16.0955
-7.40791 -3.85051 17.8843
-3.77651 -3.85051 18.9859
1.9e-05 -3.85051 19.3578
3.77655 -3.85051 18.9859
7.40794 -3.85051 17.8843
10.7547 -3.85051 16.0954
13.6881 -3.85051 13.688
16.0955 -3.85051 10.7546
17.8843 -3.85051 7.4079
18.9859 -3.85051 3.7765
19.3578 -3.85051 -3.1e-05
18.9859 -3.85051 -3.77656
17.8843 -3.85051 -7.40796
16.0954 -3.85051 -10.7547
13.688 -3.85051 -13.6881
10.7546 -3.85051 -16.0955
7.40789 -3.85051 -17.8843
3.77649 -3.85051 -18.9859
-1e-06 -7.55305 -18.2347
-3.55741 -7.55305 -17.8843
-6.97811 -7.55305 -16.8467
-10.1306 -7.55305 -15.1616
-12.8939 -7.55305 -12.8939
-15.1616 -7.55305 -10.1306
-16.8467 -7.55305 -6.97811
-17.8843 -7.55305 -3.55741
-18.2347 -7.55305 6e-06
-17.8843 -7.55305 3.55742
-16.8466 -7.55305 6.97812
-15.1616 -7.55305 10.1307
-12.8939 -7.55305 12.8939
-10.1306 -7.55305 15.1616
-6.9781 -7.55305 16.8467
-3.55739 -7.55305 17.8843
1.8e-05 -7.55305 18.2347
3.55743 -7.55305 17.8843
6.97813 -7.55305 16.8466
10.1307 -7.55305 15.1616
12.8939 -7.55305 12.8939
15.1616 -7.55305 10.1306
16.8467 -7.55305 6.97809
17.8843 -7.55305 3.55738
18.2347 -7.55305 -2.9e-05
17.8843 -7.55305 -3.55744
16.8466 -7.55305 -6.97814
15.1616 -7.55305 -10.1307
12.8938 -7.55305 -12.8939
10.1306 -7.55305 -15.1616
6.97808 -7.55305 -16.8467
3.55737 -7.55305 -17.8843
-1e-06 -10.9653 -16.4108
-3.20159 -10.9653 -16.0955
-6.28013 -10.9653 -15.1616
-9.11734 -10.9653 -13.6451
-11.6042 -10.9653 -11.6042
-13.6451 -10.9653 -9.11734
-15.1616 -10.9653 -6.28013
-16.0955 -10.9653 -3.20158
-16.4108 -10.9653 5e-06
-16.0955 -10.9653 3.20159
-15.1616 -10.9653 6.28014
-13.6451 -10.9653 9.11735
-11.6042 -10.9653 11.6042
-9.11733 -10.9653 13.6451
-6.28012 -10.9653 15.1616
-3.20157 -10.9653 16.0955
1.6e-05 -10.9653 16.4108
3.2016 -10.9653 16.0955
6.28015 -10.9653 15.1616
9.11736 -10.9653 13.6451
11.6042 -10.9653 11.6042
13.6451 -10.9653 9.11732
15.1616 -10.9653 6.28011
16.0955 -10.9653 3.20156
16.4108 -10.9653 -2.6e-05
16.0954 -10.9653 -3.20161
15.1616 -10.9653 -6.28016
13.6451 -10.9653 -9.11737
11.6042 -10.9653 -11.6042
9.11732 -10.9653 -13.6451
6.2801 -10.9653 -15.1616
3.20155 -10.9653 -16.0955
-1e-06 -13.9562 -13.9562
-2.72272 -13.9562 -13.6881
-5.34082 -13.9562 -12.8939
-7.75366 -13.9562 -11.6042
-9.86854 -13.9562 -9.86854
-11.6042 -13.9562 -7.75366
-12.8939 -13.9562 -5.34081
-13.6881 -13.9562 -2.72272
-13.9562 -13.9562 5e-06
-13.6881 -13.9562 2.72273
-12.8939 -13.9562 5.34082
-11.6042 -13.9562 7.75367
-9.86853 -13.9562 9.86855
-7.75365 -13.9562 11.6042
-5.34081 -13.9562 12.8939
-2.72271 -13.9562 13.6881
1.3e-05 -13.9562 13.9562
2.72274 -13.9562 13.6881
5.34083 -13.9562 12.8939
7.75368 -13.9562 11.6042
9.86855 -13.9562 9.86853
11.6042 -13.9562 7.75365
12.8939 -13.9562 5.3408
13.6881 -13.9562 2.7227
13.9562 -13.9562 -2.2e-05
13.6881 -13.9562 -2.72275
12.8939 -13.9562 -5.34084
11.6042 -13.9562 -7.75368
9.86852 -13.9562 -9.86856
7.75364 -13.9562 -11.6042
5.34079 -13.9562 -12.8939
2.72269 -13.9562 -13.6881
-0 -16.4108 -10.9653
-2.13923 -16.4108 -10.7546
-4.19625 -16.4108 -10.1306
-6.09201 -16.4108 -9.11734
-7.75366 -16.4108 -7.75366
-9.11734 -16.4108 -6.09201
-10.1306 -16.4108 -4.19625
-10.7546 -16.4108 -2.13923
-10.9653 -16.4108 4e-06
-10.7546 -16.4108 2.13924
-10.1306 -16.4108 4.19626
-9.11734 -16.4108 6.09202
-7.75366 -16.4108 7.75367
-6.09201 -16.4108 9.11734
-4.19624 -16.4108 10.1306
-2.13922 -16.4108 10.7546
1.1e-05 -16.4108 10.9653
2.13924 -16.4108 10.7546
4.19626 -16.4108 10.1306
6.09202 -16.4108 9.11733
7.75367 -16.4108 7.75365
9.11735 -16.4108 6.092
10.1307 -16.4108 4.19624
10.7546 -16.4108 2.13921
10.9653 -16.4108 -1.8e-05
10.7546 -16.4108 -2.13925
10.1306 -16.4108 -4.19627
9.11733 -16.4108 -6.09203
7.75365 -16.4108 -7.75368
6.09199 -16.4108 -9.11735
4.19623 -16.4108 -10.1307
2.13921 -16.4108 -10.7546
-0 -18.2347 -7.55305
-1.47353 -18.2347 -7.40792
-2.89043 -18.2347 -6.97811
-4.19625 -18.2347 -6.28013
-5.34081 -18.2347 -5.34081
-6.28013 -18.2347 -4.19625
-6.97811 -18.2347 -2.89043
-7.40792 -18.2347 -1.47353
-7.55305 -18.2347 2e-06
-7.40792 -18.2347 1.47353
-6.97811 -18.2347 2.89043
-6.28013 -18.2347 4.19625
-5.34081 -18.2347 5.34082
-4.19625 -18.2347 6.28014
-2.89042 -18.2347 6.97811
-1.47352 -18.2347 7.40792
7e-06 -18.2347 7.55305
1.47353 -18.2347 7.40792
2.89043 -18.2347 6.97811
4.19626 -18.2347 6.28013
5.34082 -18.2347 5.34081
6.28014 -18.2347 4.19624
6.97811 -18.2347 2.89042
7.40792 -18.2347 1.47352
7.55305 -18.2347 -1.2e-05
7.40792 -18.2347 -1.47354
6.9781 -18.2347 -2.89044
6.28012 -18.2347 -4.19626
5.3408 -18.2347 -5.34082
4.19624 -18.2347 -6.28014
2.89041 -18.2347 -6.97812
1.47351 -18.2347 -7.40792
-0 -19.3578 -3.85051
-0.751197 -19.3578 -3.77652
-1.47353 -19.3578 -3.55741
-2.13923 -19.3578 -3.20158
-2.72272 -19.3578 -2.72272
-3.20158 -19.3578 -2.13923
-3.55741 -19.3578 -1.47353
-3.77652 -19.3578 -0.751196
-3.85051 -19.3578 1e-06
-3.77652 -19.3578 0.751198
-3.5574 -19.3578 1.47353
-3.20158 -19.3578 2.13923
-2.72272 -19.3578 2.72272
-2.13923 -19.3578 3.20158
-1.47352 -19.3578 3.55741
-0.751194 -19.3578 3.77652
4e-06 -19.3578 3.85051
0.751201 -19.3578 3.77652
1.47353 -19.3578 3.5574
2.13923 -19.3578 3.20158
2.72272 -19.3578 2.72272
3.20158 -19.3578 2.13922
3.55741 -19.3578 1.47352
3.77652 -19.3578 0.751191
3.85051 -19.3578 -6e-06
3.77652 -19.3578 -0.751203
3.5574 -19.3578 -1.47353
3.20158 -19.3578 -2.13923
2.72271 -19.3578 -2.72273
2.13922 -19.3578 -3.20159
1.47352 -19.3578 -3.55741
0.751189 -19.3578 -3.77652
0 -19.7371 -0
3 0 1 2
3 0 2 3
3 0 3 4
3 0 4 5
3 0 5 6
3 0 6 7
3 0 7 8
3 0 8 9
3 0 9 10
3 0 10 11
3 0 11 12
3 0 12 13
3 0 13 14
3 0 14 15
3 0 15 16
3 0 16 17
3 0 17 18
3 0 18 19
3 0 19 20
3 0 20 21
3 0 21 22
3 0 22 23
3 0 23 24
3 0 24 25
3 0 25 26
3 0 26 27
3 0 27 28
3 0 28 29
3 0 29 30
3 0 30 31
3 0 31 32
3 0 32 1
3 1 33 34
3 1 34 2
3 2 34 35
3 2 35 3
3 3 35 36
3 3 36 4
3 4 36 37
3 4 37 5
3 5 37 38
3 5 38 6
3 6 38 39
3 6 39 7
3 7 39 40
3 7 40 8
3 8 40 41
3 8 41 9
3 9 41 42
3 9 42 10
3 10 42 43
3 10 43 11
3 11 43 44
3 11 44 12
3 12 44 45
3 12 45 13
3 13 45 46
3 13 46 14
3 14 46 47
3 14 47 15
3 15 47 48
3 15 48 16
3 16 48 49
3 16 49 17
3 17 49 50
3 17 50 18
3 18 50 51
3 18 51 19
3 19 51 52
3 19 52 20
3 20 52 53
3 20 53 21
3 21 53 54
3 21 54 22
3 22 54 55
3 22 55 23
3 23 55 56
3 23 56 24
3 24 56 57
3 24 57 25
3 25 57 58
3 25 58 26
3 26 58 59
3 26 59 27
3 27 59 60
3 27 60 28
3 28 60 61
3 28 61 29
3 29 61 62
3 29 62 30
3 30 62 63
3 30 63 31
3 31 63 64
3 31 64 32
3 32 64 33
3 32 33 1
3 33 65 66
3 33 66 34
3 34 66 67
3 34 67 35
3 35 67 68
3 35 68 36
3 36 68 69
3 36 69 37
3 37 69 70
3 37 70 38
3 38 70 71
3 38 71 39
3 39 71 72
3 39 72 40
3 40 72 73
3 40 73 41
3 41 73 74
3 41 74 42
3 42 74 75
3 42 75 43
3 43 75 76
3 43 76 44
3 44 76 77
3 44 77 45
3 45 77 78
3 45 78 46
3 46 78 79
3 46 79 47
3 47 79 80
3 47 80 48
3 48 80 81
3 48 81 49
3 49 81 82
3 49 82 50
3 50 82 83
3 50 83 51
3 51 83 84
3 51 84 52
3 52 84 85
3 52 85 53
3 53 85 86
3 53 86 54
3 54 86 87
3 54 87 55
3 55 87 88
3 55 88 56
3 56 88 89
3 56 89 57
3 57 89 90
3 57 90 58
3 58 90 91
3 58 91 59
3 59 91 92
3 59 92 60
3 60 92 93
3 60 93 61
3 61 93 94
3 61 94 62
3 62 94 95
3 62 95 63
3 63 95 96
3 63 96 64
3 64 96 65
3 64 65 33
3 65 97 98
3 65 98 66
3 66 98 99
3 66 99 67
3 67 99 100
3 67 100 68
3 68 100 101
3 68 101 69
3 69 101 102
3 69 102 70
3 70 102 103
3 70 103 71
3 71 103 104
3 71 104 72
3 72 104 105
3 72 105 73
3 73 105 106
3 73 106 74
3 74 106 107
3 74 107 75
3 75 107 108
3 75 108 76
3 76 108 109
3 76 109 77
3 77 109 110
3 77 110 78
3 78 110 111
3 78 111 79
3 79 111 112
3 79 112 80
3 80 112 113
3 80 113 81
3 81 113 114
3 81 114 82
3 82 114 115
3 82 115 83
3 83 115 116
3 83 116 84
3 84 116 117
3 84 117 85
3 85 117 118
3 85 118 86
3 86 118 119
3 86 119 87
3 87 119 120
3 87 120 88
3 88 120 121
3 88 121 89
3 89 121 122
3 89 122 90
3 90 122 123
3 90 123 91
3 91 123 124
3 91 124 92
3 92 124 125
3 92 125 93
3 93 125 126
3 93 126 94
3 94 126 127
3 94 127 95
3 95 127 128
3 95 128 96
3 96 128 97
3 96 97 65
3 97 129 130
3 97 130 98
3 98 130 131
3 98 131 99
3 99 131 132
3 99 132 100
3 100 132 133
3 100 133 101
3 101 133 134
3 101 134 102
3 102 134 135
3 102 135 103
3 103 135 136
3 103 136 104
3 104 136 137
3 104 137 105
3 105 137 138
3 105 138 106
3 106 138 139
3 106 139 107
3 107 139 140
3 107 140 108
3 108 140 141
3 108 141 109
3 109 141 142
3 109 142 110
3 110 142 143
3 110 143 111
3 111 143 144
3 111 144 112
3 112 144 145
3 112 145 113
3 113 145 146
3 113 146 114
3 114 146 147
3 114 147 115
3 115 147 148
3 115 148 116
3 116 148 149
3 116 149 117
3 117 149 150
3 117 150 118
3 118 150 151
3 118 151 119
3 119 151 152
3 119 152 120
3 120 152 153
3 120 153 121
3 121 153 154
3 121 154 122
3 122 154 155
3 122 155 123
3 123 155 156
3 123 156 124
3 124 156 157
3 124 157 125
3 125 157 158
3 125 158 126
3 126 158 159
3 126 159 127
3 127 159 160
3 127 160 128
3 128 160 129
3 128 129 97
3 129 161 162
3 129 162 130
3 130 162 163
3 130 163 131
3 131 163 164
3 131 164 132
3 132 164 165
3 132 165 133
3 133 165 166
3 133 166 134
3 134 166 167
3 134 167 135
3 135 167 168
3 135 168 136
3 136 168 169
3 136 169 137
3 137 169 170
3 137 170 138
3 138 170 171
3 138 171 139
3 139 171 172
3 139 172 140
3 140 172 173
3 140 173 141
3 141 173 174
3 141 174 142
3 142 174 175
3 142 175 143
3 143 175 176
3 143 176 144
3 144 176 177
3 144 177 145
3 145 177 178
3 145 178 146
3 146 178 179
3 146 179 147
3 147 179 180
3 147 180 148
3 148 180 181
3 148 181 149
3 149 181 182
3 149 182 150
3 150 182 183
3 150 183 151
3 151 183 184
3 151 184 152
3 152 184 185
3 152 185 153
3 153 185 186
3 153 186 154
3 154 186 187
3 154 187 155
3 155 187 188
3 155 188 156
3 156 188 189
3 156 189 157
3 157 189 190
3 157 190 158
3 158 190 191
3 158 191 159
3 159 191 192
3 159 192 160
3 160 192 161
3 160 161 129
3 161 193 194
3 161 194 162
3 162 194 195
3 162 195 163
3 163 195 196
3 163 196 164
3 164 196 197
3 164 197 165
3 165 197 198
3 165 198 166
3 166 198 199
3 166 199 167
3 167 199 200
3 167 200 168
3 168 200 201
3 168 201 169
3 169 201 202
3 169 202 170
3 170 202 203
3 170 203 171
3 171 203 204
3 171 204 172
3 172 204 205
3 172 205 173
3 173 205 206
3 173 206 174
3 174 206 207
3 174 207 175
3 175 207 208
3 175 208 176
3 176 208 209
3 176 209 177
3 177 209 210
3 177 210 178
3 178 210 211
3 178 211 179
3 179 211 212
3 179 212 180
3 180 212 213
3 180 213 181
3 181 213 214
3 181 214 182
3 182 214 215
3 182 215 183
3 183 215 216
3 183 216 184
3 184 216 217
3 184 217 185
3 185 217 218
3 185 218 186
3 186 218 219
3 186 219 187
3 187 219 220
3 187 220 188
3 188 220 221
3 188 221 189
3 189 221 222
3 189 222 190
3 190 222 223
3 190 223 191
3 191 223 224
3 191 224 192
3 192 224 193
3 192 193 161
3 193 225 226
3 193 226 194
3 194 226 227
3 194 227 195
3 195 227 228
3 195 228 196
3 196 228 229
3 196 229 197
3 197 229 230
3 197 230 198
3 198 230 231
3 198 231 199
3 199 231 232
3 199 232 200
3 200 232 233
3 200 233 201
3 201 233 234
3 201 234 202
3 202 234 235
3 202 235 203
3 203 235 236
3 203 236 204
3 204 236 237
3 204 237 205
3 205 237 238
3 205 238 206
3 206 238 239
3 206 239 207
3 207 239 240
3 207 240 208
3 208 240 241
3 208 241 209
3 209 241 242
3 209 242 210
3 210 242 243
3 210 243 211
3 211 243 244
3 211 244 212
3 212 244 245
3 212 245 213
3 213 245 246
3 213 246 214
3 214 246 247
3 214 247 215
3 215 247 248
3 215 248 216
3 216 248 249
3 216 249 217
3 217 249 250
3 217 250 218
3 218 250 251
3 218 251 219
3 219 251 252
3 219 252 220
3 220 252 253
3 220 253 221
3 221 253 254
3 221 254 222
3 222 254 255
3 222 255 223
3 223 255 256
3 223 256 224
3 224 256 225
3 224 225 193
3 225 257 258
3 225 258 226
3 226 258 259
3 226 259 227
3 227 259 260
3 227 260 228
3 228 260 261
3 228 261 229
3 229 261 262
3 229 262 230
3 230 262 263
3 230 263 231
3 231 263 264
3 231 264 232
3 232 264 265
3 232 265 233
3 233 265 266
3 233 266 234
3 234 266 267
3 234 267 235
3 235 267 268
3 235 268 236
3 236 268 269
3 236 269 237
3 237 269 270
3 237 270 238
3 238 270 271
3 238 271 239
3 239 271 272
3 239 272 240
3 240 272 273
3 240 273 241
3 241 273 274
3 241 274 242
3 242 274 275
3 242 275 243
3 243 275 276
3 243 276 244
3 244 276 277
3 244 277 245
3 245 277 278
3 245 278 246
3 246 278 279
3 246 279 247
3 247 279 280
3 247 280 248
3 248 280 281
3 248 281 249
3 249 281 282
3 249 282 250
3 250 282 283
3 250 283 251
3 251 283 284
3 251 284 252
3 252 284 285
3 252 285 253
3 253 285 286
3 253 286 254
3 254 286 287
3 254 287 255
3 255 287 288
3 255 288 256
3 256 288 257
3 256 257 225
3 257 289 290
3 257 290 258
3 258 290 291
3 258 291 259
3 259 291 292
3 259 292 260
3 260 292 293
3 260 293 261
3 261 293 294
3 261 294 262
3 262 294 295
3 262 295 263
3 263 295 296
3 263 296 264
3 264 296 297
3 264 297 265
3 265 297 298
3 265 298 266
3 266 298 299
3 266 299 267
3 267 299 300
3 267 300 268
3 268 300 301
3 268 301 269
3 269 301 302
3 269 302 270
3 270 302 303
3 270 303 271
3 271 303 304
3 271 304 272
3 272 304 305
3 272 305 273
3 273 305 306
3 273 306 274
3 274 306 307
3 274 307 275
3 275 307 308
3 275 308 276
3 276 308 309
3 276 309 277
3 277 309 310
3 277 310 278
3 278 310 311
3 278 311 279
3 279 311 312
3 279 312 280
3 280 312 313
3 280 313 281
3 281 313 314
3 281 314 282
3 282 314 315
3 282 315 283
3 283 315 316
3 283 316 284
3 284 316 317
3 284 317 285
3 285 317 318
3 285 318 286
3 286 318 319
3 286 319 287
3 287 319 320
3 287 320 288
3 288 320 289
3 288 289 257
3 289 321 322
3 289 322 290
3 290 322 323
3 290 323 291
3 291 323 324
3 291 324 292
3 292 324 325
3 292 325 293
3 293 325 326
3 293 326 294
3 294 326 327
3 294 327 295
3 295 327 328
3 295 328 296
3 296 328 329
3 296 329 297
3 297 329 330
3 297 330 298
3 298 330 331
3 298 331 299
3 299 331 332
3 299 332 300
3 300 332 333
3 300 333 301
3 301 333 334
3 301 334 302
3 302 334 335
3 302 335 303
3 303 335 336
3 303 336 304
3 304 336 337
3 304 337 305
3 305 337 338
3 305 338 306
3 306 338 339
3 306 339 307
3 307 339 340
3 307 340 308
3 308 340 341
3 308 341 309
3 309 341 342
3 309 342 310
3 310 342 343
3 310 343 311
3 311 343 344
3 311 344 312
3 312 344 345
3 312 345 313
3 313 345 346
3 313 346 314
3 314 346 347
3 314 347 315
3 315 347 348
3 315 348 316
3 316 348 349
3 316 349 317
3 317 349 350
3 317 350 318
3 318 350 351
3 318 351 319
3 319 351 352
3 319 352 320
3 320 352 321
3 320 321 289
3 321 353 354
3 321 354 322
3 322 354 355
3 322 355 323
3 323 355 356
3 323 356 324
3 324 356 357
3 324 357 325
3 325 357 358
3 325 358 326
3 326 358 359
3 326 359 327
3 327 359 360
3 327 360 328
3 328 360 361
3 328 361 329
3 329 361 362
3 329 362 330
3 330 362 363
3 330 363 331
3 331 363 364
3 331 364 332
3 332 364 365
3 332 365 333
3 333 365 366
3 333 366 334
3 334 366 367
3 334 367 335
3 335 367 368
3 335 368 336
3 336 368 369
3 336 369 337
3 337 369 370
3 337 370 338
3 338 370 371
3 338 371 339
3 339 371 372
3 339 372 340
3 340 372 373
3 340 373 341
3 341 373 374
3 341 374 342
3 342 374 375
3 342 375 343
3 343 375 376
3 343 376 344
3 344 376 377
3 344 377 345
3 345 377 378
3 345 378 346
3 346 378 379
3 346 379 347
3 347 379 380
3 347 380 348
3 348 380 381
3 348 381 349
3 349 381 382
3 349 382 350
3 350 382 383
3 350 383 351
3 351 383 384
3 351 384 352
3 352 384 353
3 352 353 321
3 353 385 386
3 353 386 354
3 354 386 387
3 354 387 355
3 355 387 388
3 355 388 356
3 356 388 389
3 356 389 357
3 357 389 390
3 357 390 358
3 358 390 391
3 358 391 359
3 359 391 392
3 359 392 360
3 360 392 393
3 360 393 361
3 361 393 394
3 361 394 362
3 362 394 395
3 362 395 363
3 363 395 396
3 363 396 364
3 364 396 397
3 364 397 365
3 365 397 398
3 365 398 366
3 366 398 399
3 366 399 367
3 367 399 400
3 367 400 368
3 368 400 401
3 368 401 369
3 369 401 402
3 369 402 370
3 370 402 403
3 370 403 371
3 371 403 404
3 371 404 372
3 372 404 405
3 372 405 373
3 373 405 406
3 373 406 374
3 374 406 407
3 374 407 375
3 375 407 408
3 375 408 376
3 376 408 409
3 376 409 377
3 377 409 410
3 377 410 378
3 378 410 411
3 378 411 379
3 379 411 412
3 379 412 380
3 380 412 413
3 380 413 381
3 381 413 414
3 381 414 382
3 382 414 415
3 382 415 383
3 383 415 416
3 383 416 384
3 384 416 385
3 384 385 353
3 385 417 418
3 385 418 386
3 386 418 419
3 386 419 387
3 387 419 420
3 387 420 388
3 388 420 421
3 388 421 389
3 389 421 422
3 389 422 390
3 390 422 423
3 390 423 391
3 391 423 424
3 391 424 392
3 392 424 425
3 392 425 393
3 393 425 426
3 393 426 394
3 394 426 427
3 394 427 395
3 395 427 428
3 395 428 396
3 396 428 429
3 396 429 397
3 397 429 430
3 397 430 398
3 398 430 431
3 398 431 399
3 399 431 432
3 399 432 400
3 400 432 433
3 400 433 401
3 401 433 434
3 401 434 402
3 402 434 435
3 402 435 403
3 403 435 436
3 403 436 404
3 404 436 437
3 404 437 405
3 405 437 438
3 405 438 406
3 406 438 439
3 406 439 407
3 407 439 440
3 407 440 408
3 408 440 441
3 408 441 409
3 409 441 442
3 409 442 410
3 410 442 443
3 410 443 411
3 411 443 444
3 411 444 412
3 412 444 445
3 412 445 413
3 413 445 446
3 413 446 414
3 414 446 447
3 414 447 415
3 415 447 448
3 415 448 416
3 416 448 417
3 416 417 385
3 417 449 450
3 417 450 418
3 418 450 451
3 418 451 419
3 419 451 452
3 419 452 420
3 420 452 453
3 420 453 421
3 421 453 454
3 421 454 422
3 422 454 455
3 422 455 423
3 423 455 456
3 423 456 424
3 424 456 457
3 424 457 425
3 425 457 458
3 425 458 426
3 426 458 459
3 426 459 427
3 427 459 460
3 427 460 428
3 428 460 461
3 428 461 429
3 429 461 462
3 429 462 430
3 430 462 463
3 430 463 431
3 431 463 464
3 431 464 432
3 432 464 465
3 432 465 433
3 433 465 466
3 433 466 434
3 434 466 467
3 434 467 435
3 435 467 468
3 435 468 436
3 436 468 469
3 436 469 437
3 437 469 470
3 437 470 438
3 438 470 471
3 438 471 439
3 439 471 472
3 439 472 440
3 440 472 473
3 440 473 441
3 441 473 474
3 441 474 442
3 442 474 475
3 442 475 443
3 443 475 476
3 443 476 444
3 444 476 477
3 444 477 445
3 445 477 478
3 445 478 446
3 446 478 479
3 446 479 447
3 447 479 480
3 447 480 448
3 448 480 449
3 448 449 417
3 481 450 449
3 481 451 450
3 481 452 451
3 481 453 452
3 481 454 453
3 481 455 454
3 481 456 455
3 481 457 456
3 481 458 457
3 481 459 458
3 481 460 459
3 481 461 460
3 481 462 461
3 481 463 462
3 481 464 463
3 481 465 464
3 481 466 465
3 481 467 466
3 481 468 467
3 481 469 468
3 481 470 469
3 481 471 470
3 481 472 471
3 481 473 472
3 481 474 473
3 481 475 474
3 481 476 475
3 481 477 476
3 481 478 477
3 481 479 478
3 481 480 479
3 481 449 480
OFF
# cube.off
# A cube
20 36 0
-1 -1 -1
1 -1 -1
-1 1 -1
1 1 -1
-1 -1 1
1 -1 1
-1 1 1
1 1 1
-3 -1 -1
3 -1 -1
-3 1 -1
3 1 -1
-3 -1 1
3 -1 1
-3 1 1
3 1 1
-1 -3 -1
1 -3 -1
-1 -3 1
1 -3 1
3 0 2 1
3 2 3 1
3 9 11 13
3 11 15 13
3 2 6 3
3 6 7 3
3 5 7 4
3 7 6 4
3 12 14 8
3 14 10 8
3 18 16 17
3 18 17 19
3 8 10 0
3 10 2 0
3 3 9 1
3 3 11 9
3 12 6 14
3 12 4 6
3 7 5 15
3 15 5 13
3 14 2 10
3 2 14 6
3 8 0 12
3 4 12 0
3 3 7 11
3 7 15 11
3 5 1 9
3 5 9 13
3 0 1 17
3 0 17 16
3 19 5 18
3 5 4 18
3 0 16 4
3 4 16 18
3 1 5 19
3 17 1 19
\ No newline at end of file
#ifndef AABB_H
#define AABB_H
#include <Eigen/Core>
#include "RigidObject.h"
class AABB {
public:
AABB()
: m_minCoord(
Eigen::Vector3d::Constant(std::numeric_limits<double>::min())),
m_maxCoord(
Eigen::Vector3d::Constant(std::numeric_limits<double>::max())) {}
AABB(const Eigen::Vector3d& minCoord, const Eigen::Vector3d& maxCoord)
: m_minCoord(minCoord), m_maxCoord(maxCoord) {}
const Eigen::Vector3d& getMinCoord() const { return m_minCoord; };
const Eigen::Vector3d& getMaxCoord() const { return m_maxCoord; };
void setMinCoord(const Eigen::Vector3d& minCoord) { m_minCoord = minCoord; }
void setMaxCoord(const Eigen::Vector3d& maxCoord) { m_maxCoord = maxCoord; }
bool testCollision(const AABB& other) const {
if (m_maxCoord.x() < other.m_minCoord.x() ||
other.m_maxCoord.x() < m_minCoord.x())
return false;
if (m_maxCoord.y() < other.m_minCoord.y() ||
other.m_maxCoord.y() < m_minCoord.y())
return false;
if (m_maxCoord.z() < other.m_minCoord.z() ||
other.m_maxCoord.z() < m_minCoord.z())
return false;
return true;
}
void computeAABB(const RigidObject & obj) {
Eigen::MatrixXd V;
Eigen::MatrixXi F;
obj.getMesh(V, F);
Eigen::Vector3d minCoord = V.colwise().minCoeff();
setMinCoord(minCoord);
Eigen::Vector3d maxCoord = V.colwise().maxCoeff();
setMaxCoord(maxCoord);
}
void clear() {
m_minCoord =
Eigen::Vector3d::Constant(std::numeric_limits<double>::min());
m_maxCoord =
Eigen::Vector3d::Constant(std::numeric_limits<double>::max());
}
private:
Eigen::Vector3d m_minCoord;
Eigen::Vector3d m_maxCoord;
};
#endif // AABB_H
\ No newline at end of file
//=============================================================================
// Physically-based Simulation in Computer Graphics
// ETH Zurich
//
// Author: Christian Schumacher
//=============================================================================
#pragma once
#include <vector>
#include <assert.h>
// Simple 2D array
template <typename SCALAR>
class Array2T
{
public:
// Default constructor
Array2T()
{
m_size[0] = 0;
m_size[1] = 0;
}
// Constructor with given size
Array2T(int size0, int size1, SCALAR value = (SCALAR)0)
{
resize(size0, size1, value);
}
// Copy constructor
Array2T(const Array2T<SCALAR> &m)
{
*this = m;
}
// Resize array
void resize(int size0, int size1, SCALAR value = (SCALAR)0)
{
m_size[0] = size0;
m_size[1] = size1;
m_data.resize(size0 * size1, value);
}
// Fill array with scalar s
void fill(SCALAR s)
{
std::fill(m_data.begin(), m_data.end(), s);
}
// Fill array with 0
void zero()
{
fill(0);
}
// Read & write element access
SCALAR& operator()(unsigned int i, unsigned int j)
{
assert(i >= 0 && i < m_size[0] && j >= 0 && j < m_size[1]);
return m_data[i * m_size[1] + j];
}
// Read only element access
const SCALAR& operator()(unsigned int i, unsigned int j) const
{
assert(i >= 0 && i < m_size[0] && j >= 0 && j < m_size[1]);
return m_data[i * m_size[1] + j];
}
// Dimension
int size(int dimension) const
{
assert(dimension >= 0 && dimension < 2);
return (int)m_size[dimension];
}
// Assignment
Array2T<SCALAR> &operator=(const Array2T<SCALAR> &m2)
{
if (&m2 != this)
{
resize(m2.size(0), m2.size(1));
int n = (int)m_data.size();
for (int i = 0; i < n; i++)
m_data[i] = m2.m_data[i];
}
return *this;
}
protected:
unsigned int m_size[2];
std::vector<SCALAR> m_data;
};
typedef Array2T<double> Array2d;
#ifndef ARROW_H
#define ARROW_H
#include <Eigen/Core>
#include <vector>
class Arrow {
public:
Arrow(const Eigen::RowVector3d& s, const Eigen::RowVector3d& e) {
Arrow(s, e, Eigen::RowVector3d(1.0, 0, 0));
}
Arrow(const Eigen::RowVector3d& s, const Eigen::RowVector3d& e,
const Eigen::RowVector3d& c)
: start(s), end(e), color(c) {
direction = (end - start).normalized();
Eigen::RowVector3d per1 =
direction.cross(Eigen::Vector3d(1, 0, 0)).normalized() * 0.5;
if (std::isnan(per1.sum())) {
per1 = direction.cross(Eigen::Vector3d(0, 1, 0)).normalized() * 0.5;
}
Eigen::RowVector3d per2 =
direction.cross(per1.normalized()).normalized() * 0.5;
head.resize(4);
head[0] = end - 0.1 * (direction + per1);
head[1] = end - 0.1 * (direction - per1);
head[2] = end - 0.1 * (direction + per2);
head[3] = end - 0.1 * (direction - per2);
}
Eigen::RowVector3d start;
Eigen::RowVector3d end;
Eigen::RowVector3d direction;
std::vector<Eigen::RowVector3d> head;
Eigen::RowVector3d color;
size_t id;
};
#endif // ARROW_H
\ No newline at end of file
#include "BaseObject.h"
#include <igl/per_face_normals.h>
#include <igl/per_vertex_normals.h>
#include <igl/readOBJ.h>
#include <igl/readOFF.h>
bool BaseObject::loadMesh(const std::string& path) {
bool succ = false;
std::ifstream infile(path);
if (!infile.good()) {
return false;
}
const std::string OFF(".off");
if (path.compare(path.size() - OFF.size(), OFF.size(), OFF) == 0) {
succ = igl::readOFF(path, m_mesh.V, m_mesh.F, m_mesh.V_normals);
if (succ) {
std::cout << "Reading OFF-file from " << path << " ..."
<< std::endl;
}
}
const std::string OBJ(".obj");
if (path.compare(path.size() - OBJ.size(), OBJ.size(), OBJ) == 0) {
succ = igl::readOBJ(path, m_mesh.V, m_mesh.F);
if (succ) {
std::cout << "Reading OBJ-file from " << path << " ..."
<< std::endl;
igl::per_vertex_normals(m_mesh.V, m_mesh.F, m_mesh.V_normals);
}
}
m_mesh.C = Eigen::MatrixXd(1, 3);
m_mesh.C << 255.0 / 255.0, 228.0 / 255.0, 58.0 / 255.0;
return succ;
}
void BaseObject::setMesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F) {
m_mesh.V = V;
m_mesh.F = F;
}
void BaseObject::findAndLoadMesh(const std::string& file) {
if (loadMesh(file)) return;
if (loadMesh("data/" + file)) return;
if (loadMesh("../data/" + file)) return;
if (loadMesh("../../data/" + file)) return;
if (loadMesh("../../../data/" + file)) return;
std::cerr << "Failed to find " << file << std::endl;
}
void BaseObject::reset() {
setPosition(Eigen::Vector3d::Zero());
setRotation(Eigen::Matrix3d::Identity());
resetMembers();
}
void BaseObject::recomputeCOM() {
Eigen::Vector3d COM = m_mesh.V.colwise().mean();
m_mesh.V = m_mesh.V.rowwise() - COM.transpose();
}
void BaseObject::setScale(double s) { m_scale = s; }
void BaseObject::setID(int id) { m_id = id; }
void BaseObject::setType(ObjType t) { m_type = t; }
void BaseObject::setPosition(const Eigen::Vector3d& p) { m_position = p; }
void BaseObject::setRotation(const Eigen::Quaterniond& q) {
m_quat = q;
m_rot = q.toRotationMatrix();
}
void BaseObject::setRotation(const Eigen::Matrix3d& R) {
m_rot = R;
m_quat = R;
}
void BaseObject::setColors(const Eigen::MatrixXd& C) { m_mesh.C = C; }
double BaseObject::getScale() const { return m_scale; }
int BaseObject::getID() const { return m_id; }
ObjType BaseObject::getType() const { return m_type; }
Eigen::Vector3d BaseObject::getPosition() const { return m_position; }
Eigen::Quaterniond BaseObject::getRotation() const { return m_quat; }
Eigen::Matrix3d BaseObject::getRotationMatrix() const { return m_rot; }
Eigen::Vector3d BaseObject::getVertexPosition(int vertexIndex) const {
return m_mesh.V.row(vertexIndex) * m_scale *
getRotationMatrix().transpose() +
getPosition().transpose();
}
void BaseObject::getMesh(Eigen::MatrixXd& V, Eigen::MatrixXi& F) const {
// get mesh after rotation and translation
V = (m_mesh.V * m_scale * getRotationMatrix().transpose()).rowwise() +
getPosition().transpose();
F = m_mesh.F;
}
void BaseObject::getColors(Eigen::MatrixXd& C) const { C = m_mesh.C; }
\ No newline at end of file
#ifndef BASEOBJECT_H
#define BASEOBJECT_H
#include <igl/per_face_normals.h>
#include <igl/per_vertex_normals.h>
#include <igl/readOBJ.h>
#include <igl/readOFF.h>
#include <Eigen/Core>
struct Mesh {
Eigen::MatrixXd V;
Eigen::MatrixXi F;
Eigen::MatrixXd C;
// Per face attributes
Eigen::MatrixXd F_normals; // One normal per face
// Per vertex attributes
Eigen::MatrixXd V_normals; // One normal per vertex
// UV parametrization
Eigen::MatrixXd V_uv; // UV vertices
Eigen::MatrixXi F_uv; // optional faces for UVs
};
enum class ObjType { STATIC, DYNAMIC };
class BaseObject {
public:
bool loadMesh(const std::string& path);
void setMesh(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F);
void findAndLoadMesh(const std::string& file);
void reset();
void recomputeCOM();
void setScale(double s);
void setID(int id);
virtual void setType(ObjType t);
void setPosition(const Eigen::Vector3d& p);
void setRotation(const Eigen::Quaterniond& q);
void setRotation(const Eigen::Matrix3d& R);
void setColors(const Eigen::MatrixXd& C);
double getScale() const;
int getID() const;
ObjType getType() const;
Eigen::Vector3d getPosition() const;
Eigen::Quaterniond getRotation() const;
Eigen::Matrix3d getRotationMatrix() const;
Eigen::Vector3d getVertexPosition(int vertexIndex) const;
void getMesh(Eigen::MatrixXd& V, Eigen::MatrixXi& F) const;
void getColors(Eigen::MatrixXd& C) const;
virtual ~BaseObject() {}
protected:
/*
* Reset class variables specific to a certain object. Is called by
* BaseObject::reset().
*/
virtual void resetMembers() = 0;
int m_id = -1;
Mesh m_mesh;
ObjType m_type;
double m_scale = 1.0; // Scale
Eigen::Vector3d m_position; // Position of the center of mass
Eigen::Quaterniond m_quat; // Rotation (quaternion)
Eigen::Matrix3d m_rot; // Rotation (matrix)
};
#endif
\ No newline at end of file
#ifndef GRID2_H
#define GRID2_H
#include <igl/colormap.h>
#include <Eigen/Core>
#include "Array2T.h"
class Grid2 {
public:
Grid2(int res_x, int res_y, double dx) {
m_res_x = res_x;
m_res_y = res_y;
m_dx = dx;
m_x = Array2d(res_x, res_y);
buildMesh();
}
Array2d& x() { return m_x; }
void buildMesh() {
int num_vertices = (m_res_x + 1) * (m_res_y + 1);
int num_faces = m_res_x * m_res_y * 2; // 2 triangles per cell
m_V = Eigen::MatrixXd(num_vertices, 3);
m_F = Eigen::MatrixXi(num_faces, 3);
int i = 0;
for (int y = 0; y <= m_res_y; ++y) {
for (int x = 0; x <= m_res_x; ++x) {
m_V.row(i++) = Eigen::RowVector3d(x, y, 0) * m_dx;
}
}
i = 0;
for (int y = 0; y < m_res_y; ++y) {
for (int x = 0; x < m_res_x; ++x) {
int vid = y * (m_res_x + 1) + x;
int vid_right = vid + 1;
int vid_right_up = vid_right + (m_res_x + 1);
int vid_up = vid + (m_res_x + 1);
m_F.row(i++) = Eigen::RowVector3i(vid, vid_right, vid_right_up);
m_F.row(i++) = Eigen::RowVector3i(vid, vid_right_up, vid_up);
}
}
}
void reset() {
m_x.zero();
}
void applySource(double xmin, double xmax, double ymin, double ymax) {
for (int y = (int)(ymin * m_res_y); y < (int)(ymax * m_res_y); y++) {
for (int x = (int)(xmin * m_res_x); x < (int)(xmax * m_res_x); x++) {
m_x(x, y) = 1.0;
}
}
}
void getMesh(Eigen::MatrixXd& V, Eigen::MatrixXi& F) const {
V = m_V;
F = m_F;
}
void getColors(Eigen::MatrixXd& C, bool normalize=false, bool faceColor=true) const {
if (faceColor) {
if (C.rows() == 0) {
int num_faces = m_res_x * m_res_y * 2; // 2 triangles per cell
C = Eigen::MatrixXd(num_faces, 3);
}
int i = 0;
double cmin = m_x(0, 0);
double cmax = cmin;
for (int y = 0; y < m_res_y; ++y) {
for (int x = 0; x < m_res_x; ++x) {
double c = m_x(x, y);
if (normalize) {
if (c > cmax) cmax = c;
if (c < cmin) cmin = c;
}
else {
C.row(i++).setConstant(c);
C.row(i++).setConstant(c);
}
}
}
if (!normalize) return;
else if (cmin == cmax) {
C.setZero();
return;
}
// std::cout << "cmin:" << cmin << " cmax:" << cmax << std::endl;
for (int y = 0; y < m_res_y; ++y) {
for (int x = 0; x < m_res_x; ++x) {
double c = m_x(x, y);
c = (c - cmin) / (cmax - cmin); // [0,1]
double r, g, b;
igl::colormap(igl::COLOR_MAP_TYPE_VIRIDIS, c, r, g, b);
C.row(i++) = Eigen::RowVector3d(r, g, b);
C.row(i++) = Eigen::RowVector3d(r, g, b);
}
}
}
else {
// vertex color
if (C.rows() == 0) {
int num_vertices = (m_res_x + 1) * (m_res_y + 1);
C = Eigen::MatrixXd(num_vertices, 3);
}
int i = 0;
double cmin = m_x(0, 0);
double cmax = cmin;
for (int y = 0; y <= m_res_y; ++y) {
for (int x = 0; x <= m_res_x; ++x) {
int x0 = std::max(x - 1, 0);
int x1 = std::min(x, m_res_x - 1);
int y0 = std::max(y - 1, 0);
int y1 = std::min(y, m_res_y - 1);
double c00 = m_x(x0, y0);
double c01 = m_x(x0, y1);
double c10 = m_x(x1, y0);
double c11 = m_x(x1, y1);
double c = (c00 + c01 + c10 + c11) / 4;
if (normalize) {
if (c > cmax) cmax = c;
if (c < cmin) cmin = c;
}
C.row(i++).setConstant(c);
}
}
if (!normalize) return;
else if (cmin == cmax) {
C.setZero();
return;
}
i = 0;
// std::cout << "cmin:" << cmin << " cmax:" << cmax << std::endl;
for (int y = 0; y <= m_res_y; ++y) {
for (int x = 0; x <= m_res_x; ++x) {
double c = (C(i, 0) - cmin) / (cmax - cmin); // [0,1]
double r, g, b;
igl::colormap(igl::COLOR_MAP_TYPE_VIRIDIS, c, r, g, b);
C.row(i++) = Eigen::RowVector3d(r, g, b);
}
}
}
}
protected:
int m_res_x, m_res_y;
double m_dx;
Array2d m_x;
Eigen::MatrixXd m_V;
Eigen::MatrixXi m_F;
};
#endif // GRID2_H
\ No newline at end of file
#include "Gui.h"
#include <igl/Hit.h>
#include <igl/project.h>
#include <igl/writeOFF.h>
#include <iomanip>
#include <sstream>
void Gui::setSimulation(Simulation *sim) {
p_simulator = new Simulator(sim);
p_simulator->reset();
p_simulator->setSimulationSpeed(m_simSpeed);
}
void Gui::start() {
// message: http://patorjk.com/software/taag/#p=display&v=0&f=Roman&t=DALAB
std::string usage(
R"(
oooooooooo. .o. ooooo .o. oooooooooo.
`888' `Y8b .888. `888' .888. `888' `Y8b
888 888 .8"888. 888 .8"888. 888 888
888 888 .8' `888. 888 .8' `888. 888oooo888'
888 888 .88ooo8888. 888 .88ooo8888. 888 `88b
888 d88' .8' `888. 888 o .8' `888. 888 .88P
o888bood8P' o88o o8888o o888ooooood8 o88o o8888o o888bood8P'
Computer Animation
Course Exercise Framework
Shortcuts:
[drag] Rotate scene | [space] Start/pause simulation
I,i Toggle invert normals | A,a Single step
L,l Toggle wireframe | R,r Reset simulation
T,t Toggle filled faces | C,c Clear screen
; Toggle vertex labels | : Toggle face labels
- Toggle fast forward | Z Snap to canonical view
. Turn up lighting | , Turn down lighting
O,o Toggle orthographic/perspective projection)");
std::cout << usage << std::endl;
// setting up viewer
m_viewer.data().show_lines = false;
m_viewer.data().point_size = 2.0f;
m_viewer.core().is_animating = true;
m_viewer.core().camera_zoom = 0.1;
m_viewer.core().object_scale = 1.0;
// setting up menu
igl::opengl::glfw::imgui::ImGuiMenu menu;
m_viewer.plugins.push_back(&menu);
menu.callback_draw_viewer_window = [&]() { drawMenuWindow(menu); };
showAxes(m_showAxes);
p_simulator->setNumRecords(m_numRecords);
p_simulator->setMaxSteps(m_maxSteps);
// callbacks
m_viewer.callback_key_pressed = [&](igl::opengl::glfw::Viewer &viewer,
unsigned int key, int modifiers) {
return keyCallback(viewer, key, modifiers);
};
m_viewer.callback_pre_draw = [&](igl::opengl::glfw::Viewer &viewer) {
return drawCallback(viewer);
};
m_viewer.callback_mouse_scroll = [&](igl::opengl::glfw::Viewer &viewer,
float delta_y) {
return scrollCallback(viewer, delta_y);
};
m_viewer.callback_mouse_down = [&](igl::opengl::glfw::Viewer &viewer,
int button, int modifier) {
return mouseCallback(viewer, menu, button, modifier);
};
// start viewer
m_viewer.launch();
}
void Gui::resetSimulation() {
p_simulator->reset();
m_timerAverage = 0.0;
}
#pragma region ArrowInterface
int Gui::addArrow(const Eigen::Vector3d &start, const Eigen::Vector3d &end,
const Eigen::Vector3d &color) {
m_arrows.push_back(Arrow(start, end, color));
m_arrows.back().id = m_numArrows++;
return m_arrows.back().id;
}
void Gui::removeArrow(size_t index) {
bool found = false;
for (size_t i = 0; i < m_arrows.size(); i++) {
if (m_arrows[i].id == index) {
found = true;
m_arrows.erase(m_arrows.begin() + i);
}
}
assert(found && "unable to find index");
}
void Gui::drawArrow(const Arrow &arrow) {
m_viewer.data_list[0].add_edges(arrow.start, arrow.end, arrow.color);
m_viewer.data_list[0].add_edges(arrow.end, arrow.head[0], arrow.color);
m_viewer.data_list[0].add_edges(arrow.end, arrow.head[1], arrow.color);
m_viewer.data_list[0].add_edges(arrow.end, arrow.head[2], arrow.color);
m_viewer.data_list[0].add_edges(arrow.end, arrow.head[3], arrow.color);
m_viewer.data_list[0].add_edges(arrow.head[0], arrow.head[2], arrow.color);
m_viewer.data_list[0].add_edges(arrow.head[1], arrow.head[2], arrow.color);
m_viewer.data_list[0].add_edges(arrow.head[1], arrow.head[3], arrow.color);
m_viewer.data_list[0].add_edges(arrow.head[3], arrow.head[0], arrow.color);
m_viewer.data_list[0].add_edges(arrow.head[3], arrow.head[2], arrow.color);
m_viewer.data_list[0].add_edges(arrow.head[1], arrow.head[0], arrow.color);
}
#pragma endregion ArrowInterface
void Gui::drawReferencePlane() {
m_viewer.data_list[0].add_edges(m_referencePlane.start, m_referencePlane.end, m_referencePlane.color);
}
void Gui::showVertexArrow() {
if (m_clickedArrow >= 0) {
removeArrow(m_clickedArrow);
m_clickedArrow = -1;
}
if (m_clickedVertex >= 0) {
Eigen::Vector3d pos;
Eigen::Vector3d norm;
if (callback_clicked_vertex) {
callback_clicked_vertex(m_clickedVertex, m_clickedObject, pos,
norm);
}
else {
pos = m_viewer.data_list[m_clickedObject].V.row(m_clickedVertex);
norm = m_viewer.data_list[m_clickedObject].V_normals.row(
m_clickedVertex);
}
m_clickedArrow =
addArrow(pos, pos + norm, Eigen::RowVector3d(1.0, 0, 0));
}
}
bool Gui::drawCallback(igl::opengl::glfw::Viewer &viewer) {
if (m_request_clear) {
for (auto &d : viewer.data_list) {
d.clear();
}
m_request_clear = false;
m_clickedVertex = -1;
if (m_clickedArrow >= 0) {
removeArrow(m_clickedArrow);
m_clickedArrow = -1;
}
}
viewer.data_list[0].clear();
if (m_arrows.size() > 0 || m_showReferencePlane) {
for (size_t i = 0; i < m_arrows.size(); i++) {
drawArrow(m_arrows[i]);
}
if (m_showReferencePlane) drawReferencePlane();
}
p_simulator->render(viewer);
return false;
}
bool Gui::scrollCallback(igl::opengl::glfw::Viewer &viewer, float delta_y) {
double factor = 1.5;
if (delta_y > 0)
viewer.core().camera_zoom *= factor;
else
viewer.core().camera_zoom /= factor;
return true;
}
void Gui::toggleSimulation() {
if (p_simulator->isPaused()) {
if (!p_simulator->hasStarted()) {
updateSimulationParameters();
}
p_simulator->run();
}
else {
p_simulator->pause();
}
}
void Gui::singleStep() {
if (!p_simulator->hasStarted()) {
updateSimulationParameters();
}
p_simulator->run(true);
}
void Gui::clearScreen() {
m_request_clear = true;
clearSimulation();
}
bool Gui::keyCallback(igl::opengl::glfw::Viewer &viewer, unsigned int key,
int modifiers) {
switch (key) {
case 'I':
case 'i':
for (auto &d : viewer.data_list) {
d.dirty |= igl::opengl::MeshGL::DIRTY_NORMAL;
d.invert_normals = !d.invert_normals;
}
return true;
case 'L':
case 'l':
for (auto &d : viewer.data_list) {
d.show_lines = !d.show_lines;
}
return true;
case 'T':
case 't':
for (auto &d : viewer.data_list) {
d.show_faces = !d.show_faces;
}
return true;
case ';':
for (auto &d : viewer.data_list) {
d.show_vertid = !d.show_vertid;
}
return true;
case ':':
for (auto &d : viewer.data_list) {
d.show_faceid = !d.show_faceid;
}
return true;
case ' ':
toggleSimulation();
return true;
case 'r':
case 'R':
resetSimulation();
return true;
case 'a':
case 'A':
singleStep();
case 'c':
case 'C':
clearScreen();
return true;
case '-':
if (!m_fastForward) {
p_simulator->setSimulationSpeed(240);
}
else {
p_simulator->setSimulationSpeed(m_simSpeed);
}
m_fastForward = !m_fastForward;
return true;
case '.':
viewer.core().lighting_factor += 0.1;
break;
case ',':
viewer.core().lighting_factor -= 0.1;
break;
default:
return childKeyCallback(viewer, key, modifiers);
}
viewer.core().lighting_factor =
std::min(std::max(viewer.core().lighting_factor, 0.f), 1.f);
return false;
}
bool Gui::mouseCallback(igl::opengl::glfw::Viewer &viewer,
igl::opengl::glfw::imgui::ImGuiMenu &menu, int button,
int modifier) {
// get vertices, project them onto screen and find closest vertex to mouse
float minDist = std::numeric_limits<float>::infinity();
int vertex = -1;
int object = -1;
for (size_t i = 0; i < viewer.data_list.size(); i++) {
Eigen::MatrixXf Vf = viewer.data_list[i].V.cast<float>();
Eigen::MatrixXf projections;
igl::project(Vf, viewer.core().view, viewer.core().proj,
viewer.core().viewport, projections);
Eigen::VectorXf x = projections.col(0).array() - viewer.current_mouse_x;
Eigen::VectorXf y = -projections.col(1).array() +
viewer.core().viewport(3) - viewer.current_mouse_y;
Eigen::VectorXf distances =
(x.array().square() + y.array().square()).matrix().cwiseSqrt();
int vi = -1;
float dist = distances.minCoeff(&vi);
if (dist < minDist) {
minDist = dist;
vertex = vi;
object = i;
}
}
if (minDist < 20) {
// only select vertex if user clicked "close"
m_clickedVertex = vertex;
m_clickedObject = object;
showVertexArrow();
}
return false;
}
void Gui::drawMenuWindow(igl::opengl::glfw::imgui::ImGuiMenu &menu) {
glfwSetWindowTitle(m_viewer.window, "CA Exercises");
float menu_width = 220.f * menu.menu_scaling();
// Controls
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
// ImGui::SetNextWindowSizeConstraints(ImVec2(menu_width, -1.0f),
// ImVec2(menu_width, -1.0f));
bool _viewer_menu_visible = true;
ImGui::Begin(
"Viewer", &_viewer_menu_visible,
// ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
ImGuiWindowFlags_NoSavedSettings);
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
drawMenu(m_viewer, menu);
ImGui::PopItemWidth();
ImGui::End();
// Clicking
if (m_clickedVertex >= 0) {
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiSetCond_FirstUseEver);
ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize,
ImGuiSetCond_FirstUseEver);
bool visible = true;
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
ImGui::Begin(
"ViewerLabels", &visible,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoInputs);
Eigen::Vector3d pos =
m_viewer.data_list[m_clickedObject].V.row(m_clickedVertex);
Eigen::Vector3d norm =
m_viewer.data_list[m_clickedObject].V_normals.row(m_clickedVertex);
std::string text = "(" + std::to_string(pos(0)) + ", " +
std::to_string(pos(1)) + ", " +
std::to_string(pos(2)) + ")";
ImDrawList *drawList = ImGui::GetWindowDrawList();
Eigen::Vector3f c0 = igl::project(
Eigen::Vector3f((pos + 0.1 * norm).cast<float>()),
m_viewer.core().view, m_viewer.core().proj, m_viewer.core().viewport);
drawList->AddText(ImGui::GetFont(), ImGui::GetFontSize() * 1.2,
ImVec2(c0(0), m_viewer.core().viewport[3] - c0(1)),
ImGui::GetColorU32(ImVec4(0, 0, 10, 255)), &text[0],
&text[0] + text.size());
ImGui::End();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
showVertexArrow();
}
// Stats
if (m_showStats) {
int width, height;
glfwGetWindowSize(m_viewer.window, &width, &height);
ImGui::SetNextWindowPos(ImVec2(width - menu_width, 0.0f),
ImGuiSetCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
// ImGui::SetNextWindowSizeConstraints(ImVec2(menu_width, -1.0f),
// ImVec2(menu_width, -1.0f));
ImGui::Begin("Stats", &_viewer_menu_visible,
// ImGuiWindowFlags_NoSavedSettings |
// ImGuiWindowFlags_AlwaysAutoResize);
ImGuiWindowFlags_NoSavedSettings);
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
if (!p_simulator->isPaused()) {
if (m_timerAverage > 0.0) {
double alpha = 0.95;
m_timerAverage = m_timerAverage * alpha +
(1.0 - alpha) * p_simulator->getDuration();
}
else {
m_timerAverage = p_simulator->getDuration();
}
}
ImGui::Text("Iteration: %ld", p_simulator->getSimulationStep());
ImGui::Text("Average time per iteration: %.2fms", m_timerAverage);
ImGui::Text("Current time: %.5f", p_simulator->getSimulationTime());
drawSimulationStats();
ImGui::PopItemWidth();
ImGui::End();
}
}
inline std::string getFilename(int total_numObj, int obj, int total_steps,
int step) {
std::stringstream ss;
ss << "_object" << std::setw(std::log10(total_numObj)) << std::setfill('0')
<< obj << "_" << std::setw(std::log10(total_steps)) << step << ".obj";
return ss.str();
}
void Gui::exportRecording() {
std::string path = igl::file_dialog_save();
size_t finddot = path.find_last_of(".");
path = path.substr(0, finddot);
std::cout << "Exporting Recording to " << path << "_objectxxx_xxx.obj"
<< std::endl;
auto rec = p_simulator->getRecords();
int steps = rec[0].size();
for (size_t i = 0; i < rec.size(); i++) {
int j = 0;
while (rec[i].size() > 0) {
std::string filename =
path + getFilename(rec.size(), i, steps, j++);
auto p = rec[i].front();
rec[i].pop();
bool succ = igl::writeOBJ(filename, p.first, p.second);
if (!succ) {
std::cerr << "Failed to write recording" << std::endl;
}
}
}
}
bool Gui::drawMenu(igl::opengl::glfw::Viewer &viewer,
igl::opengl::glfw::imgui::ImGuiMenu &menu) {
if (ImGui::CollapsingHeader("Simulation Control",
ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::Button(
p_simulator->isPaused() ? "Run Simulation" : "Pause Simulation",
ImVec2(-1, 0))) {
toggleSimulation();
}
if (ImGui::Button("Single Step", ImVec2(-1, 0))) {
singleStep();
}
if (ImGui::Button("Reset Simulation", ImVec2(-1, 0))) {
resetSimulation();
}
if (ImGui::Button("Clear Screen", ImVec2(-1, 0))) {
clearScreen();
}
if (ImGui::SliderInt("Steps/Second", &m_simSpeed, 1, 240)) {
p_simulator->setSimulationSpeed(m_simSpeed);
}
if (ImGui::InputInt("Max Steps", &m_maxSteps, -1, -1)) {
p_simulator->setMaxSteps(m_maxSteps);
}
}
if (ImGui::CollapsingHeader("Overlays", ImGuiTreeNodeFlags_DefaultOpen)) {
if (ImGui::CheckboxFlags("Wireframe", &(viewer.data().show_lines), 1)) {
for (size_t i = 0; i < viewer.data_list.size(); i++) {
viewer.data_list[i].show_lines = viewer.data().show_lines;
}
}
if (ImGui::CheckboxFlags("Fill", &(viewer.data().show_faces), 1)) {
for (size_t i = 0; i < viewer.data_list.size(); i++) {
viewer.data_list[i].show_faces = viewer.data().show_faces;
}
}
if (ImGui::Checkbox("Show vertex labels",
&(viewer.data().show_vertid))) {
for (size_t i = 0; i < viewer.data_list.size(); i++) {
viewer.data_list[i].show_vertid = viewer.data().show_vertid;
}
}
if (ImGui::Checkbox("Show faces labels",
&(viewer.data().show_faceid))) {
for (size_t i = 0; i < viewer.data_list.size(); i++) {
viewer.data_list[i].show_faceid = viewer.data().show_faceid;
}
}
ImGui::Checkbox("Show stats", &m_showStats);
if (ImGui::Checkbox("Show axes", &m_showAxes)) {
showAxes(m_showAxes);
}
if (ImGui::Checkbox("Show reference plane", &m_showReferencePlane)) {
;
}
}
if (ImGui::CollapsingHeader("Simulation Parameters",
ImGuiTreeNodeFlags_DefaultOpen)) {
drawSimulationParameterMenu();
}
if (ImGui::CollapsingHeader("Recording")) {
bool hasRecords = p_simulator->getRecords().size() > 0 &&
p_simulator->getRecords()[0].size() > 0;
if (!hasRecords) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
}
if (ImGui::Button("Export Recording", ImVec2(-1, 0))) {
if (hasRecords) {
exportRecording();
}
}
if (!hasRecords) {
ImGui::PopStyleColor();
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
if (ImGui::InputInt("Steps in Recording to keep", &m_numRecords, 0,
0)) {
p_simulator->setNumRecords(m_numRecords);
}
bool isRecording = p_simulator->isRecording();
ImGui::PushStyleColor(ImGuiCol_Button,
isRecording ? ImVec4(0.98f, 0.26f, 0.26f, 0.40f)
: ImVec4(0.26f, 0.98f, 0.40f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
isRecording ? ImVec4(0.98f, 0.26f, 0.26f, 1.0f)
: ImVec4(0.26f, 0.98f, 0.40f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
isRecording ? ImVec4(0.98f, 0.26f, 0.00f, 0.9f)
: ImVec4(0.00f, 0.98f, 0.40f, 0.9f));
if (ImGui::Button(isRecording ? "Stop Recording" : "Start Recording",
ImVec2(-1, 0))) {
p_simulator->setRecording(!isRecording);
}
ImGui::PopStyleColor();
ImGui::PopStyleColor();
ImGui::PopStyleColor();
}
return false;
}
void Gui::showAxes(bool show_axes) {
if (show_axes && m_axesID < 0) {
Eigen::RowVector3d origin = Eigen::Vector3d::Zero();
m_axesID = addArrow(origin, Eigen::Vector3d(1, 0, 0),
Eigen::Vector3d(1, 0, 0));
addArrow(origin, Eigen::Vector3d(0, 1, 0), Eigen::Vector3d(0, 1, 0));
addArrow(origin, Eigen::Vector3d(0, 0, 1), Eigen::Vector3d(0, 0, 1));
}
if (!show_axes && m_axesID >= 0) {
removeArrow(m_axesID);
removeArrow(m_axesID + 1);
removeArrow(m_axesID + 2);
m_axesID = -1;
}
}
\ No newline at end of file
#ifndef GUI_H
#define GUI_H
#include <igl/opengl/glfw/Viewer.h>
#include <igl/opengl/glfw/imgui/ImGuiMenu.h>
#include "Arrow.h"
#include "ReferencePlane.h"
#include "Simulator.h"
/*
* Base class to open a window with a simple GUI for simulation. Inherit from
* this class to perform a simulation and customize the menu.
*/
class Gui {
public:
Gui() {}
~Gui() {}
/*
* Set simulation to be performed in the simulator.
*/
void setSimulation(Simulation *sim);
/*
* Initialize all the necessary data structures and callbacks and open the
* window.
*/
void start();
/*
* Call the setters for your simulation in this method to update the
* parameters entered in the GUI. This method is called before the
* simulation is started for the first time.
*/
virtual void updateSimulationParameters() = 0;
/*
* Clear some custom datastructures/visualizations when the user requests
* it.
*/
virtual void clearSimulation() {}
/*
* Callback to enable custom shortcuts.
*/
virtual bool childKeyCallback(igl::opengl::glfw::Viewer &viewer,
unsigned int key, int modifiers) {
return false;
}
/*
* Setup your own (additional) ImGUI components in this method.
*/
virtual void drawSimulationParameterMenu() {}
/*
* Setup your own (additional) ImGUI debugging output.
*/
virtual void drawSimulationStats() {}
#pragma region ArrowInterface
/*
* Create and add an arrow to be displayed in the GUI. Returns the index of
* the drawn arrow (keep it if you want to delete this arrow later).
*/
int addArrow(const Eigen::Vector3d &start, const Eigen::Vector3d &end,
const Eigen::Vector3d &color=Eigen::RowVector3d(1, 0, 0));
/*
* Delete arrow at given index.
*/
void removeArrow(size_t index);
#pragma endregion ArrowInterface
/*
* Show the standard basis axis (x, y, z)
*/
void showAxes(bool show_axes);
/*
* Callback to show a different vector for a clicked vertex than the normal
*/
std::function<void(int clickedVertexIndex, int clickedObjectIndex,
Eigen::Vector3d &pos, Eigen::Vector3d &dir)>
callback_clicked_vertex = nullptr;
void turnOffLight() { m_viewer.core().lighting_factor = 0; }
protected:
void drawArrow(const Arrow &arrow);
void drawReferencePlane();
void showVertexArrow();
void toggleSimulation();
void singleStep();
void resetSimulation();
void exportRecording();
void clearScreen();
bool keyCallback(igl::opengl::glfw::Viewer &viewer, unsigned int key,
int modifiers);
bool keyReleasedCallback(igl::opengl::glfw::Viewer &viewer,
unsigned int key, int modifiers);
void drawMenuWindow(igl::opengl::glfw::imgui::ImGuiMenu &menu);
bool drawMenu(igl::opengl::glfw::Viewer &viewer,
igl::opengl::glfw::imgui::ImGuiMenu &menu);
bool drawCallback(igl::opengl::glfw::Viewer &viewer);
bool scrollCallback(igl::opengl::glfw::Viewer &viewer, float delta_y);
bool mouseCallback(igl::opengl::glfw::Viewer &viewer,
igl::opengl::glfw::imgui::ImGuiMenu &menu, int button,
int modifier);
igl::opengl::glfw::Viewer m_viewer;
Simulator *p_simulator = NULL;
bool m_request_clear = false;
int m_simSpeed = 60;
bool m_fastForward = false;
int m_clickedVertex = -1; // index of clicked vertex
int m_clickedObject = -1; // id of clicked object
int m_clickedArrow = -1; // index of arrow of clicked vertex
std::vector<Arrow> m_arrows; // data structure to store all the arrows
// to be rendered
unsigned long m_numArrows = 0; // increasing counter for arrows
int m_axesID = -1; // (lowest) id of the 3 base axes
bool m_showAxes = true;
ReferencePlane m_referencePlane;
bool m_showReferencePlane = true;
bool m_showStats = true;
double m_timerAverage = 0; // running average of execution time of
// one iteration of the simulation
int m_maxSteps = -1;
int m_numRecords = 100; // number of records to keep
};
#endif
\ No newline at end of file
#ifndef MACGRID2_H
#define MACGRID2_H
#include <igl/colormap.h>
#include <Eigen/Core>
#include "Array2T.h"
class MACGrid2 {
public:
MACGrid2(int res_x, int res_y, double dx) {
m_res_x = res_x;
m_res_y = res_y;
m_dx = dx;
m_x = Array2d(res_x + 1, res_y);
m_y = Array2d(res_x, res_y + 1);
buildGrid();
}
Array2d& x() { return m_x; }
Array2d& y() { return m_y; }
const Eigen::MatrixXd& s() { return m_start; }
const Eigen::MatrixXd& e() { return m_end; }
const Eigen::MatrixXd& vs() { return m_vs; }
const Eigen::MatrixXd& ve() { return m_ve; }
const Eigen::MatrixXd& vc() { return m_vc; }
void buildGrid() {
int num_edges = 2 * m_res_x * m_res_y + m_res_x + m_res_y;
m_start = Eigen::MatrixXd(num_edges, 3);
m_end = Eigen::MatrixXd(num_edges, 3);
int i = 0;
for (int y = 0; y <= m_res_y; ++y)
for (int x = 0; x <= m_res_x; ++x) {
if (x < m_res_x) {
m_start.row(i) = Eigen::RowVector3d(x, y, 0) * m_dx;
m_end.row(i++) = Eigen::RowVector3d(x + 1, y, 0) * m_dx;
}
if (y < m_res_y) {
m_start.row(i) = Eigen::RowVector3d(x, y, 0) * m_dx;
m_end.row(i++) = Eigen::RowVector3d(x, y + 1, 0) * m_dx;
}
}
}
void updateEdges(double scale = 1) {
int num_edges = (m_res_x + 1) * m_res_y + m_res_x * (m_res_y + 1) + m_res_x * m_res_y;
if (m_vs.rows() == 0) {
m_vs = Eigen::MatrixXd(num_edges, 3);
m_ve = Eigen::MatrixXd(num_edges, 3);
m_vc = Eigen::MatrixXd(num_edges, 3);
}
int i = 0;
for (int y = 0; y <= m_res_y; ++y)
for (int x = 0; x <= m_res_x; ++x) {
if (y < m_res_y) {
m_vc.row(i) = Eigen::RowVector3d(1, 0, 0);
m_vs.row(i) = Eigen::RowVector3d(x, y + 0.5, 0) * m_dx;
m_ve.row(i++) = Eigen::RowVector3d(x + m_x(x, y) * scale, y + 0.5, 0) * m_dx;
}
if (x < m_res_x) {
m_vc.row(i) = Eigen::RowVector3d(0, 0, 1);
m_vs.row(i) = Eigen::RowVector3d(x + 0.5, y, 0) * m_dx;
m_ve.row(i++) = Eigen::RowVector3d(x + 0.5, y + m_y(x, y) * scale, 0) * m_dx;
}
if (y < m_res_y && x < m_res_x) {
double vx = (m_x(x, y) + m_x(x + 1, y)) * 0.5;
double vy = (m_y(x, y) + m_y(x, y + 1)) * 0.5;
m_vc.row(i) = Eigen::RowVector3d(0, 1, 0);
m_vs.row(i) = Eigen::RowVector3d(x + 0.5, y + 0.5, 0) * m_dx;
m_ve.row(i++) = Eigen::RowVector3d(x + 0.5 + vx * scale, y + 0.5 + vy * scale, 0) * m_dx;
}
}
}
void reset() {
m_x.zero();
m_y.zero();
}
protected:
int m_res_x, m_res_y;
double m_dx;
Array2d m_x;
Array2d m_y;
Eigen::MatrixXd m_start;
Eigen::MatrixXd m_end;
Eigen::MatrixXd m_vs;
Eigen::MatrixXd m_ve;
Eigen::MatrixXd m_vc;
};
#endif // MACGRID2_H
\ No newline at end of file
#include <Eigen/Core>
#include <vector>
class ReferencePlane {
public:
ReferencePlane() : size(10), color(Eigen::RowVector3d(0.25, 0.25, 0.25)) {
//// for set_edges
//int num_edges = 2 * (2 * size)*(2 * size) + (2 * size) * 2;
//int num_points = (2 * size + 1)*(2 * size + 1);
//points = Eigen::MatrixXd(num_points, 3);
//edges = Eigen::MatrixXi(num_edges, 2);
//int i = 0;
//for (int z = -size; z <= size; ++z) {
// for (int x = -size; x <= size; ++x) {
// points.row(i++) = Eigen::RowVector3d(x, -5, z);
// }
//}
//i = 0;
//for (int z = 0; z <= 2*size; ++z) {
// for (int x = 0; x <= 2*size; ++x) {
// int p1 = z * (2 * size + 1) + x;
// int p2 = p1 + 1;
// int p3 = p1 + (2 * size + 1);
// if (x < 2*size)
// edges.row(i++) = Eigen::RowVector2i(p1, p2);
// if (z < 2 * size)
// edges.row(i++) = Eigen::RowVector2i(p1, p3);
// }
//}
int num_edges = 2 * (2 * size)*(2 * size) + (2 * size) * 2;
start = Eigen::MatrixXd(num_edges, 3);
end = Eigen::MatrixXd(num_edges, 3);
int e = 0;
for (int z = -size; z <= size; ++z)
for (int x = -size; x <= size; ++x) {
if (x < size) {
start.row(e) = Eigen::RowVector3d(x, 0, z);
end.row(e++) = Eigen::RowVector3d(x + 1, 0, z);
}
if (z < size) {
start.row(e) = Eigen::RowVector3d(x, 0, z);
end.row(e++) = Eigen::RowVector3d(x, 0, z + 1);
}
}
}
//Eigen::MatrixXd points;
//Eigen::MatrixXi edges;
int size;
Eigen::MatrixXd start;
Eigen::MatrixXd end;
Eigen::RowVector3d color;
};
\ No newline at end of file
#include "RigidObject.h"
RigidObject::RigidObject(const std::string& mesh_file, const ObjType t) {
findAndLoadMesh(mesh_file);
setType(t);
setMass(1.0);
// inertia of cube
setInertia(getMass() * 2.0 / 6.0 * Eigen::Matrix3d::Identity());
reset();
}
void RigidObject::resetMembers() {
setLinearMomentum(Eigen::Vector3d::Zero());
setAngularMomentum(Eigen::Vector3d::Zero());
resetForce();
resetTorque();
}
void RigidObject::applyForceToCOM(const Eigen::Vector3d& f) {
if (m_type != ObjType::DYNAMIC) return;
m_force += f;
}
void RigidObject::applyForce(const Eigen::Vector3d& f,
const Eigen::Vector3d& p) {
if (m_type != ObjType::DYNAMIC) return;
m_force += f;
m_torque += (p - m_position).cross(f);
}
void RigidObject::applyTorque(const Eigen::Vector3d& t) {
if (m_type != ObjType::DYNAMIC) return;
m_torque += t;
}
void RigidObject::printDebug(const std::string& message) const {
std::cout << std::endl;
if (message.size() > 0) {
std::cout << message << std::endl;
}
std::cout << "position: " << m_position.transpose() << std::endl;
std::cout << "rotation: " << std::endl << m_rot << std::endl;
std::cout << "linear velocity: " << m_v.transpose() << std::endl;
std::cout << "angular velocity: " << m_w.transpose() << std::endl;
std::cout << "force: " << m_force.transpose() << std::endl;
std::cout << "torque: " << m_torque.transpose() << std::endl;
std::cout << "mass (inv): " << m_mass << " (" << m_massInv << ")"
<< std::endl;
}
#pragma region GettersAndSetters
void RigidObject::setType(ObjType t) {
m_type = t;
if (m_type == ObjType::STATIC) {
m_mass = std::numeric_limits<double>::infinity();
m_massInv = 0.0;
m_inertia.setZero();
m_inertiaInv.setZero();
m_force.setZero();
m_torque.setZero();
}
}
void RigidObject::setMass(double m) {
if (m_type != ObjType::DYNAMIC) return;
m_mass = m;
m_massInv = 1.0 / m_mass;
}
void RigidObject::setInertia(const Eigen::Matrix3d& I) {
if (m_type != ObjType::DYNAMIC) return;
m_inertia = I;
m_inertiaInv = m_inertia.inverse();
}
void RigidObject::setLinearMomentum(const Eigen::Vector3d& p) {
if (m_type != ObjType::DYNAMIC) return;
m_v = m_massInv * p;
}
void RigidObject::setAngularMomentum(const Eigen::Vector3d& l) {
if (m_type != ObjType::DYNAMIC) return;
m_w = getInertiaInvWorld() * l;
}
void RigidObject::setLinearVelocity(const Eigen::Vector3d& v) {
if (m_type != ObjType::DYNAMIC) return;
m_v = v;
}
void RigidObject::setAngularVelocity(const Eigen::Vector3d& w) {
if (m_type != ObjType::DYNAMIC) return;
m_w = w;
}
void RigidObject::setForce(const Eigen::Vector3d& f) {
if (m_type != ObjType::DYNAMIC) return;
m_force = f;
}
void RigidObject::setTorque(const Eigen::Vector3d& t) {
if (m_type != ObjType::DYNAMIC) return;
m_torque = t;
}
void RigidObject::resetForce() { m_force.setZero(); };
void RigidObject::resetTorque() { m_torque.setZero(); };
double RigidObject::getMass() const { return m_mass; }
double RigidObject::getMassInv() const { return m_massInv; }
Eigen::Matrix3d RigidObject::getInertia() const { return m_inertia; }
Eigen::Matrix3d RigidObject::getInertiaInv() const { return m_inertiaInv; }
Eigen::Matrix3d RigidObject::getInertiaInvWorld() const {
return m_quat * m_inertiaInv * m_quat.inverse();
}
Eigen::Matrix3d RigidObject::getInertiaWorld() const {
return m_quat * m_inertia * m_quat.inverse();
}
Eigen::Vector3d RigidObject::getLinearMomentum() const { return m_v * m_mass; }
Eigen::Vector3d RigidObject::getAngularMomentum() const {
return getInertiaWorld() * m_w;
}
Eigen::Vector3d RigidObject::getLinearVelocity() const { return m_v; }
Eigen::Vector3d RigidObject::getVelocity(const Eigen::Vector3d& point) const {
return getLinearVelocity() +
getAngularVelocity().cross(point - getPosition());
}
Eigen::Vector3d RigidObject::getAngularVelocity() const { return m_w; }
Eigen::Vector3d RigidObject::getForce() const { return m_force; }
Eigen::Vector3d RigidObject::getTorque() const { return m_torque; }
#pragma endregion GettersAndSetters
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment