Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualMarlboroKing

Posted 09 February 2013 - 07:10 PM

This one is a pickle. Basically, I am trying to keep a 3D object in the center of the camera. I figured the easy way would be to invert the view matrix, add 5 to the mat.Forward member and everything would be O.K. Well, now I don't even see it. My previous attempts were fiddling with the UpDown / LeftRight rotations, they worked for the most part but couldn't get it corrected without really hardcoding the issue (and even then didn't work properly). Been stuck on this for the past 3 or 4 days, really not much else I can think of.

 

if( nType != EItemType.None )
{
    Matrix matWorld = Matrix.Invert( m_Player.m_Camera.View );
    matWorld.Translation += (matWorld.Forward * 5);

    m_Effect.World = matWorld;
    m_Effect.View = m_Player.m_Camera.View;
    m_Effect.Projection = m_Player.m_Camera.Projection;
    m_Effect.TextureEnabled = true;
    m_Effect.Texture = m_Texture;

    foreach( EffectPass pass in m_Effect.CurrentTechnique.Passes ) 
    {
        pass.Apply();

        m_GraphicsDevice.BlendState = BlendState.AlphaBlend;

        m_GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>( PrimitiveType.TriangleList,    m_Verts.ToArray(), 0, 2 );

    }
}

 

 

-Edit- For the most part, this works:

Matrix matWorld = Matrix.Identity *
					Matrix.CreateScale( 2f ) *
					Matrix.CreateRotationZ( -m_Player.m_Camera.UpDownRot ) *
					Matrix.CreateRotationY( m_Player.m_Camera.LeftRightRot - MathHelper.PiOver2 ) *
					Matrix.CreateTranslation( m_Player.Position + (m_Player.LookVector * 0.3f) );

 

 

I thought I introduced tearing, but nope. Was able to angle my camera just right and noticed it was my item. Fixed!


#1MarlboroKing

Posted 05 February 2013 - 12:59 AM

This one is a pickle. Basically, I am trying to keep a 3D object in the center of the camera. I figured the easy way would be to invert the view matrix, add 5 to the mat.Forward member and everything would be O.K. Well, now I don't even see it. My previous attempts were fiddling with the UpDown / LeftRight rotations, they worked for the most part but couldn't get it corrected without really hardcoding the issue (and even then didn't work properly). Been stuck on this for the past 3 or 4 days, really not much else I can think of.

 

if( nType != EItemType.None )
{
    Matrix matWorld = Matrix.Invert( m_Player.m_Camera.View );
    matWorld.Translation += (matWorld.Forward * 5);

    m_Effect.World = matWorld;
    m_Effect.View = m_Player.m_Camera.View;
    m_Effect.Projection = m_Player.m_Camera.Projection;
    m_Effect.TextureEnabled = true;
    m_Effect.Texture = m_Texture;

    foreach( EffectPass pass in m_Effect.CurrentTechnique.Passes ) 
    {
        pass.Apply();

        m_GraphicsDevice.BlendState = BlendState.AlphaBlend;

        m_GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>( PrimitiveType.TriangleList,    m_Verts.ToArray(), 0, 2 );

    }
}

 

 


PARTNERS