Files
PlanetFleet/shell.cpp
T
devZoGok 179f4c28ac factored out a state manager
using GameManager via a singleton
2021-10-30 08:09:30 +03:00

44 lines
1.8 KiB
C++
Executable File

#include "shell.h"
#include "defConfigs.h"
#include "projectileData.h"
#include "util.h"
#include "unit.h"
using namespace game::core;
using namespace game::util;
using namespace irr::core;
namespace game{
namespace content{
Shell::Shell(Unit *unit, vector3df pos, vector3df dir, vector3df left, vector3df up, int id, int weaponTypeId, int weaponId) : Projectile(unit, nullptr, pos, dir, left, up, id, weaponTypeId, weaponId) {
this->speed = projectileData::speed[id][weaponTypeId][weaponId];
node->setScale(vector3df(1, 1, 1) * projectileData::scale[id][weaponTypeId][weaponId]);
initTime = getTime();
}
void Shell::update() {
//x=v*cos(a)*t
//y=v*sin(a)*t+0.5(g*t^2)
Projectile::update();
vector3df straightVec = vector3df(dirVec.X, 0, dirVec.Z).normalize();
double time = double(getTime() - initTime)/1000,
offsetX=speed * cos(angle) * time,
offsetY=speed * sin(angle) * time - .5 * (g * time * time);
pos = initPos + straightVec * offsetX + vector3df(0, offsetY, 0);
node->setPosition(pos);
updateVecs(straightVec, time);
checkForCollision();
}
void Shell::updateVecs(vector3df straightVec, float time) {
// f'(t)=dy/dx=(v*sin(a)+g*t)/(v*cos(a))
float tanAngle = -atan((speed * sin(angle) + g * time) / (speed * cos(angle)));
quaternion rotQuat = rotQuat.fromAngleAxis( tanAngle, leftVec);
dirVec = rotQuat*straightVec, upVec = rotQuat * vector3df(0, 1, 0);
vector3df rotVec=node->getRotation();
rotVec=vector3df(tanAngle/PI*180,rotVec.Y,rotVec.Z);
node->setRotation(rotVec);
}
}
}