言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Vector3.OrthoNormalize

public static function OrthoNormalize(normal: Vector3, tangent: Vector3): void;

Description

ベクトルが正規化され他のベクトルと直交するようにします

tangent を正規化します 接線 ( tangent ) を正規化し、 normal に直交しているか確認します(つまり、間の角度は90度です) See Also: Normalize 関数

public static function OrthoNormalize(normal: Vector3, tangent: Vector3, binormal: Vector3): void;

Description

ベクトルが正規化され他のベクトルと直交するようにします

tangent を正規化します 接線 ( tangent ) を正規化し、 normal に直交しているか確認します 接線 ( binormal ) を正規化し、 normaltangent 両方に直交しているか確認します 空間の位置は、通常標準的なXYZ軸システムの座標で指定されています。しかしながら、 正規化(すなわち大きさを1としたもの)や直交(すなわち他と垂直)である場合、 3つのベクトルの"軸"として 解釈することが出来ます。 Creating your own coordinate axes is useful, say, if you want to scale a mesh in arbitrary directions rather than just along the XYZ axes - you can transform the vertices to your own coordinate system, scale them and then transform back. Often, a transformation like this will be carried out along only one axis while the other two are either left as they are or treated equally. For example, a stretching effect can be applied to a mesh by scaling up on one axis while scaling down proportionally on the other two. This means that once the first axis vector is specified, it doesn't greatly matter what the other two are as long as they are normalized and orthogonal. OrthoNormalize can be used to ensure the first vector is normal and then generate two normalized, orthogonal vectors for the other two axes.

	// Mesh "stretch" effect along a chosen axis.
	
	// The axis and amount of scaling.
	var stretchAxis: Vector3;
	var stretchFactor = 1.0;
	
	// MeshFilter component and arrays for the original and transformed vertices.
	private var mf: MeshFilter;
	private var origVerts: Vector3[];
	private var newVerts: Vector3[];
	
	// Our new basis vectors.
	private var basisA: Vector3;
	private var basisB: Vector3;
	private var basisC: Vector3;
	
	
	function Start() {
		// Get the Mesh Filter, then make a copy of the original vertices
		// and a new array to calculate the transformed vertices.
		mf = GetComponent.<MeshFilter>();
		origVerts = mf.mesh.vertices;
		newVerts = new Vector3[origVerts.Length];
	}
	
	
	function Update() {
		// BasisA is just the specified axis for stretching - the
		// other two are just arbitrary axes generated by OrthoNormalize.
		basisA = stretchAxis;
		Vector3.OrthoNormalize(basisA, basisB, basisC);
		
		// Copy the three new basis vectors into the rows of a matrix
		// (since it is actually a 4x4 matrix, the bottom right corner
		// should also be set to 1).
		var toNewSpace: Matrix4x4 = new Matrix4x4();
		toNewSpace.SetRow(0, basisA);
		toNewSpace.SetRow(1, basisB);
		toNewSpace.SetRow(2, basisC);
		toNewSpace[3, 3] = 1.0;
		
		// The scale values are just the diagonal entries of the scale
		// matrix. The vertices should be stretched along the first axis
		// and squashed proportionally along the other two.
		var scale: Matrix4x4 = new Matrix4x4();
		scale[0, 0] = stretchFactor;
		scale[1, 1] = 1.0 / stretchFactor;
		scale[2, 2] = 1.0 / stretchFactor;
		scale[3, 3] = 1.0;
		
		// The inverse of the first matrix transforms the vertices back to
		// the original XYZ coordinate space(transpose is the same as inverse
		// for an orthogonal matrix, which this is).
		var fromNewSpace: Matrix4x4 = toNewSpace.transpose;
		
		// The three matrices can now be combined into a single symmetric matrix.
		var trans: Matrix4x4 = toNewSpace * scale * fromNewSpace;
		
		// Transform each of the mesh's vertices by the symmetric matrix.
		for (var i = 0; i < origVerts.Length; i++) {
			newVerts[i] = trans.MultiplyPoint3x4(origVerts[i]);
		}
		
		// ...and finally, update the mesh with the new vertex array.
		mf.mesh.vertices = newVerts;
	}

See Also: Normalize 関数