aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/EntityPos.cpp
blob: 02f716edf8685b6c5e47d844a03475b76a08dfc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "stdafx.h"
#include "Entity.h"
#include "EntityPos.h"

EntityPos::EntityPos(double x, double y, double z, float yRot, float xRot)
{
	this->x = x;
	this->y = y;
	this->z = z;
	this->yRot = yRot;
	this->xRot = xRot;
	rot = true;
	move = true;
}

EntityPos::EntityPos(double x, double y, double z)
{
	yRot = xRot = 0.0f;

	this->x = x;
	this->y = y;
	this->z = z;
	move = true;
	rot = false;
}

EntityPos::EntityPos(float yRot, float xRot)
{
	x = y = z = 0.0;

	this->yRot = yRot;
	this->xRot = xRot;
	rot = true;
	move = false;
}

EntityPos *EntityPos::lerp(shared_ptr<Entity> e, float f)
{
	double xd = e->x+(x-e->x)*f;
	double yd = e->y+(y-e->y)*f;
	double zd = e->z+(z-e->z)*f;

	float yrdd = Mth::wrapDegrees(yRot - e->yRot);
	float xrdd = Mth::wrapDegrees(xRot - e->xRot);

	float yrd = Mth::wrapDegrees(e->yRot + yrdd * f);
	float xrd = Mth::wrapDegrees(e->xRot + xrdd * f);

	if (rot && move)
	{
		return new EntityPos(xd, yd, zd, yrd, xrd);
	}
	if (move)
	{
		return new EntityPos(xd, yd, zd);
	}
	if (rot)
	{
		return new EntityPos(yrd, xrd);
	}
	return nullptr;
}