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.PushMatrix 和GL.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 Vector3(mousePos.x / 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 Vector3(mousePos.x / 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 = Vector3(mousePos.x/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(Vector3(mousePos.x/Screen.width, mousePos.y/Screen.height, 0));
	GL.End();
	GL.PopMatrix();
}
最后修改:2011年3月21日 Monday 12:19

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。