Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualMarlboroKing

Posted 08 February 2013 - 02:38 PM

I'd do something like this:

 

- when camera moves

- the object you want to keep static to camera -> worldpos = camerapos

- camerapos.z -= 5 or += 5?

 

Tried. I figured something out new.. Well, observed. I imported a model that was designed in 3DWings into my content solution, redid my method and bam, it worked.

It appears I'm missing something (duh!) that the imported model has, that my coded model doesn't. I'm explaining what I've done below, but before I do, please note that I am still new to 3D and my code may not be completely efficient, the second is temporarily :]

 

I have a tilesheet of textures, used for the UV coordinates. I'm essentially taking the coordinates from the UV and building a array of VertexPositionTexture for the model:

 

VertexBuilder.BuildVertexFromUV

public static List<VertexPositionTexture> BuildVertexFromUV( Vector3 vecPosition, Vector2[] vecUV )
{
	List<VertexPositionTexture> ret = new List<VertexPositionTexture>();

	foreach( Vector2 uv in vecUV )
		ret.Add( new VertexPositionTexture( vecPosition + new Vector3(uv.X, uv.Y, 0), uv ) );

	return ret;
}

 

 

ItemRender.OnChangeItemInHand

public void OnChangeItemInHand( EItemType nType )
{
	if( nType != m_nItemHold )
	{
		m_Verts.Clear();

		m_Verts = BlockVertexBuilder.BuildVertexFromUV( new Vector3(0, 0, 0),
		new Vector3( 1, 0, 2 ),
		ItemTexture.m_UVMappings[(int)nType] );

		m_VB = new VertexBuffer( m_GraphicsDevice, typeof(VertexPositionTexture), m_Verts.Count, BufferUsage.WriteOnly );
		m_VB.SetData( m_Verts.ToArray() );

		m_nItemHold = nType;
	}
}

 

Again, all fine and dandy. Now, the glorified issue.

 

 

ItemRender.RenderItemInHand

 

public void RenderItemInHand( GameTime gameTime )
{
	EItemType nType = m_Player.PlayerInventory.GetHoldingItemType();
	OnChangeItemInHand( nType ); //Remember, temporarily :]

	if( nType != EItemType.None )
	{
		Matrix matWorld = Matrix.CreateScale( 2f ) *
			Matrix.CreateRotationX( fWeaponRotX ) *
			Matrix.CreateRotationY( fWeaponRotY ) *
			Matrix.CreateRotationZ( fWeaponRotZ ) *
			Matrix.CreateTranslation( vecWeaponRot ) *
			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) );

		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 );
		}
	}
}
//Values in the rotation/translation above:
float fWeaponRotX = -0.3f;
float fWeaponRotY = 0.1f;
float fWeaponRotZ = -0.1f;
Vector3 vecWeaponRot = new Vector3( 0, -0.25f, -0.2f );

 

If anyone has any idea, please. In the mean time, I am going to write a small debugger for this so I can check what's happening in-game quicker and easier.

 

(P.S: I know this question has been posted A LOT on these forums, I have searched.. For days. So I apologize for the repetitiveness!)


#1MarlboroKing

Posted 08 February 2013 - 02:37 PM

I'd do something like this:

 

- when camera moves

- the object you want to keep static to camera -> worldpos = camerapos

- camerapos.z -= 5 or += 5?

 

Tried. I figured something out new.. Well, observed. I imported a model that was designed in 3DWings into my content solution, redid my method and bam, it worked.

It appears I'm missing something (duh!) that the imported model has, that my coded model doesn't. I'm explaining what I've done below, but before I do, please note that I am still new to 3D and my code may not be completely efficient, the second is temporarily :]

 

I have a tilesheet of textures, used for the UV coordinates. I'm essentially taking the coordinates from the UV and building a array of VertexPositionTexture for the model:

 

VertexBuilder.BuildVertexFromUV

public static List<VertexPositionTexture> BuildVertexFromUV( Vector3 vecPosition, Vector2[] vecUV )
{
	List<VertexPositionTexture> ret = new List<VertexPositionTexture>();

	foreach( Vector2 uv in vecUV )
		ret.Add( new VertexPositionTexture( vecPosition + new Vector3(uv.X, uv.Y, 0), uv ) );

	return ret;
}

 

 

ItemRender.OnChangeItemInHand

public void OnChangeItemInHand( EItemType nType )
{
	if( nType != m_nItemHold )
	{
		m_Verts.Clear();

		m_Verts = BlockVertexBuilder.BuildVertexFromUV( new Vector3(0, 0, 0),
		new Vector3( 1, 0, 2 ),
		ItemTexture.m_UVMappings[(int)nType] );

		m_VB = new VertexBuffer( m_GraphicsDevice, typeof(VertexPositionTexture), m_Verts.Count, BufferUsage.WriteOnly );
		m_VB.SetData( m_Verts.ToArray() );

		m_nItemHold = nType;
	}
}

 

This happens when the delta on the Mouse.ScrollWheelValue changes. Again, all fine and dandy. Now, the glorified issue.

 

 

ItemRender.RenderItemInHand

 

public void RenderItemInHand( GameTime gameTime )
{
	EItemType nType = m_Player.PlayerInventory.GetHoldingItemType();
	OnChangeItemInHand( nType ); //Remember, temporarily :]

	if( nType != EItemType.None )
	{
		Matrix matWorld = Matrix.CreateScale( 2f ) *
			Matrix.CreateRotationX( fWeaponRotX ) *
			Matrix.CreateRotationY( fWeaponRotY ) *
			Matrix.CreateRotationZ( fWeaponRotZ ) *
			Matrix.CreateTranslation( vecWeaponRot ) *
			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) );

		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 );
		}
	}
}
//Values in the rotation/translation above:
float fWeaponRotX = -0.3f;
float fWeaponRotY = 0.1f;
float fWeaponRotZ = -0.1f;
Vector3 vecWeaponRot = new Vector3( 0, -0.25f, -0.2f );

 

If anyone has any idea, please. In the mean time, I am going to write a small debugger for this so I can check what's happening in-game quicker and easier.

 

(P.S: I know this question has been posted A LOT on these forums, I have searched.. For days. So I apologize for the repetitiveness!)


PARTNERS