Giter VIP home page Giter VIP logo

xyz's Introduction

XYZ

C++讲述的三维空间里的故事。

DataFile

三维空间数据存储文件数据转换。

Vector3

三维空间常用类模板C++实现。

Share some Class templates using in 3D space implented by C++.

在借鉴Darkziyu的Mathd项目(https://github.com/Darkziyu/Mathd ) 基础上, 对Unity类的再实现按照C++的需求部分扩展为了类模板。

Implent Unity Classes to C++ Class Templates based work on Darkziyu(https://github.com/Darkziyu/Mathd).

由于主要应用于PCL项目, 坐标系进行了调整,调换了Y轴与Z轴。

Since the code is basicly used with PCL project, Y axis and Z axis are swaped.

	/* 本类采用坐标系如下:
	y
	^
	|
	|   俯视图        z轴垂直屏幕朝上
	|
	o-----------> x
	*/

目前只实现了Vector3类模板。

Now only Vector3 Class Templates are implented.

Vector3

构造函数

  • Vector3(T _x, T _y)
  • Vector3(T _x, T _y, T _z)

类成员变量

  • back = Vector3(0, -1, 0);
  • down = Vector3(0, 0, -1);
  • forward = Vector3(0, 1, 0);
  • fwd = Vector3(0, 1, 0);
  • left = Vector3(-1, 0, 0);
  • one = Vector3(1, 1, 1);
  • right = Vector3(1, 0, 0);
  • up = Vector3(0, 0, 1);
  • zero = Vector3(0, 0, 0);

类方法

	// 点乘
	static T Dot(Vector3<T> lhs, Vector3<T> rhs);
	// 叉乘
	static Vector3<T> Cross(Vector3<T> lhs, Vector3<T> rhs);
	// 距离
	static T Distance(Vector3<T> a, Vector3<T> b);
	// 单位化
	static Vector3<T> Normalize(Vector3<T> value);
	// 夹角大小(角度)
	static T Angle(Vector3<T> from, Vector3<T> to);
	// 夹角大小(弧度)
	static T AngleBetween(Vector3<T> from, Vector3<T> to);
	// 最大值(X,Y,Z均取最大)
	static Vector3<T> Max(Vector3<T> lhs, Vector3<T> rhs);
	// 最小值(X,Y,Z均取最小)
	static Vector3<T> Min(Vector3<T> lhs, Vector3<T> rhs);
	// 向量投影
	static Vector3<T> Project(Vector3<T> vector, Vector3<T> onNormal);
	// 缩放
	static Vector3<T> Scale(Vector3<T> a, Vector3<T> b);

成员方法

	// 单位化(不改变向量本身)
	Vector3<T> normalized();
	// 缩放
	void Scale(Vector3<T> scale);
	// 设置
	void Set(T _x, T _y, T _z);
	// 返回字符串
	string ToString();

运算符重载

	// 比较是否相等
	bool operator==(const Vector3<T> &rhs) const;
	// 比较是否不相等
	bool operator!=(const Vector3<T> &rhs) const;

(以下为类外定义)
template <class T>
Vector3<T> operator+(const Vector3<T> &a, const Vector3<T> &b);

template <class T>
Vector3<T> operator-(const Vector3<T> &a, const Vector3<T> &b);

template <class T>
Vector3<T> operator*(const T d, const Vector3<T> &a);

template <class T>
Vector3<T> operator* (const Vector3<T> &a, const T d);

template <class T>
Vector3<T> operator/ (const Vector3<T> &a, const T d);

xyz's People

Contributors

duzixi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.