Files
minecraft-pe-0.6.1/src/world/phys/HitResult.cpp
2026-03-02 22:04:18 +03:00

50 lines
840 B
C++
Executable File

#include "HitResult.h"
#include "../entity/Entity.h"
HitResult::HitResult()
: type(NO_HIT),
entity(NULL),
indirectHit(false)
{}
HitResult::HitResult(int x, int y, int z, int f, const Vec3& pos)
: type(TILE),
x(x),
y(y),
z(z),
f(f),
pos(pos),
indirectHit(false),
entity(NULL)
{
}
HitResult::HitResult(Entity* entity)
: type(ENTITY),
entity(entity),
pos(entity->x, entity->y, entity->z),
indirectHit(false)
{
}
HitResult::HitResult(const HitResult& hr)
: type(hr.type),
x(hr.x),
y(hr.y),
z(hr.z),
f(hr.f),
pos(hr.pos),
indirectHit(hr.indirectHit),
entity(hr.entity)
{
}
float HitResult::distanceTo(Entity* entity) const {
float xd = pos.x - entity->x;
float yd = pos.y - entity->y;
float zd = pos.z - entity->z;
return xd * xd + yd * yd + zd * zd;
}