AA 碰撞体 就是将所有的物体设置为矩形框进行碰撞计算。下面是代码
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.replica.replicaisland;
/**
* An Axis-Aligned rectangular collision volume. This code treats other volumes as if they are
* also rectangles when calculating intersections. Therefore certain types of intersections, such
* as sphere vs rectangle, may not be absolutely precise (in the case of a sphere vs a rectangle,
* for example, a new rectangle that fits the sphere is used to perform the intersection test, so
* there is some potential for false-positives at the corners). However, for our purposes absolute
* precision isn't necessary, so this simple implementation is sufficient.
*/
public class AABoxCollisionVolume extends CollisionVolume {
private Vector2 mWidthHeight;
private Vector2 mBottomLeft;
public AABoxCollisionVolume(float offsetX, float offsetY, float width, float height) {
super();
mBottomLeft = new Vector2(offsetX, offsetY);
mWidthHeight = new Vector2(width, height);
}
public AABoxCollisionVolume(float offsetX, float offsetY, float width, float height,
int hit) {
super(hit);
mBottomLeft = new Vector2(offsetX, offsetY);
mWidthHeight = new Vector2(width, height);
}
@Override
public final float getMaxX() {
return mBottomLeft.x + mWidthHeight.x;
}
@Override
public final float getMinX() {
return mBottomLeft.x;
}
@Override
public final float getMaxY() {
return mBottomLeft.y + mWidthHeight.y;
}
@Override
public final float getMinY() {
return mBottomLeft.y;
}
/**
* Calculates the intersection of this volume and another, and returns true if the
* volumes intersect. This test treats the other volume as an AABox.
* @param position The world position of this volume.
* @param other The volume to test for intersections.
* @param otherPosition The world position of the other volume.
* @return true if the volumes overlap, false otherwise.
*/
@Override
public boolean intersects(Vector2 position, FlipInfo flip, CollisionVolume other,
Vector2 otherPosition, FlipInfo otherFlip) {
final float left = getMinXPosition(flip) + position.x;
final float right = getMaxXPosition(flip) + position.x;
final float bottom = getMinYPosition(flip) + position.y;
final float top = getMaxYPosition(flip) + position.y;
final float otherLeft = other.getMinXPosition(otherFlip) + otherPosition.x;
final float otherRight = other.getMaxXPosition(otherFlip) + otherPosition.x;
final float otherBottom = other.getMinYPosition(otherFlip) + otherPosition.y;
final float otherTop = other.getMaxYPosition(otherFlip) + otherPosition.y;
final boolean result = boxIntersect(left, right, top, bottom,
otherLeft, otherRight, otherTop, otherBottom)
|| boxIntersect(otherLeft, otherRight, otherTop, otherBottom,
left, right, top, bottom);
return result;
}
/** Tests two axis-aligned boxes for overlap. */
private boolean boxIntersect(float left1, float right1, float top1, float bottom1,
float left2, float right2, float top2, float bottom2) {
final boolean horizontalIntersection = left1 < right2 && left2 < right1;
final boolean verticalIntersection = top1 > bottom2 && top2 > bottom1;
final boolean intersecting = horizontalIntersection && verticalIntersection;
return intersecting;
}
/** Increases the size of this volume as necessary to fit the passed volume. */
public void growBy(CollisionVolume other) {
final float maxX;
final float minX;
final float maxY;
final float minY;
if (mWidthHeight.length2() > 0) {
maxX = Math.max(getMaxX(), other.getMaxX());
minX = Math.max(getMinX(), other.getMinX());
maxY = Math.max(getMaxY(), other.getMaxY());
minY = Math.max(getMinY(), other.getMinY());
} else {
maxX = other.getMaxX();
minX = other.getMinX();
maxY = other.getMaxY();
minY = other.getMinY();
}
final float horizontalDelta = maxX - minX;
final float verticalDelta = maxY - minY;
mBottomLeft.set(minX, minY);
mWidthHeight.set(horizontalDelta, verticalDelta);
}
}
分享到:
相关推荐
此文件可能是一个关于Android游戏开发的教程,可能包含了游戏编程的基本概念,如游戏循环,碰撞检测,动画处理,以及如何利用Android SDK中的Game Services来实现游戏得分和成就系统。对于希望开发Android游戏的...
它专注于硬件加速的图形应用程序,通过抽象出Direct3D和OpenGL等基础系统库的细节,提供了一个基于世界对象和直观类的接口,大大降低了复杂度,让开发者能够更专注于创意实现而非底层技术。 #### Bullet:先进物理...
总的来说,Unreal Engine是一款功能强大且全面的游戏开发引擎,它不仅适用于大型AAA级游戏,也适合独立开发者和小型团队。"UnrealEngine-release.zip"的解压和探索,将是一场深度学习和创新之旅,引领开发者进入...
它的强大之处在于支持多种操作系统,包括Windows、Linux、macOS和Android等。在“AB2D”项目中,Qt被用来创建一个接收并处理来自Arduino的加速度数据的界面。开发者可能创建了一个自定义的控件或者利用现有的Qt部件...
轴类零件加工工艺设计.zip
资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。
seaborn基本绘图人力资源数据集
移动机器人(sw三维)
自制html网页源代码查看器
3吨叉车的液压系统设计().zip
1_实验三 扰码、卷积编码及交织.ppt
北京交通大学软件学院自命题科目考试大纲.pdf
雅鲁藏布江流域 shp矢量数据 (范围+DEM).zip
基于RUST的数据结构代码示例,栈、队列、图等
NIFD:2024Q1房地产金融报告
详细介绍及样例数据:https://blog.csdn.net/li514006030/article/details/146916652
【工业机器视觉定位软件Vision-Detect】基于C#的WPF与Halcon开发的工业机器视觉定位软件(整套源码),开箱即用 有用户登录,图片加载,模板创建,通讯工具,抓边抓圆,良率统计,LOG日志,异常管理,九点标定和流程加载保存等模块,功能不是很完善,适合初学者参考学习。 资源介绍请查阅:https://blog.csdn.net/m0_37302966/article/details/146912206 更多视觉框架资源:https://blog.csdn.net/m0_37302966/article/details/146583453
内容概要:本文档详细介绍了Java虚拟机(JVM)的相关知识点,涵盖Java内存模型、垃圾回收机制及算法、垃圾收集器、内存分配策略、虚拟机类加载机制和JVM调优等内容。首先阐述了Java代码的编译和运行过程,以及JVM的基本组成部分及其运行流程。接着深入探讨了JVM的各个运行时数据区,如程序计数器、Java虚拟机栈、本地方法栈、Java堆、方法区等的作用和特点。随后,文档详细解析了垃圾回收机制,包括GC的概念、工作原理、优点和缺点,并介绍了几种常见的垃圾回收算法。此外,文档还讲解了JVM的分代收集策略,新生代和老年代的区别,以及不同垃圾收集器的工作方式。最后,文档介绍了类加载机制、JVM调优的方法和工具,以及常用的JVM调优参数。 适合人群:具备一定Java编程基础的研发人员,尤其是希望深入了解JVM内部机制、优化程序性能的技术人员。 使用场景及目标:①帮助开发人员理解Java代码的编译和执行过程;②掌握JVM内存管理机制,包括内存分配、垃圾回收等;③熟悉类加载机制,了解类加载器的工作原理;④学会使用JVM调优工具,掌握常用调优参数,提升应用程序性能。 其他说明:本文档内容详尽,适合用作面试准备材料和技术学习资料,有助于提高开发人员对JVM的理解和应用能力。
Android项目原生java语言课程设计,包含LW+ppt
戴德梁行&中国房地产协会:2021亚洲房地产投资信托基金研究报告