Skip to content

Commit dbd3f35

Browse files
committed
カーブを実際に適用できるようにした
1 parent b63826f commit dbd3f35

File tree

6 files changed

+30
-74
lines changed

6 files changed

+30
-74
lines changed

curve_editor/ce_curve_id.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,23 +364,38 @@ void ce::Curve_ID::reverse_points()
364364
//---------------------------------------------------------------------
365365
double ce::Curve_ID::get_value(double ratio, double st, double ed)
366366
{
367-
if (!ISINRANGE(ratio, 0, 1)) return 0;
367+
// 進捗が0~1の範囲外であった場合
368+
if (!ISINRANGE(ratio, 0, 1))
369+
return 0;
370+
// 進捗に相当する区間を調べる
368371
for (int i = 0; i < control_points.size() - 1; i++) {
369372
if (ISINRANGE(ratio, control_points[i].pt_center.x / (double)CE_GR_RES, control_points[i + 1].pt_center.x / (double)CE_GR_RES)) {
370373
double range = (control_points[i + 1].pt_center.x - control_points[i].pt_center.x) / (double)CE_GR_RES;
371-
double x1 = (control_points[i].pt_right.x - control_points[i].pt_center.x) / (control_points[i + 1].pt_center.x - control_points[i].pt_center.x);
372-
double y1 = (control_points[i].pt_right.y - control_points[i].pt_center.y) / (control_points[i + 1].pt_center.y - control_points[i].pt_center.y);
373-
double x2 = (control_points[i + 1].pt_center.x - control_points[i + 1].pt_left.x) / (control_points[i + 1].pt_center.x - control_points[i].pt_center.x);
374-
double y2 = (control_points[i + 1].pt_center.y - control_points[i + 1].pt_left.y) / (control_points[i + 1].pt_center.y - control_points[i].pt_center.y);
375-
double st2 = st + control_points[i].pt_center.y * (ed - st) / (double)CE_GR_RES;
376-
double ed2 = st + control_points[i + 1].pt_center.y * (ed - st) / (double)CE_GR_RES;
374+
// 区間内での進捗の相対値(0~1)
375+
double ratio2 = (ratio - control_points[i].pt_center.x / (double)CE_GR_RES) / range;
376+
// 区間ごとの制御点1のX座標(相対値、0~1)
377+
double x1 = (control_points[i].pt_right.x - control_points[i].pt_center.x) / (double)(control_points[i + 1].pt_center.x - control_points[i].pt_center.x);
378+
// 区間ごとの制御点1のY座標(相対値)
379+
double y1 = (control_points[i].pt_right.y - control_points[i].pt_center.y) / (double)(control_points[i + 1].pt_center.y - control_points[i].pt_center.y);
380+
// 区間ごとの制御点2のX座標(相対値、0~1)
381+
double x2 = (control_points[i + 1].pt_left.x - control_points[i].pt_center.x) / (double)(control_points[i + 1].pt_center.x - control_points[i].pt_center.x);
382+
// 区間ごとの制御点2のY座標(相対値)
383+
double y2 = (control_points[i + 1].pt_left.y - control_points[i].pt_center.y) / (double)(control_points[i + 1].pt_center.y - control_points[i].pt_center.y);
384+
385+
// 区間ごとの始値、終値(相対値ではなく、実際の値)
386+
double st2 = st + control_points[i].pt_center.y / (double)CE_GR_RES * (ed - st);
387+
double ed2 = st + control_points[i + 1].pt_center.y / (double)CE_GR_RES * (ed - st);
388+
// y1,y2を相対値から実際の値に修正
389+
y1 = st2 + (ed2 - st2) * y1;
390+
y2 = st2 + (ed2 - st2) * y2;
391+
// ベジェの計算
377392
double tl = 0;
378393
double tr = 1;
379394
double ta = 0.5 * (tl + tr);
380395
double xta;
381-
for (int j = 1; j < 10; j++) {
396+
for (int j = 0; j < 10; j++) {
382397
xta = (1 - 3 * x2 + 3 * x1) * std::pow(ta, 3) + (x2 - 2 * x1) * 3 * std::pow(ta, 2) + 3 * x1 * ta;
383-
if (ratio < xta) tr = ta;
398+
if (ratio2 < xta) tr = ta;
384399
else tl = ta;
385400
ta = 0.5 * (tl + tr);
386401
}

curve_editor/ce_func.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ void ini_load_configs(FILTER* fp)
7272
}
7373

7474

75-
//---------------------------------------------------------------------
76-
// XMLから設定を読み込む
77-
//---------------------------------------------------------------------
78-
void read_xml_configs()
79-
{
80-
// レイアウト
81-
//xmlパーサ(msxml)
82-
83-
}
84-
85-
8675
//---------------------------------------------------------------------
8776
// 子ウィンドウを生成
8877
//---------------------------------------------------------------------

curve_editor/ce_func_graphics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void d2d_draw_handle(ID2D1SolidColorBrush* pBrush, DoublePoint st, DoublePoint e
154154
D2D1::Ellipse(
155155
D2D1::Point2F(st.x, st.y),
156156
CE_POINT_SIZE, CE_POINT_SIZE),
157-
pBrush, CE_POINT_SIZE * 1.5
157+
pBrush, CE_POINT_SIZE * 1.6
158158
);
159159
}
160160

curve_editor/ce_macro.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define CE_CT_SEARCH_H 20
6161
#define CE_CT_ICON_SIZE 22
6262
#define CE_CT_APPLY_SIZE 34
63-
#define CE_CT_APPLY_TEXT "Apply"
63+
#define CE_CT_APPLY_TEXT "Copy"
6464

6565
#define CE_WD_SIDE_MINW 120
6666
#define CE_WD_EDT_MINW 200

curve_editor/ce_main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ FILTER_DLL g_filter = {
9393
//処理関数
9494
int get_result(lua_State* L)
9595
{
96+
// index: カーブのID
97+
// ratio: 進捗(0~1)
98+
// st: トラックバーでの開始時の値
99+
// ed: トラックバーでの終了時の値
96100
int index = lua_tointeger(L, 1);
97101
double ratio = lua_tonumber(L, 2);
98102
double st = lua_tonumber(L, 3);

curve_editor/curve_editor.xml

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)