forked from MagicBane/Server
FatBoy-DOTC
10 months ago
11 changed files with 181 additions and 150 deletions
@ -1,50 +1,62 @@ |
|||||||
package engine.CollisionEngine; |
package engine.CollisionEngine; |
||||||
|
|
||||||
|
import engine.math.Vector3f; |
||||||
|
import engine.math.Vector3fImmutable; |
||||||
import engine.objects.Building; |
import engine.objects.Building; |
||||||
|
import org.pmw.tinylog.Logger; |
||||||
|
|
||||||
import java.awt.geom.Line2D; |
import java.awt.geom.Line2D; |
||||||
|
|
||||||
|
import java.awt.geom.Point2D; |
||||||
import java.awt.geom.Rectangle2D; |
import java.awt.geom.Rectangle2D; |
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
||||||
|
|
||||||
public class Mesh { |
public class Mesh { |
||||||
public ArrayList<Triangle> triangles; |
public ArrayList<Triangle> triangles; |
||||||
public ArrayList<Line2D> BoundingLines; |
public Vector3f mesh_end_point; |
||||||
public Rectangle2D boundsRect; |
public Vector3f mesh_ref_point; |
||||||
public float maxY; |
public Vector3f mesh_location; |
||||||
public float minY; |
public float mesh_max_y; |
||||||
public Building parentBuilding; |
public float mesh_min_y; |
||||||
|
public Vector3f mesh_scale; |
||||||
public boolean BoundsCollides(Line2D line){ |
public int mesh_id; |
||||||
for(Line2D side : BoundingLines) |
public int parent_prop_id; |
||||||
if(side.intersectsLine(line)) |
public int parent_structure_id; |
||||||
return true; |
public int parentUUID; |
||||||
|
public Rectangle2D.Float mesh_bounds; |
||||||
return false; |
|
||||||
} |
public void AdoptTriangles(float rotation){ |
||||||
|
if(CollisionManager.mesh_triangles.containsKey(this.mesh_id) == false){ |
||||||
public boolean MeshCollides(Line2D line, float charHeight, float charY){ |
Logger.error("Failed To Bake Triangles For Mesh: " + this.mesh_id); |
||||||
|
return; |
||||||
//check if movement path intersects this mesh
|
|
||||||
if(boundsRect == null){ |
|
||||||
return false; |
|
||||||
} |
} |
||||||
|
|
||||||
if(!line.intersects(boundsRect) && !boundsRect.contains(line.getP1()) && !boundsRect.contains(line.getP2())) |
this.triangles = new ArrayList<>(); |
||||||
return false; |
double radian = (double)rotation; |
||||||
|
for(Triangle tri : CollisionManager.mesh_triangles.get(this.mesh_id)){ |
||||||
|
|
||||||
|
Triangle newTri = new Triangle(); |
||||||
|
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y),mesh_location,radian); |
||||||
|
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y),mesh_location,radian); |
||||||
|
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y),mesh_location,radian); |
||||||
|
|
||||||
//check to see if character is under or over the mesh
|
newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z); |
||||||
float head = charY + charHeight; |
newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z); |
||||||
if(head < this.minY || charY > this.maxY) |
newTri.point3 = new Point2D.Float(rotatedPoint3.x,rotatedPoint3.z); |
||||||
return false; |
|
||||||
|
newTri.sides = new ArrayList<>(); |
||||||
|
newTri.sides.add(new Line2D.Float(newTri.point1,newTri.point2)); |
||||||
|
newTri.sides.add(new Line2D.Float(newTri.point2,newTri.point3)); |
||||||
|
newTri.sides.add(new Line2D.Float(newTri.point3,newTri.point1)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
//check if any triangles intersect the movement path
|
public void MakeBounds(float rotation){ |
||||||
for(Triangle tri : triangles) |
double radian = (double)rotation; |
||||||
if(tri.collides(line)) |
Vector3f rotatedEnd = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_end_point.x,mesh_location.y,this.mesh_end_point.z),mesh_location,radian); |
||||||
return true; |
Vector3f rotatedRef = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_ref_point.x,mesh_location.y,this.mesh_ref_point.z),mesh_location,radian); |
||||||
|
|
||||||
//characters movement path did not intersect this mesh
|
this.mesh_bounds = new Rectangle2D.Float(); |
||||||
return false; |
this.mesh_bounds.setRect(rotatedEnd.x,rotatedEnd.z,Math.abs(rotatedEnd.x) - Math.abs(rotatedRef.x),Math.abs(rotatedEnd.z) - Math.abs(rotatedRef.z)); |
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,59 @@ |
|||||||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||||
|
// Magicbane Emulator Project © 2013 - 2022
|
||||||
|
// www.magicbane.com
|
||||||
|
|
||||||
|
|
||||||
|
package engine.devcmd.cmds; |
||||||
|
|
||||||
|
import engine.CollisionEngine.Mesh; |
||||||
|
import engine.Enum; |
||||||
|
import engine.devcmd.AbstractDevCmd; |
||||||
|
import engine.objects.*; |
||||||
|
|
||||||
|
public class ColliderCmd extends AbstractDevCmd { |
||||||
|
|
||||||
|
public ColliderCmd() { |
||||||
|
super("collider"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void _doCmd(PlayerCharacter pc, String[] words, |
||||||
|
AbstractGameObject target) { |
||||||
|
|
||||||
|
String newline = "\r\n "; |
||||||
|
String output; |
||||||
|
if(target.getObjectType().equals(Enum.GameObjectType.Building) == false){ |
||||||
|
throwbackInfo(pc,"Please Select A Building To Show Collider Data"); |
||||||
|
} |
||||||
|
Building building = (Building)target; |
||||||
|
output = "Collision Info:" + newline; |
||||||
|
output += "Total Meshes: " + building.buildingMeshes.size() + newline; |
||||||
|
for(Mesh mesh : building.buildingMeshes){ |
||||||
|
output += "-----------------------------"; |
||||||
|
output += "Mesh ID: " + mesh.mesh_id + newline; |
||||||
|
output += "Mesh Location: " + mesh.mesh_location + newline; |
||||||
|
output += "Mesh Min/Max: " + mesh.mesh_min_y + "/" + mesh.mesh_max_y + newline; |
||||||
|
output += "Mesh Triangle Count: " + mesh.triangles.size() + newline; |
||||||
|
output += "Mesh Rect: " + mesh.mesh_bounds + newline; |
||||||
|
output += "-----------------------------"; |
||||||
|
} |
||||||
|
|
||||||
|
throwbackInfo(pc,output); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String _getHelpString() { |
||||||
|
return "Displays Information About Colliders"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String _getUsageString() { |
||||||
|
return "' /collider displays collision info when selected on a building"; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue