Skip to content

Commit

Permalink
ENGINES: Add makeLookAt overload with coordinates for K1/K2
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii authored and DrMcCoy committed Jul 15, 2018
1 parent e3c8c96 commit ca3bae9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/engines/kotor/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ void Object::setOrientation(float x, float y, float z, float angle) {
_orientation[3] = angle;
}

void Object::makeLookAt(Object *target) {
float dx = target->_position[0] - _position[0];
float dy = target->_position[1] - _position[1];
void Object::makeLookAt(float x, float y) {
float dx = x - _position[0];
float dy = y - _position[1];
setOrientation(0.0f, 0.0f, 1.0f, Common::rad2deg(std::atan2(dy, dx)) - 90.0f);
}

void Object::makeLookAt(Object *target) {
makeLookAt(target->_position[0], target->_position[1]);
}

Room *Object::getRoom() {
return _room;
}
Expand Down
1 change: 1 addition & 0 deletions src/engines/kotor/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Object : public Aurora::NWScript::Object, public KotOR::ScriptContainer {
/** Set the object's orientation. */
virtual void setOrientation(float x, float y, float z, float angle);

void makeLookAt(float x, float y);
void makeLookAt(Object *target);

/** Get a room the object is in. */
Expand Down
10 changes: 7 additions & 3 deletions src/engines/kotor2/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ void Object::setOrientation(float x, float y, float z, float angle) {
_orientation[3] = angle;
}

void Object::makeLookAt(Object *target) {
float dx = target->_position[0] - _position[0];
float dy = target->_position[1] - _position[1];
void Object::makeLookAt(float x, float y) {
float dx = x - _position[0];
float dy = y - _position[1];
setOrientation(0.0f, 0.0f, 1.0f, Common::rad2deg(std::atan2(dy, dx)) - 90.0f);
}

void Object::makeLookAt(Object *target) {
makeLookAt(target->_position[0], target->_position[1]);
}

Room *Object::getRoom() {
return _room;
}
Expand Down
1 change: 1 addition & 0 deletions src/engines/kotor2/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Object : public Aurora::NWScript::Object, public KotOR2::ScriptContainer {
/** Set the object's orientation. */
virtual void setOrientation(float x, float y, float z, float angle);

void makeLookAt(float x, float y);
void makeLookAt(Object *target);

/** Get a room the object is in. */
Expand Down

0 comments on commit ca3bae9

Please sign in to comment.