Camera Ray Generation
2016-09-17 01:39
417 查看
#include <fstream> #include "xmlload.cpp" #include "scene.cpp" using namespace std; int main(){ // load scene: root node, camera, image LoadScene("scenes/prj0.xml"); // variables for generating camera rays int w = renderImage.GetWidth(); int h = renderImage.GetHeight(); int size = w * h; Color24 white = {237, 237, 237}; Color24 black = {27, 27, 27}; Color24* img = renderImage.GetPixels(); float fov = camera.fov; float aspectRatio = (float) w / (float) h; float imageDistance = 1; float imageTipY = imageDistance * tan(fov / 2.0 * M_PI / 180.0); float imageTipX = imageTipY * aspectRatio; float dX = (2.0 * imageTipX) / w; float dY = (2.0 * imageTipY) / h; Point3 *imageTopLeftV = new Point3(-imageTipX, imageTipY, -imageDistance); Point3 *dXV = new Point3(dX, 0.0, 0.0); Point3 *dYV = new Point3(0.0, -dY, 0.0); Point3 firstPixel = *imageTopLeftV + (*dXV * 0.5) + (*dYV * 0.5); // generate camera rays for every pixel for(int i = 0; i < size; i++){ // generate current ray in camera space int pX = i % w; int pY = i / w; Point3 curr = firstPixel + (*dXV * pX) + (*dYV * pY); curr.Normalize(); // transform ray into world space // traverse through scene DOM // transform rays into model space // detect ray intersections ---> update pixel } // output ray-traced image & z-buffer //renderImage.SaveImage("images/image.ppm"); //renderImage.SaveZImage("images/z-image.ppm"); }
主要的思路就是:
把一张800 * 400的图片,映射到 一个w * h 大小的viewport上。
那么 图片上的一个像素的w间隔在viewport上就是w / 800, 图片上的 h 间隔在viewport上就是 h / 400 。
相关文章推荐
- 【Ray Tracing in One Weekend】(ch10)Positionable camera
- 《Ray Tracing in One Weekend》——Chapter 3: Rays, a simple camera, and background
- camera.ScreenPointToRay(),camera.ScreenToWorldPoint()与Raycast()
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition)会报错 空引用
- Android_照相机Camera_使用intent调用系统照相机在onActivityResult返回data为空
- OpenCV 3.10+Visual Studio 2013+Camera
- 用adb 启动camera
- sc7731 Android 5.1 Camera 学习之二 framework 到 HAL接口整理
- 射线与平面的相交检测(Ray-Plane intersection test)【转】
- Android 5.0 Camera (3):open camera
- 你都认识下面这些参数么?【Camera】
- 华为机型 cordova-plugin-camera从图库获取报错
- cocos2dx Camera类型
- 高通camera框架_流程浅析(1)
- Unity教程之-让物体朝摄像机Camera观察方向移动(一)
- Qualcomm平台camera调试移植入门
- Camera.Parameters 参数
- Android-->MediaMuxer,MediaCodec,AudioRecord及Camera实现音频视频混合MP4文件
- 嵌入式Linux下Camera编程--V4L2 ---fwqlzz love is for ever
- Displaying Graphics with OpenGL ES(四)——Applying Projection and Camera Views