⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 line3.h

📁 java实现的简单的分形树。简单易学!是学习分形知识的很好的例子。其java语法简单
💻 H
字号:
// --------------------------------------------------------------------------
// Dingus project - a collection of subsystems for game/graphics applications
// --------------------------------------------------------------------------

#ifndef __LINE_H
#define __LINE_H

#include "Vector3.h"

namespace dingus {
	
	
class SLine3 {
public:
	SLine3() { };
	SLine3( const SVector3& v0, const SVector3& v1 ) : pos(v0), vec(v1-v0) { };
	
	void set( const SVector3& v0, const SVector3& v1 ) {
		pos = v0;
		vec = v1-v0;
	}
	const SVector3&	getStart() const { return pos; }
	const SVector3&	getVector() const { return vec; }
	SVector3	getEnd() const { return (pos+vec); };
	float		length() const { return vec.length(); };
	float		lengthSq() const { return vec.lengthSq(); }

	/** Distance from point to line. */
	float distance( const SVector3& p ) const {
		SVector3 diff( p-pos );
		float l = vec.lengthSq();
		if( l > 1.0e-6f ) {
			float t = vec.dot(diff) / l;
			diff = diff - vec*t;
			return diff.length();
		} else {
			// line is really a point...
			SVector3 v( p-pos );
			return v.length();
		}
	};
	
	/** Returns parametric point projection onto this line. */
	float project( const SVector3& p ) const {
		SVector3 diff( p-pos );
		float l = vec.lengthSq();
		assert( l > 1.0e-6f );
		return vec.dot(diff) / l;
	}
	
	SVector3 interpolate( float t ) const { return pos + vec*t; }
	
public:
	/** Line start point. */
	SVector3	pos;
	/** Line vector (end point minus start point). */
	SVector3	vec;
};

}; // namespace
	
	
#endif

⌨️ 快捷键说明

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