0
我有一個物體「角色」,它可以左右轉動自己並朝着它的臉部方向前進,並且相機總是看着物體並可以圍繞它旋轉。OpenGL模擬波斯王子相機
的問題是:我想要攝像機的方向移動,在其方向的對象移動的攝像頭,無論是在波斯的王子,如果對攝像機的方向和字符的字符臉前進這意味着如果相機沒有移動角色變得更靠近相機,所以如果相機可移動,則相機應該移回以使它們之間的距離相同,如果角色朝右看則相機應該移動到其右邊照相機具有位置,前,右和向上矢量以及偏航和俯仰角度,角色具有位置和偏航角度以及俯仰角度。 這使得字符移動的代碼是:
void Mesh::Move(Move_Directions direction, GLfloat deltaTime) {
GLfloat velocity = 50 * this->movementSpeed * deltaTime;
if (direction == FORWARD) {
glm::vec3 t = glm::vec3(sin(glm::radians(yaw)), 0.0, cos(glm::radians(yaw))) * velocity;
matrix = glm::translate(matrix, t);
for (GLuint i = 0; i < this->m_Entries.size(); i++) {
this->m_Entries[i].setModelMatrix(matrix);
}
//scene->getDefCamera()->Translate(t);
}
if (direction == BACKWARD) {
glm::vec3 t = glm::vec3(sin(glm::radians(yaw)), 0.0, cos(glm::radians(yaw))) * velocity;
matrix = glm::translate(matrix, -t);
for (GLuint i = 0; i < this->m_Entries.size(); i++) {
this->m_Entries[i].setModelMatrix(matrix);
}
//scene->getDefCamera()->Translate(t);
}
if (direction == RIGHT) {
matrix = glm::rotate(matrix, (GLfloat) -M_PI*deltaTime, glm::vec3(0.0, 1.0, 0.0));
for (GLuint i = 0; i < this->m_Entries.size(); i++) {
this->m_Entries[i].setModelMatrix(matrix);
}
}
if (direction == LEFT) {
matrix = glm::rotate(matrix, (GLfloat) M_PI*deltaTime, glm::vec3(0.0, 1.0, 0.0));
for (GLuint i = 0; i < this->m_Entries.size(); i++) {
this->m_Entries[i].setModelMatrix(matrix);
}
}
}
和攝像頭的代碼是:
void Camera::updateVectors() {
GLfloat radius = glm::length(center - position);
position.x = radius * cos(glm::radians(this->yaw)) * cos(glm::radians(this->pitch));
position.y = radius * sin(glm::radians(this->pitch));
position.z = radius * sin(glm::radians(this->yaw)) * cos(glm::radians(this->pitch));
this->front = glm::normalize(center - position);
this->right = glm::normalize(glm::cross(this->front, this->worldUp));
this->up = glm::normalize(glm::cross(this->right, this->front));
}
字符和相機「波斯王子」的【第三人稱視角]你創造的名字( https://en.wikipedia.org/wiki/Virtual_camera_system#Third-person_view)?無論如何,我沒有看到一個問題被問到。 –
我知道第三人稱相機,但在波斯王子的行爲是不同於普通的射擊遊戲,我添加了一個圖像來描述更多我想要的 – Mohamed
你想添加一個行爲到你的相機基地,也許在距離物體的距離。也許增加一個閾值,如果camera.pos - object.pos