- 浏览: 577869 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
wzh051527:
我是大四实习生一个,自我感觉技术能力在第三年。。唯一不明白,为 ...
十年技术,不要再迷茫 -
room_bb:
.hrl文件怎么加入到编译规则里面?比如:pp.hrl文件-d ...
Erlang中用的makefile的一点解释 -
吉米家:
感觉帆软报表的flash打印就很不错哇,特别好用
JSP 实现报表打印 -
雪碧爱芬达:
苦逼程序员的辛酸反省与总结 -
mlyjxx:
...
十年技术,不要再迷茫
之前,在坛里看到过有朋友贴过不规则物体碰撞检测的类,这里,我再贴个一位牛老外写的一个类,经自己测试,用一个1500*1500的矢量图和一个 10*10的不短移动的小球进行碰状检测,CPU占用仅4%左右,超级高效!!!
这里是代码:
Actionscript:
package ws.tink.display { import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.DisplayObject; import flash.display.Sprite; import flash.geom.ColorTransform; import flash.geom.Matrix; import flash.geom.Point; import flash.geom.Rectangle; public class HitTest { public static function complexHitTestObject( target1:DisplayObject, target2:DisplayObject, accurracy:Number = 1 ):Boolean { return complexIntersectionRectangle( target1, target2, accurracy ).width != 0; } public static function intersectionRectangle( target1:DisplayObject, target2:DisplayObject ):Rectangle { // If either of the items don't have a reference to stage, then they are not in a display list // or if a simple hitTestObject is false, they cannot be intersecting. if( !target1.root || !target2.root || !target1.hitTestObject( target2 ) ) return new Rectangle(); // Get the bounds of each DisplayObject. var bounds1:Rectangle = target1.getBounds( target1.root ); var bounds2:Rectangle = target2.getBounds( target2.root ); // Determine test area boundaries. var intersection:Rectangle = new Rectangle(); intersection.x = Math.max( bounds1.x, bounds2.x ); intersection.y = Math.max( bounds1.y, bounds2.y ); intersection.width = Math.min( ( bounds1.x + bounds1.width ) - intersection.x, ( bounds2.x + bounds2.width ) - intersection.x ); intersection.height = Math.min( ( bounds1.y + bounds1.height ) - intersection.y, ( bounds2.y + bounds2.height ) - intersection.y ); return intersection; } public static function complexIntersectionRectangle( target1:DisplayObject, target2:DisplayObject, accurracy:Number = 1 ):Rectangle { if( accurracy <= 0 ) throw new Error( "ArgumentError: Error #5001: Invalid value for accurracy", 5001 ); // If a simple hitTestObject is false, they cannot be intersecting. if( !target1.hitTestObject( target2 ) ) return new Rectangle(); var hitRectangle:Rectangle = intersectionRectangle( target1, target2 ); // If their boundaries are no interesecting, they cannot be intersecting. if( hitRectangle.width * accurracy <1 || hitRectangle.height * accurracy <1 ) return new Rectangle(); var bitmapData:BitmapData = new BitmapData( hitRectangle.width * accurracy, hitRectangle.height * accurracy, false, 0x000000 ); // Draw the first target. bitmapData.draw( target1, HitTest.getDrawMatrix( target1, hitRectangle, accurracy ), new ColorTransform( 1, 1, 1, 1, 255, -255, -255, 255 ) ); // Overlay the second target. bitmapData.draw( target2, HitTest.getDrawMatrix( target2, hitRectangle, accurracy ), new ColorTransform( 1, 1, 1, 1, 255, 255, 255, 255 ), BlendMode.DIFFERENCE ); // Find the intersection. var intersection:Rectangle = bitmapData.getColorBoundsRect( 0xFFFFFFFF,0xFF00FFFF ); bitmapData.dispose(); // Alter width and positions to compensate for accurracy if( accurracy != 1 ) { intersection.x /= accurracy; intersection.y /= accurracy; intersection.width /= accurracy; intersection.height /= accurracy; } intersection.x += hitRectangle.x; intersection.y += hitRectangle.y; return intersection; } protected static function getDrawMatrix( target:DisplayObject, hitRectangle:Rectangle, accurracy:Number ):Matrix { var localToGlobal:Point;; var matrix:Matrix; var rootConcatenatedMatrix:Matrix = target.root.transform.concatenatedMatrix; localToGlobal = target.localToGlobal( new Point( ) ); matrix = target.transform.concatenatedMatrix; matrix.tx = localToGlobal.x - hitRectangle.x; matrix.ty = localToGlobal.y - hitRectangle.y; matrix.a = matrix.a / rootConcatenatedMatrix.a; matrix.d = matrix.d / rootConcatenatedMatrix.d; if( accurracy != 1 ) matrix.scale( accurracy, accurracy ); return matrix; } } }
发表评论
-
as3 Loader 加载资源后内存泄露无法释放的问题。
2014-06-21 10:30 640as3 Loader 加载资源后内存泄露无法释放的问题。 ... -
as3判断flash player版本的函数
2014-06-10 20:35 799//判断当前版本是否高于9.0.115.0为例子. pr ... -
CSS 中文字体的英文名称 (simhei, simsun) 宋体 微软雅黑
2014-04-03 15:25 966华文细黑:STHeiti Light [STXihei]华文 ... -
as3.0的垃圾回收机制
2013-09-07 14:02 1464还是同样的博客,还是同样的作者(Daniel Sidhio ... -
AIR程序多开
2013-09-07 13:55 968AIR应用通常不能像QQ那样能进行多开操作。为了让一个用AI ... -
starling性能优化总结
2013-07-22 14:06 1441在项目开发的过程中总结了一下starling的性能优化方案: ... -
AS3 Socket从零开始
2013-07-22 12:54 1071大家如果想学AS3 Socket直接在百度里搜一下,会找到很 ... -
绕开AS3安全沙箱 跨域加载SWF
2013-07-11 12:53 866AS3的安全沙箱的确是 ... -
解决AS3在ie中初始化时stageWidth和stageHeight为0
2013-06-14 09:23 973先看下面的一段脚本,这是比较经典的初始化脚本: pac ... -
动态获取swc中的类
2013-05-25 10:32 909想通过代码生成,来获取swc中的类,并且可以作为普通类正常使 ... -
AS3 中字符串的format功能实现
2013-05-25 10:19 805使用C#的朋友都知道,string.Format();还是挺 ... -
总结调用Flash的几种方法
2013-05-02 16:18 1624一、Adobe 提供的方法 <object wi ... -
Flash3D错误集锦
2013-05-02 14:03 895VerifyError: Error #1014: 无法找到 ... -
使用scale拉伸之后的坐标问题
2013-04-12 09:38 1238最近发现论坛多了很多 ... -
30个实用的网页设计工具
2013-03-20 09:58 780作为一位网页设计师或开发者,你一直需要搜寻获取强大的网页设计 ... -
如何成为强大的程序员?
2013-03-11 11:27 698Aaron Stannard是新创公 ... -
漫谈重构
2013-03-11 11:09 821因为工作内容的原因, ... -
AS3使用谷歌API生成二维码
2012-12-10 16:24 1311二维码在新闻杂志,网站,网络广告,电视广告等地方随处可见 ... -
OOP的聚合原则
2012-12-10 16:21 899什么是聚合? 聚合可以很好地表达对象是什么和做 ... -
压缩速率追踪
2012-11-02 14:16 1424Flash Player 11.3添加了一个压缩和解压B ...
相关推荐
这次做了一个并没有什么用的不规则图形碰撞检测, 代码还是蛮简单的,不过并不建议真的用来做游戏引擎中的检测部分,这个效率不够,玩玩看还可以。 并没有用双缓冲,只是做了一个Demo233
iOS 碰撞检测 ,包含不规则的碰撞,封装成一个类,方便调用
求不规则物体的体积,求不规则物体的体积课件,求不规则物体的体积PPT
不规则物体的体积的练习题.pdf
基于opencv测量不规则物体的宽度 在获得的区域内选取任意一点,以该点画圆,半径逐步增加,设定条件(在该圆中的烟草区域/圆的面积<某阈值),当不符合时,将圆进行空白区域中心的反向半径方向移动,直到满足条件...
不规则物体的体积.docx
五年级数学下册课课练习3.15不规则物体体积的计算.pdf
1. AABB包围盒 在游戏中,为了简化物体之间的碰撞检测运算,通常会对物体创建一个规则的几何外形将其包围 2. 二维场景中的AABB碰撞检测原理
小学五年级数学下册不规则物体的体积文档资料PPT教案.pptx
新人教小学五年级数学下册求不规则物体体积PPT课件.pptx
《有趣的测量(不规则物体体积的测量方法)》编写说明及教学建议(1).doc
基于裁剪近端策略优化算法的软机械臂不规则物体抓取是一种用于软机械臂控制的算法。该算法结合了裁剪近端策略和优化方法,旨在实现对不规则物体的精确抓取。 传统的机械臂通常用硬件材料组成,而软机械臂由柔性材料...
测量不规则物体的体积.ppt
求不规则物体的体积.doc
我们使用超光谱曲线研究整数和半奇数整数秩的不规则保形状态。 光谱曲线是超对称不规则矩阵模型的环方程。 整数秩的情况对应于NS扇区的超对称顶点算子的碰撞极限,而Ramond扇区的奇数为半奇数。 光谱曲线在Nekrasov-...
巧求不规则物体的体积作文.doc
用排水法求不规则物体体积.ppt
五年级数学求不规则物体体积.ppt
不规则物体的体积教学设计说明.doc
求不规则物体的体积教学设计说明.doc