Jump to content
  • Advertisement
Sign in to follow this  

[C#] Changing cameras, setting shared parameters and game components.

This topic is 2953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When drawing objects I set all the shared parameters for the current active camera once:

public void SetSharedParameters(Camera camera)
int backBufferWidth = graphicsDevice.PresentationParameters.BackBufferWidth;
int backBufferHeight = graphicsDevice.PresentationParameters.BackBufferHeight;

Vector2 halfPixel = new Vector2();
halfPixel.X = 1.0f / graphicsDevice.Viewport.Width;
halfPixel.Y = -1.0f / graphicsDevice.Viewport.Height;

//Vector2 halfTexel = new Vector2();
//halfTexel.X = 0.5f / backBufferWidth;
//halfTexel.Y = 0.5f / backBufferHeight;


If the active camera changes then the shared parameters are updated:

public Camera ActiveCamera
get { return activeCamera; }

This works fine until I come to batch drawing objects. Take for example my shaped drawer:

private void FlushDrawing()
if (IndexCount > 0)
vertexBuffer.SetData(Vertices, 0, VertexCount, SetDataOptions.Discard);
indexBuffer.SetData(Indices, 0, IndexCount, SetDataOptions.Discard);

GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionColor.SizeInBytes);
GraphicsDevice.Indices = indexBuffer;
GraphicsDevice.VertexDeclaration = game.VertexDeclarations["VertexPositionColor"];


GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, VertexCount, 0, IndexCount / 2);


IndexCount = 0;
VertexCount = 0;

I have to call FlushDrawing() each time the camera changes, as all vertices are stored in one array.

This leads to complications when using Game Components as they are drawn automatically. I realise that I can set them to Visible = false and call the Draw() method when I like but I'm still not happy with this camera set up.

Has anybody got any suggestions for this area?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!