Skip to content

Latest commit

 

History

History
72 lines (54 loc) · 1.54 KB

Utility.md

File metadata and controls

72 lines (54 loc) · 1.54 KB

ユーティリティ

Show 関数

Show(Args&&... args);

様々なオブジェクトを出力でき、マルチプラットフォームで動作します。PC の場合標準出力、マイコンの場合 USB シリアルへ送信します。また Udon::Showln 関数を用いると最後に改行を出力します。

void setup()
{
    Serial.begin(115200);  // マイコンを使用する場合必要
    Udon::Show("Hello world!");
}

ユーザー定義型の出力

struct Sample
{
    int i;
    double d;
    UDON_ENUMERABLE(i, d);
};

void setup()
{
    Serial.begin(115200);
    Udon::Show(Sample{ 10, 20.0 });
    Udon::Show(Sample{ 10, 20.0 });
}
{ 10, 20 }{ 10, 20 }

Assert 関数

Assert(bool expression, const char* const message = "", AssertAction action = AssertAction::Abort);

expression が false となるとき、任意のメッセージを出力しプログラムを中断する関数です。actionUdon::AssertAction::Skip を指定することで中断しないように設定できます。

#include <Udon.hpp>

static Udon::PadPS5BT pad;

void setup()
{
    Serial.begin(115200);
    Udon::Assert(pad.begin(), "PS5 BT failed to start!");
}

Normalized 関数

double Normalized(double value, double min, double max);

-∞~+∞ の範囲を min~max の範囲に変換します。最小値が設定できるようになった剰余算のイメージです。

Normalized(190, -180, 180) == 10
Normalized(-200, -180, 180) == -20