Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

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

This topic is 3035 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;

parameter_CameraPosition.SetValue(camera.Position);
parameter_CameraUp.SetValue(camera.Up);
parameter_HalfPixel.SetValue(halfPixel);
parameter_InverseViewProjection.SetValue(Matrix.Invert(camera.ViewProjectionMatrix));
parameter_Projection.SetValue(camera.ProjectionMatrix);
parameter_View.SetValue(camera.ViewMatrix);
parameter_ViewProjection.SetValue(camera.ViewProjectionMatrix);
}




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"];

effect.Begin();
effect.CurrentTechnique.Passes[0].Begin();

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

effect.CurrentTechnique.Passes[0].End();
effect.End();
}

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!