注册会员 登录
Project1 返回首页

墨凌羽的个人空间 https://rpg.blue/?324060 [收藏] [复制] [分享] [RSS]

日志

又一个轮子

已有 305 次阅读2015-11-5 16:18 |个人分类:MV

Range =  function () {
this.initialize.apply(this, arguments);
}

Range.prototype = function () {};

Range.prototype.constructor = Range;

Range.prototype.initialize = function (start, stop) {
this.start = start;
this.stop = stop;
}

Range.prototype.containValue = function (value) {
return value >= this.start && value <= this.stop;
}

Range.prototype.intersects = function (range) {
return !(this.stop < range.start || this.start > range.stop);
}

AABB = function () {
this.initialize.apply(this, arguments);
}

AABB.prototype = Rectangle;

AABB.prototype.constructor = AABB;

AABB.prototype.initialize = function (x, y, width, height) {
Rectangle.prototype.initialize.call(this, x, y, width, height);
this.setCencter();
this.setCorners();
this.setRange();
}

AABB.prototype.setCencter = function () {
this._cencter = new Point(this.x / 2, this.y / 2);
}

AABB.prototype.setCorners = function () {
this._leftUpPoint = new Point(this.x, this.y);
this._rightUpPoint = new Point(this.x + this.width, this.y);
this._leftDownPoint = new Point(this.x, this.y + this.height);
this._rightDownPoint = new Point(this.x + this.width, this.y + this.height);
}

AABB.prototype.setRange = function () {
this._wRange = new Range(this.x, this.x + this.width);
this._hRange = new Range(this.y, this.y + this.height);
}

AABB.prototype.getCenter = function () {
return this._cencter;
}

AABB.prototype.getCorners = function () {
return [this._leftUpPoint, this._rightUpPoint, this._leftDownPoint, this._rightDownPoint];
}

AABB.prototype.intersects = function (aabb) {
return this._wRange.intersects(aabb._wRange) && this._hRange.intersects(aabb._hRange);
}

AABB.prototype.containPoint = function (point) {
return point.x >= this.x && point.x <= this._rightDownPoint.x && point.y >= this.y && point.y <= this._rightDownPoint.y;
}

AABB.prototype.merge = function (aabb) {
var x = Math.min(this.x, aabb.x);
var y = Math.min(this.y, aabb.y);
var width = Math.max(this.x + this.width, aabb.x + aabb.width) - x;
var height = Math.max(this.y + this.height, this.y + aabb.height) - y;
return new AABB(x, y, width, height);

AABB.prototype.reset = function (x, y, width, height) {
Rectangle.prototype.initialize.call(this, x, y, width, height);
this.setCencter();
this.setCorners();
this.setRange();
}

轴对齐包围盒。那个 Range 差不多相当于一维的包围盒吧【笑
构造函数和rectangle一样。
getCenter 获得中心点 返回值是个Point对象
getCorners 获得四个顶点 返回值是个Point对象数组
intersects 检查两个包围盒是否相交 参数是个AABB对象
containPoint 检查点是否在包围盒内 参数是个Point对象
merge 返回一个能容纳两个包围盒的最小包围盒 参数是个AABB对象
reset 重置包围盒对象


鸡蛋

鲜花

评论 (0 个评论)

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-20 13:53

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部