mirror of
https://github.com/CedricGuillemet/ImGuizmo.git
synced 2026-01-18 21:21:19 +01:00
Added docs
This commit is contained in:
158
README.md
158
README.md
@@ -1,8 +1,13 @@
|
||||
# ImGuizmo
|
||||
|
||||
Latest stable tagged version is 1.83. Current master version is 1.84 WIP.
|
||||
|
||||
What started with the gizmo is now a collection of dear imgui widgets and more advanced controls.
|
||||
|
||||
## Guizmos
|
||||
|
||||
### ImViewGizmo
|
||||
|
||||
Manipulate view orientation with 1 single line of code
|
||||
|
||||

|
||||
@@ -21,14 +26,15 @@ There is now a sample for Win32/OpenGL ! With a binary in bin directory.
|
||||

|
||||
|
||||
### ImSequencer
|
||||
|
||||
A WIP little sequencer used to edit frame start/end for different events in a timeline.
|
||||

|
||||
Check the sample for the documentation. More to come...
|
||||
|
||||
|
||||
### Graph Editor
|
||||
|
||||
Nodes + connections. Custom draw inside nodes is possible with the delegate system in place.
|
||||

|
||||

|
||||
|
||||
### API doc
|
||||
|
||||
@@ -71,7 +77,7 @@ example:
|
||||
```
|
||||
|
||||
These functions have some numerical stability issues for now. Use with caution.
|
||||
|
||||
|
||||
```C++
|
||||
void DecomposeMatrixToComponents(const float *matrix, float *translation, float *rotation, float *scale);
|
||||
void RecomposeMatrixFromComponents(const float *translation, const float *rotation, const float *scale, float *matrix);**
|
||||
@@ -84,22 +90,22 @@ void DrawCube(const float *view, const float *projection, float *matrix);**
|
||||
```
|
||||
|
||||
Call it when you want a gizmo
|
||||
Needs view and projection matrices.
|
||||
Needs view and projection matrices.
|
||||
Matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional. snap points to a float[3] for translation and to a single float for scale or rotation. Snap angle is in Euler Degrees.
|
||||
|
||||
```C++
|
||||
enum OPERATION
|
||||
{
|
||||
TRANSLATE,
|
||||
ROTATE,
|
||||
SCALE
|
||||
};
|
||||
enum OPERATION
|
||||
{
|
||||
TRANSLATE,
|
||||
ROTATE,
|
||||
SCALE
|
||||
};
|
||||
|
||||
enum MODE
|
||||
{
|
||||
LOCAL,
|
||||
WORLD
|
||||
};
|
||||
enum MODE
|
||||
{
|
||||
LOCAL,
|
||||
WORLD
|
||||
};
|
||||
|
||||
void Manipulate(const float *view, const float *projection, OPERATION operation, MODE mode, float *matrix, float *deltaMatrix = 0, float *snap = 0);**
|
||||
```
|
||||
@@ -113,64 +119,74 @@ Code for :
|
||||
```C++
|
||||
void EditTransform(const Camera& camera, matrix_t& matrix)
|
||||
{
|
||||
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||
if (ImGui::IsKeyPressed(90))
|
||||
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
if (ImGui::IsKeyPressed(69))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
if (ImGui::IsKeyPressed(82)) // r Key
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
||||
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
||||
if (ImGui::IsKeyPressed(90))
|
||||
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
if (ImGui::IsKeyPressed(69))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
if (ImGui::IsKeyPressed(82)) // r Key
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
|
||||
mCurrentGizmoOperation = ImGuizmo::ROTATE;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
|
||||
mCurrentGizmoOperation = ImGuizmo::SCALE;
|
||||
float matrixTranslation[3], matrixRotation[3], matrixScale[3];
|
||||
ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
|
||||
ImGui::InputFloat3("Tr", matrixTranslation, 3);
|
||||
ImGui::InputFloat3("Rt", matrixRotation, 3);
|
||||
ImGui::InputFloat3("Sc", matrixScale, 3);
|
||||
ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
|
||||
|
||||
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||
{
|
||||
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||
}
|
||||
static bool useSnap(false);
|
||||
if (ImGui::IsKeyPressed(83))
|
||||
useSnap = !useSnap;
|
||||
ImGui::Checkbox("", &useSnap);
|
||||
ImGui::SameLine();
|
||||
vec_t snap;
|
||||
switch (mCurrentGizmoOperation)
|
||||
{
|
||||
case ImGuizmo::TRANSLATE:
|
||||
snap = config.mSnapTranslation;
|
||||
ImGui::InputFloat3("Snap", &snap.x);
|
||||
break;
|
||||
case ImGuizmo::ROTATE:
|
||||
snap = config.mSnapRotation;
|
||||
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||
break;
|
||||
case ImGuizmo::SCALE:
|
||||
snap = config.mSnapScale;
|
||||
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||
break;
|
||||
}
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||
if (mCurrentGizmoOperation != ImGuizmo::SCALE)
|
||||
{
|
||||
if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
|
||||
mCurrentGizmoMode = ImGuizmo::LOCAL;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
|
||||
mCurrentGizmoMode = ImGuizmo::WORLD;
|
||||
}
|
||||
static bool useSnap(false);
|
||||
if (ImGui::IsKeyPressed(83))
|
||||
useSnap = !useSnap;
|
||||
ImGui::Checkbox("", &useSnap);
|
||||
ImGui::SameLine();
|
||||
vec_t snap;
|
||||
switch (mCurrentGizmoOperation)
|
||||
{
|
||||
case ImGuizmo::TRANSLATE:
|
||||
snap = config.mSnapTranslation;
|
||||
ImGui::InputFloat3("Snap", &snap.x);
|
||||
break;
|
||||
case ImGuizmo::ROTATE:
|
||||
snap = config.mSnapRotation;
|
||||
ImGui::InputFloat("Angle Snap", &snap.x);
|
||||
break;
|
||||
case ImGuizmo::SCALE:
|
||||
snap = config.mSnapScale;
|
||||
ImGui::InputFloat("Scale Snap", &snap.x);
|
||||
break;
|
||||
}
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
|
||||
ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
|
||||
}
|
||||
```
|
||||
|
||||
### License
|
||||
## Install
|
||||
|
||||
ImGuizmo is licensed under the MIT License, see LICENSE for more information.
|
||||
ImGuizmo can be installed via [vcpkg](https://github.com/microsoft/vcpkg) and used cmake
|
||||
|
||||
```bash
|
||||
vcpkg install vcpkg
|
||||
```
|
||||
|
||||
See the [vcpkg example](/vcpkg-example) for more details
|
||||
|
||||
## License
|
||||
|
||||
ImGuizmo is licensed under the MIT License, see [LICENSE](/LICENSE) for more information.
|
||||
|
||||
52
vcpkg-example/README.md
Normal file
52
vcpkg-example/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# ImGuizmo example
|
||||
|
||||
ImGuizmo example app that uses [cmake][cmake] and [vcpkg][vcpkg]
|
||||
|
||||
## Setup
|
||||
|
||||
Assuming cmake and vcpkg are installed, all that is required is to add the vcpkg toolchain file to
|
||||
the cmake configure and all dependencies will be downloaded and installed into the project
|
||||
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystem/vcpkg.cmake
|
||||
```
|
||||
|
||||
### Visual Studio
|
||||
|
||||
Rather than running directly, IDEs usually configure the cmake. Visual studio can be integrated
|
||||
directly with the `vcpkg integrate install` command or by specifying the path to the toolchain file
|
||||
in the project cmake settings
|
||||
|
||||
### VSCode
|
||||
|
||||
When using the cmake tools extension the command can be added to the `.vscode/settings.json` file as
|
||||
follows
|
||||
|
||||
```json
|
||||
{
|
||||
"cmake.configureArgs": [
|
||||
"-DCMAKE_TOOLCHAIN_FILE=C:\\dev\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
> :heavy_check_mark: If you include the settings file in your repo, a good practice would be to use
|
||||
an environment variable for the path to the vcpkg install and variable substitution in the toolchain
|
||||
file path so the settings work across machines. eg `"-DCMAKE_TOOLCHAIN_FILE={$env:VCPKG_ROOT}\\scripts\\buildsystems\\vcpkg.cmake"`
|
||||
|
||||
This can also be added to the system-wide settings rather than added to each project individually
|
||||
|
||||
## How It Works
|
||||
|
||||
The example contains a `vcpkg.json` manifest file that contains the dependencices. When cmake is
|
||||
supplied with the vcpkg toolchain file, the script detects this manifest file and then downloads and
|
||||
compiles the dependencies there-in
|
||||
|
||||
In `CMakeLists.txt` the `find_package(imguizmo CONFIG REQUIRED)` command finds the cmake config
|
||||
added by the vcpkg install and `target_link_libraries(example-app PRIVATE imguizmo::imguizmo)` adds
|
||||
the includes and lib to the target
|
||||
|
||||
[cmake]: https://cmake.org/
|
||||
[vcpkg]: https://github.com/microsoft/vcpkg
|
||||
Reference in New Issue
Block a user