簡體   English   中英

用glm創建視圖矩陣

[英]Creating a view matrix with glm

我正在嘗試使用glm創建視圖矩陣。 我知道glm::lookAt並了解它是如何工作的。 我想知道是否有類似的函數可以實現采用不同參數的相同結果。 例如,是否有一個函數接受一個上矢量,一個在垂直於該矢量的平面上定向的方向以及一個角度? (即,天空就是這樣,我向左轉動N度/弧度,然后將頭部向上傾斜M度/弧度)。

您可以通過組合一組操作來構建矩陣:

// define your up vector
glm::vec3 upVector = glm::vec3(0, 1, 0);
// rotate around to a given bearing: yaw
glm::mat4 camera = glm::rotate(glm::mat4(), bearing, upVector);
// Define the 'look up' axis, should be orthogonal to the up axis
glm::vec3 pitchVector = glm::vec3(1, 0, 0);
// rotate around to the required head tilt: pitch
camera = glm::rotate(camera, tilt, pitchVector);

// now get the view matrix by taking the camera inverse
glm::mat4 view = glm::inverse(camera);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM