Example 1 : A Single Sample Ray Tracer

原创 2016年06月01日 08:03:24
#include<vector>
#include<iostream>
#include"Vector3.h"
#include"rgb.h"
#include"Image.h"
#include"Shape.h"
#include"Triangle.h"
#include"Sphere.h"
#include <fstream>
using namespace std;

int main()
{
	ofstream testFile("test.ppm");
	HitRecord rec;
	bool is_a_hit;
	float tmax;
	Vector3 dir(0, 0, -1);

	vector<Shape*> shapes;
	shapes.push_back( new Sphere(Vector3(250, 250, -1000), 150, rgb(0.2, 0.2, 0.8), rgb(1, 1, 1), 1));
	shapes.push_back(new Triangle(Vector3(300.0f, 600.0f, -800.0f), Vector3(0, 100, -1000), Vector3(450, 20, -1000),
		rgb(0.8, 0.2, 0.2), rgb(1, 1, 1), 1));

	Image im(500, 500);
	for (int i = 0; i < 500; i++){
		for (int j = 0; j < 500; j++){
			tmax = 100000.0f;
			is_a_hit = false;
			Ray r(Vector3(i, j, 0), dir);
			for (int k = 0; k < shapes.size(); k++){
				if (shapes[k]->hit(r, 0.000001f, tmax, 0, rec)){
					tmax = rec.t;
					is_a_hit = true;
				}
			}
			if (is_a_hit){
				im.set(i, j, rec.color);
			}
			else{
				im.set(i, j, rgb(0.2f, 0.2f, 0.2f));
			}

		}
	}

	//im.writePPM(cout);
	im.writePPM(testFile);

}


1. generate a simple image using spheres and triangles with an  orthographic 。







simple ray tracer的实现

研究下ray tracer,传统3D的逆向思维 svn co https://jet-ray-tracer.svn.sourceforge.net/svnroot/jet-ray-tracer je...

Tracer Example

Tracer Example IntroductionThis example demonstrates the Tracer . Tracer is a tracing feature bu...
  • xgbjmxn
  • xgbjmxn
  • 2011年01月31日 18:03
  • 429

<Ejb3InAction> Sample02 for Glassfish - Simple example of Stateless, Stateful, MDB and JPA Enity

0. Prerequisite 1) JDBC resources We use default JDBC resources, which is based on database sun-ap...
  • sun_xo
  • sun_xo
  • 2017年04月02日 16:36
  • 159

<Ejb3InAction> Sample02 for Weblogic - Simple example of Stateless, Stateful, MDB and JPA Enity

0. Prerequisite Actually this sample is postponed, please reference to prerequisites of sample03 a...
  • sun_xo
  • sun_xo
  • 2017年03月22日 15:12
  • 102

Seven ways to improve example-based single image super resolution笔记

最近一直在看super resolution的文章,看到2016年CVPR论文中有一篇关于improve example-based super resolution的通用方法,就简单总结一下,笔者是...

This chapter walks you through an example of single sign-on for intranet and extranet web users who

This chapter walks you through an example of single sign-on for intranet and extranet web users who ...

Packet Tracer6.0静态路由,RIP,OSPF路由方案配置(1)

BackGround: 建立如下网络拓扑,并进行IP编址。   1 以静态路由方案,配置连通网络   (1) 配置各设备IP地址,掩码,A,B网关 (2)配置R1,R2,R3 静态路由 2 以动态...

[原创]packet tracer详解1_软…

一、概述 Packet Tracer 是由Cisco公司发布的一个辅助学习工具,为学习思科网络课程的初学者去设计、配置、排除网络故障提供了网络模拟环境。用户可以在软件的图形用户界面上直接使用拖曳方法建...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Example 1 : A Single Sample Ray Tracer
举报原因:
原因补充:

(最多只允许输入30个字)