refactor: Rename heading to facing to match nwscript.nss

This commit is contained in:
Vsevolod Kremianskii 2020-12-14 22:42:10 +07:00
parent 851c0f88ea
commit 4c0d51e172
26 changed files with 85 additions and 87 deletions

View file

@ -327,7 +327,7 @@ void ActionExecutor::executeJumpToObject(const shared_ptr<Object> &actor, Object
auto spatialActor = static_pointer_cast<SpatialObject>(actor);
spatialActor->setPosition(spatialObject->position());
spatialActor->setHeading(spatialObject->heading());
spatialActor->setFacing(spatialObject->facing());
action.complete();
}
@ -335,7 +335,7 @@ void ActionExecutor::executeJumpToObject(const shared_ptr<Object> &actor, Object
void ActionExecutor::executeJumpToLocation(const shared_ptr<Object> &actor, LocationAction &action, float dt) {
auto spatialActor = static_pointer_cast<SpatialObject>(actor);
spatialActor->setPosition(action.location()->position());
spatialActor->setHeading(action.location()->facing());
spatialActor->setFacing(action.location()->facing());
action.complete();
}

View file

@ -35,8 +35,8 @@ void Camera::update(float dt) {
void Camera::stopMovement() {
}
float Camera::heading() const {
return _heading;
float Camera::facing() const {
return _facing;
}
shared_ptr<CameraSceneNode> Camera::sceneNode() const {

View file

@ -36,11 +36,11 @@ public:
virtual void stopMovement();
float heading() const;
float facing() const;
std::shared_ptr<scene::CameraSceneNode> sceneNode() const;
protected:
float _heading { 0.0f };
float _facing { 0.0f };
std::shared_ptr<scene::CameraSceneNode> _sceneNode;
Camera() = default;

View file

@ -49,8 +49,8 @@ bool FirstPersonCamera::handle(const SDL_Event &event) {
}
bool FirstPersonCamera::handleMouseMotion(const SDL_MouseMotionEvent &event) {
_heading = glm::mod(
_heading - event.xrel * kMouseMultiplier,
_facing = glm::mod(
_facing - event.xrel * kMouseMultiplier,
glm::two_pi<float>());
_pitch = glm::clamp(
@ -65,7 +65,7 @@ bool FirstPersonCamera::handleMouseMotion(const SDL_MouseMotionEvent &event) {
void FirstPersonCamera::updateSceneNode() {
glm::quat orientation(glm::vec3(glm::half_pi<float>(), 0.0f, 0.0f));
orientation *= glm::quat(glm::vec3(_pitch, _heading, 0.0f));
orientation *= glm::quat(glm::vec3(_pitch, _facing, 0.0f));
glm::mat4 transform(1.0f);
transform = glm::translate(transform, _position);
@ -121,31 +121,31 @@ bool FirstPersonCamera::handleKeyUp(const SDL_KeyboardEvent &event) {
}
void FirstPersonCamera::update(float dt) {
float headingSin = glm::sin(_heading) * kMovementSpeed * dt;
float headingCos = glm::cos(_heading) * kMovementSpeed * dt;
float facingSin = glm::sin(_facing) * kMovementSpeed * dt;
float facingCos = glm::cos(_facing) * kMovementSpeed * dt;
float pitchSin = glm::sin(_pitch) * kMovementSpeed * dt;
bool positionChanged = false;
if (_moveForward) {
_position.x -= headingSin;
_position.y += headingCos;
_position.x -= facingSin;
_position.y += facingCos;
_position.z += pitchSin;
positionChanged = true;
}
if (_moveLeft) {
_position.x -= headingCos;
_position.y -= headingSin;
_position.x -= facingCos;
_position.y -= facingSin;
positionChanged = true;
}
if (_moveBackward) {
_position.x += headingSin;
_position.y -= headingCos;
_position.x += facingSin;
_position.y -= facingCos;
_position.z -= pitchSin;
positionChanged = true;
}
if (_moveRight) {
_position.x += headingCos;
_position.y += headingSin;
_position.x += facingCos;
_position.y += facingSin;
positionChanged = true;
}
if (positionChanged) {
@ -165,8 +165,8 @@ void FirstPersonCamera::setPosition(const glm::vec3 &pos) {
updateSceneNode();
}
void FirstPersonCamera::setHeading(float heading) {
_heading = heading;
void FirstPersonCamera::setFacing(float facing) {
_facing = facing;
updateSceneNode();
}

View file

@ -32,7 +32,7 @@ public:
void stopMovement() override;
void setPosition(const glm::vec3 &position);
void setHeading(float heading);
void setFacing(float facing);
private:
glm::vec3 _position { 0.0f };

View file

@ -94,16 +94,16 @@ void ThirdPersonCamera::update(float dt) {
if (_rotationSpeed > kMaxRotationSpeed) {
_rotationSpeed = kMaxRotationSpeed;
}
_heading += (_rotateCCW ? 1.0f : -1.0f) * _rotationSpeed * dt;
_heading = glm::mod(_heading, glm::two_pi<float>());
_facing += (_rotateCCW ? 1.0f : -1.0f) * _rotationSpeed * dt;
_facing = glm::mod(_facing, glm::two_pi<float>());
updateSceneNode();
}
void ThirdPersonCamera::updateSceneNode() {
glm::vec3 position(_targetPosition);
position.x += _style.distance * glm::sin(_heading);
position.y -= _style.distance * glm::cos(_heading);
position.x += _style.distance * glm::sin(_facing);
position.y -= _style.distance * glm::cos(_facing);
position.z += _style.height;
if (_findObstacle) {
@ -132,8 +132,8 @@ void ThirdPersonCamera::setTargetPosition(const glm::vec3 &position) {
updateSceneNode();
}
void ThirdPersonCamera::setHeading(float heading) {
_heading = heading;
void ThirdPersonCamera::setFacing(float facing) {
_facing = facing;
updateSceneNode();
}

View file

@ -36,7 +36,7 @@ public:
void stopMovement() override;
void setTargetPosition(const glm::vec3 &position);
void setHeading(float heading);
void setFacing(float facing);
void setFindObstacle(const std::function<bool(const glm::vec3 &, const glm::vec3 &, glm::vec3 &)> &fn);
void setStyle(const CameraStyle& style);

View file

@ -283,7 +283,7 @@ void Game::toggleInGameCameraType() {
FirstPersonCamera &firstPerson = static_cast<FirstPersonCamera &>(area->getCamera(CameraType::FirstPerson));
ThirdPersonCamera &thirdPerson = static_cast<ThirdPersonCamera &>(area->getCamera(CameraType::ThirdPerson));
firstPerson.setPosition(thirdPerson.sceneNode()->absoluteTransform()[3]);
firstPerson.setHeading(thirdPerson.heading());
firstPerson.setFacing(thirdPerson.facing());
_cameraType = CameraType::FirstPerson;
break;
}

View file

@ -231,7 +231,7 @@ void PartySelection::changeParty() {
party.addMember(creature);
}
area->loadParty(player->position(), player->heading());
area->loadParty(player->position(), player->facing());
area->fill(_game->sceneGraph());
}

View file

@ -161,24 +161,24 @@ void Map::drawPartyLeader(Mode mode, const glm::vec4 &bounds) const {
arrowPos.y = bounds[1] + 0.5f * bounds[3];
}
float heading;
float facing;
switch (_northAxis) {
case 0:
heading = -partyLeader->heading();
facing = -partyLeader->facing();
break;
case 1:
heading = glm::pi<float>() - partyLeader->heading();
facing = glm::pi<float>() - partyLeader->facing();
break;
case 2:
heading = glm::three_over_two_pi<float>() - partyLeader->heading();
facing = glm::three_over_two_pi<float>() - partyLeader->facing();
break;
default:
heading = glm::half_pi<float>() - partyLeader->heading();
facing = glm::half_pi<float>() - partyLeader->facing();
break;
}
glm::mat4 transform(1.0f);
transform = glm::translate(transform, arrowPos);
transform = glm::rotate(transform, heading, glm::vec3(0.0f, 0.0f, 1.0f));
transform = glm::rotate(transform, facing, glm::vec3(0.0f, 0.0f, 1.0f));
transform = glm::translate(transform, glm::vec3(-0.5f * kArrowSize, -0.5f * kArrowSize, 0.0f));
transform = glm::scale(transform, glm::vec3(kArrowSize, kArrowSize, 1.0f));

View file

@ -258,7 +258,7 @@ void Area::loadCameras(const GffStruct &git) {
}
}
void Area::initCameras(const glm::vec3 &entryPosition, float entryHeading) {
void Area::initCameras(const glm::vec3 &entryPosition, float entryFacing) {
glm::vec3 position(entryPosition);
position.z += 1.7f;
@ -266,12 +266,12 @@ void Area::initCameras(const glm::vec3 &entryPosition, float entryHeading) {
_firstPersonCamera = make_unique<FirstPersonCamera>(sceneGraph, _cameraAspect, glm::radians(kDefaultFieldOfView));
_firstPersonCamera->setPosition(position);
_firstPersonCamera->setHeading(entryHeading);
_firstPersonCamera->setFacing(entryFacing);
_thirdPersonCamera = make_unique<ThirdPersonCamera>(sceneGraph, _cameraAspect, _cameraStyle);
_thirdPersonCamera->setFindObstacle(bind(&Area::findCameraObstacle, this, _1, _2, _3));
_thirdPersonCamera->setTargetPosition(position);
_thirdPersonCamera->setHeading(entryHeading);
_thirdPersonCamera->setFacing(entryFacing);
_dialogCamera = make_unique<DialogCamera>(sceneGraph, _cameraStyle, _cameraAspect);
_dialogCamera->setFindObstacle(bind(&Area::findCameraObstacle, this, _1, _2, _3));
@ -417,7 +417,7 @@ ObjectList &Area::getObjectsByType(ObjectType type) {
void Area::landObject(SpatialObject &object) {
glm::vec3 position(object.position());
float heading = object.heading();
float facing = object.facing();
Room *room = nullptr;
if (getElevationAt(position, &object, room, position.z)) {
@ -435,13 +435,13 @@ void Area::landObject(SpatialObject &object) {
}
}
void Area::loadParty(const glm::vec3 &position, float heading) {
void Area::loadParty(const glm::vec3 &position, float facing) {
Party &party = _game->party();
for (int i = 0; i < party.size(); ++i) {
shared_ptr<Creature> member(party.getMember(i));
member->setPosition(position);
member->setHeading(heading);
member->setFacing(facing);
landObject(*member);
add(member);
@ -560,8 +560,8 @@ bool Area::moveCreatureTowards(const shared_ptr<Creature> &creature, const glm::
glm::vec2 delta(dest - glm::vec2(position));
glm::vec2 dir(glm::normalize(delta));
float heading = -glm::atan(dir.x, dir.y);
creature->setHeading(heading);
float facing = -glm::atan(dir.x, dir.y);
creature->setFacing(facing);
float speed = run ? creature->runSpeed() : creature->walkSpeed();
float speedDt = speed * dt;
@ -660,11 +660,11 @@ glm::vec3 Area::getSelectableScreenCoords(const shared_ptr<SpatialObject> &objec
return glm::project(position, view, projection, viewport);
}
void Area::update3rdPersonCameraHeading() {
void Area::update3rdPersonCameraFacing() {
shared_ptr<SpatialObject> partyLeader(_game->party().leader());
if (!partyLeader) return;
_thirdPersonCamera->setHeading(partyLeader->heading());
_thirdPersonCamera->setFacing(partyLeader->facing());
}
void Area::startDialog(const shared_ptr<SpatialObject> &object, const string &resRef) {

View file

@ -72,11 +72,11 @@ public:
void destroyObject(const SpatialObject &object);
void fill(scene::SceneGraph &sceneGraph);
void initCameras(const glm::vec3 &entryPosition, float entryHeading);
void initCameras(const glm::vec3 &entryPosition, float entryFacing);
bool moveCreatureTowards(const std::shared_ptr<Creature> &creature, const glm::vec2 &dest, bool run, float dt);
void onPartyLeaderMoved();
void startDialog(const std::shared_ptr<SpatialObject> &object, const std::string &resRef);
void update3rdPersonCameraHeading();
void update3rdPersonCameraFacing();
void update3rdPersonCameraTarget();
std::shared_ptr<SpatialObject> getObjectAt(int x, int y) const;
@ -113,7 +113,7 @@ public:
// Party
void loadParty(const glm::vec3 &position, float heading);
void loadParty(const glm::vec3 &position, float facing);
void unloadParty();
// END Party

View file

@ -86,7 +86,7 @@ void Creature::loadTransform(const GffStruct &gffs) {
float dirX = gffs.getFloat("XOrientation");
float dirY = gffs.getFloat("YOrientation");
_heading = -glm::atan(dirX, dirY);
_facing = -glm::atan(dirX, dirY);
updateTransform();
}

View file

@ -53,7 +53,7 @@ void Door::load(const GffStruct &gffs) {
_position[1] = gffs.getFloat("Y");
_position[2] = gffs.getFloat("Z");
_heading = gffs.getFloat("Bearing");
_facing = gffs.getFloat("Bearing");
_linkedToModule = boost::to_lower_copy(gffs.getString("LinkedToModule"));
_linkedTo = boost::to_lower_copy(gffs.getString("LinkedTo"));

View file

@ -51,7 +51,7 @@ void Module::load(const string &name, const GffStruct &ifo) {
loadInfo(ifo);
loadArea(ifo);
_area->initCameras(_info.entryPosition, _info.entryHeading);
_area->initCameras(_info.entryPosition, _info.entryFacing);
_area->runSpawnScripts();
loadPlayer();
@ -64,7 +64,7 @@ void Module::loadInfo(const GffStruct &ifo) {
float dirX = ifo.getFloat("Mod_Entry_Dir_X");
float dirY = ifo.getFloat("Mod_Entry_Dir_Y");
_info.entryHeading = -glm::atan(dirX, dirY);
_info.entryFacing = -glm::atan(dirX, dirY);
_info.entryArea = ifo.getString("Mod_Entry_Area");
}
@ -86,24 +86,24 @@ void Module::loadPlayer() {
void Module::loadParty(const string &entry) {
glm::vec3 position(0.0f);
float heading = 0.0f;
getEntryPoint(entry, position, heading);
float facing = 0.0f;
getEntryPoint(entry, position, facing);
_area->loadParty(position, heading);
_area->loadParty(position, facing);
_area->onPartyLeaderMoved();
_area->update3rdPersonCameraHeading();
_area->update3rdPersonCameraFacing();
_area->runOnEnterScript();
}
void Module::getEntryPoint(const string &waypoint, glm::vec3 &position, float &heading) const {
void Module::getEntryPoint(const string &waypoint, glm::vec3 &position, float &facing) const {
position = _info.entryPosition;
heading = _info.entryHeading;
facing = _info.entryFacing;
if (!waypoint.empty()) {
shared_ptr<SpatialObject> object(_area->find(waypoint));
if (object) {
position = object->position();
heading = object->heading();
facing = object->facing();
}
}
}

View file

@ -45,7 +45,7 @@ namespace game {
struct ModuleInfo {
std::string entryArea;
glm::vec3 entryPosition { 0.0f };
float entryHeading { 0.0f };
float entryFacing { 0.0f };
};
class Door;
@ -82,7 +82,7 @@ private:
void onObjectClick(const std::shared_ptr<SpatialObject> &object);
void onPlaceableClick(const std::shared_ptr<Placeable> &placeable);
void getEntryPoint(const std::string &waypoint, glm::vec3 &position, float &heading) const;
void getEntryPoint(const std::string &waypoint, glm::vec3 &position, float &facing) const;
// Loading

View file

@ -56,7 +56,7 @@ void Placeable::load(const GffStruct &gffs) {
_position[1] = gffs.getFloat("Y");
_position[2] = gffs.getFloat("Z");
_heading = gffs.getFloat("Bearing");
_facing = gffs.getFloat("Bearing");
updateTransform();
}

View file

@ -100,7 +100,7 @@ void SpatialObject::face(const SpatialObject &other) {
if (_id == other._id) return;
glm::vec2 dir(glm::normalize(other._position - _position));
_heading = -glm::atan(dir.x, dir.y);
_facing = -glm::atan(dir.x, dir.y);
updateTransform();
}
@ -156,8 +156,8 @@ const glm::vec3 &SpatialObject::position() const {
return _position;
}
float SpatialObject::heading() const {
return _heading;
float SpatialObject::facing() const {
return _facing;
}
const glm::mat4 &SpatialObject::transform() const {
@ -208,16 +208,16 @@ void SpatialObject::updateTransform() {
_transform = glm::translate(glm::mat4(1.0f), _position);
_transform *= glm::mat4_cast(_orientation);
if (_heading != 0.0f) {
_transform *= glm::eulerAngleZ(_heading);
if (_facing != 0.0f) {
_transform *= glm::eulerAngleZ(_facing);
}
if (_model) {
_model->setLocalTransform(_transform);
}
}
void SpatialObject::setHeading(float heading) {
_heading = heading;
void SpatialObject::setFacing(float facing) {
_facing = facing;
updateTransform();
}

View file

@ -64,7 +64,7 @@ public:
scene::SceneGraph &sceneGraph();
Room *room() const;
const glm::vec3 &position() const;
float heading() const;
float facing() const;
const glm::mat4 &transform() const;
bool visible() const;
std::shared_ptr<scene::ModelSceneNode> model() const;
@ -73,7 +73,7 @@ public:
void setRoom(Room *room);
void setPosition(const glm::vec3 &position);
void setHeading(float heading);
void setFacing(float facing);
void setVisible(bool visible);
// Inventory
@ -95,7 +95,7 @@ protected:
scene::SceneGraph *_sceneGraph { nullptr };
glm::vec3 _position { 0.0f };
glm::quat _orientation { 1.0f, 0.0f, 0.0f, 0.0f };
float _heading { 0.0f };
float _facing { 0.0f };
glm::mat4 _transform { 1.0f };
bool _visible { true };
std::shared_ptr<scene::ModelSceneNode> _model;

View file

@ -43,7 +43,7 @@ void Waypoint::load(const GffStruct &gffs) {
float dirX = gffs.getFloat("XOrientation");
float dirY = gffs.getFloat("YOrientation");
_heading = -glm::atan(dirX, dirY);
_facing = -glm::atan(dirX, dirY);
updateTransform();
}

View file

@ -112,17 +112,17 @@ void Player::update(float dt) {
shared_ptr<Creature> partyLeader(_party->leader());
if (!partyLeader || partyLeader->isMovementRestricted()) return;
float heading = 0.0f;
float facing = 0.0f;
bool movement = true;
if (_moveForward) {
heading = _camera->heading();
facing = _camera->facing();
} else if (_moveBackward) {
heading = _camera->heading() + glm::pi<float>();
facing = _camera->facing() + glm::pi<float>();
} else if (_moveLeft) {
heading = _camera->heading() + glm::half_pi<float>();
facing = _camera->facing() + glm::half_pi<float>();
} else if (_moveRight) {
heading = _camera->heading() - glm::half_pi<float>();
facing = _camera->facing() - glm::half_pi<float>();
} else {
movement = false;
}
@ -133,8 +133,8 @@ void Player::update(float dt) {
actions.clear();
glm::vec2 dest(partyLeader->position());
dest.x -= 100.0f * glm::sin(heading);
dest.y += 100.0f * glm::cos(heading);
dest.x -= 100.0f * glm::sin(facing);
dest.y += 100.0f * glm::cos(facing);
if (_area->moveCreatureTowards(partyLeader, dest, true, dt)) {
partyLeader->setMovementType(Creature::MovementType::Run);

View file

@ -71,7 +71,7 @@ private:
const VariableTypesList &argTypes,
const T &fn) {
_routines.emplace_back(name, retType, argTypes, std::bind(fn, this, _1, _2));
_routines.emplace_back(name, retType, argTypes, std::bind(fn, this, std::placeholders::_1, std::placeholders::_2));
}
void addKotorRoutines();

View file

@ -46,7 +46,7 @@ Variable Routines::getLocation(const VariablesList &args, ExecutionContext &ctx)
auto object = getSpatialObject(args, 0);
if (object) {
glm::vec3 position(object->position());
float facing = object->heading();
float facing = object->facing();
result.engineType = make_shared<Location>(move(position), facing);
} else {
warn("Routines: getLocation: object is invalid");

View file

@ -18,7 +18,6 @@
#include "routines.h"
using namespace std;
using namespace std::placeholders;
using namespace reone::script;

View file

@ -188,7 +188,7 @@ Variable Routines::getFacing(const VariablesList &args, ExecutionContext &ctx) {
warn("Routines: getFacing: target is invalid");
return -1.0f;
}
return glm::degrees(target->heading());
return glm::degrees(target->facing());
}
Variable Routines::getPosition(const VariablesList &args, ExecutionContext &ctx) {

View file

@ -18,7 +18,6 @@
#include "routines.h"
using namespace std;
using namespace std::placeholders;
using namespace reone::script;