Category:LSL Vector/ja
LSL ポータル | 関数 | イベント | 型 | 演算子 | 定数 | 実行制御 | スクリプトライブラリ | カテゴリ別スクリプトライブラリ | チュートリアル |
Vector
vectorは3個の{floatの値のセットを含むデータ型(type)です。
成分
各要素は変数名の後に .x、.y、.zを付加することにより個別にアクセスできます。 <syntaxhighlight lang="lsl2"> vector vec = <1, 2, 3>; float x = vec.x; // 1.0 float y = vec.y; // 2.0 float z = vec.z; // 3.0 </syntaxhighlight>
用途
vector型は次のデータを保持するために使うことができます:
演算子
vector型は次の操作をサポートしています:
加算、"+" 演算子
<syntaxhighlight lang="lsl2"> vector v = <1, 2, 3> + <0.5, 0.0, 3>; // <1.5, 2.0, 6.0> </syntaxhighlight>
減算、"-" 演算子
<syntaxhighlight lang="lsl2"> vector v = <1, 1, 1> - <0.5, 0.0, 3>; // <0.5, 1.0, -2.0> </syntaxhighlight>
乗算 (内積)、 "*" 演算子
<syntaxhighlight lang="lsl2"> float f = <9, 2, 7> * <4, 8, 10>; // 122.0 </syntaxhighlight>
外積、"%" 演算子
<syntaxhighlight lang="lsl2"> vector v = <2, 3, 4> % <5, 6, 7>; // <-3, 6, -3> </syntaxhighlight>
スカラー
ベクトルは、Float/jaまたはInteger/jaで乗算または除算してスケーリングできます。
ベクトルの各成分は、同じ値で乗算または除算されます。 <syntaxhighlight lang="lsl2"> vector v = <1, 2, 3> * 1.5; // <1.5, 3.0, 4.5> vector v = <1, 2, 3> / 1.5; // <0.666667, 1.333333, 2.000000> </syntaxhighlight>
回転
vector型はクォータニオンの乗算または除算によって回転させることができます。 <syntaxhighlight lang="lsl2"> // Z軸(上向き)を中心に45度回転 rotation r = llEuler2Rot(<0, 0, 45> * DEG_TO_RAD);
// 東方向へ1メートルの方向を持つベクトル vector v = <1, 0, 0>;
// 北東方向を向いたベクトル vector rotated = v * r; // <0.707107, 0.707107, 0.000000>
// 南東方向を向いたベクトル // (除算は逆方向に回転を行います) vector rotated = v / r; // <0.707107, -0.707107, 0.000000> </syntaxhighlight>
便利なスニペット
文字がVectorかチェックする <source lang="lsl2">integer IsVector(string s) {
list split = llParseString2List(s, [" "], ["<", ">", ","]); if(llGetListLength(split) != 7)//we must check the list length, or the next test won't work properly. return 0; return !((string)((vector)s) == (string)((vector)((string)llListInsertList(split, ["-"], 5)))); //it works by trying to flip the sign on the Z element of the vector, //if it works or breaks the vector then the values won't match. //if the vector was already broken then the sign flip will have no affect and the values will match //we cast back to string so we can catch negative zero which allows for support of ZERO_VECTOR
}//Strife Onizuka</source>
Pages in category "LSL Vector/ja"
The following 6 pages are in this category, out of 6 total.