• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MarlboroKing

Moving object based on camera direction

5 posts in this topic

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!

Edited by MarlboroKing
0

Share this post


Link to post
Share on other sites
if you just want it infront of the camera, set its local to the position you want infront of the cameraa and multiply it with the view matrix. Edited by Tordin
0

Share this post


Link to post
Share on other sites

One of the first few things I tried, perhaps I made a mistake on that particular one.. I'll give that a go again.

What bugs me is that the most obvious solutions seems to work, just not as expected, eg;

                Matrix matWorld = Matrix.Identity *
                    Matrix.CreateTranslation( m_Player.Position + m_Player.LookVector );

		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; 

 

 

 (Note that this attempt was copy/pasted from a part that determines which object the player is looking at, which works flawlessly, however said part multiplies Look by x)
The result is the object moving when the player looks, but it 'lags' behind (it doesn't keep up with the camera if the camera looks too far around). But, won't appear where the player is looking. It appears to have a different position when the game is running (I mean, when the game starts, I need to turn around completely in order to see it).
The LookVector appears to be correct before Normalizing, as well as Position during debugging.
 
I'm basically at a stand-still and completely baffled how it works perfectly on ClassA, except ClassB appears to just... Well, not work.
0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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!)

Edited by MarlboroKing
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0