Effects Manager

In reading the documentation it seems that you cannot have a (working)camera without passing through an effects.

Would it then be better to create an effects manager class to handle exposing an effect update method accepting a camera argument, or better to just load up an effects cache and have the camera class grab what it needs each time.?

[365 byte] By [SteveHoff] at [2007-12-24]
# 1

The effects uses the WorldViewProjection matrix as you may have to implement a camera in your game project.

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Components;

using Microsoft.Xna.Framework.Graphics;

namespace XNACamera

{

publicclassCamera :GameComponent

{

privateMatrix _View, _Projection;

publicMatrix View {get {return _View; } }

publicMatrix Projection {get {return _Projection; } }

privatefloat _Yaw, _Pitch, _Roll;

publicfloat Yaw

{

get {returnMathHelper.ToDegrees ( _Yaw ); }

set { _Yaw =MathHelper.ToRadians (value ); }

}

publicfloat Pitch

{

get {return -MathHelper.ToDegrees ( _Pitch ); }

set { _Pitch =MathHelper.ToRadians ( -value ); }

}

publicfloat Roll

{

get {returnMathHelper.ToDegrees ( _Roll ); }

set { _Roll =MathHelper.ToRadians (value ); }

}

privatefloat _AspectRatio;

Vector3 _CameraReference =newVector3 ( 0, 0, 10 );

Vector3 _HeadOffset =newVector3 ( 0, 0, 0 );

float _clipFar = 2500, _clipNear = 0f;

privateVector3 _Position =newVector3(0, 0, 0);

publicfloat X

{

get {return _Position.X; }

set { _Position.X =value; }

}

publicfloat Y

{

get {return _Position.Y; }

set { _Position.Y =value; }

}

publicfloat Z

{

get {return _Position.Z; }

set { _Position.Z =value; }

}

publicfloat AbsX

{

get {return _Position.X; }

set

{

Matrix Move =

Matrix.CreateRotationX ( _Pitch ) *

Matrix.CreateRotationY ( _Yaw ) *

Matrix.CreateRotationZ ( _Roll );

Vector3 v =newVector3 (value++, 0, 0 );

v =Vector3.Transform ( v, Move );

_Position.X += v.X;

_Position.Y += v.Y;

_Position.Z += v.Z;

}

}

publicfloat AbsY

{

get {return _Position.Y; }

set

{

Matrix Move =

Matrix.CreateRotationX ( _Pitch ) *

Matrix.CreateRotationY ( _Yaw ) *

Matrix.CreateRotationZ ( _Roll );

Vector3 v =newVector3 ( 0,value++, 0 );

v =Vector3.Transform ( v, Move );

_Position.X += v.X;

_Position.Y += v.Y;

_Position.Z += v.Z;

}

}

publicfloat AbsZ

{

get {return _Position.X; }

set

{

Matrix Move =

Matrix.CreateRotationX ( _Pitch ) *

Matrix.CreateRotationY ( _Yaw ) *

Matrix.CreateRotationZ ( _Roll );

Vector3 v =newVector3 ( 0, 0,value++ );

v =Vector3.Transform ( v, Move );

_Position.X += v.X;

_Position.Y += v.Y;

_Position.Z += v.Z;

}

}

privateVector3 _LookAt;

publicVector3 LookAt

{

get {return _LookAt; }

}

publicoverridevoid Start ( )

{

IGraphicsDeviceService graphics = (IGraphicsDeviceService )

Game.GameServices.GetService<IGraphicsDeviceService> ( );

_AspectRatio =

(float ) graphics.GraphicsDevice.DisplayMode.Width /

(float ) graphics.GraphicsDevice.DisplayMode.Height;

}

publicoverridevoid Update ( )

{

Matrix rotationMatrix =

Matrix.CreateRotationX ( _Pitch ) *

Matrix.CreateRotationY ( _Yaw ) *

Matrix.CreateRotationZ ( _Roll );

Vector3 headOffset =Vector3.Transform (

_HeadOffset, rotationMatrix );

Vector3 camPos = _Position + headOffset;

Vector3 transformedRef =Vector3.Transform (

_CameraReference, rotationMatrix );

Vector3 camLookAt = transformedRef + camPos;

_LookAt = camLookAt;

_View =Matrix.CreateLookAt (

camPos, camLookAt,newVector3 ( 0, 1, 0 ) );

_Projection =Matrix.CreatePerspectiveFieldOfView (

MathHelper.PiOver4, _AspectRatio, _clipNear, _clipFar );

}

}

}

I hope this will help get you started. All you have to do is multiply object's World * camera's View * camera's projection and you can be able to view the object with an effect.

GraysonPeddie at 2007-10-8 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...