GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — math/src/view/com/clip_plane.cpp at master · cppd/math Expand file tree/ Copy pathclip_plane.cppMore file actions 123 lines (104 loc) · 3.06 KB / Copy pathclip_plane.cppFile metadata and controls123 lines (104 loc) · 3.06 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 /* Copyright (C) 2017-2026 Topological Manifold This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "clip_plane.h" #include "camera.h" #include <src/com/error.h> #include <src/com/print.h> #include <src/numerical/vector.h> #include <src/view/event.h> #include <cmath> #include <functional> #include <optional> #include <utility> #include <variant> namespace ns::view::com { namespace { numerical::Vector4d clip_plane_equation(const Camera::Plane& camera_plane, const double position) { ASSERT(camera_plane.normal.is_unit()); ASSERT(camera_plane.near > camera_plane.far); ASSERT(position >= 0 && position <= 1); // camera plane: n * x = d // clip plane: -n * x = -d // -n * x + d = 0 return { -camera_plane.normal[0], -camera_plane.normal[1], -camera_plane.normal[2], std::lerp(camera_plane.far, camera_plane.near, position), }; } } ClipPlane::ClipPlane( const Camera* const camera, std::function<void(const std::optional<numerical::Vector4d>&)> set_clip_plane) : camera_(camera), set_clip_plane_(std::move(set_clip_plane)) { } void ClipPlane::exec(const ClipPlaneCommand& command) { std::visit( [this](const auto& v) { cmd(v); }, command); } void ClipPlane::set_position(const double position) { if (!camera_plane_) { error("Clip plane is not set"); } if (!(position >= 0 && position <= 1)) { error("Error clip plane position " + to_string(position)); } position_ = position; set_clip_plane_(clip_plane_equation(*camera_plane_, position_)); } void ClipPlane::cmd(const command::ClipPlaneHide&) { camera_plane_.reset(); set_clip_plane_(std::nullopt); } void ClipPlane::cmd(const command::ClipPlaneSetPosition& v) { set_position(v.position); } void ClipPlane::cmd(const command::ClipPlaneShow& v) { camera_plane_ = camera_->plane(); set_position(v.position); } std::optional<numerical::Vector4d> ClipPlane::equation() const { if (!camera_plane_) { return std::nullopt; } return clip_plane_equation(*camera_plane_, position_); } [[nodiscard]] std::optional<double> ClipPlane::position() const { if (!camera_plane_) { return std::nullopt; } return position_; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |