<commit_before>#include <Horde3DUtils.h>

#include "entity.h"
#include "math3d.h"


QHash<H3DNode, Entity*> Entity::entities;
QList<Entity*> Entity::scheduledOnceEntities;
QList<Entity*> Entity::scheduledRepeatingEntities;


Entity::Entity() :
	QObject(), _node(0), scheduledOnce(false), scheduledRepeating(false),
	_parentChanged(false), _transformChanged(false), _awaitingRemove(false),
	_logger(PLogManager::getLogger("entity")), _mgr(Horde3DManager::instance())
{
	throw new std::exception;
} // end Entity

Entity::Entity(H3DNode node, QObject *parent) :
	QObject(parent), _node(node), scheduledOnce(false), scheduledRepeating(false),
	_parentChanged(false), _transformChanged(false), _awaitingRemove(false),
	_logger(PLogManager::getLogger("entity")), _mgr(Horde3DManager::instance())
{
	float x, y, z;

	h3dGetNodeTransform(node,
			&x, &y, &z,
			&_pitch, &_heading, &_roll,
			NULL, NULL, NULL);

	_pos = QVector3D(x, y, z);
} // end Entity


Entity::Flags Entity::flags() const
{
	return (Entity::Flags) h3dGetNodeFlags(_node);
} // end flags

QQuaternion Entity::orientation() const
{
	return eulerToQuat(_heading, _pitch, _roll);
} // end orientation

qreal Entity::heading() const
{
	return _heading;
} // end heading

qreal Entity::pitch() const
{
	return _pitch;
} // end pitch

qreal Entity::roll() const
{
	return _roll;
} // end roll

QVector3D Entity::pos() const
{
	return _pos;
} // end pos

Entity* Entity::parent() const
{
	return _parent;
} // end parent

void Entity::setPos(qreal x, qreal y, qreal z)
{
	setPos(QVector3D(x, y, z));
} // end setPos

void Entity::setState(QString key, QVariant value)
{
	_state[key] = value;

	emit stateChanged();
} // end setState

void Entity::updateState(QVariantMap delta)
{
	for(QVariantMap::iterator it = delta.begin(); it != delta.end(); )
	{
		_state.insert(it.key(), it.value());
		it++;
	} // end for

	emit stateChanged();
} // end updateState

QVariant Entity::getState(QString key, QVariant defaultValue)
{
	return _state.value(key, defaultValue);
} // end getState

void Entity::setFlags(Flags flags)
{
	h3dSetNodeFlags(_node, flags, false);
	emit flagsChanged(flags);
} // end setFlags

void Entity::setOrientation(QQuaternion orientation)
{
	_transformChanged = true;

	quatToHPR(orientation, &_heading, &_pitch, &_roll);

	emit orientationChanged();
	emit headingChanged(_heading);
	emit pitchChanged(_pitch);
	emit rollChanged(_roll);

	scheduleOnce();
} // end setOrientation

void Entity::setHeading(qreal heading)
{
	_transformChanged = true;

	_heading = heading;

	emit orientationChanged();
	emit headingChanged(heading);

	scheduleOnce();
} // end setHeading

void Entity::setPitch(qreal pitch)
{
	_transformChanged = true;

	_pitch = pitch;<commit_msg>Convert radians to degrees when setting orientation from a quaternion.<commit_after>#include <cmath>

#include <Horde3DUtils.h>

#include "entity.h"
#include "math3d.h"


const qreal radiansPerDegree = 180 / M_PI;

QHash<H3DNode, Entity*> Entity::entities;
QList<Entity*> Entity::scheduledOnceEntities;
QList<Entity*> Entity::scheduledRepeatingEntities;


Entity::Entity() :
	QObject(), _node(0), scheduledOnce(false), scheduledRepeating(false),
	_parentChanged(false), _transformChanged(false), _awaitingRemove(false),
	_logger(PLogManager::getLogger("entity")), _mgr(Horde3DManager::instance())
{
	throw new std::exception;
} // end Entity

Entity::Entity(H3DNode node, QObject *parent) :
	QObject(parent), _node(node), scheduledOnce(false), scheduledRepeating(false),
	_parentChanged(false), _transformChanged(false), _awaitingRemove(false),
	_logger(PLogManager::getLogger("entity")), _mgr(Horde3DManager::instance())
{
	float x, y, z;

	h3dGetNodeTransform(node,
			&x, &y, &z,
			&_pitch, &_heading, &_roll,
			NULL, NULL, NULL);

	_pos = QVector3D(x, y, z);
} // end Entity


Entity::Flags Entity::flags() const
{
	return (Entity::Flags) h3dGetNodeFlags(_node);
} // end flags

QQuaternion Entity::orientation() const
{
	return eulerToQuat(_heading, _pitch, _roll);
} // end orientation

qreal Entity::heading() const
{
	return _heading;
} // end heading

qreal Entity::pitch() const
{
	return _pitch;
} // end pitch

qreal Entity::roll() const
{
	return _roll;
} // end roll

QVector3D Entity::pos() const
{
	return _pos;
} // end pos

Entity* Entity::parent() const
{
	return _parent;
} // end parent

void Entity::setPos(qreal x, qreal y, qreal z)
{
	setPos(QVector3D(x, y, z));
} // end setPos

void Entity::setState(QString key, QVariant value)
{
	_state[key] = value;

	emit stateChanged();
} // end setState

void Entity::updateState(QVariantMap delta)
{
	for(QVariantMap::iterator it = delta.begin(); it != delta.end(); )
	{
		_state.insert(it.key(), it.value());
		it++;
	} // end for

	emit stateChanged();
} // end updateState

QVariant Entity::getState(QString key, QVariant defaultValue)
{
	return _state.value(key, defaultValue);
} // end getState

void Entity::setFlags(Flags flags)
{
	h3dSetNodeFlags(_node, flags, false);
	emit flagsChanged(flags);
} // end setFlags

void Entity::setOrientation(QQuaternion orientation)
{
	_transformChanged = true;

	quatToHPR(orientation, &_heading, &_pitch, &_roll);
	_heading *= radiansPerDegree;
	_pitch *= radiansPerDegree;
	_roll *= radiansPerDegree;

	emit orientationChanged();
	emit headingChanged(_heading);
	emit pitchChanged(_pitch);
	emit rollChanged(_roll);

	scheduleOnce();
} // end setOrientation

void Entity::setHeading(qreal heading)
{
	_transformChanged = true;

	_heading = heading;

	emit orientationChanged();
	emit headingChanged(heading);

	scheduleOnce();
} // end setHeading

void Entity::setPitch(qreal pitch)
{
	_transformChanged = true;

	_pitch = pitch;
{'fraction_non_alphanumeric': 0.14469283576835065, 'fraction_numerical': 0.005104735081851787, 'mean_word_length': 5.692579505300353, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3475699', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1950, 'n_words': 449}