Ray类定义

定义光线,书中已经有原理。

类声明:

#ifndef __RAY_HEADER__
#define __RAY_HEADER__

#include "geometry.h"

class Ray {
public:
	Ray();
	~Ray();
	Ray(const Point3& ori , const Vector3& dir);
	Ray(const Ray& r);
	Ray& operator=(const Ray& r);
	Point3 o;
	Vector3 d;
};
#endif

 

类实现:

#include "pch.h"
#include "ray.h" //光线应该新建一个文件,这里是ray.h

Ray::Ray() :o(), d() {}

Ray::~Ray() {}

Ray::Ray(const Point3& ori, const Vector3& dir) : o(ori), d(dir) {}

Ray::Ray(const Ray& r) : o(r.o), d(r.d) {}

Ray& Ray::operator=(const Ray& r) {
	if (this == &r)
		return *this;
	o = r.o;
	d = r.d;
	return *this;
}

  

原文地址:https://www.cnblogs.com/dalgleish/p/12602723.html