Android Open Source - RollOverSphere---a-simple-libgdx-game Collision Helper From Project Back to project page RollOverSphere---a-simple-libgdx-game .
License The source code is released under:
MIT License
If you think the Android project RollOverSphere---a-simple-libgdx-game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.igorcrevar.rolloverchuck.utils;
/ / w w w . j a v a 2 s . c o m
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
public class CollisionHelper {
private static Vector2 segmentV = new Vector2();
private static Vector2 ptV = new Vector2();
private static Vector2 tmpV2 = new Vector2();
private static Vector2 closestPointOnSegment(Vector2 segA, Vector2 segB, Vector2 circleCenter) {
segmentV.set(segB).sub(segA);
ptV.set(circleCenter).sub(segA);
float segmentVLen = segmentV.len();
if (segmentVLen == 0f) {
throw new IllegalArgumentException("segA == segB for closestPointOnSegment" );
}
Vector2 segVUnit = segmentV.scl(1 / segmentVLen);
float proj = ptV.dot(segVUnit);
if (proj <= 0f) {
return segA;
}
if (proj >= segmentVLen) {
return segB;
}
segVUnit.scl(proj).add(segA);
return segVUnit;
}
public static boolean intersection(Vector2 segA, Vector2 segB, Vector3 circleCenter, float circleRadius) {
tmpV2.set(circleCenter.x, circleCenter.z);
return intersection(segA, segB, tmpV2, circleRadius);
}
public static boolean intersection(Vector2 segA, Vector2 segB, Vector2 circleCenter, float circleRadius) {
Vector2 closest = closestPointOnSegment(segA, segB, circleCenter);
tmpV2.set(circleCenter); // for god sake
tmpV2.sub(closest);
float len = tmpV2.len();
if (len > circleRadius) {
return false; // no collision
}
if (len == 0) {
return false;
}
return true;
/*closest = closest_point_on_seg(seg_a, seg_b, circ_pos)
dist_v = circ_pos - closest
if dist_v.len() > circ_rad:
return vec(0, 0)
if dist_v.len() <= 0:
raise ValueError, "Circle's center is exactly on segment"
offset = dist_v / dist_v.len() * (circ_rad - dist_v.len())
return offset*/
}
}
Java Source Code List com.google.example.games.basegameutils.GameHelperUtils.java com.google.example.games.basegameutils.GameHelper.java com.igorcrevar.rolloverchuck.DesktopRunner.java com.igorcrevar.rolloverchuck.GameConsts.java com.igorcrevar.rolloverchuck.GameData.java com.igorcrevar.rolloverchuck.GameListener.java com.igorcrevar.rolloverchuck.GameManager.java com.igorcrevar.rolloverchuck.GameType.java com.igorcrevar.rolloverchuck.IActivityRequestHandler.java com.igorcrevar.rolloverchuck.ISceneManager.java com.igorcrevar.rolloverchuck.IScene.java com.igorcrevar.rolloverchuck.mesh.CubeMeshWithNormals.java com.igorcrevar.rolloverchuck.mesh.CubeMesh.java com.igorcrevar.rolloverchuck.mesh.FieldMesh.java com.igorcrevar.rolloverchuck.mesh.IMesh.java com.igorcrevar.rolloverchuck.mesh.SphereMesh.java com.igorcrevar.rolloverchuck.objects.BoxObject.java com.igorcrevar.rolloverchuck.objects.ChuckObject.java com.igorcrevar.rolloverchuck.objects.ChuckSpriteObject.java com.igorcrevar.rolloverchuck.objects.EndGameButtonsObject.java com.igorcrevar.rolloverchuck.objects.FieldObject.java com.igorcrevar.rolloverchuck.objects.GameButton.java com.igorcrevar.rolloverchuck.objects.IntroSceneButtonsObject.java com.igorcrevar.rolloverchuck.objects.MainWallObject.java com.igorcrevar.rolloverchuck.objects.StarsObject.java com.igorcrevar.rolloverchuck.objects.TextButton.java com.igorcrevar.rolloverchuck.objects.TrailObject.java com.igorcrevar.rolloverchuck.objects.boxes.BoxManager.java com.igorcrevar.rolloverchuck.objects.boxes.BoxRegionManager.java com.igorcrevar.rolloverchuck.objects.boxes.BoxRegion.java com.igorcrevar.rolloverchuck.objects.boxes.BoxTypeFactory.java com.igorcrevar.rolloverchuck.objects.boxes.IBoxRegion.java com.igorcrevar.rolloverchuck.objects.boxes.IBoxType.java com.igorcrevar.rolloverchuck.physics.CollisionSolver.java com.igorcrevar.rolloverchuck.physics.ICollisionIterationHandler.java com.igorcrevar.rolloverchuck.physics.SphereMoving.java com.igorcrevar.rolloverchuck.points.PlayerPoint.java com.igorcrevar.rolloverchuck.points.PointsManager.java com.igorcrevar.rolloverchuck.scenes.GameLoadingScene.java com.igorcrevar.rolloverchuck.scenes.GameScene.java com.igorcrevar.rolloverchuck.scenes.IntroScene.java com.igorcrevar.rolloverchuck.scenes.GameMode.ArcadeGameMode.java com.igorcrevar.rolloverchuck.scenes.GameMode.IGameMode.java com.igorcrevar.rolloverchuck.scenes.GameMode.StressFreeGameMode.java com.igorcrevar.rolloverchuck.utils.CollisionHelper.java com.igorcrevar.rolloverchuck.utils.GameHelper.java com.igorcrevar.rolloverchuck.utils.IMyFontDrawerFont.java com.igorcrevar.rolloverchuck.utils.Mathf.java com.igorcrevar.rolloverchuck.utils.MyFontDrawerBatch.java com.igorcrevar.rolloverchuck.utils.MyFontDrawerDefaultFont.java com.igorcrevar.rolloverchuck.utils.MyFontDrawer.java com.igorcrevar.rolloverchuck.utils.ShaderAssetLoader.java com.wayilookatgames.rolloverball.MainActivity.java