Irrlicht学习之向量变化部分
来源:互联网 发布:淘宝网汉服女装 编辑:程序博客网 时间:2024/05/17 01:19
有2D向量和3D向量。
2D向量涉及到旋转,点乘,叉乘,归一化操作。
如下:
#ifndef __IRR_POINT_2D_H_INCLUDED__#define __IRR_POINT_2D_H_INCLUDED__#include "irrTypes.h"namespace irr{namespace core{template <typename T>inline void rotateBy(f64 degrees, T& x, T& y, T centerx, T centery){degrees *=GRAD_PI2;T cs = (T)cos(degrees);T sn = (T)sin(degrees);x -= centerx;y -= centery;}} // end namespace core} // end namespace irr#endif
/**************************** * 2015年5月24 星期日 零点 *(周六一天写了仿真的代码,晚上闲余来敲一敲IRRLICHT引擎的代码,不知不觉已经到了周日凌晨了。) *(要学习Irrlicht的编码方式和各种编程方法。以提高自己用C++编码以及思考的能力。) ***************************/#ifndef _IRR_POINT_3D_H_INCLUDE_#define _IRR_POINT_3D_H_INCLUDE_#include <math.h>#include "irrTypes.h"namespace irr{namespace core{template<typename T>class vector3d{public:vector3d():X(0), Y(0), Z(0){};vector3d( T nx, T ny, T nz) : X(nx), Y(ny), Z(nz){};vector3d(const vector3d<T>& other ) :X(other.X), Y(other.Y), Z(other.Z){};// 操作符 a + b + c a +=bvector3d<T>& operator=(const vector3d<T>& other){ X = other.X; Y = other.Y; Z = other.Z; return *this; }vector3d<T> operator+(const vector3d<T>& other) const { return vector3d<T>(X + other.X, Y + other.Y, Z + other.Z); }vector3d<T>& operator+=(const vector3d<T>& other){ X+=other.X; Y+=other.Y; Z+=other.Z; return *this; }vector3d<T> operator-(const vector3d<T>& other) const { return vector3d<T>(X - other.X, Y - other.Y, Z - other.Z); }vector3d<T>& operator-=(const vector3d<T>& other) { X-=other.X; Y-=other.Y; Z-=other.Z; return *this; }vector3d<T> operator*(const vector3d<T>& other) const { return vector3d<T>(X*other.X, Y*other.Y, Z*other.Z); }vector3d<T>& operator*=(const vector3d<T>& other) { X*=other.X; Y*=other.Y; Z*=other.Z; return *this; }vector3d<T> operator*(const T v) const { return vector3d<T>(X*v, Y*v, Z*v); }vector3d<T>& operator*=(const T v){ X*=v; Y*=v; Z*=v; return *this; }vector3d<T> operator/(const vector3d<T>& other) const { return vector3d<T>(X/other.X, Y/other.Y, Z/other.Z); }vector3d<T>& operator/=(const vector3d<T>& other){ X/=other.X; Y/=other.Y; Z/=other.Z; return *this; }vector3d<T> operator/(const T v) const { T i=(T)1.0/v; return vector3d<T>(X*i, Y*i, Z*i); }vector3d<T>& operator/=(const T v) { T i=(T)1.0/v; X*=i; Y*=i; Z*=i; return *this; }bool operator<=(const vector3d<T>& other) const { return X<=other.X && Y<=other.Y && Z<=other.Z; };bool operator>=(const vector3d<T>& other) const { return X>=other.X && Y>=other.Y && z>=other.Z; };bool operator==(const vector3d<T>& other) const { return other.X==X && other.Y==Y && other.Z==Z; }bool operator!=(const vector3d<T>& other) const { return other.X!=X || other.Y!=Y && other.Z!=Z; }// 方法void set(const T nx, const T ny, const T nz) {X=nx; Y=ny; Z=nz; }void set(const vector3d<T>& p) { X=p.X; Y=p.Y; Z=p.Z; }// 返回向量的长度值f64 getLength() const { return sqrt(X*X + Y*Y + Z*Z); }// 返回两个向量的点乘值T dotProduct( const vector3d<T>& other) const{return X*other.X + Y*other.Y + Z*other.Z;}// 返回点和点之间的距离。此处向量被用作为三位坐标空间中的一个点。f64 getDistanceFrom(const vector3d<T>& other) const{f64 vx = X - other.X; f64 vy = Y - other.Y; f64 vz = Z - other.Z;return sqrt(vx*vx + vy*vy + vz*vz);}vector3d<T> corssProduct(const vector3d<T>& p) const{return vector3d<T>(Y * p.Z - Z * p.Y, Z * p.X - X * p.Z, X * p.Y - Y * p.X );}// 未完// 成员变量T X, Y, Z;};//! Typedef for a f32 3d vectortypedef vector3d<f32> vector3df;//! Typedef for an integer 3d vectortypedef vector3d<s32> vector3di;} // end namespace irr} // end namespace core#endif
分析待完善。
0 0
- Irrlicht学习之向量变化部分
- Irrlicht之材质部分
- Irrlicht之学习准备
- Irrlicht学习之创建GUI界面
- Irrlicht学习之添加中文的支持
- Irrlicht学习之摄像机的探究
- Irrlicht学习之光照的研究
- Irrlicht学习之粒子系统的研究
- Irrlicht学习之水波特效的研究
- Irrlicht学习之使用着色器
- Irrlicht纹理部分
- Irrlicht for android 学习之二: 再编译
- Irrlicht学习之载入网格(mesh)文件
- Irrlicht学习之载入irr文件和自定义场景节点
- IRRLICHT 学习成果,呵呵
- Irrlicht系统学习---文件系统
- Irrlicht之HelloWorld详解
- irrlicht
- GET请求解读编码
- 会错意表错情,搭错车上错床——“度日如年”的故事及“feof()”的故事
- [安卓]手机管家(三)homeActivity
- python 白云黄鹤十大
- AD用户操作
- Irrlicht学习之向量变化部分
- 作业
- 浅谈Tomcat性能优化---APR篇
- 基于乐观锁的配置服务器与XServer的交互
- Android之NDK开发问题解决办法
- 15 组合模式
- webmachine
- linux 内核新手入门
- 华为OJ之中级篇Ⅱ