mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Add basic function for model picking. Needs to be addressed by #29.
This commit is contained in:
parent
e95429dbef
commit
e97ff0da1f
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
@ -31,6 +32,24 @@ namespace ClassicalSharp {
|
||||
}
|
||||
}
|
||||
|
||||
public byte GetClosetPlayer( Vector3 eyePos, Vector3 dir ) {
|
||||
float dist = float.PositiveInfinity;
|
||||
byte targetId = 255;
|
||||
|
||||
for( int i = 0; i < Players.Length - 1; i++ ) { // -1 because we don't want to pick against local player
|
||||
Player p = Players[i];
|
||||
if( p == null ) continue;
|
||||
BoundingBox bounds = p.Bounds;
|
||||
|
||||
float t0, t1;
|
||||
if( IntersectionUtils.RayIntersectsBox( eyePos, dir, bounds.Min, bounds.Max, out t0, out t1 ) ) {
|
||||
dist = t0;
|
||||
targetId = (byte)i;
|
||||
}
|
||||
}
|
||||
return targetId;
|
||||
}
|
||||
|
||||
public Player this[int id] {
|
||||
get { return Players[id]; }
|
||||
set { Players[id] = value; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user