资源简介
1、构建一个三维场景
可利用glut提供的各种简单形体来搭建,或者读入别的模型,并加入光照效果
2、用键盘操作一个物体(如一艘飞船,或一个机器人),在三维场景中漫游
视点可以放在物体上,或跟随物体,利用gluLookAt()函数来实现对视点的控制

代码片段和文件信息
#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
相关资源
- makefiletest.tar.gz
- OpenGL参考手册
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- 外点法程序
- 外罚函数程序
- Qt Creator opengl实现四元数鼠标控制轨迹
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- OpenGL文档,api大全,可直接查询函数
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- opengl轮廓字体源代码
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - MFC读三维模型obj文件
- 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
评论
共有 条评论