Fishhole类定义和实现
2024-09-05 20:16:13
当眼睛处于水中,产生类似的鱼眼视角,fov永远是psi_max的2倍。具体算法参考书籍。
类声明:
#pragma once
#ifndef __FISHHOLE_HEADER__
#define __FISHHOLE_HEADER__ #include "camera.h" class Fishhole :public Camera {
public:
Fishhole();
~Fishhole();
Fishhole(const Fishhole& fh);
void set_fov(const ldouble fov);
void set_angle(const ldouble deg);
Vector3 ray_direction(const Point3& pp, const integer hres, const integer vres, const ldouble s, ldouble& r_squared) const;
virtual Camera* clone() const;
virtual void render_scene(World& w);
Fishhole& operator=(const Fishhole& fh);
private:
ldouble psi_max;//fov/2
};
#endif
类实现:
#include "pch.h"
#include "fishhole.h"
#include "../utilities/world.h"
#include "../utilities/viewplane.h"
#include "../samplers/sampler.h"
#include "../tracers/tracer.h" Fishhole::Fishhole() :Camera(), psi_max(180) {} Fishhole::~Fishhole() {} Fishhole::Fishhole(const Fishhole& fh) : Camera(fh), psi_max(fh.psi_max) {} void Fishhole::set_fov(const ldouble fov) {
psi_max = fov / 2;
} void Fishhole::set_angle(const ldouble deg) {
ldouble rad = radian(deg);
up = Point3(std::cos(rad) * up.x - std::sin(rad) * up.y,
std::sin(rad) * up.x + std::cos(rad) * up.y, up.z);
} Vector3 Fishhole::ray_direction(const Point3& pp, const integer hres, const integer vres, const ldouble s, ldouble& r_squared) const {
Point3 pn(2.0 / (s * hres) * pp.x, 2.0 / (s * vres) * pp.y, 0);
r_squared = pn.x * pn.x + pn.y * pn.y;
Vector3 dir;
if (r_squared <= 1.0) {
ldouble r = std::sqrt(r_squared);
ldouble psi = r * radian(psi_max);
ldouble sin_psi = std::sin(psi), cos_psi = std::cos(psi), sin_alpha = pn.y / r, cos_alpha = pn.x / r;
dir = sin_psi * cos_alpha * u + sin_psi * sin_alpha * v - cos_psi * w;
}
return dir;
} Camera* Fishhole::clone() const {
return new Fishhole(*this);
} void Fishhole::render_scene(World& w) {
Ray ray;
ViewPlane vp(w.vp);
integer depth = 0;
Point3 sp, pp;
ldouble r_squared;
w.open_window(vp.hres, vp.vres);
ray.o = eye;
vp.s = 1 / vp.s;
for (integer r = vp.vres - 1; r >= 0; r--)//render from left-corner to right-corner
for (integer c = 0; c < vp.hres; c++) {
RGBColor color;
for (integer p = 0; p < vp.nsamples; p++) {
sp = vp.sampler->sample_unit_square();
pp.x = (c - 0.5 * vp.hres + sp.x) * vp.s;
pp.y = (r - 0.5 * vp.vres + sp.y) * vp.s;
ray.d = ray_direction(pp, vp.hres, vp.vres, vp.s, r_squared);
if (r_squared <= 1.0)
color += w.tracer_ptr->trace_ray(ray);
}
color /= vp.nsamples;
color *= exposure_time;
w.display_pixel(r, c, color);
}
} Fishhole& Fishhole::operator=(const Fishhole& fh) {
if (this == &fh)
return *this;
Camera::operator=(fh);
psi_max = fh.psi_max;
return *this;
}
测试效果图(fov是180度):
最新文章
- web移动端开发技巧与注意事项汇总
- Java实验四
- 快速入门系列--WCF--06并发限流、可靠会话和队列服务
- 帕雷托最优(Pareto optimality)、帕雷托效率(Pareto efficiency)
- maven记录
- 使用Python玩转WMI
- python中的getattr函数
- clock gate cell
- C#实现注销、重启和关机代码
- ARCGIS 10中添加excel点字段生产点shp文件的工具
- JAVA Web项目的编码过滤器
- Android中网络流量控制(防火墙)——Iptables
- ASP.NET Core 2.0 支付宝当面付之扫码支付
- <;meta http-equiv=";X-UA-Compatible"; content=";IE=edge";>;的作用
- Logback日志配置的简单使用
- 探索未知种族之osg类生物---渲染遍历之Renderer::draw()简介
- stark组件之delete按钮、filter过滤
- ";errcode";:40163,";errmsg";:";code been used...报错,做PC微信登录时出现code been used...报错问题
- Jedis关于Set的API Demo
- 【Atcoder ARC060F】最良表現 / Best Representation
热门文章
- 每天一个 HTTP 状态码 101
- Go中rune类型浅析
- Clickhouse实时数仓建设
- 低代码前景可期,JNPF灵活易用,用智能定义新型办公模式
- GitHub 简介
- JAVA - 请说明”static”关键字是什么意思?Java中是否可以覆盖(override)一个private或者是static的方法?
- go-zero 微服务实战系列(二、服务拆分)
- Integer.MAX_VALUE 和 Integer.MIN_VALUE
- 在linux上配置Maven环境变量
- 【Java面试】简单说一下你对序列化和反序列化的理解