クラス定義と実装Fishhole

眼は水である場合には、FOVは常にpsi_max 2倍である、似た魚眼視点を持っています。アルゴリズムの参考書。

 

クラスの宣言:

#pragma回
#ifndefの__FISHHOLE_HEADER__ 
の#define __FISHHOLE_HEADER__ 

の#include "camera.h" 

クラスFishhole:公共カメラ{ 
パブリック:
	Fishhole(); 
	〜Fishhole(); 
	Fishhole(定数Fishhole&FH); 
	空set_fov(定数ldouble FOV)。
	ボイドset_angle(CONST ldouble度)
	するVector3 ray_direction(Point3と&PP、CONST整数HRES、CONST整数VRES、CONST CONST ldouble S、ldouble&r_squared)CONST。
	仮想カメラ*クローン()constは、
	仮想空render_scene(ワールド&W)。
	(Fishhole&FH CONST)Fishhole&演算子=。
プライベート:
	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():カメラ()、psi_max(180){} 

Fishhole ::〜Fishhole(){} 

(Fishhole&FH CONST)Fishhole :: Fishhole:カメラ( FH)、psi_max(fh.psi_max){} 

ボイドFishhole :: set_fov(CONST ldouble FOV){ 
	psi_max = FOV / 2。
} 

ボイドFishhole :: set_angle(CONST ldouble DEG){ 
	ldouble RAD =ラジアン(度)
	アップ= Point3と(STD :: COS(RAD)* up.x -のstd ::罪(RAD)* up.y、
		STD ::罪(RAD)* up.x +のstd :: COS(RAD)*アップ。 Y、up.z)。
}

するVector3 Fishhole :: ray_direction(Point3と&PP、CONST整数HRES、CONST整数VRES、CONST ldouble S、ldouble&r_squared CONST)の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 *ラジアン(psi_max)。
		ldouble sin_psi = STD ::罪(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。
	} 
	DIRを戻します。
} 

カメラ* Fishhole ::クローン()constは{ 
	新しいFishhole(* this)を返します。
} 
 
ボイドFishhole :: render_scene(ワールド&W){
	レイ線;
	ViewPlane VP(w.vp)。
	整数深さ= 0。
	POINT3 SP、PP。
	ldoubleはr_squared。
	w.open_window(vp.hres、vp.vres)。
	ray.o =目; 
	vp.s = 1 / vp.s。
	(整数R = vp.vres - 1、R> = 0; R - )のための//左コーナーから右コーナーにレンダリング
		するための(整数C = 0; C <vp.hres、C ++){ 
			てRGBColor色; 
			以下のための(整数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) 
			色/ = vp.nsamples。 
					色+ = w.tracer_ptr-> trace_ray(光線);
			} 
			カラー* = exposure_time。
			w.display_pixel(R、C、色)。
		} 
} 

Fishhole&Fishhole ::演算子=(Fishhole&FH CONST){ 
	IF(この==&FH)
		リターン*この; 
	カメラ::演算子=(FH); 
	psi_max = fh.psi_max。
	*これを返します。
}

図試験結果(FOVが180度です)。

おすすめ

転載: www.cnblogs.com/dalgleish/p/12651150.html