2011-06-08 17 views
1

进出口试图对其形状创建具有球跷跷板,其基于所述形状角度,球滚动。球滚动轴承在DirectX用C#

这里是它的屏幕截图。

enter image description here

所以,基于由跟踪条值generatated角度的跷跷板运动的形状。

下面是声明的变量:

private const float ONE_DEGREE = 0.0174532924f; 
     private ID3DMesh tab;   
     private ID3DMesh ball; 

的 '标签' 是可变的形状。

此方法将形状的角度:

public void setShapeAngle(float degree) 
{    
    tabTargetAngle = Util.DegreeToRadian(degree); 
} 

这里是更新它的方法:

public void Update(int elapsedTime) 
     { 

      if (tab.Pitch != tabTargetAngle) 
      { 
       if (tabTargetAngle > tab.Pitch) 
       { 
        if (tab.Pitch >= (tabTargetAngle - ONE_DEGREE)) 
        { 
         tab.Pitch = tabTargetAngle; 

        } 
        else 
        { 
         tab.Pitch += tabuaSpeed * elapsedTime;       
        } 
       } 
       else if (tabTargetAngle < tab.Pitch) 
       { 
        if (tab.Pitch <= (tabTargetAngle + ONE_DEGREE)) 
        { 
         tab.Pitch = tabTargetAngle; 

        } 
        else 
        { 
         tab.Pitch -= tabuaSpeed * elapsedTime;       

        } 

       } 

      }             
     } 

对象的一切,都是ID3DMesh对象。这是ID3DMesh类的代码。

public interface ID3DMesh : IDisposable 
    { 
     Color Ambient { get; set; } 
     CollisionTestMethod CollisionDetectionMethod { get; set; } 
     Mesh D3DXMesh { get; } 
     Color Diffuse { get; set; } 
     Color Emissive { get; set; } 
     Material[] Materials { get; set; } 
     ID3DMesh Parent { get; set; } 
     float Pitch { get; set; } 
     Vector3 PivotOffset { get; set; } 
     float PivotOffsetX { get; set; } 
     float PivotOffsetY { get; set; } 
     float PivotOffsetZ { get; set; } 
     Vector3 Position { get; set; } 
     RenderOptions RenderSettings { get; set; } 
     float Roll { get; set; } 
     Vector3 Scale { get; set; } 
     float ScaleX { get; set; } 
     float ScaleY { get; set; } 
     float ScaleZ { get; set; } 
     Color Specular { get; set; } 
     float SpecularSharpness { get; set; } 
     Texture[] Textures { get; set; } 
     Color WireColor { get; set; } 
     float X { get; set; } 
     float Y { get; set; } 
     float Yaw { get; set; } 
     float Z { get; set; } 

     MeshBoundingBox GetBoundingBox(); 
     MeshBoundingSphere GetBoundingSphere(); 
     float GetDepth(); 
     float GetHeight(); 
     float GetWidth(); 
     Matrix GetWorldMatrix(); 
     bool Intersects(ID3DMesh mesh); 
     void Link(ID3DMesh parentMesh, Vector3 linkPosition); 
     void Move(float xAmount, float yAmount, float zAmount); 
     void Render(); 
     void RenderPlanarShadow(Plane groundPlane, Light light, bool allowDoubleBlending); 
     void SetDepth(float depth); 
     void SetDepth(float depth, bool uniformScale); 
     void SetHeight(float height); 
     void SetHeight(float height, bool uniformScale); 
     void SetPlanarShadowOpacity(float shadowOpacity); 
     void SetScale(float amount); 
     void SetScale(float xAmount, float yAmount, float zAmount); 
     void SetSize(float width, float height, float depth); 
     void SetWidth(float width); 
     void SetWidth(float width, bool uniformScale); 
    } 

我试着使用Move(float,float,float)方法。但它并没有像它应该的那样移动。如果你能帮助我。

谢谢。

回答

2

(注:下面我会忽略第三个层面,因为球总是沿着同一平面上移动)

如果我们把跷跷板作为参照系,我想的运动球将类似于harmonic oscillator。也就是说,在给定的时间瞬间沿跷跷板的球的位置,S(t)的,将通过下面的公式给出:

S(t)的= L cos(2π吨/ T +φ)

其中L是跷跷板的长度(谐波的幅度),T是球从跷跷板的一端移动到另一端并返回到开始所花费的时间(谐波的周期)。 φ是谐波的初始相位,用来调整公式,所以s(0)给出了起始位置。如果你想让它在中心开始,你需要使s(0)= 0,这意味着你需要余弦为0.所以你必须使φ为π/ 2(90度),因为cos(π/2)= 0.

有了这个,你可以通过改变世界变换把球放在原地。如果将它旋转到跷跷板的当前角度(我们称之为θ(t)),则可以将球沿着xx轴平移s(t)的值。

这相当于将(s(t),θ(t))视为极坐标中球的位置。然后,你可以在给定的时间笛卡尔坐标(X(t),Y(t))的这些公式:

X(t)= S(t)的COS(θ)

ÿ (t)= s(t)sin(θ)

1

(假设上矢量为(0,1,0),标签与X轴对齐)

你能想象的球会必须“滚”下沿的标签X轴,你将不得不计算的Y位置,让它坚持选项卡。

你可以使用Move()方法为X位置,球的速度都有影响它是在一个相对的方式X位置。

通过设置Y属性,可以更容易地计算每个X位置的Y位置(只要球保留在选项卡上)。

如果我是你,我会通过创建计算Y位置,以使球“贴标签”的任何X位置的方法开始。

如果没有你指出正确的方向,请更多地讨论“它没有移动,因为它应该”有点。