mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Add Register and ConvertRotation member functions. ConvertRotation converts from degrees to the -32768 to 32767 system the renderer seems to expect.
Changed clamp values to -359 and 359, as 360 = -360 = 0.
This commit is contained in:
parent
61284fe571
commit
d00428f3fb
2 changed files with 28 additions and 3 deletions
|
@ -1,6 +1,17 @@
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
#include "GameScriptRotation.h"
|
#include "GameScriptRotation.h"
|
||||||
|
|
||||||
|
void GameScriptRotation::Register(sol::state* state)
|
||||||
|
{
|
||||||
|
state->new_usertype<GameScriptRotation>("Rotation",
|
||||||
|
sol::constructors<GameScriptRotation(int, int, int)>(),
|
||||||
|
"X", sol::property(&GameScriptRotation::GetX, &GameScriptRotation::SetX),
|
||||||
|
"Y", sol::property(&GameScriptRotation::GetY, &GameScriptRotation::SetY),
|
||||||
|
"Z", sol::property(&GameScriptRotation::GetZ, &GameScriptRotation::SetZ)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GameScriptRotation::GameScriptRotation(int x, int y, int z)
|
GameScriptRotation::GameScriptRotation(int x, int y, int z)
|
||||||
{
|
{
|
||||||
SetX(x);
|
SetX(x);
|
||||||
|
@ -8,6 +19,14 @@ GameScriptRotation::GameScriptRotation(int x, int y, int z)
|
||||||
SetZ(z);
|
SetZ(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GameScriptRotation::ConvertRotation(int a)
|
||||||
|
{
|
||||||
|
short component = std::clamp(a, -359, 359);
|
||||||
|
component = static_cast<int>(lround((component/360.0f) * std::numeric_limits<unsigned short>::max()));
|
||||||
|
component = component - std::numeric_limits<short>::max();
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
int GameScriptRotation::GetX() const
|
int GameScriptRotation::GetX() const
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
|
@ -15,7 +34,7 @@ int GameScriptRotation::GetX() const
|
||||||
|
|
||||||
void GameScriptRotation::SetX(int x)
|
void GameScriptRotation::SetX(int x)
|
||||||
{
|
{
|
||||||
this->x = std::clamp(x, -360, 360);
|
this->x = ConvertRotation(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameScriptRotation::GetY() const
|
int GameScriptRotation::GetY() const
|
||||||
|
@ -25,7 +44,7 @@ int GameScriptRotation::GetY() const
|
||||||
|
|
||||||
void GameScriptRotation::SetY(int y)
|
void GameScriptRotation::SetY(int y)
|
||||||
{
|
{
|
||||||
this->y = std::clamp(y, -360, 360);
|
this->y = ConvertRotation(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameScriptRotation::GetZ() const
|
int GameScriptRotation::GetZ() const
|
||||||
|
@ -35,5 +54,5 @@ int GameScriptRotation::GetZ() const
|
||||||
|
|
||||||
void GameScriptRotation::SetZ(int z)
|
void GameScriptRotation::SetZ(int z)
|
||||||
{
|
{
|
||||||
this->z = std::clamp(z, -360, 360);
|
this->z = ConvertRotation(z);
|
||||||
}
|
}
|
|
@ -2,14 +2,20 @@
|
||||||
|
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
|
|
||||||
|
namespace sol {
|
||||||
|
class state;
|
||||||
|
}
|
||||||
|
|
||||||
class GameScriptRotation {
|
class GameScriptRotation {
|
||||||
private:
|
private:
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int z;
|
int z;
|
||||||
|
int ConvertRotation(int a);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameScriptRotation(int x, int y, int z);
|
GameScriptRotation(int x, int y, int z);
|
||||||
|
static void Register(sol::state*);
|
||||||
|
|
||||||
int GetX() const;
|
int GetX() const;
|
||||||
void SetX(int x);
|
void SetX(int x);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue