Windows phone 7 带触摸的Windows phone 3D模型旋转

Windows phone 7 带触摸的Windows phone 3D模型旋转,windows-phone-7,xna,rotation,3d-modelling,Windows Phone 7,Xna,Rotation,3d Modelling,在我的windows phone应用程序中,我想使用屏幕触摸输入旋转3d模型 问题是, 起初一切正常,我可以使用触摸移动模型,但当我通过X轴旋转使对象倒置时,Y轴旋转会反转。 这是因为我的世界轴也改变了。 我试过很多方法 第一: 第二: 第三: 第四 结果是一样的。。现在我的思想在不受控制地旋转 如何使用旋转后不改变的静态轴?还有其他建议吗 谢谢。问题是你的数学没有问题。第二个轴的运动是反向的,因为从相反方向看,这是正确的运动,这是由旋转另一个轴引起的 与其在每一帧中从头开始围绕固定轴创建旋转,

在我的windows phone应用程序中,我想使用屏幕触摸输入旋转3d模型

问题是,

起初一切正常,我可以使用触摸移动模型,但当我通过X轴旋转使对象倒置时,Y轴旋转会反转。 这是因为我的世界轴也改变了。 我试过很多方法

第一:

第二:

第三:

第四

结果是一样的。。现在我的思想在不受控制地旋转

如何使用旋转后不改变的静态轴?还有其他建议吗


谢谢。

问题是你的数学没有问题。第二个轴的运动是反向的,因为从相反方向看,这是正确的运动,这是由旋转另一个轴引起的

与其在每一帧中从头开始围绕固定轴创建旋转,不如尝试存储一些当前方向向量(向上和向右、向前和向左),并将这些方向的小增量旋转应用于持久世界矩阵。当然,你也必须对你的方向进行同样的改变

这样,无论矩阵当前面对的是什么方向,都可以始终相对于它并按照您想要的方向旋转

编辑(代码):

class gameclass
{
Vector3 forward = Vector3.UnitZ;    //persistent orientation variables
Vector3 left    = -1 * Vector3.UnitX;
Vector3 up      = Vector3.UnitY

Matrix world = Matrix.Identitiy;

InputClass inputputclass;           //something to get your input data

void Update()
{
Vector3 pitch = inputclass.getpitch();          //vertical swipe
forward = Vector3.transform(forward,
    Matrix.CreateFromAxisAngle(left, pitch));
up      = Vector3.transform(up,
    Matrix.CreateFromAxisAngle(left, pitch));

Vector3 yaw = inputclass.getyaw();              //horizontal swipe

forward = Vector3.transform(forward,
    Matrix.CreateFromAxisAngle(up, yaw));
left    = Vector3.transform(left,
    Matrix.CreateFromAxisAngle(up, yaw));

forward.Normalize(); left.Normalize(); top.Normalize();  //avoid rounding errors

world = Matrix.CreateWorld(
    postition                     //this isn't defined in my code
    forward,
    up);
}


}

拥有自由的球形旋转并非易事。:)

问题是你的数学没有问题。第二个轴的运动是反向的,因为从相反方向看,这是正确的运动,这是由旋转另一个轴引起的

与其在每一帧中从头开始围绕固定轴创建旋转,不如尝试存储一些当前方向向量(向上和向右、向前和向左),并将这些方向的小增量旋转应用于持久世界矩阵。当然,你也必须对你的方向进行同样的改变

这样,无论矩阵当前面对的是什么方向,都可以始终相对于它并按照您想要的方向旋转

编辑(代码):

class gameclass
{
Vector3 forward = Vector3.UnitZ;    //persistent orientation variables
Vector3 left    = -1 * Vector3.UnitX;
Vector3 up      = Vector3.UnitY

Matrix world = Matrix.Identitiy;

InputClass inputputclass;           //something to get your input data

void Update()
{
Vector3 pitch = inputclass.getpitch();          //vertical swipe
forward = Vector3.transform(forward,
    Matrix.CreateFromAxisAngle(left, pitch));
up      = Vector3.transform(up,
    Matrix.CreateFromAxisAngle(left, pitch));

Vector3 yaw = inputclass.getyaw();              //horizontal swipe

forward = Vector3.transform(forward,
    Matrix.CreateFromAxisAngle(up, yaw));
left    = Vector3.transform(left,
    Matrix.CreateFromAxisAngle(up, yaw));

forward.Normalize(); left.Normalize(); top.Normalize();  //avoid rounding errors

world = Matrix.CreateWorld(
    postition                     //this isn't defined in my code
    forward,
    up);
}


}

拥有自由的球形旋转并非易事。:)

首先谢谢你的回答。我无法完全理解保持当前向量。世界的当前向量还是单位矩阵?一个简短的伪代码可能很有用。我正在编写你的代码。我的问题仍然存在。这并没有解决我的问题。但是你给了我一个解决这个问题的好主意,所以非常感谢你的考虑。我希望我能解决这个问题。首先谢谢你的回答。我无法完全理解保持当前向量。世界的当前向量还是单位矩阵?一个简短的伪代码可能很有用。我正在编写你的代码。我的问题仍然存在。这并没有解决我的问题。但是你给了我一个解决这个问题的好主意,所以非常感谢你的考虑。我希望我能解决这个问题。
  Matrix world = Matrix.Identity *Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),somerotation));
    world *= Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), somerotation));
    world *= Matrix.CreateTranslation(0,0,0);
Matrix world = Matrix.Identity;
            world = Matrix.CreateFromAxisAngle(Vector3.Up,somerotation);
            world *= Matrix.CreateFromAxisAngle(Vector3.Right,somerotation);
            world *= Matrix.CreateTranslation(0, 0,0);
class gameclass
{
Vector3 forward = Vector3.UnitZ;    //persistent orientation variables
Vector3 left    = -1 * Vector3.UnitX;
Vector3 up      = Vector3.UnitY

Matrix world = Matrix.Identitiy;

InputClass inputputclass;           //something to get your input data

void Update()
{
Vector3 pitch = inputclass.getpitch();          //vertical swipe
forward = Vector3.transform(forward,
    Matrix.CreateFromAxisAngle(left, pitch));
up      = Vector3.transform(up,
    Matrix.CreateFromAxisAngle(left, pitch));

Vector3 yaw = inputclass.getyaw();              //horizontal swipe

forward = Vector3.transform(forward,
    Matrix.CreateFromAxisAngle(up, yaw));
left    = Vector3.transform(left,
    Matrix.CreateFromAxisAngle(up, yaw));

forward.Normalize(); left.Normalize(); top.Normalize();  //avoid rounding errors

world = Matrix.CreateWorld(
    postition                     //this isn't defined in my code
    forward,
    up);
}


}