资源简介
opengl的相机类的实现方法,可以实现视野的放大的缩小等功能,供大家参考

代码片段和文件信息
#include “Camera.h“
#include
#include
#include
using namespace std;
Camera::Camera()
{
_world_BLx = 0;
_world_BLy = 0;
_world_W = 1;
_world_H = 1;
_window_W = 100;
_window_H = 100;
_fb_W = 100;
_fb_H = 100;
_window = NULL;
}
Camera::Camera(double world_BLx double world_BLy
double world_W double world_H
int window_W int window_H
GLFWwindow* window)
{
_world_BLx = world_BLx;
_world_BLy = world_BLy;
_world_W = world_W;
_world_H = world_H;
_window_W = window_W;
_window_H = window_H;
_fb_W = window_W;
_fb_H = window_H;
_window = window;
}
void Camera::mouse_to_world(int mx int my double &wx double &wy)
{
int vx = mx;
int vy = (int)(_window_H - my);
viewport_to_world(vx vy wx wy);
}
void Camera::viewport_to_world(int vx int vy double &wx double &wy)
{
double x_fraction = vx / _window_W;
double y_fraction = vy / _window_H;
// cout << “fractions: “ << x_fraction << “ “ << y_fraction << “\n“;
wx = _world_BLx + x_fraction * _world_W;
wy = _world_BLy + y_fraction * _world_H;
}
void Camera::world_to_viewport(double wx double wy
int& vx int& vy) {
vx = (int)((wx - _world_BLx) / _world_W * _window_W + 0.5);
vy = (int)((wx - _world_BLy) / _world_H * _window_H + 0.5);
}
void Camera::begin_drawing()
{
glViewport(00 (int)_fb_W (int)_fb_H);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double half_W = _world_W / 2;
double half_H = _world_H / 2;
glOrtho(-half_W +half_W
-half_H +half_H
0 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(-(_world_BLx + half_W)
-(_world_BLy + half_H)
-1);
}
void Camera::check_resize()
{
int width height;
glfwGetframebufferSize(_window &width &height);
_fb_W = width;
_fb_H = height;
}
void Camera::draw_grid(double minor_spacing double major_spacing)
{
double xy;
glDisable(GL_DEPTH_TEST);
glLineWidth(1); // lines as thin as possible
glBegin(GL_LINES); // every two glVertex calls will draw a line segment
double left = (int)(_world_BLx - 1);
double right = left + _world_W + 3;
double bottom = (int)(_world_BLy - 1);
double top = bottom + _world_H + 3;
// the minor vertical grid lines
glColor3d(0.6 0.4 0.4); // darkish red
for (x = left; x <= right; x += minor_spacing)
{
glVertex2d(x bottom);
glVertex2d(x top);
}
// the minor horizontal grid lines
for (y = bottom; y <= top; y += minor_spacing)
{
glVertex2d(left y);
glVertex2d(right y);
}
// the major vertical grid lines: darkish green
gl
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3625 2017-11-26 18:14 Camera.cpp
文件 1929 2017-11-03 14:11 Camera.h
相关资源
- OpenGL参考手册
- Qt Creator opengl实现四元数鼠标控制轨迹
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- OpenGL导入贴图的Texture类
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- OPENGL实现世界上最小的3D游戏
- VS2012OpenGL配置所需要的全部libdllh文件
- 基于OpenGL的仿蝗虫机器人三维动态仿
- 图形学 - OpenGL实现3种三维茶壶显示源
- opengl程序-会跳舞的骷髅
- opengl实现三维网格光顺Laplacian算法
- opengl——爆炸
- OpenGL三维地形建模
- opengl游戏编程徐明亮版(含源码)
- 用OPENGL画的一个简单的直升飞机
- opengl完美天空盒
- 3D绘图程序设计:使用Direct3D 10/9和Ope
- OpenGL绘制可运动自行车源程序.zip
- OpenGL实现飘动效果
- opengl室内场景的绘制,包括碰撞检测
评论
共有 条评论