Я разрабатываю 3D-игру, в которой у меня есть камера за космическим кораблем, чтобы передвигаться. Я также добавил несколько астероидов в игру и хочу добавить маркеры. Я использовал кватернионы для управления траекторией космического корабля и камерой за ним. Тем не менее, когда я использую одни и те же кватернионы (определенное вращение, чтобы я мог рассчитать путь пули) на пуле, я получаю действительно забавный эффект, и пути совершенно неверны. Есть идеи, почему это происходит?
public void Update(GameTime gameTime)
{
lazerRotation = spaceship.spaceShipRotation;
Vector3 rotVector = Vector3.Transform(new Vector3(0, 0, -1), lazerRotation);
Position += rotVector* 10 * (float)gameTime.ElapsedGameTime.TotalSeconds;
//
}
//spaceShipRotation = Quaternion.Identity;
//Quaternion additionalRot = Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), leftRightRot) * Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRot);
//spaceShipRotation *= additionalRot;
//Vector3 addVector = Vector3.Transform(new Vector3(0, 0, -1), spaceShipRotation);
// futurePosition += addVector * movement * velocity;
public void Draw(Matrix view, Matrix projection)
{
// //Quaternion xaxis = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), spaceship.leftrightrot);
// //Quaternion yaxis = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), spaceship.updownrot);
// //Quaternion rot = xaxis * yaxis;
//Matrix x = Matrix.CreateRotationX(spaceship.leftrightrot);
//Matrix y = Matrix.CreateRotationY(spaceship.updownrot);
//Matrix rot = x * y;
Matrix[] transforms = new Matrix[Model.Bones.Count];
Model.CopyAbsoluteBoneTransformsTo(transforms);
Matrix worldMatrix = Matrix.CreateFromQuaternion(lazerRotation) * Matrix.CreateTranslation(Position);
foreach (ModelMesh mesh in Model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = worldMatrix * transforms[mesh.ParentBone.Index]; //position
effect.View = view; //camera
effect.Projection = projection; //2d to 3d
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
}
mesh.Draw();
}
}
Имейте в виду, что мой космический корабль - это поле объекта пули, и именно так я получаю космический корабль. Вращение кватерниона. Заранее спасибо.