Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 电子游戏中的物理,在角加速度上施加扭矩_C++_Math_Physics_Game Physics - Fatal编程技术网

C++ 电子游戏中的物理,在角加速度上施加扭矩

C++ 电子游戏中的物理,在角加速度上施加扭矩,c++,math,physics,game-physics,C++,Math,Physics,Game Physics,我正在做一个游戏项目,关于2d中自上而下的汽车游戏。我想自己管理所有的物理。我正在写这本书:实现物理学 从现在起,我的物理引擎可以处理不同轴上的力。但是我在实现正确的旋转模拟时遇到了一些问题。我试着施加一些力矩来求角加速度。所以我实现了一个惯性张量矩阵: setMass(400.f); Matrix3 it; it.setBlockInertiaTensor(Vector3(2, 1, 1), 400); setInertiaTensor(it); void setBlockInertiaTe

我正在做一个游戏项目,关于2d中自上而下的汽车游戏。我想自己管理所有的物理。我正在写这本书:实现物理学

从现在起,我的物理引擎可以处理不同轴上的力。但是我在实现正确的旋转模拟时遇到了一些问题。我试着施加一些力矩来求角加速度。所以我实现了一个惯性张量矩阵:

setMass(400.f);
Matrix3 it;
it.setBlockInertiaTensor(Vector3(2, 1, 1), 400);
setInertiaTensor(it);

void setBlockInertiaTensor(const Vector3 &halfSizes, float mass)
{
    Vector3 squares = halfSizes.componentProduct(halfSizes);
    setInertiaTensorCoeffs(0.3f*mass*(squares.y + squares.z),
        0.3f*mass*(squares.x + squares.z),
        0.3f*mass*(squares.x + squares.y));
}
为了施加扭矩,我在我的汽车的车身点上施加一个力,通过一个叉积得到扭矩:

player->addForceAtBodyPoint(Vector3(-2000, 1000, 0), Vector3(0, 100, 0));

void AObject::addForceAtBodyPoint(const Vector3 &force, const Vector3 &point)
{
    Vector3 pt = getPointInWorldSpace(point);
    addForceAtPoint(force, pt);
}

void AObject::addForceAtPoint(const Vector3 &force,
    const Vector3 &point)
{
    // Convert to coordinates relative to center of mass.
    Vector3 pt = point;
    pt -= _position;

    _forceAccumulate += force;
    _torqueAccumulate += pt % force;
    //std::cout << "torque x " << pt.x << " y " << pt.y  <<  " z "<< pt.z <<  std::endl;
}

Vector3 Vector3::operator%(const Vector3 &vector) const
{
    return Vector3(y*vector.z - z*vector.y,
        z*vector.x - x*vector.z,
        x*vector.y - y*vector.x);
}

而且定位根本不起作用。我不太擅长物理方面的东西,所以我认为我误解了惯性张量对力矩的物理实现

如果你的游戏是2D自上而下的,那么你只能在Z方向旋转。即进入和离开屏幕。因此,您可以简化问题并避免使用3D张量。在这种情况下,在你的汽车类中,我会有一个叫做旋转的私有变量。e、 g

private:
    double angle;
    double tourque;
public:
    void updateTorque(*some way of passing forces*)
    {
        double total_t = 0;
        for each force
        {
            double t = use cosine and length to point to generate a tourque
            total_t = t + total_t
        }
    }
    void update_angle // place your integration routine here and call once per loop
阅读,也许这会有所帮助。
private:
    double angle;
    double tourque;
public:
    void updateTorque(*some way of passing forces*)
    {
        double total_t = 0;
        for each force
        {
            double t = use cosine and length to point to generate a tourque
            total_t = t + total_t
        }
    }
    void update_angle // place your integration routine here and call once per loop