Commit c2535f0f authored by TheNumbat's avatar TheNumbat
Browse files

upstream changes

parent 8b8ee1f1
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
...
......@@ -19,3 +19,4 @@ settings.json
media/test.*
media/env_maps/
media/test/
debug.log
......@@ -29,7 +29,7 @@ Finally, to build the project:
```
mkdir build
cd build
cmake ..
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j4
```
......@@ -73,7 +73,7 @@ To build the project:
```
mkdir build
cd build
cmake ..
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j4
```
......
......@@ -4,216 +4,218 @@
#include <imgui/imgui_impl_sdl.h>
#include "app.h"
#include "scene/renderer.h"
#include "geometry/util.h"
#include "platform/platform.h"
#include "scene/renderer.h"
App::App(Settings set, Platform* plt) :
window_dim(plt ? plt->window_draw() : Vec2{1.0f}),
camera(plt ? plt->window_draw() : Vec2{1.0f}),
plt(plt),
scene(Gui::n_Widget_IDs),
gui(scene, plt ? plt->window_size() : Vec2{1.0f}),
undo(scene, gui) {
if(!set.headless) assert(plt);
std::string err;
bool loaded_scene = true;
if(!set.scene_file.empty()) {
info("Loading scene file...");
err = scene.load(true, undo, gui, set.scene_file);
gui.set_file(set.scene_file);
}
if(!err.empty()) {
warn("Error loading scene: %s", err.c_str());
loaded_scene = false;
}
if(!set.env_map_file.empty()) {
info("Loading environment map...");
err = scene.set_env_map(set.env_map_file);
if(!err.empty()) warn("Error loading environment map: %s", err.c_str());
}
if(!set.headless) {
GL::global_params();
Renderer::setup(window_dim);
apply_window_dim(plt->window_draw());
} else if(loaded_scene) {
info("Rendering scene...");
err = gui.get_render().headless_render(gui.get_animate(), scene, set.output_file,
set.animate, set.w, set.h, set.s, set.ls, set.d, set.exp, set.w_from_ar);
if(!err.empty()) warn("Error rendering scene: %s", err.c_str());
else {
auto [build,render] = gui.get_render().completion_time();
info("Built scene in %.2fs, rendered in %.2fs", build, render);
}
}
App::App(Settings set, Platform *plt)
: window_dim(plt ? plt->window_draw() : Vec2{1.0f}),
camera(plt ? plt->window_draw() : Vec2{1.0f}), plt(plt), scene(Gui::n_Widget_IDs),
gui(scene, plt ? plt->window_size() : Vec2{1.0f}), undo(scene, gui) {
if (!set.headless)
assert(plt);
std::string err;
bool loaded_scene = true;
if (!set.scene_file.empty()) {
info("Loading scene file...");
err = scene.load(true, undo, gui, set.scene_file);
gui.set_file(set.scene_file);
}
if (!err.empty()) {
warn("Error loading scene: %s", err.c_str());
loaded_scene = false;
}
if (!set.env_map_file.empty()) {
info("Loading environment map...");
err = scene.set_env_map(set.env_map_file);
if (!err.empty())
warn("Error loading environment map: %s", err.c_str());
}
if (!set.headless) {
GL::global_params();
Renderer::setup(window_dim);
apply_window_dim(plt->window_draw());
} else if (loaded_scene) {
info("Rendering scene...");
err = gui.get_render().headless_render(gui.get_animate(), scene, set.output_file,
set.animate, set.w, set.h, set.s, set.ls, set.d,
set.exp, set.w_from_ar);
if (!err.empty())
warn("Error rendering scene: %s", err.c_str());
else {
auto [build, render] = gui.get_render().completion_time();
info("Built scene in %.2fs, rendered in %.2fs", build, render);
}
}
}
App::~App() {
Renderer::shutdown();
}
App::~App() { Renderer::shutdown(); }
void App::event(SDL_Event e) {
ImGuiIO& IO = ImGui::GetIO();
IO.DisplayFramebufferScale = plt->scale(Vec2{1.0f, 1.0f});
ImGuiIO &IO = ImGui::GetIO();
IO.DisplayFramebufferScale = plt->scale(Vec2{1.0f, 1.0f});
switch(e.type) {
case SDL_KEYDOWN: {
if(IO.WantCaptureKeyboard) break;
if(gui.keydown(undo, e.key.keysym, scene, camera)) break;
switch (e.type) {
case SDL_KEYDOWN: {
if (IO.WantCaptureKeyboard)
break;
if (gui.keydown(undo, e.key.keysym, scene, camera))
break;
#ifdef __APPLE__
Uint16 mod = KMOD_GUI;
Uint16 mod = KMOD_GUI;
#else
Uint16 mod = KMOD_CTRL;
Uint16 mod = KMOD_CTRL;
#endif
if(e.key.keysym.sym == SDLK_z) {
if(e.key.keysym.mod & mod) {
undo.undo();
}
}
else if(e.key.keysym.sym == SDLK_y) {
if(e.key.keysym.mod & mod) {
undo.redo();
}
}
} break;
case SDL_WINDOWEVENT: {
if (e.window.event == SDL_WINDOWEVENT_RESIZED ||
e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
apply_window_dim(plt->window_draw());
}
} break;
case SDL_MOUSEMOTION: {
Vec2 d(e.motion.xrel, e.motion.yrel);
Vec2 p = plt->scale(Vec2{e.button.x, e.button.y});
Vec2 dim = plt->window_draw();
Vec2 n = Vec2(2.0f * p.x / dim.x - 1.0f, 2.0f * p.y / dim.y - 1.0f);
if(gui_capture) {
gui.drag_to(scene, camera.pos(), n, screen_to_world(p));
} else if(cam_mode == Camera_Control::orbit) {
camera.mouse_orbit(d);
} else if(cam_mode == Camera_Control::move) {
camera.mouse_move(d);
} else {
gui.hover(p, camera.pos(), n, screen_to_world(p));
}
} break;
case SDL_MOUSEBUTTONDOWN: {
if(IO.WantCaptureMouse) break;
Vec2 p = plt->scale(Vec2{e.button.x, e.button.y});
Vec2 dim = plt->window_draw();
Vec2 n = Vec2(2.0f * p.x / dim.x - 1.0f, 2.0f * p.y / dim.y - 1.0f);
if(e.button.button == SDL_BUTTON_LEFT) {
Scene_ID id = Renderer::get().read_id(p);
if(cam_mode == Camera_Control::none && (plt->is_down(SDL_SCANCODE_LSHIFT) | plt->is_down(SDL_SCANCODE_RSHIFT))) {
cam_mode = Camera_Control::orbit;
} else if(gui.select(scene, undo, id, camera.pos(), n, screen_to_world(p))) {
cam_mode = Camera_Control::none;
plt->grab_mouse();
gui_capture = true;
} else if(id) {
selection_changed = true;
}
mouse_press = Vec2(e.button.x, e.button.y);
} else if(e.button.button == SDL_BUTTON_RIGHT) {
if(cam_mode == Camera_Control::none) {
cam_mode = Camera_Control::move;
}
} else if(e.button.button == SDL_BUTTON_MIDDLE) {
cam_mode = Camera_Control::orbit;
}
} break;
case SDL_MOUSEBUTTONUP: {
Vec2 p = plt->scale(Vec2{e.button.x, e.button.y});
Vec2 dim = plt->window_draw();
Vec2 n = Vec2(2.0f * p.x / dim.x - 1.0f, 2.0f * p.y / dim.y - 1.0f);
if(e.button.button == SDL_BUTTON_LEFT) {
if(!IO.WantCaptureMouse && gui_capture) {
gui_capture = false;
gui.drag_to(scene, camera.pos(), n, screen_to_world(p));
gui.end_drag(undo, scene);
plt->ungrab_mouse();
break;
} else {
Vec2 diff = mouse_press - Vec2(e.button.x, e.button.y);
if(!selection_changed && diff.norm() <= 3) {
gui.clear_select();
}
selection_changed = false;
}
}
if((e.button.button == SDL_BUTTON_LEFT && cam_mode == Camera_Control::orbit) ||
(e.button.button == SDL_BUTTON_MIDDLE && cam_mode == Camera_Control::orbit) ||
(e.button.button == SDL_BUTTON_RIGHT && cam_mode == Camera_Control::move)) {
cam_mode = Camera_Control::none;
}
} break;
case SDL_MOUSEWHEEL: {
if(IO.WantCaptureMouse) break;
camera.mouse_radius((float)e.wheel.y);
} break;
}
if (e.key.keysym.sym == SDLK_z) {
if (e.key.keysym.mod & mod) {
undo.undo();
}
} else if (e.key.keysym.sym == SDLK_y) {
if (e.key.keysym.mod & mod) {
undo.redo();
}
}
} break;
case SDL_WINDOWEVENT: {
if (e.window.event == SDL_WINDOWEVENT_RESIZED ||
e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
apply_window_dim(plt->window_draw());
}
} break;
case SDL_MOUSEMOTION: {
Vec2 d(e.motion.xrel, e.motion.yrel);
Vec2 p = plt->scale(Vec2{e.button.x, e.button.y});
Vec2 dim = plt->window_draw();
Vec2 n = Vec2(2.0f * p.x / dim.x - 1.0f, 2.0f * p.y / dim.y - 1.0f);
if (gui_capture) {
gui.drag_to(scene, camera.pos(), n, screen_to_world(p));
} else if (cam_mode == Camera_Control::orbit) {
camera.mouse_orbit(d);
} else if (cam_mode == Camera_Control::move) {
camera.mouse_move(d);
} else {
gui.hover(p, camera.pos(), n, screen_to_world(p));
}
} break;
case SDL_MOUSEBUTTONDOWN: {
if (IO.WantCaptureMouse)
break;
Vec2 p = plt->scale(Vec2{e.button.x, e.button.y});
Vec2 dim = plt->window_draw();
Vec2 n = Vec2(2.0f * p.x / dim.x - 1.0f, 2.0f * p.y / dim.y - 1.0f);
if (e.button.button == SDL_BUTTON_LEFT) {
Scene_ID id = Renderer::get().read_id(p);
if (cam_mode == Camera_Control::none &&
(plt->is_down(SDL_SCANCODE_LSHIFT) | plt->is_down(SDL_SCANCODE_RSHIFT))) {
cam_mode = Camera_Control::orbit;
} else if (gui.select(scene, undo, id, camera.pos(), n, screen_to_world(p))) {
cam_mode = Camera_Control::none;
plt->grab_mouse();
gui_capture = true;
} else if (id) {
selection_changed = true;
}
mouse_press = Vec2(e.button.x, e.button.y);
} else if (e.button.button == SDL_BUTTON_RIGHT) {
if (cam_mode == Camera_Control::none) {
cam_mode = Camera_Control::move;
}
} else if (e.button.button == SDL_BUTTON_MIDDLE) {
cam_mode = Camera_Control::orbit;
}
} break;
case SDL_MOUSEBUTTONUP: {
Vec2 p = plt->scale(Vec2{e.button.x, e.button.y});
Vec2 dim = plt->window_draw();
Vec2 n = Vec2(2.0f * p.x / dim.x - 1.0f, 2.0f * p.y / dim.y - 1.0f);
if (e.button.button == SDL_BUTTON_LEFT) {
if (!IO.WantCaptureMouse && gui_capture) {
gui_capture = false;
gui.drag_to(scene, camera.pos(), n, screen_to_world(p));
gui.end_drag(undo, scene);
plt->ungrab_mouse();
break;
} else {
Vec2 diff = mouse_press - Vec2(e.button.x, e.button.y);
if (!selection_changed && diff.norm() <= 3) {
gui.clear_select();
}
selection_changed = false;
}
}
if ((e.button.button == SDL_BUTTON_LEFT && cam_mode == Camera_Control::orbit) ||
(e.button.button == SDL_BUTTON_MIDDLE && cam_mode == Camera_Control::orbit) ||
(e.button.button == SDL_BUTTON_RIGHT && cam_mode == Camera_Control::move)) {
cam_mode = Camera_Control::none;
}
} break;
case SDL_MOUSEWHEEL: {
if (IO.WantCaptureMouse)
break;
camera.mouse_radius((float)e.wheel.y);
} break;
}
}
void App::render() {
proj = camera.get_proj();
view = camera.get_view();
iviewproj = (proj * view).inverse();
proj = camera.get_proj();
view = camera.get_view();
iviewproj = (proj * view).inverse();
Renderer& r = Renderer::get();
r.begin();
r.proj(proj);
gui.render_3d(scene, camera);
r.complete();
Renderer &r = Renderer::get();
r.begin();
r.proj(proj);
gui.render_ui(scene, undo, camera);
gui.render_3d(scene, camera);
r.complete();
gui.render_ui(scene, undo, camera);
}
Vec3 App::screen_to_world(Vec2 mouse) {
Vec2 t(2.0f * mouse.x / window_dim.x - 1.0f,
1.0f - 2.0f * mouse.y / window_dim.y);
Vec3 p = iviewproj * Vec3(t.x, t.y, 0.1f);
return (p - camera.pos()).unit();
Vec2 t(2.0f * mouse.x / window_dim.x - 1.0f, 1.0f - 2.0f * mouse.y / window_dim.y);
Vec3 p = iviewproj * Vec3(t.x, t.y, 0.1f);
return (p - camera.pos()).unit();
}
void App::apply_window_dim(Vec2 new_dim) {
window_dim = new_dim;
camera.set_ar(window_dim);
gui.update_dim(plt->window_size());
Renderer::get().update_dim(window_dim);
window_dim = new_dim;
camera.set_ar(window_dim);
gui.update_dim(plt->window_size());
Renderer::get().update_dim(window_dim);
}
#pragma once
#include <SDL2/SDL.h>
#include <map>
#include <string>
#include <SDL2/SDL.h>
#include "util/camera.h"
#include "lib/mathlib.h"
#include "gui/manager.h"
#include "lib/mathlib.h"
#include "util/camera.h"
#include "scene/scene.h"
#include "scene/undo.h"
......@@ -16,49 +16,47 @@ class Platform;
class App {
public:
struct Settings {
std::string scene_file;
std::string env_map_file;
bool headless = false;
// If headless is true, use all of these
std::string output_file = "out.png";
int w = 640;
int h = 360;
int s = 128;
int ls = 16;
int d = 4;
bool animate = false;
float exp = 1.0f;
bool w_from_ar = false;
};
struct Settings {
std::string scene_file;
std::string env_map_file;
bool headless = false;
// If headless is true, use all of these
std::string output_file = "out.png";
int w = 640;
int h = 360;
int s = 128;
int ls = 16;
int d = 4;
bool animate = false;
float exp = 1.0f;
bool w_from_ar = false;
};
App(Settings set, Platform* plt = nullptr);
~App();
App(Settings set, Platform *plt = nullptr);
~App();
void render();
void event(SDL_Event e);
void render();
void event(SDL_Event e);
private:
void apply_window_dim(Vec2 new_dim);
Vec3 screen_to_world(Vec2 mouse);
// Camera data
enum class Camera_Control {
none,
orbit,
move
};
Vec2 window_dim, mouse_press;
bool selection_changed = false;
Camera_Control cam_mode = Camera_Control::none;
Camera camera;
Mat4 view, proj, iviewproj;
// Systems
Platform* plt = nullptr;
Scene scene;
Gui::Manager gui;
Undo undo;
bool gui_capture = false;
void apply_window_dim(Vec2 new_dim);
Vec3 screen_to_world(Vec2 mouse);
// Camera data
enum class Camera_Control { none, orbit, move };
Vec2 window_dim, mouse_press;
bool selection_changed = false;
Camera_Control cam_mode = Camera_Control::none;
Camera camera;
Mat4 view, proj, iviewproj;
// Systems
Platform *plt = nullptr;
Scene scene;
Gui::Manager gui;
Undo undo;
bool gui_capture = false;
};
This diff is collapsed.
This diff is collapsed.
#pragma once
#include "../lib/mathlib.h"
#include <map>
#include <set>
#include "../lib/mathlib.h"
template<typename T>
class Spline {
template <typename T> class Spline {
public:
// Returns the interpolated value.
T at(float time) const;
// Purely for convenience, returns the exact same
// value as at()---simply lets one evaluate a spline
// value as at()---simply lets one evaluate a spline
// f as though it were a function f(t) (which it is!)
T operator()(float time) const { return at(time); }
......@@ -42,7 +40,8 @@ public:
// Returns set of keys
std::set<float> keys() const {
std::set<float> ret;
for(auto& e : control_points) ret.insert(e.first);
for (auto &e : control_points)
ret.insert(e.first);
return ret;
}
......@@ -52,18 +51,19 @@ private:
// Given a time between 0 and 1, evaluates a cubic polynomial with
// the given endpoint and tangent values at the beginning (0) and
// end (1) of the interval
static T cubic_unit_spline(float time,
const T& position0, const T& position1,
const T& tangent0, const T& tangent1);
static T cubic_unit_spline(float time, const T &position0, const T &position1,
const T &tangent0, const T &tangent1);
};
template<>
class Spline<Quat> {
template <> class Spline<Quat> {
public:
Quat at(float time) const {
if(values.empty()) return Quat::euler(Vec3(0.0f));
if(values.size() == 1) return values.begin()->second;
if(values.begin()->first > time)
if (values.empty())
return Quat::euler(Vec3(0.0f));
if (values.size() == 1)
return values.begin()->second;
if (values.begin()->first > time)
return values.begin()->second;
auto k2 = values.upper_bound(time);
if (k2 == values.end())
......@@ -94,27 +94,22 @@ public:
}
float norm_t = (time - t1) / dt;
Quat qa = tangent(p0,p1,p2);
Quat pb = tangent(p1,p2,p3);
Quat qa = tangent(p0, p1, p2);
Quat pb = tangent(p1, p2, p3);
float slerpT = 2.0f * norm_t * (1.0f - norm_t);
Quat slerp1 = p1.slerp(p2, norm_t);
Quat slerp2 = qa.slerp(pb, norm_t);
return slerp1.slerp(slerp2, slerpT);
}
Quat operator()(float time) const {
return at(time);
}
void set(float time, Quat value) {
values[time] = value;
}
void erase(float time) {
values.erase(time);
Quat slerp1 = p1.slerp(p2, norm_t);
Quat slerp2 = qa.slerp(pb, norm_t);
return slerp1.slerp(slerp2, slerpT);
}
Quat operator()(float time) const { return at(time); }
void set(float time, Quat value) { values[time] = value; }
void erase(float time) { values.erase(time); }
std::set<float> keys() const {
std::set<float> ret;
for(auto& e : values) ret.insert(e.first);
for (auto &e : values)
ret.insert(e.first);
return ret;
}
bool has(float t) const { return values.count(t); }
......@@ -127,22 +122,21 @@ public:
private:
std::map<float, Quat> values;
static Quat tangent(const Quat& q0, const Quat& q1, const Quat& q2) {
static Quat tangent(const Quat &q0, const Quat &q1, const Quat &q2) {
Quat q1inv = q1.inverse();
Quat c1 = q1inv * q2;
Quat c2 = q1inv * q0;
c1.make_log();
c2.make_log();
Quat c3 = c2 + c1;
c3.scale(-0.25f);
c3.make_exp();
Quat r = q1 * c3;
return r.unit();
Quat c1 = q1inv * q2;
Quat c2 = q1inv * q0;
c1.make_log();
c2.make_log();
Quat c3 = c2 + c1;
c3.scale(-0.25f);
c3.make_exp();
Quat r = q1 * c3;
return r.unit();
}
};
template<typename T, typename... Ts>
class Splines {
template <typename T, typename... Ts> class Splines {
public:
void set(float t, T arg, Ts... args) {
head.set(t, arg);
......@@ -152,12 +146,8 @@ public:
head.erase(t);
tail.erase(t);
}
bool any() const {
return head.any() || tail.any();
}
bool has(float t) const {
return head.has(t) || tail.has(t);
}
bool any() const { return head.any() || tail.any(); }
bool has(float t) const { return head.has(t) || tail.has(t); }
void clear() {
head.clear();
tail.clear();
......@@ -167,7 +157,7 @@ public:
tail.crop(t);
}
std::set<float> keys() const {
auto first = head.keys();
auto first = head.keys();
auto rest = tail.keys();
rest.insert(first.begin(), first.end());
return rest;
......@@ -176,38 +166,21 @@ public:
return std::tuple_cat(std::make_tuple(head.at(t)), tail.at(t));
}
private:
private:
Spline<T> head;
Splines<Ts...> tail;
};
template<typename T>
class Splines<T> {
template <typename T> class Splines<T> {
public:
void set(float t, T arg) {
head.set(t, arg);
}
void erase(float t) {
head.erase(t);
}
bool any() const {
return head.any();
}
bool has(float t) const {
return head.has(t);
}
void crop(float t) {
head.crop(t);
}
void clear() {
head.clear();
}
std::set<float> keys() const {
return head.keys();
}
std::tuple<T> at(float t) const {
return std::make_tuple(head.at(t));
}
void set(float t, T arg) { head.set(t, arg); }
void erase(float t) { head.erase(t); }
bool any() const { return head.any(); }
bool has(float t) const { return head.has(t); }
void crop(float t) { head.crop(t); }
void clear() { head.clear(); }
std::set<float> keys() const { return head.keys(); }
std::tuple<T> at(float t) const { return std::make_tuple(head.at(t)); }
private:
Spline<T> head;
......
This diff is collapsed.
......@@ -7,42 +7,42 @@
namespace Util {
GL::Mesh cube_mesh(float radius);
GL::Mesh square_mesh(float radius);
GL::Mesh quad_mesh(float x, float y);
GL::Mesh cyl_mesh(float radius, float height, int sides = 12, bool cap = true);
GL::Mesh torus_mesh(float iradius, float oradius, int segments = 48, int sides = 24);
GL::Mesh sphere_mesh(float r, int subdivsions);
GL::Mesh hemi_mesh(float r);
GL::Mesh cone_mesh(float bradius, float tradius, float height, int sides = 12, bool cap = true);
GL::Mesh capsule_mesh(float h, float r);
GL::Mesh arrow_mesh(float base, float tip, float height);
GL::Mesh scale_mesh();
GL::Lines spotlight_mesh(Vec3 color, float inner, float outer);
namespace Gen {
struct Data {
std::vector<GL::Mesh::Vert> verts;
std::vector<GL::Mesh::Index> elems;
};
struct LData {
std::vector<GL::Lines::Vert> verts;
};
GL::Mesh merge(Data&& l, Data&& r);
LData merge(LData&& l, LData&& r);
LData circle(Vec3 color, float r, int sides);
Data cube(float r);
Data quad(float x, float y);
// https://wiki.unity3d.com/index.php/ProceduralPrimitives
Data ico_sphere(float radius, int level);
Data uv_hemisphere(float radius);
Data cone(float bradius, float tradius, float height, int sides, bool caps);
Data torus(float iradius, float oradius, int segments, int sides);
}
}
GL::Mesh cube_mesh(float radius);
GL::Mesh square_mesh(float radius);
GL::Mesh quad_mesh(float x, float y);
GL::Mesh cyl_mesh(float radius, float height, int sides = 12, bool cap = true);
GL::Mesh torus_mesh(float iradius, float oradius, int segments = 48, int sides = 24);
GL::Mesh sphere_mesh(float r, int subdivsions);
GL::Mesh hemi_mesh(float r);
GL::Mesh cone_mesh(float bradius, float tradius, float height, int sides = 12, bool cap = true);
GL::Mesh capsule_mesh(float h, float r);
GL::Mesh arrow_mesh(float base, float tip, float height);
GL::Mesh scale_mesh();
GL::Lines spotlight_mesh(Vec3 color, float inner, float outer);
namespace Gen {
struct Data {
std::vector<GL::Mesh::Vert> verts;
std::vector<GL::Mesh::Index> elems;
};
struct LData {
std::vector<GL::Lines::Vert> verts;
};
GL::Mesh merge(Data &&l, Data &&r);
LData merge(LData &&l, LData &&r);
LData circle(Vec3 color, float r, int sides);
// https://wiki.unity3d.com/index.php/ProceduralPrimitives
Data cube(float r);
Data quad(float x, float y);
Data ico_sphere(float radius, int level);
Data uv_hemisphere(float radius);
Data cone(float bradius, float tradius, float height, int sides, bool caps);
Data torus(float iradius, float oradius, int segments, int sides);
} // namespace Gen
} // namespace Util
This diff is collapsed.
#pragma once
#include <set>
#include <SDL2/SDL.h>
#include "widgets.h"
#include <SDL2/SDL.h>
#include <set>
namespace Gui {
......@@ -15,7 +15,7 @@ public:
Anim_Camera(Vec2 dim) : dim(dim) {}
Camera at(float t) const;
void set(float t, const Camera& cam);
void set(float t, const Camera &cam);
Splines<Vec3, Quat, float, float> splines;
......@@ -25,31 +25,32 @@ private:
class Animate {
public:
Animate(Vec2 screen_dim) :
ui_camera(screen_dim), anim_camera(screen_dim), ui_render(screen_dim) {}
Animate(Vec2 screen_dim)
: ui_camera(screen_dim), anim_camera(screen_dim), ui_render(screen_dim) {}
void update_dim(Vec2 dim);
bool keydown(Widgets& widgets, Undo& undo, Scene_ID sel, SDL_Keysym key);
bool keydown(Widgets &widgets, Undo &undo, Scene_ID sel, SDL_Keysym key);
Vec3 selected_pos(Scene_Item& item);
void end_transform(Undo& undo, Scene_Item& obj);
void apply_transform(Widgets& widgets, Scene_Item& obj);
bool select(Scene& scene, Widgets& widgets, Scene_ID selected, Scene_ID id, Vec3 cam, Vec2 spos, Vec3 dir);
Vec3 selected_pos(Scene_Item &item);
void end_transform(Undo &undo, Scene_Item &obj);
void apply_transform(Widgets &widgets, Scene_Item &obj);
bool select(Scene &scene, Widgets &widgets, Scene_ID selected, Scene_ID id, Vec3 cam, Vec2 spos,
Vec3 dir);
void render(Scene &scene, Scene_Maybe obj_opt, Widgets &widgets, Camera &cam);
void timeline(Manager &manager, Undo &undo, Scene &scene, Scene_Maybe obj, Camera &user_cam);
void UIsidebar(Manager &manager, Undo &undo, Scene_Maybe obj_opt, Camera &user_cam);
void render(Scene& scene, Scene_Maybe obj_opt, Widgets& widgets, Camera& cam);
void timeline(Manager& manager, Undo& undo, Scene& scene, Scene_Maybe obj, Camera& user_cam);
void UIsidebar(Manager& manager, Undo& undo, Scene_Maybe obj_opt, Camera& user_cam);
void clear();
void update(Scene& scene);
void refresh(Scene& scene);
void update(Scene &scene);
void refresh(Scene &scene);
std::string pump_output(Scene& scene);
Camera set_time(Scene& scene, float time);
std::string pump_output(Scene &scene);
Camera set_time(Scene &scene, float time);
float fps() const;
int n_frames() const;
const Anim_Camera& camera() const;
Anim_Camera& camera();
const Anim_Camera &camera() const;
Anim_Camera &camera();
void set(int n_frames, int fps);
private:
......@@ -64,9 +65,9 @@ private:
Widget_Render ui_render;
Anim_Camera anim_camera;
Joint* joint_select = nullptr;
Joint *joint_select = nullptr;
unsigned int joint_id_offset = 0;
Pose old_pose;
Mat4 old_p_to_j;
Vec3 old_euler;
......@@ -75,7 +76,8 @@ private:
bool camera_selected = false;
Scene_ID prev_selected = 0;
std::unordered_map<Scene_ID, GL::Lines> spline_cache;
void make_spline(Scene_ID id, const Anim_Pose& pose);
void make_spline(Scene_ID id, const Anim_Pose &pose);
void camera_spline();
};
}
} // namespace Gui
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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