tray.h

来自「关于OpenGL的实例教程源代码」· C头文件 代码 · 共 52 行

H
52
字号
#ifndef tray_h

#define tray_h



#include <iostream.h>

#include "mathex.h"

#include "tvector.h"



///////////////////////////////////////////////////////////////////////

//  Class Line

///////////////////////////////////////////////////////////////////////



class TRay

{

	private:

		TVector _P; // Any point on the line

		TVector _V; // Direction of the line



		// Input and output

		ostream &write(ostream &out) const;

		istream &read(istream &in);



      // Close



	public:

		// Constructors

		TRay() {}



		// Line betwen two points OR point and a direction

		TRay(const TVector &point1, const TVector &point2);



		// Adjacent points on both lines

		bool adjacentPoints(const TRay &ray, TVector &point1, TVector &point2) const;



		// Unary operator

		static TRay &invert(const TRay &r, TRay &result) { result._P = r._P; TVector::invert(r._V, result._V); return result; }

		TRay operator-() const { return invert(*this, TRay()); }



		// Selectors

		TVector P() const { return _P; }

		TVector V() const { return _V; }

		int isValid() const { return V().isUnit() && P().isValid(); }



		// Distances

		double dist(const TRay &ray) const;

		double dist(const TVector &point) const;



		// Streaming

		friend ostream &operator<<(ostream &out, const TRay &o) { return o.write(out); }

		friend istream &operator>>(istream &in, TRay &o) { return o.read(in); }

};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?