Add basic function for model picking. Needs to be addressed by #29.

This commit is contained in:
UnknownShadow200 2015-07-02 08:00:38 +10:00
parent e95429dbef
commit e97ff0da1f

View File

@ -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; }