[算法][包围盒]AABB简单类
2016-04-13 11:12
393 查看
头文件:
cpp文件
打印什么的自己看着办,没时间搞
#pragma once #include <iostream> //一个假的点类型 struct Vector3 { float x; float y; float z; }; class AABB { public: AABB(); AABB(const AABB &aabb); ~AABB(); void add(const Vector3 &v); void clear(); void makeAABB(Vector3 V[], int n); Vector3 min, max, center; }; void aabbPrint(AABB &ab);
cpp文件
#include "AABB.h" AABB::AABB() { } AABB::AABB(const AABB &aabb) { min = aabb.min; max = aabb.max; center = aabb.center; } void AABB::clear() { min.x = min.y = min.z = FLT_MAX; //careful: This is not FLT_MIN, 'cause FLT_MIN is a little larger than 0, //hence not a minus value. max.x = max.y = max.z = -FLT_MAX; } void AABB::add(const Vector3 &v) { if (v.x < min.x) min.x = v.x; if (v.y < min.y) min.y = v.y; if (v.z < min.z) min.z = v.z; if (v.x > max.x) max.x = v.x; if (v.y > max.y) max.y = v.y; if (v.z > max.z) max.z = v.z; } //make AABB out of Vector3 points void AABB::makeAABB(Vector3 V[], int n) { if (!V) return; for (int i = 0; i < n; i++) add(V[i]); center.x = (min.x + max.x) * 0.5f; center.y = (min.y + max.y) * 0.5f; center.z = (min.z + max.z) * 0.5f; } AABB::~AABB() { } void aabbPrint(AABB &ab) { std::cout<<"AABB min is: "; ab.min.x; ab.min.y; ab.min.z; std::cout<<"AABB max is: "; ab.max.x; ab.max.y; ab.max.z; std::cout<<std::endl; }
打印什么的自己看着办,没时间搞
相关文章推荐
- ViewPagerindicator 源码解析
- 网络流
- eclipse安装svn插件集合(第四种亲测)
- java序列化和反序列化
- 心跳包机制及Socket通信服务的心跳包
- 蛇形矩阵填写二维数组
- 析构函数
- Oracle之BBED之(二)-----BBED更改数据块
- 轻松把玩HttpClient之封装HttpClient工具类(二),插件式配置HttpClient对象
- FFT模板
- 172.The SQL statements executed in a user session are as follows:
- 字符集和编码
- Hbase 伪分布安装及Hbase shell操作
- 没有显示器且IP未知的情况下登录树莓派
- unity3d插件Daikon Forge GUI 中文教程3-基础控件Button和Sprite的使用
- HTML5 Input 类型
- 推荐eclipse插件Properties Editor
- MySQL中数据类型的验证
- bzoj3231 [Sdoi2008]递归数列
- 去掉点击a链接带来的虚框