我正在嘗試關注計算機圖形學的這門課,但我被困在作業1.我不明白矢量eye
和up
的作用。作業描述可以找到in this link,也有第一個作業的骨架。計算機圖形學中的變換
到目前爲止,我有以下代碼:
// Transform.cpp: implementation of the Transform class.
#include "Transform.h"
//Please implement the following functions:
// Helper rotation function.
mat3 Transform::rotate(const float degrees, const vec3& axis) {
// Please implement this.
float radians = degrees * M_PI/180.0f;
mat3 r1(cos(radians));
mat3 r2(0, -axis.z, axis.y, axis.z, 0, -axis.x, -axis.y, axis.x, 0);
mat3 r3(axis.x*axis.x, axis.x*axis.y, axis.x*axis.z,
axis.x*axis.y, axis.y*axis.y, axis.y*axis.z,
axis.x*axis.z, axis.z*axis.y, axis.z*axis.z);
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
r2[i][j] = r2[i][j]*sin(radians);
r3[i][j] = r3[i][j]*(1-cos(radians));
}
}
return r1 + r2 + r3;
}
// Transforms the camera left around the "crystal ball" interface
void Transform::left(float degrees, vec3& eye, vec3& up) {
eye = eye * rotate(degrees, up);
}
// Transforms the camera up around the "crystal ball" interface
void Transform::up(float degrees, vec3& eye, vec3& up) {
vec3 newAxis = glm::cross(eye, up);
}
// Your implementation of the glm::lookAt matrix
mat4 Transform::lookAt(vec3 eye, vec3 up) {
return lookAtMatrix;
}
Transform::Transform()
{
}
Transform::~Transform()
{
}
它似乎是在做正確的事情,這就是,左右旋轉y軸的對象left
方法(其實我不知道如果物體正在移動,或者我正在移動的是相機,有人可以澄清?)。
爲up
方法我不能讓它的工作將圍繞X軸旋轉對象(或相機?)(至少這是我認爲)。
最後,我不明白lookAt
方法應該做什麼。
有人可以幫助我理解要執行的操作嗎? 有人能解釋什麼是載體eye
和up
的作用?
大概'eye'是一個向量,它定義了查找的方向,'up'通常是一個幫助「相機」的向量,或者任何正在轉換的向量。否則,物體可以自由地圍繞眼軸旋轉,這對於許多應用來說是不自然的。 – Skurmedel
因此,物體一旦位於特定的位置,我只需要移動「眼睛」和「向上」矢量? – BRabbit27