载入中...
搜索中...
未找到
SnowFieldTarget.cpp
浏览该文件的文档.
2
3#include "weather/SnowField.h"
4
5#include <algorithm>
6#include <cmath>
7#include <utility>
8
9namespace eve::lighting_editing {
10
12 : id_(std::move(id)), field_(field) {}
13int SnowFieldTarget::width() const { return field_ ? field_->getWidth() : 0; }
14int SnowFieldTarget::height() const { return field_ ? field_->getHeight() : 0; }
15bool SnowFieldTarget::containsCell(int x, int y) const { return field_ && field_->inBounds(x, y); }
16float SnowFieldTarget::readScalar(int x, int y) const {
17 return containsCell(x, y) ? field_->height(x, y) : 0.0F;
18}
20 if (!containsCell(x, y) || !std::isfinite(value)) return editing::FieldWriteStatus::Rejected;
21 value = std::clamp(value, 0.0F, 1.0F);
22 if (field_->height(x, y) == value) return editing::FieldWriteStatus::Unchanged;
23 field_->setHeight(x, y, value);
24 ++revision_;
25 dirty_.include(x, y);
27}
28float SnowFieldTarget::sampleScalar(float x, float y) const {
29 if (!field_ || width() <= 0 || height() <= 0 || !std::isfinite(x) || !std::isfinite(y)) return 0.0F;
30 x = std::clamp(x, 0.0F, static_cast<float>(width() - 1));
31 y = std::clamp(y, 0.0F, static_cast<float>(height() - 1));
32 const int x0 = static_cast<int>(std::floor(x));
33 const int y0 = static_cast<int>(std::floor(y));
34 const int x1 = std::min(x0 + 1, width() - 1);
35 const int y1 = std::min(y0 + 1, height() - 1);
36 const float tx = x - static_cast<float>(x0);
37 const float ty = y - static_cast<float>(y0);
38 const float top = readScalar(x0, y0) + (readScalar(x1, y0) - readScalar(x0, y0)) * tx;
39 const float bottom = readScalar(x0, y1) + (readScalar(x1, y1) - readScalar(x0, y1)) * tx;
40 return top + (bottom - top) * ty;
41}
42
43} // namespace eve::lighting_editing
double value
SQInteger top
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
std::string id
Definition PlayHost.cpp:108
float bottom
float readScalar(int x, int y) const override
Reads scalar.
SnowFieldTarget(std::string id, weather::SnowField *field)
Bind a live snow field which must outlive this adapter.
editing::FieldWriteStatus writeScalar(int x, int y, float value) override
Writes scalar.
float sampleScalar(float x, float y) const override
Sample scalar.
bool containsCell(int x, int y) const override
True if cell.
Interactive snow depth field: a dense [0,1] float grid.
Definition SnowField.h:21
bool inBounds(int x, int y) const
Compatibility predicate returning whether a cell is inside the field.
Definition SnowField.cpp:35
int getWidth() const
Returns the width.
Definition SnowField.h:31
int getHeight() const
Returns the height.
Definition SnowField.h:33
float height(int x, int y) const
Cell value in [0,1]; out-of-bounds reads 0.
Definition SnowField.cpp:51
void setHeight(int x, int y, float h)
Set one cell (clamped to [0,1]); out-of-bounds is a no-op.
Definition SnowField.cpp:45
FieldWriteStatus
FieldWriteStatus public API.
void include(int x, int y)
Include.