1、构建一个三维场景
可利用glut提供的各种简单形体来搭建,或者读入别的模型,并加入光照效果
2、用键盘操作一个物体(如一艘飞船,或一个机器人),在三维场景中漫游
视点可以放在物体上,或跟随物体,利用gluLookAt()函数来实现对视点的控制
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 311 2020-04-27 09:01 Readme.md
文件 1624766 2020-05-12 19:58 三维场景漫游.gif
目录 0 2020-04-27 08:58 作业6代码
文件 2204 2020-03-24 21:56 作业6代码camera.cpp
文件 1198 2020-04-27 08:38 作业6代码camera.h
文件 192 2020-03-24 22:19 作业6代码CVector3D.h
文件 3171 2020-03-24 22:33 作业6代码CViewframe.cpp
文件 699 2020-03-24 22:39 作业6代码CViewframe.h
文件 11020 2020-04-27 08:45 作业6代码main.cpp
文件 97792 2020-04-27 08:45 作业6代码MyTask06-3DSceneRoaming.exe
目录 0 2019-05-06 10:23 作业6附件
文件 474451 2019-04-29 13:56 作业6附件作业6-三维场景漫游.pdf
文件 658545 2019-05-06 10:20 作业6附件作业6-问题讨论与思考.pdf
#include “Camera.h“
Camera::Camera(glm::vec3 position glm::vec3 up float yaw float pitch)
: Forward(glm::vec3(0.0f 0.0f -1.0f))
MovementSpeed(SPEED)
Mouse_Sensiticity(SENSITIVITY)
Zoom(ZOOM)
{
this->Position = position;
this->World_up = up;
this->Yaw = yaw;
this->Pitch = pitch;
UpdateCameraVectors();
}
Camera::Camera(float pos_x float pos_y float pos_z float up_x float up_y float up_z float yaw float pitch)
: Forward(glm::vec3(0.0f 0.0f -1.0f))
MovementSpeed(SPEED)
Mouse_Sensiticity(SENSITIVITY)
Zoom(ZOOM)
{
this->Position = glm::vec3(pos_x pos_y pos_z);
this->World_up = glm::vec3(up_x up_y up_z);
this->Yaw = yaw;
this->Pitch = pitch;
UpdateCameraVectors();
}
Camera::~Camera()
{
}
glm::mat4 Camera::GetViewMatrix()
{
return glm::lookAt(Position Position + Forward Up);
}
//对应键盘移动事件
void Camera::ProcessKeyboard(Camera_Movement direction float deltaTime)
{
float velocity = MovementSpeed * deltaTime;
if (direction == FORWARD)
Position += Forward * velocity;
if (direction == BACKWARD)
Position -= Forward * velocity;
if (direction == LEFT)
Position -= Right * velocity;
if (direction == RIGHT)
Position += Right * velocity;
}
//对应鼠标移动事件
void Camera::ProcessMouseMovement(float xoffset float yoffset GLboolean constrainPitch)
{
xoffset *= Mouse_Sensiticity;
yoffset *= Mouse_Sensiticity;
Yaw += xoffset;
Pitch += yoffset;
if (constrainPitch)
{
if (Pitch > 89.0f)
Pitch = 89.0f;
if (Pitch < -89.0f)
Pitch = -89.0f;
}
UpdateCameraVectors();
}
//对应鼠标滚轮事件
void Camera::ProcessMouseScroll(float yoffset)
{
if (Zoom >= 1.0f && Zoom <= 45.0f)
Zoom -= yoffset;
if (Zoom <= 1.0f)
Zoom = 1.0f;
if (Zoom >= 45.0f)
Zoom = 45.0f;
}
void Camera::UpdateCameraVectors()
{
glm::vec3 front;
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
Forward = glm::normalize(front);
Right = glm::normalize(glm::cross(Forward World_up));
Up = glm::normalize(glm::cross(Right Forward));
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 311 2020-04-27 09:01 Readme.md
文件 1624766 2020-05-12 19:58 三维场景漫游.gif
目录 0 2020-04-27 08:58 作业6代码
文件 2204 2020-03-24 21:56 作业6代码camera.cpp
文件 1198 2020-04-27 08:38 作业6代码camera.h
文件 192 2020-03-24 22:19 作业6代码CVector3D.h
文件 3171 2020-03-24 22:33 作业6代码CViewfr
文件 699 2020-03-24 22:39 作业6代码CViewfr
文件 11020 2020-04-27 08:45 作业6代码main.cpp
文件 97792 2020-04-27 08:45 作业6代码MyTask06-3DSceneRoaming.exe
目录 0 2019-05-06 10:23 作业6附件
文件 474451 2019-04-29 13:56 作业6附件作业6-三维场景漫游.pdf
文件 658545 2019-05-06 10:20 作业6附件作业6-问题讨论与思考.pdf
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)