资源简介
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
相关资源
- VS2012OpenGL配置所需要的全部libdllh文件
- 基于OpenGL的仿蝗虫机器人三维动态仿
- 图形学 - OpenGL实现3种三维茶壶显示源
- opengl程序-会跳舞的骷髅
- opengl实现三维网格光顺Laplacian算法
- opengl——爆炸
- OpenGL三维地形建模
- opengl游戏编程徐明亮版(含源码)
- 用OPENGL画的一个简单的直升飞机
- opengl完美天空盒
- 3D绘图程序设计:使用Direct3D 10/9和Ope
- OpenGL绘制可运动自行车源程序.zip
- OpenGL实现飘动效果
- opengl室内场景的绘制,包括碰撞检测
- OpenGL场景漫游
- 用opengl实现的太阳系模型
- OpenGL 3D贪吃蛇程序,很小
- OpenGL爆炸碎片化效果 源码
- OpenGL三茶壶三光源光源绕着茶壶旋转
- 10个OpenGL的源码
- vc写的一个游戏里面三维场景漫游
- OpenGL实现的简单游戏引擎
- OpenGL游戏程序设计源码
- glew最新版本glew1.11.0
- OpenGL 火箭
- 天空盒和地面
- 三维场景漫游.zip
- openGL实现的正方体六面贴图
- opengl简易翻牌游戏
- Qt Openglwidget 显示图片纹理贴图
评论
共有 条评论