public Effect( Renderer renderer, string filename ) { //if (!File.Exists(filename)) // throw new FileNotFoundException(filename); if ( renderer == null ) throw new ArgumentNullException( "renderer", "Can't create an Effect without a valid renderer." ); string compilationErrors = ""; try { effect = Direct3D.Effect.FromFile( renderer.Device, filename, null, null, null, ShaderFlags.None, null, out compilationErrors ); } catch { Log.Write( "Unable to create effect " + filename + ". The compilation errors were: \n\n" + compilationErrors ); } renderer.AddGraphicsObject( this ); }
/// <summary> /// Initializes a new instance of LightNode. /// </summary> public LightNode( Renderer renderer, SceneGraph sceneGraph, Matrix localTransform, float range, float intensity, Color lightColor) : base(renderer, sceneGraph) { Vector2 pos = Vector2.TransformCoordinate( new Vector2(), localTransform ); light = renderer.RegisterNewLight( range, intensity, pos, lightColor ); }
/// <summary> /// Initializes a new instance of GeometryNode. /// </summary> public GeometryNode( Renderer renderer, SceneGraph sceneGraph, Matrix localTransform, IRenderable renderObject, string material) : base(renderer, sceneGraph) { this.localTransform = localTransform; this.renderObject = renderObject; this.material = material; }
/// <summary> /// Initializes a new instance of Surface. /// </summary> public Surface( Renderer renderer, string materialName, Size size ) { this.renderer = renderer; this.materialName = materialName; this.size = size; quad = Mesh.Rectangle( renderer, Color.White, size.Width, size.Height ); }
public Cursor( Renderer renderer, string materialName, Size size ) { this.renderer = renderer; this.size = size; surface = new Surface( renderer, materialName, size ); mouse = new MouseDevice( null ); }
/// <summary> /// Initializes a new instance of Surface. /// </summary> public Surface( Renderer renderer, string materialName, Size size, float textureMapTiling) { this.renderer = renderer; this.materialName = materialName; this.size = size; quad = Mesh.Rectangle( renderer, Color.Black, size.Width, size.Height, textureMapTiling ); }
public Obstacle( Renderer renderer, bool invisible, string material ) : base(renderer, EntityType.Obstacle) { this.invisible = invisible; this.material = material; this.mesh = obstacleMesh; mass = config.GetSetting<float>( "RobotMass" ); shadows = config.GetSetting<bool>( "Shadows" ); }
/// <summary> /// Builds the material using a standard Direct3D material structure and the name of the VisualEffect. /// </summary> public Material( Renderer renderer, Direct3D.Material material, string visualEffectName ) { if ( renderer == null ) throw new ArgumentNullException( "renderer", "Cannot create a material with a null renderer reference." ); this.renderer = renderer; d3dMaterial = material; this.visualEffectName = visualEffectName; }
/// <summary> /// Initializes a new instance of VisualEffect. /// </summary> /// <param name="renderer"></param> public VisualEffect( Renderer renderer ) { if ( renderer == null ) { Log.Write( "Can't create a VisualEffect with a null Renderer reference." ); throw new ArgumentNullException( "renderer", "Can't create a VisualEffect with a null Renderer reference." ); } this.renderer = renderer; }
public Cursor( Renderer renderer, string materialName, Size size, float movementScaleFactor) { this.renderer = renderer; this.size = size; this.movementScaleFactor = movementScaleFactor; surface = new Surface( renderer, materialName, size ); mouse = new MouseDevice( null ); }
public Game( Renderer renderer ) { this.renderer = renderer; physicsTimeStep = config.GetSetting<float>( "PhysicsTimeStep" ); SetupMusic(); fsm.AddState( new SplashScreenState( renderer ) ); fsm.AddState( new MainMenuState( renderer ) ); fsm.AddState( new DuelState( renderer ) ); fsm.DefaultStateID = ( int )StateTypes.SplashScreen; }
/// <summary> /// Builds the material using default parameters. /// </summary> public Material( Renderer renderer ) { if ( renderer == null ) throw new ArgumentNullException( "renderer", "Cannot create a material with a null renderer reference." ); this.renderer = renderer; d3dMaterial = new Direct3D.Material(); d3dMaterial.Ambient = DefaultAmbientColor; d3dMaterial.Diffuse = DefaultDiffuseColor; d3dMaterial.Specular = DefaultSpecularColor; d3dMaterial.SpecularSharpness = DefaultShininess; }
/// <summary> /// Creates an effect from a file. If the effect has already been created, the cached version /// is returned. /// </summary> public static Effect CreateEffectFromFile( Renderer renderer, string filename ) { // Search cache first foreach ( string cachedFilename in effectCache.Keys ) { if ( StringHelper.CaseInsensitiveCompare( cachedFilename, filename ) ) return effectCache[ cachedFilename ] as Effect; } Effect newEffect = new Effect( renderer, filename ); effectCache.Add( filename, newEffect ); return newEffect; }
public Scene( Renderer renderer ) { this.renderer = renderer; camera = new Camera( renderer ); crosshair = new Cursor( renderer, "crosshair", new Size( 50, 49 ) ); arenaSize = new Size( config.GetSetting<int>( "ArenaWidth" ), config.GetSetting<int>( "ArenaHeight" ) ); aimMode = config.GetSetting<string>( "AimMode" ); cameraMode = config.GetSetting<string>( "CameraMode" ); shadows = config.GetSetting<bool>( "Shadows" ); if ( aimMode != "Relative" && aimMode != "Absolute" ) { Log.Write( "Invalid value for setting 'AimMode'. Defaulting to AimMode = 'Absolute'." ); aimMode = "Absolute"; } if ( cameraMode != "Fixed" && cameraMode != "Floating" ) { Log.Write( "Invalid value for setting 'CameraMode'. Defaulting to CameraMode = 'Floating'." ); cameraMode = "Floating"; } lavaTexCoordTiling = config.GetSetting<float>( "LavaTexCoordTiling" ); arenaGround = new Surface( renderer, "arenaGround", arenaSize, 2.0f ); lava = new Surface( renderer, "lava", new Size( renderer.FullscreenSize.Width, renderer.FullscreenSize.Height ), lavaTexCoordTiling ); playerBot = new Robot( renderer, new PlayerRobotControl( crosshair ), this ); cpuBot = new Robot( renderer, new CPURobotControl( this ), this ); statsFont = new Gas.Graphics.Font( renderer, "Arial", 14 ); statsFont.ShadowColor = Color.Black; playerBot.Position = new Vector2( 500.0f, 0.0f ); cpuBot.Position = new Vector2( -500.0f, 0.0f ); entityArbiter.AddEntity( playerBot ); entityArbiter.AddEntity( cpuBot ); PopulateArenaWithObstacles(); }
public ExplodingProjectile( Renderer renderer, Vector2 startPos, Vector2 direction, Vector2 initialVelocity, Scene scene) : base(renderer, startPos, direction, initialVelocity) { lifetime = config.GetSetting<float>( "ExplodingProjectileTimer" ); clusterSize = config.GetSetting<int>( "ExplodingProjectileClusterSize" ); projectileDamage = config.GetSetting<float>( "ExplodingProjectileDamage" ); speed = config.GetSetting<float>( "ExplodingProjectileSpeed" ); mesh = renderer.CreateCircularMesh(Color.Black, 13.0f, 6 ); light = renderer.RegisterNewLight( 200.0f, 1.0f, startPos, Color.Red ); this.velocity = initialVelocity + direction * speed; this.scene = scene; }
/// <summary> /// Creates a font. If the font has already been created, the cached version is returned. /// </summary> public static Font CreateFont( Renderer renderer, string familyName, int height ) { // Search cache first foreach ( CachedFont cf in fontCache.Keys ) { if ( StringHelper.CaseInsensitiveCompare( cf.FamilyName, familyName ) && cf.Height == height ) return fontCache[ cf ] as Font; } Font newFont = new Font( renderer, familyName, height ); CachedFont cachedFont = new CachedFont(); cachedFont.FamilyName = familyName; cachedFont.Height = height; fontCache.Add( cachedFont, newFont ); return newFont; }
public Projectile( Renderer renderer, Vector2 startPos, Vector2 direction, Vector2 initialVelocity) : base(renderer, EntityType.Projectile) { this.renderer = renderer; this.Position = startPos; this.direction = direction; this.initialVelocity = initialVelocity; lifetime = config.GetSetting<float>( "ProjectileLifetime" ); speed = config.GetSetting<float>( "ProjectileSpeed" ); projectileDamage = config.GetSetting<float>( "ProjectileDamage" ); //light = renderer.RegisterNewLight(250.0f, 1.0f, this.Position, Color.Green); mesh = Mesh.Circle( renderer, Color.Black, 5.0f, 6 ); this.velocity = initialVelocity + direction * speed; }
/// <summary> /// Initializes a new instance of SceneGraphNode. /// </summary> public SceneGraphNode( Renderer renderer, SceneGraph sceneGraph ) { if ( renderer == null ) { Log.Write( "Cannot create a SceneGraphNode with a null Renderer reference." ); throw new ArgumentNullException( "renderer", "Cannot create a SceneGraphNode with a null Renderer reference." ); } if ( sceneGraph == null ) { Log.Write( "Cannot create a SceneGraphNode with a null SceneGraph reference." ); throw new ArgumentNullException( "sceneGraph", "Cannot create a SceneGraphNode with a null SceneGraph reference." ); } this.renderer = renderer; this.sceneGraph = sceneGraph; }
/// <summary> /// Creates the texture from a file. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="filename">The name of the texture file to load.</param> public Texture( Renderer renderer, string filename ) { if ( renderer == null ) throw new ArgumentNullException( "renderer", "Unable to create texture without a valid renderer reference." ); if ( String.IsNullOrEmpty( filename ) ) throw new ArgumentNullException( "filename", "Unable to create texture without valid filename." ); this.renderer = renderer; texFilename = filename; // Try to load the texture try { if ( File.Exists( filename ) == false ) throw new FileNotFoundException( filename ); ImageInformation imageInfo = TextureLoader.ImageInformationFromFile( filename ); size = new Size( imageInfo.Width, imageInfo.Height ); if ( size.Width == 0 || size.Height == 0 ) throw new InvalidOperationException( "Image size=" + size + " is invalid, unable to create texture." ); hasAlpha = imageInfo.Format == Format.Dxt5 || imageInfo.Format == Format.Dxt3 || imageInfo.Format.ToString().StartsWith( "A" ); d3dTexture = TextureLoader.FromFile( this.renderer.Device, filename ); loaded = true; renderer.AddGraphicsObject( this ); } catch ( Exception ex ) { loaded = false; Log.Write( "Failed to load texture " + filename + ", will use empty texture! Error: " + ex.ToString() ); } }
public Robot( Renderer renderer, Scene scene ) : base(renderer, EntityType.Robot) { mesh = Mesh.Circle( renderer, Color.White, 60, 24 ); turret = new Surface( renderer, "turret", new Size( 20, 75 ) ); this.scene = scene; frictionalCoefficient = config.GetSetting<float>( "FrictionalCoefficient" ); mass = config.GetSetting<float>( "RobotMass" ); coefficientOfRestitution = config.GetSetting<float>( "CoefficientOfRestitution" ); projectileFireInterval = config.GetSetting<float>( "ProjectileFireInterval" ); timeSinceLastProjFire = projectileFireInterval; explodingProjFireInterval = config.GetSetting<float>( "ExplodingProjectileFireInterval" ); timeSinceLastExplodingProjFire = explodingProjFireInterval; health = config.GetSetting<int>( "RobotStartHealth" ); }
public Light( Renderer renderer, float range, float intensity ) { if ( renderer == null ) { Log.Write( "'renderer' is null." ); throw new ArgumentNullException( "renderer", "Can't create a Light with a null " + "renderer reference." ); } if ( intensity < 0.0f || intensity > 1.0f ) { Log.Write( "'intensity' is out of range." ); throw new ArgumentOutOfRangeException( "intensity", intensity, "'intensity' is outside of the range [0,1]." ); } this.renderer = renderer; this.range = range; this.intensity = intensity; }
/// <summary> /// Initializes the BloomPostProcessor. /// </summary> public BloomPostProcessor( Renderer renderer ) { if ( renderer == null ) throw new ArgumentNullException( "renderer", "Can't create the BloomPostProcessor with a " + "null Renderer reference." ); this.renderer = renderer; brightPassTex = new Texture( renderer, renderer.FullscreenSize.Width / 2, renderer.FullscreenSize.Height / 2, true ); blurHorizontalTex = new Texture( renderer, renderer.FullscreenSize.Width / 2, renderer.FullscreenSize.Height / 2, true ); blurVerticalTex = new Texture( renderer, renderer.FullscreenSize.Width / 2, renderer.FullscreenSize.Height / 2, true ); finalBloomImage = new Texture( renderer, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height, true ); fullscreenQuad = Mesh.Rectangle( renderer, Color.Black, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height ); bloomEffect = GlobalResourceCache.CreateEffectFromFile( renderer, @".\\FXFiles\\Bloom.fx" ); }
/// <summary> /// Constructs the font object using the desired font family. If the desired family /// is not supported, the fallback family defined in the Settings file is used. /// </summary> public Font( Renderer renderer, string familyName, int height ) { this.renderer = renderer; this.familyName = familyName; this.height = height + 5; // Attempt to create the Windows font object try { windowsFont = new System.Drawing.Font( familyName, this.height, System.Drawing.FontStyle.Regular ); } catch { // Attempt to create the font using the "fallback" font family // defined in the Settings file Log.Write( "The desired font family was not available." ); } d3dFont = new Direct3D.Font( renderer.Device, windowsFont ); textSprite = new Direct3D.Sprite( renderer.Device ); renderer.AddGraphicsObject( this ); }
/// <summary> /// Builds a circular mesh centered around the origin. /// </summary> public static Mesh Circle( Renderer renderer, Color color, float radius, int numSubdivisions) { return Mesh.Circle( renderer, color, radius, numSubdivisions, 1.0f ); }
public SplashScreenState( Renderer renderer ) { this.renderer = renderer; type = ( int )StateTypes.SplashScreen; splashScreen = new Surface( renderer, "splashScreen", renderer.FullscreenSize ); }
public MainMenuState( Renderer renderer ) { type = ( int )StateTypes.MainMenu; this.renderer = renderer; background = new Surface( renderer, "mainMenuBg", renderer.FullscreenSize ); cursor = new Cursor( renderer, "cursor", new Size( 50, 50 ) ); mainMenu = new Menu( renderer, new Vector2( 0, -30 ), 80.0f, config.GetSetting<string>( "MainMenuFont" ), cursor, "buttonPressed", "buttonUnpressed", new Size( 200, 50 ) ); mainMenu.AddButton( "Duel", "Duel" ); mainMenu.AddButton( "Survival", "Survival" ); mainMenu.AddButton( "Quit", "Quit" ); mainMenu.GetButton( "Duel" ).Pressed += new EventHandler( OnDuelPressed ); mainMenu.GetButton( "Survival" ).Pressed += new EventHandler( OnSurvivalPressed ); mainMenu.GetButton( "Quit" ).Pressed += new EventHandler( OnQuitButtonPressed ); }
public DuelState( Renderer renderer ) { this.renderer = renderer; type = ( int )StateTypes.DuelState; ShadowManager.Initialize( renderer ); scene = new Scene( renderer ); }
/// <summary> /// Builds a rectangular mesh, centered around the origin. /// </summary> public static Mesh Rectangle( Renderer renderer, Color color, float width, float height, float textureMapTiling) { Mesh rectMesh = new Mesh( renderer, 4, 2 ); rectMesh.AddVertex( 0, new Vector3( -width / 2, height / 2, 1.0f ), color, new Vector2( 0.0f, 0.0f ) ); rectMesh.AddVertex( 1, new Vector3( width / 2, height / 2, 1.0f ), color, new Vector2( textureMapTiling, 0.0f ) ); rectMesh.AddVertex( 2, new Vector3( width / 2, -height / 2, 1.0f ), color, new Vector2( textureMapTiling, textureMapTiling ) ); rectMesh.AddVertex( 3, new Vector3( -width / 2, -height / 2, 1.0f ), color, new Vector2( 0.0f, textureMapTiling ) ); rectMesh.AddTriangle( 0, 0, 1, 2 ); rectMesh.AddTriangle( 1, 0, 2, 3 ); return rectMesh; }
/// <summary> /// Builds a rectangular mesh, centered around the origin. /// </summary> public static Mesh Rectangle( Renderer renderer, Color color, float width, float height ) { return Mesh.Rectangle( renderer, color, width, height, 1.0f ); }
/// <summary> /// Builds a circular mesh centered around the origin. /// </summary> public static Mesh Circle( Renderer renderer, Color color, float radius, int numSubdivisions, float textureMapTiling) { Mesh circleMesh = new Mesh( renderer, numSubdivisions, numSubdivisions - 2 ); float angleStep = ( 2 * ( float )Math.PI ) / numSubdivisions; for ( int i = 0; i < numSubdivisions; ++i ) { Vector2 texCoords = textureMapTiling * ( new Vector2( ( float )Math.Cos( angleStep * i ) / 2.0f + 0.5f, 1.0f - ( ( float )Math.Sin( angleStep * i ) / 2.0f + 0.5f ) ) ); circleMesh.AddVertex( i, new Vector3( radius * ( float )Math.Cos( angleStep * i ), radius * ( float )Math.Sin( angleStep * i ), 1.0f ), color, texCoords ); } for ( int i = 2, count = 0; i < numSubdivisions - 1; ++i, ++count ) { circleMesh.AddTriangle( count, 0, i, i - 1 ); } circleMesh.AddTriangle( numSubdivisions - 3, 0, numSubdivisions - 2, numSubdivisions - 1 ); return circleMesh; }