Camera Control
From NeoAxisWiki
Code Snippets: Camera Control
Introduction
The controlling of the camera is quite important. How else would the player to see what is going on? :)
Render-To-Texture
In this case it is used for a UI
void InitCameraViewFromTarget()
{
int textureSize = 256;
//Texture cameraTexture
cameraTexture = TextureManager.Instance.Create(
TextureManager.Instance.GetUniqueName("RemoteView"), Texture.Type.Type2D,
new Vec2i(textureSize, textureSize), 1, 0, PixelFormat.R8G8B8, Texture.Usage.RenderTarget);
RenderTexture renderTexture = cameraTexture.GetBuffer().GetRenderTarget();
rmCamera = SceneManager.Instance.CreateCamera();
rmCamera.ProjectionType = ProjectionTypes.Perspective;
rmCamera.PolygonMode = PolygonMode.Wireframe;
renderTexture.AddViewport(rmCamera);
}
void GetCameraViewFromTarget()
{
Mech mecha = GetPlayerUnit() as Mech;
Unit unit;
if (mecha == null) return;
else if (mecha != null && mecha.CurrentMissileTarget != null)
{
unit = mecha.CurrentMissileTarget;
}
else
{
hudControl.Controls["Game/TargetWindow"].BackTexture = null;
rmCamera.Visible = false;
return;
}
Vec3 dir = (unit.Position - mecha.Position);
rmCamera.FixedUp = (Vec3.ZAxis);
rmCamera.Visible = true;
rmCamera.Position = mecha.CurrentMissileTarget.Position + mecha.CurrentMissileTarget.Rotation.GetDirection() * 10f;
rmCamera.LookAt(mecha.CurrentMissileTarget.Position);
rmCamera.PolygonMode = PolygonMode.Wireframe;
rmCamera.NearClipDistance = 1.0f;
rmCamera.FarClipDistance = (mecha.CurrentMissileTarget.Position - rmCamera.Position).LengthFast() * 1.3f;
hudControl.Controls["Game/TargetWindow"].BackTexture = cameraTexture;
}
[Contributor] Wellu
[Organizer] Qudeid
