GL.modelview 模型视图

static var modelview : Matrix4x4

Description描述

The current modelview matrix.

返回目前的模型视图矩阵。

Assigning to this variable is equivalent to glLoadMatrix(mat) in OpenGL; in other graphics APIs the corresponding functionality is emulated.

这个参数和OpenGL中的glLoadMatrix(mat) 一样。在其它的图形API中也有对应的功能参数。

Changing modelview matrix overrides current camera's view parameters, so most often you want to save and restore matrix using GL.PushMatrix and GL.PopMatrix.

改变模型视图矩阵会覆盖当前的camera' 的参数,许多情况下你需要用到GL.PushMatrixGL.PopMatrix矩阵函数.来保存和恢复。

Reading this variable returns the current modelview matrix.

读这个参数返回当前的模型视图矩阵。

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	public Material mat;

	private Vector3 startVertex;

	private Vector3 mousePos;

	void Update() {

	mousePos = Input.mousePosition;

		if (Input.GetKeyDown(KeyCode.Space))

			startVertex = new Screen.width, mousePos.y / Screen.height, 0);



	}

	void OnPostRender() {

		if (!mat) {

			Debug.LogError("Please Assign a material on the inspector");

			return;

		}

		GL.PushMatrix();

		mat.SetPass(0);

		GL.LoadOrtho();

		GL.Begin(GL.LINES);

		GL.Color(Color.red);

		GL.Vertex(startVertex);

		GL.Vertex(new Screen.width, mousePos.y / Screen.height, 0));

		GL.End();

		GL.PopMatrix();

	}

	void Awake() {

		startVertex = new Vector3(0, 0, 0);

	}

}
// Draws a line from "startVertex" var to the curent mouse position.

//从startVertex绘制一条线到当前的鼠标位置

var mat : Material;

private var startVertex : Vector3;

private var mousePos : Vector3;

startVertex = Vector3(0,0,0);



function Update() {

	mousePos = Input.mousePosition;

	// Press space to update startVertex

	//按下空格更新startVertex

	if(Input.GetKeyDown(KeyCode.Space)){

		startVertex = Screen.width, mousePos.y/Screen.height, 0);

	}

}



function OnPostRender() {

	if (!mat) {

		Debug.LogError("Please Assign a material on the inspector");

		return;

	}

	GL.PushMatrix();

	mat.SetPass(0);

	GL.LoadOrtho();

	GL.Begin(GL.LINES);

	GL.Color(Color.red);

	GL.Vertex(startVertex);

	GL.Vertex(Screen.width, mousePos.y/Screen.height, 0));

	GL.End();

	GL.PopMatrix();

}
Page last updated: 2011-3-21