从矢量中获取xyz

时间:2014-09-11 20:31:09

标签: c++ vector coordinates

下面是一个帮助控制汽车的功能,它创建一个矩阵然后使用该矩阵创建一个矢量,现在我希望能够从该矢量获得x,y和z。 我已经尝试了i32 CarX = vecVel.GetX;,但我得到了这三个错误

error C3867: 'Vec2::GetX': function call missing argument list; use '&Vec2::GetX' to create a pointer to member
error C2440: '=' : cannot convert from 'const float (__thiscall Vec2::* )(void) const' to 'i32'
IntelliSense: a pointer to a bound function may only be used to call the function

我认为i32 carX = vecVel[0];可能有效,但没有。 i32 carX = vecVel.FX;无效,因为它说FX受到保护

void APIENTRY Car_Update(Object *pObject)
{

    Car *pCar=(Car *)pObject;
    Matrix mat;
    Matrix *pmat;
    Object_GetMatrix(pObject,&mat);
    Object_GetMatrixPtr(pObject,&pmat);

    Vec3 vecVel(pCar->vecBounce + mat.GetColumn(2) * pCar->fSpeed);

    pCar->vecBounce = pCar->vecBounce *0.5f;
    mat.RotY(pCar->fRot);
    mat.SetColumn(3, vecVel + mat.GetColumn(3));
    //mat.GetColumn;

    pCar->fSpeed *= 0.8f;// friction

    pCar->fRotWheelLast = pCar->fRotWheel;
    pCar->fRotWheel += (pCar->fSpeed*30.f);

    Level_GenerateDraw( &mat.GetColumn(3) );
    Level_GenerateAlphas( &mat.GetColumn(3) );

    Car_Light(pCar);

    Collision_UpdateMat(pCar->pBox, &mat);

    float fCol=1.f;

    while(Level_TestBoxCollide( pCar->pBox ))
    {

        ColData Data;
        float fDot;

        Collision_GetColData(&Data);    

        fDot = -1.8f * Data.normal.Dot(vecVel);

        pCar->vecBounce = (vecVel + Data.normal * fDot)*fCol;

        pCar->fSpeed = 0.f;

        mat.SetColumn(3, pmat->GetColumn(3) + pCar->vecBounce);

        Collision_UpdateMat(pCar->pBox, &mat);

        vecVel = pCar->vecBounce;

        fCol-=0.1f;

        if(fCol<0.f)
        {
            pCar->vecBounce.Set(0.f,0.f,0.f);
            mat.SetColumn(3, pmat->GetColumn(3));

            Collision_UpdateMat(pCar->pBox, &mat);

            ASSERT(!Level_TestBoxCollide( pCar->pBox ), "still colliding");
        }
    }

    Object_SetMatrix(pObject, &mat);

    Vec3 vecWidth(mat.GetColumn(0)*0.2f);
    Vec3 vecWheel1(mat.GetColumn(3) - mat.GetColumn(0)*0.6f);
    Vec3 vecWheel2(mat.GetColumn(3) + mat.GetColumn(0)*0.6f);

    vecWheel1.SetY( vecWheel1.GetY() - 0.7f );
    vecWheel2.SetY( vecWheel2.GetY() - 0.7f );
    Trail_AddPoint((Object*)pCar->pTrail[0], vecWheel1, vecWidth);
    Trail_AddPoint((Object*)pCar->pTrail[1], vecWheel2, vecWidth);

}

1 个答案:

答案 0 :(得分:0)

编译器告诉您,为了在类上调用函数,您必须使用括号跟随调用: i32 carX = vecVel.FX() 。这假设FX是一个在Vec2上返回i32值的函数。