Implement SetActorRot(x,y,z,TRUE) and IsActorTurning.

This commit is contained in:
Daniel Schepler 2003-08-22 11:37:39 +00:00
parent b57b823c2b
commit b18077ac5d
3 changed files with 51 additions and 9 deletions

View File

@ -28,17 +28,28 @@
Actor::Actor(const char *name) :
name_(name), talkColor_(255, 255, 255), pos_(0, 0, 0),
pitch_(0), yaw_(0), roll_(0), walkRate_(0), turnRate_(0),
visible_(true), talkSound_(NULL)
visible_(true), talkSound_(NULL), turning_(false)
{
Engine::instance()->registerActor(this);
}
void Actor::turnTo(float pitch, float yaw, float roll) {
pitch_ = pitch;
roll_ = roll;
if (yaw_ != yaw) {
turning_ = true;
destYaw_ = yaw;
}
else
turning_ = false;
}
void Actor::walkForward() {
float dist = Engine::instance()->perSecond(walkRate_);
float yaw_deg = yaw_ * (M_PI / 180), pitch_deg = pitch_ * (M_PI / 180);
Vector3d forwardVec(-std::sin(yaw_deg) * std::cos(pitch_deg),
std::cos(yaw_deg) * std::cos(pitch_deg),
std::sin(pitch_deg));
float yaw_rad = yaw_ * (M_PI / 180), pitch_rad = pitch_ * (M_PI / 180);
Vector3d forwardVec(-std::sin(yaw_rad) * std::cos(pitch_rad),
std::cos(yaw_rad) * std::cos(pitch_rad),
std::sin(pitch_rad));
pos_ += forwardVec * dist;
}
@ -48,8 +59,8 @@ void Actor::turn(int dir) {
}
float Actor::angleTo(const Actor &a) const {
float yaw_deg = yaw_ * (M_PI / 180);
Vector3d forwardVec(-std::sin(yaw_deg), std::cos(yaw_deg), 0);
float yaw_rad = yaw_ * (M_PI / 180);
Vector3d forwardVec(-std::sin(yaw_rad), std::cos(yaw_rad), 0);
Vector3d delta = a.pos() - pos_;
delta.z() = 0;
return angle(forwardVec, delta) * (180 / M_PI);
@ -136,6 +147,23 @@ Costume *Actor::findCostume(const char *name) {
}
void Actor::update() {
if (turning_) {
float turnAmt = Engine::instance()->perSecond(turnRate_);
float dyaw = destYaw_ - yaw_;
while (dyaw > 180)
dyaw -= 360;
while (dyaw < -180)
dyaw += 360;
if (turnAmt >= std::abs(dyaw)) {
yaw_ = destYaw_;
turning_ = false;
}
else if (dyaw > 0)
yaw_ += turnAmt;
else
yaw_ -= turnAmt;
}
for (std::list<Costume *>::iterator i = costumeStack_.begin();
i != costumeStack_.end(); i++)
(*i)->update();

View File

@ -40,6 +40,8 @@ public:
void setRot(float pitch, float yaw, float roll) {
pitch_ = pitch; yaw_ = yaw; roll_ = roll;
}
void turnTo(float pitch, float yaw, float roll);
bool isTurning() const { return turning_; }
float pitch() const { return pitch_; }
float yaw() const { return yaw_; }
float roll() const { return roll_; }
@ -92,6 +94,10 @@ private:
ResPtr<Sound> talkSound_;
std::list<Costume *> costumeStack_;
// Variables for gradual turning
bool turning_;
float destYaw_;
friend class Engine;
};

10
lua.cpp
View File

@ -273,6 +273,9 @@ static void SetActorRot() {
float pitch = luaL_check_number(2);
float yaw = luaL_check_number(3);
float roll = luaL_check_number(4);
if (getbool(5))
act->turnTo(pitch, yaw, roll);
else
act->setRot(pitch, yaw, roll);
}
@ -283,6 +286,11 @@ static void GetActorRot() {
lua_pushnumber(act->roll());
}
static void IsActorTurning() {
Actor *act = check_actor(1);
pushbool(act->isTurning());
}
static void GetAngleBetweenActors() {
Actor *act1 = check_actor(1);
Actor *act2 = check_actor(2);
@ -949,7 +957,6 @@ static char *stubFuncs[] = {
"IsActorResting",
"IsActorMoving",
"CompleteActorChore",
"IsActorTurning",
"SetActorRoll",
"SetActorPitch",
"GetPointSector",
@ -1182,6 +1189,7 @@ struct luaL_reg builtins[] = {
{ "GetActorPos", GetActorPos },
{ "SetActorRot", SetActorRot },
{ "GetActorRot", GetActorRot },
{ "IsActorTurning", IsActorTurning },
{ "GetAngleBetweenActors", GetAngleBetweenActors },
{ "PutActorInSet", PutActorInSet },
{ "SetActorWalkRate", SetActorWalkRate },