package com.jacobi.comm.engine
{
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
{
/*
该方法返回 碰撞 true/false
*/
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;
}
}
}
相关推荐
一套干净简洁的UnityUI
一套干净简洁的UI,比较完整的一套通用UI,带点击动画
ActionScript学习笔记(八)——碰撞检测
碰撞检测的种类很多,2D而言有:点碰撞,矩形碰撞,球形碰撞以及像素碰撞。不同的游戏引擎也会有其他检测碰撞的不同方式。AS原生的库已经封装了一套碰撞检测方法,我们可以很简单的实现碰撞检测。当然还不能忽略注册点对于碰撞的影响 1、距离碰撞检测(球形碰撞检测) 最简单的也就是距离碰撞检测了,球形碰撞检测也是基于距离碰撞检测而来的,因此不需要过多的说明了,直接上公式。 var dx:Number...
unity 屏幕模糊
例如你要打开提示面板,对话面板 一系列的提示框 ,你都可以使用这个,他会截取屏幕一张图然后模糊化,非常好用
像素完美碰撞检测(使用cocos2d-x)
Pixel Perfect Collision Detection (Using Cocos2d-x) This post found its way because I couldnt find the answer to one of the questio
unity3d 解三角形 数学工具类
封装了些解三角形的公式...(有详细中文注释) 可用于在unity中 通过一些边和角,全解出一个三角形, 或者用于求出某个边,某个角度
船舶轨迹预测中的5个常见坑:基于LSTM单步预测的避坑实践
本文针对船舶轨迹预测中LSTM单步预测的常见问题,系统总结了五个典型陷阱及避坑实践。重点分析了如何正确处理AIS数据的非均匀采样与清洗、对航向角进行周期性编码、采用轨迹级归一化策略、缓解单步滚动预测的误差累积,并设计贴合业务的评估指标。这些实践能有效提升预测模型的准确性与实用性。
像素级碰撞
碰撞检测在游戏中是很常见的应用; 像素级碰撞最初来源于Flash,它是Flash中的一个碰撞算法。在Flash中,任何形状的元件都是被包含在一个完整的矩形容器里的,当两个矩形容器进行交汇时即为碰撞。比如,在你的游戏中,如果有物体发生碰撞,你会想要它们处理一些事情,这时就需要你能发现它们是否发生碰撞以及和多少个物体发生了碰撞。而像素级碰撞,顾名思义就是精确到像素级的碰撞算法。 像素级...
Python异步协程爬虫优化:解决aiohttp中ServerDisconnectedError的高效策略
本文深入探讨了在Python异步协程爬虫中使用aiohttp时,如何高效解决常见的ServerDisconnectedError问题。核心策略包括全局复用ClientSession、精细配置TCPConnector连接池、实施请求重试与速率限制,从而构建稳定、高效的异步爬虫架构,有效避免服务器断开连接错误。
[ActionScript 3.0] 像素级碰撞检测
1 package 2 { 3 import flash.display.BitmapData; 4 import flash.display.BlendMode; 5 import flash.display.DisplayObject; 6 import flash.display.Sprite; ...
Arduino安装图文教程:小白也能轻松上手
手把手带你完成Arduino安装全过程,无论你是编程新手还是硬件小白,都能快速搭建开发环境。结合arduino安装教程与实操步骤,避开常见错误,让创作即刻启程。
基于STM32设计的校园智慧路灯系统(华为云IOT)(212)
当前设计并研发了基于STM32的智慧路灯系统,本系统的目的是打造一个高效节能、智能化管理的校园照明环境。通过集成STM32F103RCT6高性能微控制器为核心,结合多种传感器模块如BH1750光敏传感器、热释电人体感应模块以及中科微电子GPS模块等,实现了对校园路灯的精准控制与实时监控。
java 像素级碰撞检测,» 像素级碰撞检测类
//像素级碰撞检测package{import flash.display.BitmapData;import flash.display.BlendMode;import flash.display.DisplayObject;import flash.display.Sprite;import flash.geom.ColorTransform;import flash.geom.Matrix...
max96712 GMSL1/2 相机调试记录
在部分相机调试中,使用i2cdetect 无法进行i2c扫描,一旦进行扫描会影响整个I2C总线通信异常,但是其能使用i2ctranfer命令进行读写操作,并不影响相机的开发调试。max96712的流路径分布如下图所示,需要通过对max96712进行相关配置,对GMSL-A/B/C/D进入的数据规划pipe。确认VID_PKL_DET 状态。max96712相关状态确认。MAX97612 状态确认。Linux 状态确认。
as3.0像素级碰撞检测
//像素级碰撞检测 package { import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.DisplayObject; import flash.display.Sprite; import flash.geom.ColorTransform; import
Android 13.0 不过gms认证,使用google商店不报没有获得Google认证的问题解决
在13.0的系统rom定制化开发中,在某些时候一个小项目需求用到google商店,但是不想过认证出这笔大费用,就需要 想做一个fingerprint的白名单,然后再联网的时候不弹出没有获得Google认证,正常使用google商店,接下来解决这个问题
点云语义分割:RandLANet模型推理C++部署(2)
一、数据读取及预处理 二、模型推理 三、结果保存
java 不规则碰撞检测,一个超高效的不规则物体碰撞检测的类 | 学步园
在坛里看到过有朋友贴过不规则物体碰撞检测的类,这里,我再贴个一位牛老外写的一个类,经自己测试,用一个1500*1500的矢量图和一个10*10的不短移动的小球进行碰状检测,CPU占用仅4%左右,超级高效!!!这里是代码:Actionscript:CODE:package ws.tink.display{import flash.display.BitmapData;import flash.dis...
claude code desktop中出现Doesn‘t look like an Anthropic model - expected a gateway model route 解决方案
本文主要介绍了claude code desktop中出现Doesn’t look like an Anthropic model - expected a gateway model route referencing an Anthropic model和Server is busy. Retrying的解决方案,希望能对使用claude code desktop的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案
java 像素矩阵_Java像素碰撞检测原理?
展开全部Java像素碰撞检测原理大体分为基于屏幕像素颜色检测,当移动的62616964757a686964616fe78988e69d8331333337396332目标坐标像素的颜色与目标颜色相同时为发生碰撞。坐标检测,就是维持各感兴趣物体的坐标数据,判断二者坐标相同时为发生碰撞。可以使用ActionScript3.0自带bitmapdata功能对像素级碰撞检测:package{importf...
WINCC7.3破解文件
WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!
InTheHand.Net.Personal+BlueTooth4,蓝牙开发
项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。
flash中物体运动基础之七---------碰撞处理
碰撞处理这是个很大的话题,要研究的东西太多了,就我所知,就as3而言它提供了三种方法来检测碰撞,它们是: hitTestPoint,hitTestObject,hitTest 前两个方法是应用于显示对象上的,后面一个用于位图像素级的碰撞检测,具体使用方法帮助文档中有详细介绍的。 关于位图的碰撞检测和更高级的碰撞检测在《Flash Actionscript 3.0 动画高级教程》中有详细介绍,...
Outlook Express 6 (OE6) for Win7/Win8/Win10
英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。
329



被折叠的 条评论
为什么被折叠?



