Проблема моделирования XNA 3D Skybox с положением камеры и переводом модели - PullRequest
0 голосов
/ 16 апреля 2019

Я создал 3D-проект XNA 4.0 в сообществе VS 2015. У этого есть Скайбокс с моделью пули, которую я пытаюсь моделировать траекторию. Кажется, я не могу поставить камеру в правильное положение, и кажется, что перевод работает не по той оси.

Я попытался изменить положение модели, камеры и даже перспективы.

protected override void Update(GameTime gameTime)
{
    // Allows the game to exit
    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
        this.Exit();

    mDeltaTime = gameTime;
    mFlightTime += 0.1f;


    //if (mAngleInput != 0)
    //{
    //    mVelocity.X = (float)(mVelocityInput * Math.Cos(DegreeToRadian(mAngleInput)));
    //    mVelocity.Y = (float)(mVelocityInput * Math.Sin(DegreeToRadian(mAngleInput)));
    //}

    position = (mStartingPosition + mVelocity * mFlightTime) - (0.5f * mAcceleration * (float)Math.Pow(mFlightTime, 2)) / 5;


    // This updates the world matrix, so that it reflects the changes to the position
    // and angle.  Remember that this matrix determines where the model will be located
    // at in the 3D world.

    //   camTarget += new Vector3(0.1f,0,0);

    //           world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);
    //            view = Matrix.CreateLookAt(camTarget, position,  Vector3.UnitY);

    cameraPosition =  (distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)));
    Vector3 cameraTarget = position;
    //original Vector3 cameraTarget = new Vector3(0, 0, 0);

    viewVector = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(0));
    // viewVector.Normalize();

    angle += 0.002f;

    world = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);
    view = Matrix.CreateLookAt(cameraTarget, cameraPosition, Vector3.UnitY);
    //original view = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY);

    base.Update(gameTime);
}

Я надеялся, что модель запустится в определенной позиции и переместится по горизонтальной оси X и опустится вниз по вертикальной оси Y на основе формулы траектории, которую я использую. Остановка при достижении определенного значения Y.

1 Ответ

0 голосов
/ 19 апреля 2019

Вы перемещаете Камеру так, что она вращается вокруг Мирового начала на плоскости XZ по кругу с радиусом distance, постоянно глядя на пулю.

Чтобы увидеть движение пули,Камера должна находиться в фиксированном положении и вращаться.Принимая исходное положение маркера (0,0,0), ваша камера должна быть смещена по оси Z, чтобы вектор LookAt не выродился в NaN.

. Вы можете переместить камеруследовать за маркером на оси X, но он будет начинаться в середине экрана и опускаться прямо вниз.

Protected override void Update(GameTime gameTime)
{

    //mDeltaTime = gameTime;  
    mFlightTime += 0.1f;

    //position = (mStartingPosition + mVelocity * mFlightTime) - (0.5f * mAcceleration * (float)Math.Pow(mFlightTime, 2)) / 5;
    // The previous line can be simplified, assuming you do not need to jump to a specific time:
    position += mVelocity;
    mVelocity +=mAcceleration;
    mAcceleration += mDrag;
    mDrag = -bulletCoefficient * airDensity * mBulletCrossSection * (float)Math.Pow(mVelocity, 2) / 2; 

    cameraTarget = new Vector3(0,0,0);
    cameraPosition = new Vector3(0,0,-1);   

    world = Matrix.CreateScale(0.5f) * Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(position);
    view = Matrix.CreateLookAt(cameraTarget, cameraPosition, Vector3.UnitY);    

    base.Update(gameTime);
}
`
...