Tutorial 14 - Camera Control - Part 1
来源:互联网 发布:sql select 多张表 编辑:程序博客网 时间:2024/06/01 17:31
以下只关注变化部分:
camera.h:
#ifndef CAMERA_H#defineCAMERA_H#include "math_3d.h"//==================================================================//类名:Camera//功能: 封装摄像机的所有操作,该类保存摄像机的参数,基于接收的事件来改变这些参数,从而控制摄像机的运动。//==================================================================class Camera{public: Camera(); Camera(const Vector3f &Pos, const Vector3f &Target, const Vector3f &Up); //================================================================== //函数名: OnKeyboard //功能: 当按下上下方向键时候,摄像机会沿着lookat方向移动, //而左右方向键则会使摄像机沿着左右方向移动,注意,移动的是摄像机 //输入参数:int Key按下的特殊键 //返回值: void //================================================================== bool OnKeyboard(int Key); const Vector3f &GetPos() const { return m_pos; } const Vector3f &GetTarget() const { return m_target; } const Vector3f &GetUp() const { return m_up; }private: Vector3f m_pos; Vector3f m_target; Vector3f m_up;};#endif/* CAMERA_H */
camera.cpp:
#include <GL/freeglut.h>#include "camera.h"const static float StepScale = 0.1f;Camera::Camera(){ m_pos = Vector3f(0.0f, 0.0f, 0.0f); m_target = Vector3f(0.0f, 0.0f, 1.0f); m_up = Vector3f(0.0f, 1.0f, 0.0f);}Camera::Camera(const Vector3f &Pos, const Vector3f &Target, const Vector3f &Up){ m_pos = Pos; m_target = Target; m_target.Normalize(); m_up = Up; m_up.Normalize();}bool Camera::OnKeyboard(int Key){ bool Ret = false; switch (Key) { case GLUT_KEY_UP: { m_pos += (m_target * StepScale); Ret = true; } break; case GLUT_KEY_DOWN: { m_pos -= (m_target * StepScale); Ret = true; } break; case GLUT_KEY_LEFT: { Vector3f Left = m_target.Cross(m_up); Left.Normalize(); Left *= StepScale; m_pos += Left; Ret = true; } break; case GLUT_KEY_RIGHT: { Vector3f Right = m_up.Cross(m_target); Right.Normalize(); Right *= StepScale; m_pos += Right; Ret = true; } break; } return Ret;}
main:
static void SpecialKeyboardCB(int Key, int x, int y){ GameCamera.OnKeyboard(Key);}static void InitializeGlutCallbacks(){ glutDisplayFunc(RenderSceneCB); glutIdleFunc(RenderSceneCB); glutSpecialFunc(SpecialKeyboardCB);//注册特殊键事件回调函数}
- Tutorial 14 - Camera Control - Part 1
- Tutorial 15 - Camera Control - Part 2
- GMF Tutorial Part 1
- GObject Tutorial Part 1
- Rich Client Tutorial Part 1
- Tutorial - Deferred Rendering (Part 1)
- Transparency Tutorial with C# - Part 1
- Windows Debuggers: Part 1: A WinDbg Tutorial
- Rich Client Tutorial Part 1(翻译)
- MFC Tutorial Part 1 - Creating a Window
- Ajax Tutorial for Beginners: Part 1
- iPhone JSON Flickr Tutorial – Part 1
- iPhone JSON Flickr Tutorial – Part 1
- iPhone JSON Flickr Tutorial – Part 1
- Windows Debuggers: Part 1: A WinDbg Tutorial
- COM Interop Part 1: C# Client Tutorial
- WPF Cover Flow Tutorial : Part 1
- Transparency Tutorial with C# - Part 1
- 使用select函数的TCP和UDP回射服务器程序
- 它们翻滚着的飞秋下载
- poj 1523 SPF
- 神奇的构造代码块
- 做为技术人员为什么要写博客
- Tutorial 14 - Camera Control - Part 1
- Android_ListView_Adapter使用和数据动态加载
- Python挑战的解决方案(1-10)
- 【白话经典算法系列之十七】 数组中只出现一次的数
- 飞鸽传书 桌面上常见的窗口:
- 随机生成四则运算式及答案(含括号)
- 【模拟】【数论】最大公约数和最小公倍数问题
- 多线程下的懒汉式和饿汉式
- 网站用户忠诚度