1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-10 04:42:38 +01:00

Script: 0176 (Get Object Heading)

This commit is contained in:
Jannik Vogel 2016-05-27 13:15:30 +02:00
parent 7e3eb744f8
commit 0d089c9f5d
3 changed files with 16 additions and 0 deletions

View File

@ -104,6 +104,7 @@ public:
virtual glm::quat getRotation() const;
virtual void setRotation(const glm::quat &orientation);
float getHeading() const;
/**
* @brief setHeading Rotates the object to face heading, in degrees.
*/

View File

@ -3,6 +3,7 @@
#include <loaders/LoaderDFF.hpp>
#include <engine/Animator.hpp>
#include <data/Skeleton.hpp>
#include <glm/gtc/quaternion.hpp>
GameObject::~GameObject()
{
@ -32,6 +33,12 @@ void GameObject::setRotation(const glm::quat& orientation)
rotation = orientation;
}
float GameObject::getHeading() const
{
auto hdg = glm::roll(getRotation());
return hdg / glm::pi<float>() * 180.f;
}
void GameObject::setHeading(float heading)
{
auto hdg = (heading / 180.f) * glm::pi<float>();

View File

@ -512,6 +512,13 @@ void game_set_player_heading(const ScriptArguments& args)
object->setHeading(args[1].real);
}
template <class Tobject>
void game_get_object_heading(const ScriptArguments& args)
{
auto object = args.getObject<Tobject>(0);
*args[1].globalReal = object->getHeading();
}
template <class Tobject>
void game_set_object_heading(const ScriptArguments& args)
{
@ -1172,6 +1179,7 @@ ObjectModule::ObjectModule()
bindUnimplemented(0x0174, game_get_character_heading, 2, "Get Vehicle Heading" );
bindFunction(0x0175, game_set_object_heading<VehicleObject>, 2, "Set Vehicle heading" );
bindFunction(0x0176, game_get_object_heading<InstanceObject>, 2, "Get Object heading" );
bindFunction(0x0177, game_set_object_heading<InstanceObject>, 2, "Set Object heading" );
bindUnimplemented( 0x0192, game_character_stand_still, 1, "Make character stand still" );