├── 1046.pdf ├── 1047.pdf ├── 1187.html ├── 1590590813-1225 ├── CarLib │ ├── AssemblyInfo.cs │ ├── Car.cs │ ├── CarLib.csproj │ ├── CarLib.csproj.user │ ├── Euler.cs │ ├── LFI.cs │ ├── Vector.cs │ └── Wheel.cs ├── GameAI │ ├── AIState.cs │ ├── AssemblyInfo.cs │ ├── Class1.cs │ ├── Expression.cs │ ├── Fact.cs │ ├── GameAI.csproj │ ├── GameAI.csproj.user │ ├── Logic.cs │ ├── Thinker.cs │ └── Transitioner.cs ├── GameEngine │ ├── AssemblyInfo.cs │ ├── BillBoard.cs │ ├── Camera.cs │ ├── Cloth.cs │ ├── Console.cs │ ├── Copy of hud.cs │ ├── D3DApp.cs │ ├── D3DApp.resx │ ├── D3DEnumeration.cs │ ├── D3DFont.cs │ ├── D3DSettingsForm.cs │ ├── D3DSettingsForm.resx │ ├── D3DUtil.cs │ ├── DXUtil.cs │ ├── GameCommand.cs │ ├── GameEngine.cs │ ├── GameEngine.csproj │ ├── GameEngine.csproj.user │ ├── GameEngine.sln │ ├── GameEngine.suo │ ├── GameInput.cs │ ├── Interfaces.cs │ ├── Lights.cs │ ├── Listener.cs │ ├── Math.cs │ ├── Model.cs │ ├── Music.cs │ ├── Object3D.cs │ ├── Particles.cs │ ├── Quad.cs │ ├── SkyBox.cs │ ├── SoundEffect.cs │ ├── Terrain.cs │ ├── UserInterface.cs │ ├── hud.cs │ ├── jukebox.cs │ └── oldD3DApp.cs ├── Readme.txt └── SampleGame │ ├── App.cs │ ├── App.ico │ ├── AssemblyInfo.cs │ ├── Car.cs │ ├── Opponent.cs │ ├── Ownship.cs │ ├── Particles.cs │ ├── Resources │ ├── Beethoven9.wma │ ├── Console.jpg │ ├── DevSplash.jpg │ ├── Dunes_Back.tga │ ├── Dunes_Bottom.tga │ ├── Dunes_Front.tga │ ├── Dunes_Left.tga │ ├── Dunes_Right.tga │ ├── Dunes_Top.tga │ ├── GameSplash.jpg │ ├── Options1.jpg │ ├── Options2.jpg │ ├── PlayHover.bmp │ ├── PlayHover.jpg │ ├── PlayHover.tif │ ├── PlayOff.bmp │ ├── PlayOff.jpg │ ├── PlayOn.bmp │ ├── PlayOn.jpg │ ├── QuitHover.bmp │ ├── QuitHover.jpg │ ├── QuitOff.bmp │ ├── QuitOff.jpg │ ├── Quiton.bmp │ ├── Quiton.jpg │ ├── SprintRacer.x │ ├── Thump.wav │ ├── bluepost.dds │ ├── cactus.dds │ ├── canyon.mid │ ├── car_idle.wav │ ├── carbody.bmp │ ├── crash.wav │ ├── cursor.dds │ ├── flag.jpg │ ├── heightmap.jpg │ ├── knowledge.xml │ ├── palmtree.dds │ ├── particle.bmp │ ├── redpost.dds │ ├── sand1.jpg │ ├── small_crash.wav │ └── tire.bmp │ ├── SampleGame.csproj │ ├── SampleGame.csproj.user │ ├── SampleGame.sln │ ├── SampleGame.suo │ ├── SelectControls.cs │ └── SelectControls.resx ├── 719.html ├── 9781590590812.jpg ├── LICENSE.txt ├── README.md └── contributing.md /1046.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1046.pdf -------------------------------------------------------------------------------- /1047.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1047.pdf -------------------------------------------------------------------------------- /1187.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1187.html -------------------------------------------------------------------------------- /1590590813-1225/CarLib/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /1590590813-1225/CarLib/CarLib.csproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 22 | 40 | 58 | 59 | 60 | 65 | 70 | 75 | 76 | 77 | 78 | 79 | 84 | 89 | 94 | 99 | 104 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /1590590813-1225/CarLib/CarLib.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 37 | 38 | 39 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /1590590813-1225/CarLib/Euler.cs: -------------------------------------------------------------------------------- 1 | // created on 10/22/2002 at 2:12 PM 2 | using System; 3 | 4 | namespace VehicleDynamics 5 | { 6 | public class Euler 7 | { 8 | 9 | private double psi; 10 | private double theta; 11 | private double phi; 12 | private double cpsi; 13 | private double ctheta; 14 | private double cphi; 15 | private double spsi; 16 | private double stheta; 17 | private double sphi; 18 | private double[,] mat = new double[3,3]; 19 | private bool matrix_current = false; 20 | 21 | // The default class constructor 22 | public Euler () {psi = 0.0; theta=0.0; phi=0.0;} 23 | 24 | // A constructor which accepts three floats defining the angles 25 | public Euler ( 26 | double x_psi, 27 | double x_theta, 28 | double x_phi 29 | ) {Psi = x_psi; Theta=x_theta; Phi=x_phi;} 30 | 31 | // A copy constructor 32 | public Euler ( 33 | Euler x_angle 34 | ) {psi = x_angle.Psi; theta=x_angle.Theta; phi=x_angle.Phi;} 35 | 36 | // The class destructor 37 | ~Euler () {} 38 | 39 | // Calculates the difference between two copies of the class. 40 | public Euler Delta ( 41 | Euler from 42 | ) { return new Euler( psi - from.psi, theta - from.theta, phi - from.phi ); } 43 | 44 | public double DeltaPsi ( 45 | Euler from 46 | ) { return psi - from.psi; } 47 | 48 | public double DeltaTheta ( 49 | Euler from 50 | ) { return theta - from.theta; } 51 | 52 | public double DeltaPhi ( 53 | Euler from 54 | ) { return phi - from.phi; } 55 | 56 | public Euler ABSDelta ( 57 | Euler from 58 | ) { return new Euler( Math.Abs(psi - from.psi), Math.Abs(theta - from.theta), Math.Abs(phi - from.phi) ); } 59 | 60 | public double ABSDeltaPsi ( 61 | Euler from 62 | ) { return Math.Abs(psi - from.psi); } 63 | 64 | public double ABSDeltaTheta ( 65 | Euler from 66 | ) { return Math.Abs(theta - from.theta); } 67 | 68 | public double ABSDeltaPhi ( 69 | Euler from 70 | ) { return Math.Abs(phi - from.phi); } 71 | 72 | /* // Operator functions. 73 | public bool operator< ( 74 | Euler other 75 | ) {return psi < other.psi && theta < other.theta && phi < other.phi;} 76 | public bool operator== ( 77 | Euler that 78 | ) {return psi==that.psi && theta==that.theta && phi==that.phi;} 79 | 80 | public Euler operator - () {return Euler(-psi, -theta, -phi);} 81 | public Euler operator - ( 82 | public Euler that 83 | ) {return Euler(psi - that.psi, theta - that.theta, phi - that.phi);} 84 | public Euler operator -= ( 85 | Euler that 86 | ) {psi-= that.psi; theta-= that.theta; phi-= that.phi; return *this;} 87 | public Euler operator + ( 88 | Euler that 89 | ) {return Euler(psi + that.psi, theta + that.theta, phi + that.phi);} 90 | public Euler operator += ( 91 | Euler that 92 | ) {psi+= that.psi; theta+= that.theta; phi+= that.phi; return *this;} 93 | public Euler operator / ( 94 | float value 95 | ) {return Euler(psi/value, theta/value, phi/value);} 96 | public Euler operator /= ( 97 | float value 98 | ) {psi/= value; theta/= value; phi/= value; return *this;} 99 | public Euler operator * ( 100 | float that 101 | ) {return Euler(psi*that, theta*that, phi*that);} 102 | public Euler operator *= ( 103 | float that 104 | ) {psi*= that; theta*= that; phi*= that; return *this;} 105 | 106 | public Euler operator + ( 107 | Vector that 108 | ) {return Euler(psi + that.Z(), theta + that.Y(), phi + that.X());} 109 | */ 110 | public static Euler operator * (Euler first, float value) {return new Euler(first.psi*value, first.theta*value, first.phi*value);} 111 | public static Euler operator + (Euler first, Euler second) {return new Euler(first.psi+second.psi, first.theta+second.theta, first.phi+second.phi);} 112 | // Accessor functions. 113 | public double Psi { get {return psi;} set { matrix_current = psi == value && matrix_current; psi=value;/*psi = AEPCPI(value); */cpsi=(float)Math.Cos(psi); spsi=(float)Math.Sin(psi); } } 114 | public double Theta { get {return theta;} set {matrix_current = theta == value && matrix_current; theta = AEPCPI(value); ctheta=(float)Math.Cos(theta); stheta=(float)Math.Sin(theta); } } 115 | public double Phi { get {return phi;} set {matrix_current = phi == value && matrix_current; phi = AEPCPI(value); cphi=(float)Math.Cos(phi); sphi=(float)Math.Sin(phi); } } 116 | public double cosPsi () {return cpsi;} 117 | public double cosTheta () {return ctheta;} 118 | public double cosPhi () {return cphi;} 119 | public double sinPsi () {return spsi;} 120 | public double sinTheta () {return stheta;} 121 | public double sinPhi () {return sphi;} 122 | public double PsiAsDegrees () {return (psi*180.0/Math.PI);} 123 | public double ThetaAsDegrees () {return (theta*180.0/Math.PI);} 124 | public double PhiAsDegrees () {return (phi*180.0/Math.PI);} 125 | 126 | // Set functions. 127 | public Euler SetToZero () {psi= 0; theta= 0; phi= 0; return this;} 128 | 129 | public Euler SetPsiAsDegrees ( 130 | double x_psi 131 | ) {Psi = (x_psi*Math.PI/180.0); return this;} 132 | public Euler SetThetaAsDegrees ( 133 | double x_theta 134 | ) {Theta = (x_theta*Math.PI/180.0); return this;} 135 | public Euler SetPhiAsDegrees ( 136 | double x_phi 137 | ) {Phi = (x_phi*Math.PI/180.0); return this;} 138 | 139 | public float AEPCPI( float angle) 140 | { 141 | while ( angle > (Math.PI+Math.PI) ) angle -= (float)(Math.PI+Math.PI); 142 | while ( angle < 0.0f ) angle += (float)(Math.PI+Math.PI); 143 | return angle; 144 | } 145 | public double AEPCPI( double angle) 146 | { 147 | while ( angle > (Math.PI+Math.PI) ) angle -= (Math.PI+Math.PI); 148 | while ( angle < 0.0 ) angle += (Math.PI+Math.PI); 149 | return angle; 150 | } 151 | 152 | 153 | 154 | public void Limits ( 155 | ) 156 | 157 | { 158 | // Flip heading and roll when we go over the top or through the bottom. 159 | if ( theta > (Math.PI/2.0) ) 160 | { 161 | theta = Math.PI - Theta; 162 | psi = AEPCPI( Psi + Math.PI ); 163 | phi = AEPCPI( Phi + Math.PI ); 164 | } 165 | else if ( theta < -(Math.PI/2.0) ) 166 | { 167 | theta = -Math.PI - Theta; 168 | psi = AEPCPI( Psi + Math.PI ); 169 | phi = AEPCPI( Phi + Math.PI ); 170 | } 171 | else 172 | { 173 | psi = AEPCPI( Psi ); 174 | phi = AEPCPI( Phi ); 175 | } 176 | 177 | } // end Limits 178 | 179 | 180 | 181 | 182 | 183 | /////////////////////////////////////////////////////////////////////////////// 184 | public void Limits ( 185 | Euler results 186 | ) 187 | 188 | { 189 | // Flip heading and roll when we go over the top or through the bottom. 190 | if ( results.Theta > (Math.PI/2.0) ) 191 | { 192 | theta = (float)Math.PI - results.Theta; 193 | psi = (float)AEPCPI( results.Psi + (float)Math.PI ); 194 | phi = (float)AEPCPI( results.Phi + (float)Math.PI ); 195 | } 196 | else if ( results.Theta < -(Math.PI/2.0) ) 197 | { 198 | theta = -(float)Math.PI - results.Theta; 199 | psi = (float)AEPCPI( results.Psi + (float)Math.PI ); 200 | phi = (float)AEPCPI( results.Phi + (float)Math.PI ); 201 | } 202 | else 203 | { 204 | theta = results.Theta; 205 | psi = (float)AEPCPI( results.Psi ); 206 | phi = (float)AEPCPI( results.Phi ); 207 | } 208 | 209 | } // end Limits 210 | 211 | 212 | 213 | 214 | 215 | /////////////////////////////////////////////////////////////////////////////// 216 | public void Limits ( 217 | float x_psi, 218 | float x_theta, 219 | float x_phi 220 | ) 221 | 222 | { 223 | // Flip heading and roll when we go over the top or through the bottom 224 | if ( x_theta > (Math.PI/2.0) ) 225 | { 226 | theta = (float)Math.PI - x_theta; 227 | psi = (float)AEPCPI( x_psi + Math.PI ); 228 | phi = (float)AEPCPI( x_phi + Math.PI ); 229 | } 230 | else if ( x_theta < -(Math.PI/2.0) ) 231 | { 232 | theta = -(float)Math.PI - x_theta; 233 | psi = (float)AEPCPI( x_psi + Math.PI ); 234 | phi = (float)AEPCPI( x_phi + Math.PI ); 235 | } 236 | else 237 | { 238 | theta = x_theta; 239 | psi = (float)AEPCPI( x_psi ); 240 | phi = (float)AEPCPI( x_phi ); 241 | } 242 | 243 | } // end Limits 244 | 245 | 246 | 247 | 248 | 249 | /////////////////////////////////////////////////////////////////////////////// 250 | public float AngularDifference( float ang1, float ang2 ) 251 | { 252 | float result; 253 | 254 | result = ang1 - ang2; 255 | 256 | if ( result < 0.0 ) 257 | { 258 | result *= -1.0f; 259 | } 260 | 261 | return result; 262 | } 263 | //======================================================================= 264 | public void RotateAtoE( Vector num ) 265 | { 266 | double[] temp = new double[3]; 267 | 268 | if ( !matrix_current ) CalcMatrix(); 269 | 270 | temp[0] = mat[0,0] * num.X + mat[0,1] * num.Y + mat[0,2] * num.Z; 271 | temp[1] = mat[1,0] * num.X + mat[1,1] * num.Y + mat[1,2] * num.Z; 272 | temp[2] = mat[2,0] * num.X + mat[2,1] * num.Y + mat[2,2] * num.Z; 273 | 274 | num.SetX(temp[0]); 275 | num.SetY(temp[1]); 276 | num.SetZ(temp[2]); 277 | } 278 | //======================================================================= 279 | public void RotateEtoA( Vector num ) 280 | { 281 | double[] temp = new double[3]; 282 | 283 | if ( !matrix_current ) CalcMatrix(); 284 | 285 | temp[0] = mat[0,0] * num.X + mat[1,0] * num.Y + mat[2,0] * num.Z; 286 | temp[1] = mat[0,1] * num.X + mat[1,1] * num.Y + mat[2,1] * num.Z; 287 | temp[2] = mat[0,2] * num.X + mat[1,2] * num.Y + mat[2,2] * num.Z; 288 | 289 | num.SetX(temp[0]); 290 | num.SetY(temp[1]); 291 | num.SetZ(temp[2]); 292 | } 293 | //==================================================================================================== 294 | public void CalcMatrix() 295 | { 296 | mat[0,0] = ctheta * cpsi; 297 | mat[0,1] = sphi * stheta * cpsi - cphi * spsi; 298 | mat[0,2] = cphi * stheta * cpsi + sphi * spsi; 299 | 300 | mat[1,0] = ctheta * spsi; 301 | mat[1,1] = sphi * stheta * spsi + cphi * cpsi; 302 | mat[1,2] = cphi * stheta * spsi - sphi * cpsi; 303 | 304 | mat[2,0] = -stheta; 305 | mat[2,1] = sphi * ctheta; 306 | mat[2,2] = cphi * ctheta; 307 | 308 | matrix_current = true; 309 | } 310 | 311 | }; 312 | } 313 | -------------------------------------------------------------------------------- /1590590813-1225/CarLib/LFI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace VehicleDynamics 4 | { 5 | /// 6 | ///Class for Linear Function Interpolation 7 | /// 8 | public class LFI 9 | { 10 | private double[] data = new double[101]; 11 | private double slope = 1.0; 12 | private double intercept = 0.0; 13 | 14 | public double Slope 15 | { 16 | get { return slope; } 17 | set { slope = value; } 18 | } 19 | public double Intercept 20 | { 21 | get { return intercept; } 22 | set { intercept = value; } 23 | } 24 | 25 | 26 | /// 27 | ///Method to place curve data into the class 28 | /// 29 | public bool SetDataPoint(double index_value, float data_point) 30 | { 31 | bool result = false; 32 | int index = (int)(index_value / slope - intercept); 33 | 34 | if ( index >= 0 && index <= 100 ) 35 | { 36 | data[index] = data_point; 37 | result = true; 38 | } 39 | 40 | return result; 41 | 42 | } 43 | 44 | /// 45 | ///Method to interpolate linearly to get a value from a data curve. 46 | /// 47 | public double Interpolate( double index_value ) 48 | { 49 | double delta; 50 | double result = 0.0; 51 | 52 | try 53 | { 54 | double scaled_value = index_value / slope - intercept; 55 | int index = (int)scaled_value; 56 | delta = data[index+1] - data[index]; 57 | result = data[index] + delta * (scaled_value - index); 58 | } 59 | catch ( Exception e ) 60 | { 61 | System.Diagnostics.Debug.WriteLine(e.Message); 62 | } 63 | 64 | return result; 65 | 66 | } 67 | 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /1590590813-1225/CarLib/Vector.cs: -------------------------------------------------------------------------------- 1 | // created on 10/22/2002 at 11:39 AM 2 | using System; 3 | 4 | namespace VehicleDynamics 5 | { 6 | public class Vector 7 | { 8 | 9 | public Vector() {x=0.0; y=0.0; z=0.0;} 10 | public Vector ( Vector other ) {x=other.x; y=other.y; z=other.z;} 11 | public Vector ( double new_x, double new_y, double new_z ) 12 | {x=new_x; y=new_y; z=new_z;} 13 | ~Vector () {} 14 | 15 | // Operator functions. 16 | public static bool operator <( Vector first, Vector second ) {return (first.x < second.x && first.y < second.y && first.z < second.z);} 17 | public static bool operator >( Vector first, Vector second ) {return (first.x > second.x && first.y > second.y && first.z > second.z);} 18 | public static bool operator ==(Vector first, Vector second ) {return first.x==second.x && first.y==second.y && first.z==second.z;} 19 | public bool Equals( Vector second ) {return x==second.x && y==second.y && z==second.z;} 20 | public static bool operator !=(Vector first, Vector second ) {return first.x!=second.x || first.y!=second.y || first.z!=second.z;} 21 | 22 | public static Vector operator -(Vector first) {return new Vector(-first.x, -first.y, -first.z);} 23 | public static Vector operator - (Vector first, Vector second) {return new Vector(first.x - second.x, first.y - second.y, first.z - second.z);} 24 | public static Vector operator + (Vector first, Vector second) {return new Vector(first.x + second.x, first.y + second.y, first.z + second.z);} 25 | public static Vector operator / (Vector first, float value) {return new Vector(first.x/value, first.y/value, first.z/value);} 26 | public static Vector operator * (Vector first, float value) {return new Vector(first.x*value, first.y*value, first.z*value);} 27 | public static double operator * (Vector first, Vector second) {return (first.x*second.x + first.y*second.y + first.z*second.z);} 28 | 29 | // Accessor functions. 30 | public double X { get {return x;} set { x = value; } } 31 | public double Y { get {return y;} set { y = value; } } 32 | public double Z { get {return z;} set { z = value; } } 33 | 34 | // Set functions. 35 | public Vector Set ( 36 | double new_x, 37 | double new_y, 38 | double new_z 39 | ) {x= new_x; y= new_y; z= new_z; return this;} 40 | public Vector SetX ( 41 | double new_x 42 | ) {x= new_x; return this;} 43 | public Vector SetY ( 44 | double new_y 45 | ) {y= new_y; return this;} 46 | public Vector SetZ ( 47 | double new_z 48 | ) {z= new_z; return this;} 49 | public Vector SetToZero () {x= 0; y= 0; z= 0; return this;} 50 | 51 | // Limiting functions. 52 | public Vector Limit ( 53 | Vector value, 54 | Vector limit 55 | ) 56 | { 57 | return new Vector( Math.Min( limit.X, Math.Max( limit.X, value.X) ), 58 | Math.Min( limit.Y, Math.Max( limit.Y, value.Y) ), 59 | Math.Min( limit.Z, Math.Max( limit.Z, value.Z) ) );} 60 | 61 | public Vector Limit ( 62 | Vector limit 63 | ) 64 | { 65 | LimitX( limit.X ); 66 | LimitY( limit.Y ); 67 | LimitZ( limit.Z ); return this;} 68 | 69 | public double LimitX ( 70 | double min_value, 71 | double max_value 72 | ) {return Math.Min( max_value, Math.Max( min_value, x) );} 73 | public double LimitX ( 74 | double value 75 | ) {return Math.Min( value, Math.Max( -value, x) );} 76 | public double LimitY ( 77 | double min_value, 78 | double max_value 79 | ) {return Math.Min( max_value, Math.Max( min_value, y) );} 80 | public double LimitY ( 81 | double value 82 | ) {return Math.Min( value, Math.Max( -value, y) );} 83 | public double LimitZ ( 84 | double min_value, 85 | double max_value 86 | ) {return Math.Min( max_value, Math.Max( min_value, z) );} 87 | public double LimitZ ( 88 | double value 89 | ) {return Math.Min( value, Math.Max( -value, z) );} 90 | 91 | public Vector Delta ( 92 | Vector from 93 | ) {return new Vector(x - from.x, y - from.y, z - from.z);} 94 | public double DeltaX ( 95 | Vector from 96 | ) {return x - from.x;} 97 | public double DeltaY ( 98 | Vector from 99 | ) {return y - from.y;} 100 | public double DeltaZ ( 101 | Vector from 102 | ) {return z - from.z;} 103 | public Vector ABSDelta ( 104 | Vector from 105 | ) {return new Vector(Math.Abs(x - from.x), Math.Abs(y - from.y), Math.Abs(z - from.z));} 106 | public double ABSDeltaX ( 107 | Vector from 108 | ) {return Math.Abs(x - from.x);} 109 | public double ABSDeltaY ( 110 | Vector from 111 | ) {return Math.Abs(y - from.y);} 112 | public double ABSDeltaZ ( 113 | Vector from 114 | ) {return Math.Abs(z - from.z);} 115 | /* 116 | public float XYDotProduct ( 117 | Vector other 118 | ) { return new Vector( *this ).SetZ( 0. ).DotProduct( Vector( other ).SetZ( 0. ) ); } 119 | 120 | public float XZDotProduct ( 121 | Vector other 122 | ) { return new Vector( *this ).SetY( 0. ).DotProduct( Vector( other ).SetY( 0. ) ); } 123 | public float YZDotProduct ( 124 | Vector other 125 | ) { return new Vector( *this ).SetX( 0. ).DotProduct( Vector( other ).SetX( 0. ) ); } 126 | */ 127 | 128 | protected double x; 129 | protected double y; 130 | protected double z; 131 | 132 | 133 | private double DistanceFrom ( Vector from ) 134 | { 135 | return Math.Sqrt((x-from.x)*(x-from.x) + (y-from.y)*(y-from.y) + (z-from.z)*(z-from.z)); 136 | 137 | } // end otherDistanceFrom 138 | 139 | 140 | /////////////////////////////////////////////////////////////////////////////// 141 | public double otherXYDistanceFrom ( 142 | Vector from 143 | ) 144 | 145 | { 146 | return Math.Sqrt((x-from.x)*(x-from.x) + (y-from.y)*(y-from.y)); 147 | 148 | } // end otherXYDistanceFrom 149 | 150 | 151 | 152 | /////////////////////////////////////////////////////////////////////////////// 153 | public double otherDistanceFrom () 154 | { 155 | return Math.Sqrt( (x*x) + (y*y) + (z*z) ); 156 | 157 | } // end otherDistanceFrom 158 | 159 | /////////////////////////////////////////////////////////////////////////////// 160 | public double DistanceFrom ( ) 161 | { 162 | return Math.Sqrt( (x*x) + (y*y) + (z*z) ); 163 | 164 | } // end DistanceFrom 165 | 166 | 167 | /////////////////////////////////////////////////////////////////////////////// 168 | public double XYDistanceFrom ( Vector from ) 169 | { 170 | return Math.Sqrt((x-from.x)*(x-from.x) + (y-from.y)*(y-from.y)); 171 | 172 | } // end XYDistanceFrom 173 | 174 | /////////////////////////////////////////////////////////////////////////////// 175 | public double XYDistanceFrom () 176 | { 177 | return Math.Sqrt( (x*x) + (y*y) ); 178 | 179 | } // end XYDistanceFrom 180 | 181 | /////////////////////////////////////////////////////////////////////////////// 182 | public double otherXYDistanceFrom () 183 | { 184 | return Math.Sqrt( (x*x) + (y*y) ); 185 | 186 | } // end otherXYDistanceFrom 187 | 188 | /////////////////////////////////////////////////////////////////////////////// 189 | public Vector Normalize () 190 | { 191 | float temp = (float)Math.Sqrt(x*x + y*y + z*z); 192 | if ( temp != 0.0f ) 193 | return new Vector( x/temp, y/temp, z/temp ); 194 | 195 | return new Vector (0.0f, 0.0f, 0.0f ); 196 | 197 | } // end otherUnitNormal 198 | 199 | /////////////////////////////////////////////////////////////////////////////// 200 | public double otherDotProduct ( Vector other ) 201 | { 202 | double cosine_theta = 0.0; 203 | if ( !( other.x == 0.0 && other.y == 0.0 && other.z == 0.0 ) && 204 | !( x == 0.0 && y == 0.0 && z == 0.0 ) ) 205 | { 206 | double dist1= other.DistanceFrom(); 207 | double dist2= DistanceFrom(); 208 | cosine_theta= x*other.x + y*other.y + z*other.z / ( dist1 * dist2 ); 209 | } 210 | 211 | return cosine_theta; 212 | 213 | } // end otherDotProduct 214 | 215 | 216 | /////////////////////////////////////////////////////////////////////////////// 217 | Vector CrossProduct ( Vector that) 218 | { 219 | return new Vector(y*that.z - z*that.y, z*that.x - x*that.z, x*that.y - y*that.x); 220 | 221 | } // end CrossProduct 222 | 223 | /////////////////////////////////////////////////////////////////////////////// 224 | public Vector otherCrossProduct ( Vector other ) 225 | { 226 | return new Vector(y*other.z - z*other.y, z*other.x - x*other.z, x*other.y - y*other.x); 227 | 228 | } // end otherCrossProduct 229 | 230 | 231 | 232 | 233 | 234 | /////////////////////////////////////////////////////////////////////////////// 235 | public double otherSinThetaCrossProduct ( 236 | Vector other, 237 | Vector product 238 | ) 239 | { 240 | double sine_theta = 0.0; 241 | if ( !( other.x == 0.0 && other.y == 0.0 && other.z == 0.0 ) && 242 | !( x == 0.0 && y == 0.0 && z == 0.0 ) ) 243 | { 244 | double dist1= other.DistanceFrom(); 245 | double dist2= DistanceFrom(); 246 | product= other.CrossProduct(this); 247 | sine_theta= ( product.X - product.Y + product.Z ) / ( dist1 * dist2 ) ; 248 | } 249 | 250 | return sine_theta; 251 | 252 | } // end otherSinThetaCrossProduct 253 | 254 | 255 | 256 | 257 | 258 | /////////////////////////////////////////////////////////////////////////////// 259 | public double otherElevBrg ( 260 | Vector other 261 | ) 262 | 263 | { 264 | double xy_length= XYDistanceFrom( other ); 265 | double elev_brg= Math.Atan2( DeltaZ( other ), xy_length ); 266 | 267 | while ( elev_brg > Math.PI ) elev_brg -= Math.PI; 268 | while ( elev_brg < -Math.PI ) elev_brg += Math.PI; 269 | 270 | return elev_brg; 271 | 272 | } // end otherElevBrg 273 | 274 | 275 | 276 | 277 | 278 | /////////////////////////////////////////////////////////////////////////////// 279 | public double otherRelBrg ( 280 | Vector other 281 | ) 282 | 283 | { 284 | return Math.Atan2( Y-other.Y, X-other.X ); 285 | 286 | } // end otherRelBrg 287 | 288 | 289 | /////////////////////////////////////////////////////////////////////////////// 290 | bool otherIsParallelWith ( 291 | Vector other 292 | ) 293 | 294 | { 295 | return CrossProduct(other) == new Vector(0.0f, 0.0f, 0.0f); 296 | 297 | } // end otherIsParallelWith 298 | 299 | 300 | 301 | 302 | 303 | /////////////////////////////////////////////////////////////////////////////// 304 | /* 305 | float otherDistanceFromLine ( 306 | Vector point0, 307 | Vector point1 308 | ) 309 | 310 | { 311 | float distance= point0.DistanceFrom(point1); 312 | return (distance > 0.001)? ((point0 - point1).CrossProduct(this - point1).DistanceFrom() / distance) : DistanceFrom(point0); 313 | 314 | } // end otherDistanceFromLine 315 | */ 316 | 317 | public void IncrementX(double value) 318 | { 319 | x += value; 320 | } 321 | 322 | public void IncrementY(double value) 323 | { 324 | y += value; 325 | } 326 | 327 | public void IncrementZ(double value) 328 | { 329 | z += value; 330 | } 331 | 332 | }; 333 | } 334 | -------------------------------------------------------------------------------- /1590590813-1225/CarLib/Wheel.cs: -------------------------------------------------------------------------------- 1 | // created on 10/22/2002 at 12:02 PM 2 | using System; 3 | 4 | namespace VehicleDynamics 5 | { 6 | public enum WhichWheel { LeftFront=0, RightFront, LeftRear, RightRear }; 7 | 8 | public struct Wheel 9 | { 10 | #region Attributes 11 | 12 | public Vector offset; 13 | public Vector earth_location; 14 | private double rel_heading; 15 | public double radius; 16 | public double ground_height; 17 | public double altitude; 18 | public double height_above_ground; 19 | private double weight_over_wheel; 20 | private double static_weight_over_wheel; 21 | public double suspension_offset; 22 | public double max_suspension_offset; 23 | private double upwards_force; 24 | public double friction; 25 | private double stiction; 26 | private double sliding_friction; 27 | public bool bottomed_out; 28 | public bool touching_ground; 29 | public bool squealing; 30 | public bool sliding; 31 | public bool drive_wheel; 32 | public WhichWheel position; 33 | 34 | private static double spring_constant = 61000.0; 35 | private static double damping = -700.0; 36 | #endregion 37 | 38 | #region Properties 39 | 40 | public double RelHeading { set { rel_heading = value; } } 41 | public double UpwardsForce { get { return upwards_force; } } 42 | public double WeightOverWheel { set { weight_over_wheel = value; } get { return weight_over_wheel; } } 43 | public double StaticWeightOverWheel { set { static_weight_over_wheel = value; } } 44 | public double Stiction 45 | { 46 | set 47 | { 48 | stiction = value; 49 | sliding_friction = 0.6f * stiction; 50 | } 51 | } 52 | #endregion 53 | 54 | public Wheel(WhichWheel where) 55 | { 56 | position = where; 57 | offset = new Vector(0.0, 0.0, 0.0); 58 | earth_location = new Vector(0.0, 0.0, 0.0); 59 | rel_heading = 0.0; 60 | radius = 0.5; 61 | height_above_ground = 0.0; 62 | ground_height = 0.0; 63 | friction = 1.0; 64 | weight_over_wheel = 0.0; 65 | static_weight_over_wheel = 0.0; 66 | suspension_offset = 0.0; 67 | max_suspension_offset = 0.25; 68 | altitude = 0.0; 69 | bottomed_out = false; 70 | drive_wheel = false; 71 | sliding = false; 72 | sliding_friction = 0.0; 73 | squealing = false; 74 | stiction = 1.0; 75 | upwards_force = 0.0; 76 | touching_ground = true; 77 | } 78 | 79 | public void Process(float delta_t, Euler attitude, Vector acceleration, Vector velocity, Vector position) 80 | { 81 | double temp; 82 | double susp_delta; 83 | double squeel_force; 84 | double slide_force; 85 | double grab_force; 86 | double tire_side_force; 87 | 88 | earth_location.X = offset.X; 89 | earth_location.Y = offset.Y; 90 | earth_location.Z = offset.Z + suspension_offset; 91 | attitude.RotateAtoE( earth_location ); 92 | 93 | altitude = position.Z + earth_location.Z - radius; 94 | 95 | height_above_ground = altitude - ground_height; 96 | 97 | touching_ground = height_above_ground <= 0.0f; 98 | 99 | if ( touching_ground ) 100 | { 101 | suspension_offset = -height_above_ground; 102 | } 103 | else 104 | { 105 | suspension_offset = -max_suspension_offset; 106 | } 107 | 108 | susp_delta = (suspension_offset + height_above_ground) * delta_t; 109 | if ( Math.Abs(upwards_force - weight_over_wheel) < 2.0 ) 110 | { 111 | suspension_offset -= susp_delta; 112 | } 113 | if ( suspension_offset > max_suspension_offset ) 114 | { 115 | suspension_offset = max_suspension_offset; 116 | } 117 | else if ( suspension_offset < -max_suspension_offset ) 118 | { 119 | suspension_offset = -max_suspension_offset; 120 | } 121 | bottomed_out = suspension_offset == max_suspension_offset; 122 | 123 | temp = ( 0.3f * ( suspension_offset * suspension_offset ) / (max_suspension_offset * max_suspension_offset ) ); 124 | if ( suspension_offset < 0.0f ) 125 | { 126 | temp *= -1.0f; 127 | } 128 | if ( Math.Abs(suspension_offset) < 0.3f ) 129 | { 130 | temp = 0.0f; // suspension neutral 131 | } 132 | temp += 1.0f; 133 | if ( !touching_ground ) 134 | { 135 | temp = 0.0f; 136 | } 137 | 138 | double spring_force = spring_constant * suspension_offset; 139 | double damping_force = damping * suspension_offset / max_suspension_offset; 140 | 141 | if ( touching_ground ) 142 | { 143 | upwards_force = (spring_force + damping_force); 144 | } 145 | else 146 | { 147 | upwards_force = 0.0; 148 | } 149 | // upwards_force = static_weight_over_wheel * temp; 150 | 151 | if ( (upwards_force - weight_over_wheel) > 2.0f ) 152 | { 153 | suspension_offset -= 0.5f * delta_t; 154 | } 155 | else if ( (upwards_force - weight_over_wheel) < -2.0f ) 156 | { 157 | suspension_offset += 0.5f * delta_t; 158 | } 159 | 160 | slide_force = 32.0f * stiction * friction; 161 | squeel_force = 0.9f * slide_force; 162 | grab_force = 32.0f * sliding_friction; 163 | 164 | if ( (acceleration.Y > 0.0f && rel_heading > 0.0f ) || (acceleration.Y < 0.0f && rel_heading < 0.0f ) ) 165 | { 166 | tire_side_force = (float)Math.Abs(acceleration.Y * (1.0f - Math.Cos(rel_heading))); 167 | } 168 | else 169 | { 170 | tire_side_force = (float)Math.Abs(acceleration.Y * Math.Cos(rel_heading)); 171 | } 172 | 173 | squealing = false; 174 | sliding = false; 175 | if ( drive_wheel && acceleration.X >= slide_force ) 176 | { 177 | sliding = true; 178 | } 179 | if ( (acceleration.X < -squeel_force && acceleration.X > -slide_force) || 180 | (tire_side_force > squeel_force && tire_side_force < slide_force) ) 181 | { 182 | squealing = true; 183 | } 184 | if ( acceleration.X <= -slide_force || tire_side_force >= slide_force ) 185 | { 186 | sliding = true; 187 | } 188 | if ( Math.Abs(acceleration.X) < grab_force && Math.Abs(velocity.Y)< grab_force && tire_side_force < grab_force ) 189 | { 190 | sliding = false; 191 | } 192 | } 193 | 194 | }; 195 | } 196 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/AIState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Xml; 4 | 5 | namespace GameAI 6 | { 7 | /// 8 | /// Summary description for AIState. 9 | /// 10 | public class AIState 11 | { 12 | #region Attributes 13 | private string m_name; 14 | private ArrayList m_transition_list; 15 | private ArrayList m_actions; 16 | #endregion 17 | 18 | #region Properties 19 | public string Name { get { return m_name; } } 20 | #endregion 21 | 22 | public AIState(string name) 23 | { 24 | m_name = name; 25 | m_transition_list = new ArrayList(); 26 | m_actions = new ArrayList(); 27 | } 28 | 29 | public void AddAction( Thinker.ActionMethod method ) 30 | { 31 | m_actions.Add( method ); 32 | } 33 | 34 | public void DoActions( Thinker thinker ) 35 | { 36 | foreach ( Thinker.ActionMethod act in m_actions ) 37 | { 38 | act(thinker); 39 | } 40 | } 41 | 42 | public AIState Think() 43 | { 44 | AIState new_state; 45 | 46 | foreach ( Transitioner trans in m_transition_list ) 47 | { 48 | new_state = trans.Evaluate( this ); 49 | if ( new_state != this ) 50 | { 51 | return new_state; 52 | } 53 | } 54 | return this; 55 | } 56 | 57 | public void AddTransitioner ( Transitioner trans ) 58 | { 59 | m_transition_list.Add( trans ); 60 | } 61 | 62 | public void WriteStateName( XmlTextWriter writer ) 63 | { 64 | writer.WriteStartElement("StateName"); 65 | writer.WriteElementString("name", m_name); 66 | writer.WriteEndElement(); 67 | } 68 | 69 | public void WriteFullState( XmlTextWriter writer, Thinker thinker ) 70 | { 71 | writer.WriteStartElement("StateDefinition"); 72 | writer.WriteElementString("name", m_name); 73 | foreach ( Transitioner trans in m_transition_list ) 74 | { 75 | trans.Write( writer ); 76 | } 77 | foreach ( Thinker.ActionMethod act in m_actions ) 78 | { 79 | writer.WriteStartElement("StateAction"); 80 | writer.WriteElementString("name", Thinker.GetActionName( act )); 81 | writer.WriteEndElement(); 82 | } 83 | writer.WriteEndElement(); 84 | } 85 | 86 | public void Read ( XmlTextReader reader, Thinker thinker ) 87 | { 88 | bool done = false; 89 | Transitioner trans = null; 90 | Expression exp = null; 91 | 92 | while ( !done ) 93 | { 94 | reader.Read(); 95 | 96 | if ( reader.NodeType == XmlNodeType.EndElement && 97 | reader.Name == "StateDefinition" ) 98 | { 99 | done =true; 100 | } 101 | // Process a start of element node. 102 | else if (reader.NodeType == XmlNodeType.Element) 103 | { 104 | // Process a text node. 105 | if ( reader.Name == "Target" ) 106 | { 107 | while (reader.NodeType != XmlNodeType.Text) 108 | { 109 | reader.Read(); 110 | } 111 | AIState state = thinker.GetState(reader.Value); 112 | exp = new Expression(); 113 | trans = new Transitioner( exp, state ); 114 | AddTransitioner( trans ); 115 | trans.Read( reader, thinker ); 116 | } 117 | if ( reader.Name == "StateAction" ) 118 | { 119 | while (reader.NodeType != XmlNodeType.Text) 120 | { 121 | reader.Read(); 122 | } 123 | Thinker.ActionMethod method = Thinker.GetAction(reader.Value); 124 | m_actions.Add( method ); 125 | } 126 | } 127 | }// End while loop 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/Class1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GameAI 4 | { 5 | /// 6 | /// Summary description for Class1. 7 | /// 8 | public class Class1 9 | { 10 | public Class1() 11 | { 12 | // 13 | // TODO: Add constructor logic here 14 | // 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/Expression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Xml; 4 | 5 | namespace GameAI 6 | { 7 | /// 8 | /// Summary description for Expression. 9 | /// 10 | public class Expression 11 | { 12 | #region Attributes 13 | private ArrayList m_logic_list; 14 | private bool m_and_values = true; 15 | #endregion 16 | 17 | #region Properties 18 | public bool CombineByAnding { set { m_and_values = value; } } 19 | #endregion 20 | 21 | public Expression() 22 | { 23 | m_logic_list = new ArrayList(); 24 | } 25 | 26 | public void Clear() 27 | { 28 | m_logic_list.Clear(); 29 | } 30 | 31 | public void AddLogic( Logic logic ) 32 | { 33 | m_logic_list.Add(logic); 34 | } 35 | 36 | public bool Evaluate() 37 | { 38 | bool result = false; 39 | bool first_logic = true; 40 | 41 | foreach ( Logic logic in m_logic_list ) 42 | { 43 | bool val = logic.Evaluate(); 44 | 45 | if ( first_logic ) 46 | { 47 | result = val; 48 | } 49 | else 50 | { 51 | if ( m_and_values ) 52 | { 53 | result = result && val; 54 | } 55 | else 56 | { 57 | result = result || val; 58 | } 59 | } 60 | } 61 | 62 | return result; 63 | } 64 | 65 | public void Write( XmlTextWriter writer ) 66 | { 67 | writer.WriteStartElement("Expression"); 68 | writer.WriteElementString("AndValues", m_and_values.ToString()); 69 | foreach ( Logic logic in m_logic_list ) 70 | { 71 | logic.Write( writer ); 72 | } 73 | writer.WriteEndElement(); 74 | } 75 | 76 | public void Read ( XmlTextReader reader, Thinker thinker ) 77 | { 78 | bool done = false; 79 | 80 | while ( !done ) 81 | { 82 | reader.Read(); 83 | 84 | if ( reader.NodeType == XmlNodeType.EndElement && 85 | reader.Name == "Expression" ) 86 | { 87 | done =true; 88 | } 89 | // Process a start of element node. 90 | else if (reader.NodeType == XmlNodeType.Element) 91 | { 92 | // Process a text node. 93 | if ( reader.Name == "Logic" ) 94 | { 95 | Logic logic = new Logic(); 96 | logic.Read( reader, thinker ); 97 | m_logic_list.Add( logic ); 98 | } 99 | else if ( reader.Name == "AndValues" ) 100 | { 101 | while (reader.NodeType != XmlNodeType.Text) 102 | { 103 | reader.Read(); 104 | } 105 | m_and_values = bool.Parse(reader.Value); 106 | } 107 | } 108 | }// End while loop 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/Fact.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml; 3 | 4 | namespace GameAI 5 | { 6 | public enum Operator { 7 | Equals, 8 | LessThan, 9 | GreaterThan, 10 | LessThanEquals, 11 | GreaterThanEquals, 12 | NotEqual, 13 | And, 14 | Or, 15 | True, 16 | False 17 | }; 18 | /// 19 | /// Summary description for Fact 20 | /// 21 | public class Fact 22 | { 23 | #region Attributes 24 | private string m_Name; 25 | private float m_Value; 26 | 27 | private static float m_Epsilon = 0.001f; 28 | #endregion 29 | #region Properties 30 | public string Name { get { return m_Name; } } 31 | public float Value { get { return m_Value; } set { m_Value = value; } } 32 | public bool IsTrue { get { return (Math.Abs(m_Value) > m_Epsilon); } } 33 | 34 | public static float Epsilon { set { m_Epsilon = value; } } 35 | #endregion 36 | 37 | public Fact(string name) 38 | { 39 | m_Name = name; 40 | } 41 | 42 | public void Write( XmlTextWriter writer ) 43 | { 44 | writer.WriteStartElement("Fact"); 45 | writer.WriteElementString("name", m_Name); 46 | writer.WriteElementString("Value", XmlConvert.ToString(m_Value)); 47 | writer.WriteEndElement(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/GameAI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 22 | 40 | 58 | 59 | 60 | 65 | 70 | 75 | 80 | 81 | 82 | 83 | 84 | 89 | 94 | 99 | 104 | 109 | 114 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/GameAI.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 37 | 38 | 39 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/Logic.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml; 3 | using System.Diagnostics; 4 | 5 | namespace GameAI 6 | { 7 | /// 8 | /// Summary description for Logic. 9 | /// 10 | public class Logic 11 | { 12 | #region Attributes 13 | private Fact m_first; 14 | private Fact m_second; 15 | private Operator m_operator; 16 | #endregion 17 | 18 | #region Properties 19 | public Fact FirstFact { get { return m_first; } set { m_first = value; } } 20 | public Fact SecondFact { get { return m_second; } set { m_second = value; } } 21 | public Operator Operation { get { return m_operator; } set { m_operator = value; } } 22 | #endregion 23 | 24 | public Logic() 25 | { 26 | m_first = null; 27 | m_second = null; 28 | m_operator = Operator.Equals; 29 | } 30 | 31 | public Logic(Fact first, Fact second, Operator op) 32 | { 33 | m_first = first; 34 | m_second = second; 35 | m_operator = op; 36 | } 37 | 38 | public bool Evaluate() 39 | { 40 | bool result = false; 41 | 42 | if ( m_first != null ) 43 | { 44 | switch ( m_operator ) 45 | { 46 | case Operator.And: 47 | if ( m_second != null ) 48 | { 49 | result = m_first.IsTrue && m_second.IsTrue; 50 | } 51 | else 52 | { 53 | Debug.WriteLine("second fact missing in Logic"); 54 | } 55 | break; 56 | case Operator.Equals: 57 | if ( m_second != null ) 58 | { 59 | result = m_first.Value == m_second.Value; 60 | } 61 | else 62 | { 63 | Debug.WriteLine("second fact missing in Logic"); 64 | } 65 | break; 66 | case Operator.GreaterThan: 67 | if ( m_second != null ) 68 | { 69 | result = m_first.Value > m_second.Value; 70 | } 71 | else 72 | { 73 | Debug.WriteLine("second fact missing in Logic"); 74 | } 75 | break; 76 | case Operator.GreaterThanEquals: 77 | if ( m_second != null ) 78 | { 79 | result = m_first.Value >= m_second.Value; 80 | } 81 | else 82 | { 83 | Debug.WriteLine("second fact missing in Logic"); 84 | } 85 | break; 86 | case Operator.LessThan: 87 | if ( m_second != null ) 88 | { 89 | result = m_first.Value < m_second.Value; 90 | } 91 | else 92 | { 93 | Debug.WriteLine("second fact missing in Logic"); 94 | } 95 | break; 96 | case Operator.LessThanEquals: 97 | if ( m_second != null ) 98 | { 99 | result = m_first.Value <= m_second.Value; 100 | } 101 | else 102 | { 103 | Debug.WriteLine("second fact missing in Logic"); 104 | } 105 | break; 106 | case Operator.NotEqual: 107 | if ( m_second != null ) 108 | { 109 | result = m_first.Value != m_second.Value; 110 | } 111 | else 112 | { 113 | Debug.WriteLine("second fact missing in Logic"); 114 | } 115 | break; 116 | case Operator.Or: 117 | if ( m_second != null ) 118 | { 119 | result = m_first.IsTrue || m_second.IsTrue; 120 | } 121 | else 122 | { 123 | Debug.WriteLine("second fact missing in Logic"); 124 | } 125 | break; 126 | case Operator.True: 127 | result = m_first.IsTrue; 128 | break; 129 | case Operator.False: 130 | result = !m_first.IsTrue; 131 | break; 132 | } 133 | } 134 | else 135 | { 136 | Debug.WriteLine("first fact missing in Logic"); 137 | } 138 | 139 | return result; 140 | } 141 | 142 | public void Write( XmlTextWriter writer ) 143 | { 144 | writer.WriteStartElement("Logic"); 145 | writer.WriteElementString("Fact1", m_first.Name); 146 | writer.WriteElementString("Operator", m_operator.ToString()); 147 | writer.WriteElementString("Fact2", m_second.Name); 148 | writer.WriteEndElement(); 149 | } 150 | 151 | public void Read ( XmlTextReader reader, Thinker thinker ) 152 | { 153 | bool done = false; 154 | 155 | while ( !done ) 156 | { 157 | reader.Read(); 158 | 159 | if ( reader.NodeType == XmlNodeType.EndElement && 160 | reader.Name == "Logic" ) 161 | { 162 | done =true; 163 | } 164 | // Process a start of element node. 165 | else if (reader.NodeType == XmlNodeType.Element) 166 | { 167 | // Process a text node. 168 | if ( reader.Name == "Fact1" ) 169 | { 170 | while (reader.NodeType != XmlNodeType.Text) 171 | { 172 | reader.Read(); 173 | } 174 | m_first = thinker.GetFact(reader.Value); 175 | } 176 | if ( reader.Name == "Fact2" ) 177 | { 178 | while (reader.NodeType != XmlNodeType.Text) 179 | { 180 | reader.Read(); 181 | } 182 | m_second = thinker.GetFact(reader.Value); 183 | } 184 | if ( reader.Name == "Operator" ) 185 | { 186 | while (reader.NodeType != XmlNodeType.Text) 187 | { 188 | reader.Read(); 189 | } 190 | switch ( reader.Value ) 191 | { 192 | case "And": 193 | m_operator = Operator.And; 194 | break; 195 | case "Equals": 196 | m_operator = Operator.Equals; 197 | break; 198 | case "GreaterThan": 199 | m_operator = Operator.GreaterThan; 200 | break; 201 | case "GreaterThanEquals": 202 | m_operator = Operator.GreaterThanEquals; 203 | break; 204 | case "LessThan": 205 | m_operator = Operator.LessThan; 206 | break; 207 | case "LessThanEquals": 208 | m_operator = Operator.LessThanEquals; 209 | break; 210 | case "NotEqual": 211 | m_operator = Operator.NotEqual; 212 | break; 213 | case "Or": 214 | m_operator = Operator.Or; 215 | break; 216 | case "True": 217 | m_operator = Operator.True; 218 | break; 219 | case "False": 220 | m_operator = Operator.False; 221 | break; 222 | } 223 | } 224 | } 225 | }// End while loop 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /1590590813-1225/GameAI/Thinker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Threading; 4 | using System.Diagnostics; 5 | using System.Xml; 6 | using GameEngine; 7 | 8 | namespace GameAI 9 | { 10 | /// 11 | /// Summary description for Thinker. 12 | /// 13 | public class Thinker : IDisposable 14 | { 15 | #region delegates 16 | public delegate void SensorMethod( Thinker the_thinker ); 17 | public delegate void ActionMethod( Thinker the_thinker ); 18 | #endregion 19 | 20 | #region Attributes 21 | private ArrayList m_state_list = null; 22 | private ArrayList m_sensor_methods = null; 23 | private AIState m_current_state = null; 24 | private SortedList m_fact_list; 25 | private Thread m_think_thread; 26 | private Model m_model = null; 27 | private bool m_thread_active = true; 28 | 29 | private static SortedList m_methods = new SortedList(); 30 | #endregion 31 | 32 | #region Properties 33 | public Model Self { get { return m_model; } } 34 | #endregion 35 | 36 | public Thinker( Model model ) 37 | { 38 | m_model = model; 39 | m_state_list = new ArrayList(); 40 | m_sensor_methods = new ArrayList(); 41 | m_fact_list = new SortedList(); 42 | 43 | m_methods = new SortedList(); 44 | 45 | m_think_thread = new Thread(new ThreadStart(Execute)); 46 | m_think_thread.IsBackground = true; 47 | m_think_thread.Start(); 48 | } 49 | 50 | public static void AddAction( string action_name, ActionMethod method ) 51 | { 52 | if ( !m_methods.Contains( action_name ) ) 53 | { 54 | m_methods.Add(action_name, method); 55 | } 56 | } 57 | 58 | public static ActionMethod GetAction( string action_name ) 59 | { 60 | ActionMethod method = null; 61 | 62 | if ( m_methods.Contains( action_name ) ) 63 | { 64 | int index = m_methods.IndexOfKey( action_name ); 65 | method = (ActionMethod)m_methods.GetByIndex(index); 66 | } 67 | 68 | return method; 69 | } 70 | 71 | public static string GetActionName( ActionMethod method ) 72 | { 73 | string action_name = null; 74 | 75 | if ( m_methods.Contains( method ) ) 76 | { 77 | int index = m_methods.IndexOfValue( method ); 78 | action_name = (string)m_methods.GetKey(index); 79 | } 80 | 81 | return action_name; 82 | } 83 | 84 | public void Execute() 85 | { 86 | Debug.WriteLine("thinker thread started"); 87 | while ( m_thread_active ) 88 | { 89 | if ( m_current_state != null ) 90 | { 91 | foreach ( SensorMethod method in m_sensor_methods ) 92 | { 93 | method( this ); 94 | } 95 | 96 | m_current_state.DoActions( this ); 97 | m_current_state = m_current_state.Think(); 98 | } 99 | } 100 | Debug.WriteLine("thinker thread terminated"); 101 | 102 | } 103 | 104 | public void Dispose() 105 | { 106 | m_thread_active = false; 107 | 108 | while ( m_think_thread.IsAlive ) Thread.Sleep(1); 109 | } 110 | 111 | public AIState GetState( string name ) 112 | { 113 | AIState the_state = null; 114 | 115 | foreach ( AIState state in m_state_list ) 116 | { 117 | if ( state.Name == name ) 118 | { 119 | the_state = state; 120 | } 121 | } 122 | return the_state; 123 | } 124 | 125 | public Fact GetFact( string name ) 126 | { 127 | Fact the_fact = null; 128 | 129 | if ( m_fact_list.Contains( name ) ) 130 | { 131 | int index = m_fact_list.IndexOfKey( name ); 132 | the_fact = (Fact)m_fact_list.GetByIndex(index); 133 | } 134 | else 135 | { 136 | the_fact = new Fact(name); 137 | the_fact.Value = 0.0f; 138 | m_fact_list.Add( name, the_fact ); 139 | } 140 | return the_fact; 141 | } 142 | 143 | public void SetFact( string name, float value ) 144 | { 145 | if ( m_fact_list.Contains( name ) ) 146 | { 147 | int index = m_fact_list.IndexOfKey( name ); 148 | Fact fact = (Fact)m_fact_list.GetByIndex(index); 149 | fact.Value = value; 150 | } 151 | else 152 | { 153 | Fact fact = new Fact(name); 154 | fact.Value = value; 155 | m_fact_list.Add( name, fact ); 156 | } 157 | } 158 | 159 | public void AddSensorMethod( SensorMethod method ) 160 | { 161 | m_sensor_methods.Add( method ); 162 | } 163 | 164 | public void AddState( AIState state ) 165 | { 166 | m_state_list.Add( state ); 167 | } 168 | 169 | public void Write( string filename ) 170 | { 171 | XmlTextWriter writer = new XmlTextWriter( filename, null ); 172 | 173 | writer.WriteStartDocument(); 174 | writer.WriteStartElement("Knowledge"); 175 | 176 | //Use indentation for readability. 177 | writer.Formatting = Formatting.Indented; 178 | writer.Indentation = 4; 179 | 180 | int num_facts = m_fact_list.Count; 181 | 182 | for ( int i=0; i 7 | /// Summary description for Transitioner. 8 | /// 9 | public class Transitioner 10 | { 11 | #region Attributes 12 | private Expression m_expression = null; 13 | private AIState m_target_state; 14 | #endregion 15 | 16 | #region Properties 17 | #endregion 18 | 19 | public Transitioner(Expression expression, AIState target_state) 20 | { 21 | m_expression = expression; 22 | m_target_state = target_state; 23 | } 24 | 25 | public AIState Evaluate( AIState old_state ) 26 | { 27 | AIState new_state = old_state; 28 | 29 | if ( m_expression != null ) 30 | { 31 | if ( m_expression.Evaluate() ) 32 | { 33 | new_state = m_target_state; 34 | } 35 | } 36 | 37 | return new_state; 38 | } 39 | 40 | 41 | public void Write( XmlTextWriter writer ) 42 | { 43 | writer.WriteStartElement("Transitioner"); 44 | writer.WriteElementString("Target", m_target_state.Name); 45 | m_expression.Write( writer ); 46 | writer.WriteEndElement(); 47 | } 48 | 49 | public void Read ( XmlTextReader reader, Thinker thinker ) 50 | { 51 | bool done = false; 52 | 53 | while ( !done ) 54 | { 55 | reader.Read(); 56 | 57 | if ( reader.NodeType == XmlNodeType.EndElement && 58 | reader.Name == "Transitioner" ) 59 | { 60 | done =true; 61 | } 62 | // Process a start of element node. 63 | else if (reader.NodeType == XmlNodeType.Element) 64 | { 65 | // Process a text node. 66 | if ( reader.Name == "Expression" ) 67 | { 68 | m_expression.Read( reader, thinker ); 69 | } 70 | } 71 | }// End while loop 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("GameEngine")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("Lynn T. Harrison")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/BillBoard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Drawing; 4 | using Microsoft.DirectX; 5 | using Microsoft.DirectX.Direct3D; 6 | 7 | namespace GameEngine 8 | { 9 | /// 10 | /// Summary description for BillBoard. 11 | /// 12 | public class BillBoard : Object3D, IDisposable 13 | { 14 | #region Attributes 15 | private CustomVertex.PositionNormalTextured[] m_Corners; 16 | private Texture m_Texture; // image for face 17 | private bool m_bValid = false; 18 | private string m_sTexture; 19 | 20 | private static string m_sLastTexture; 21 | private static VertexBuffer m_VB; 22 | private static Matrix m_TheMatrix; 23 | 24 | private static ArrayList m_List = new ArrayList(); 25 | 26 | public static ArrayList Objects { get { return m_List; } } 27 | 28 | 29 | public bool Valid { get { return m_bValid; } } 30 | #endregion 31 | 32 | private static void SetupMatrix( Camera cam ) 33 | { 34 | // Set up a rotation matrix to orient the billboard towards the camera. 35 | Vector3 vDir = Vector3.Subtract(cam.LookAtVector, cam.EyeVector); 36 | if( vDir.X > 0.001f ) 37 | m_TheMatrix = Matrix.RotationY( (float)(-Math.Atan(vDir.Z/vDir.X)+Math.PI/2) ); 38 | else if( vDir.X < -0.001f ) 39 | m_TheMatrix = Matrix.RotationY( (float)(-Math.Atan(vDir.Z/vDir.X)-Math.PI/2) ); 40 | else 41 | { 42 | if ( cam.Heading < 179.0f || cam.Heading > 181.0f ) 43 | m_TheMatrix = Matrix.Identity; 44 | else 45 | m_TheMatrix = Matrix.RotationY( (float)Math.PI ); 46 | } 47 | } 48 | 49 | public static void Add( float north, float east, float altitude, string sName, 50 | string sTextureName, float fWidth, float fHeight) 51 | { 52 | BillBoard obj; 53 | 54 | if ( sTextureName.CompareTo(m_sLastTexture) == 0 ) 55 | { 56 | BillBoard lastObject = (BillBoard)m_List[m_List.Count-1]; 57 | obj = new BillBoard(sName,lastObject); 58 | } 59 | else 60 | { 61 | obj = new BillBoard(sName, sTextureName, fWidth, fHeight); 62 | } 63 | m_sLastTexture = sTextureName; 64 | 65 | float height = CGameEngine.Ground.TerrainHeight(east,north); 66 | 67 | if ( altitude < height ) 68 | { 69 | altitude = height; 70 | } 71 | 72 | obj.m_vPosition.X = east; 73 | obj.m_vPosition.Y = altitude; 74 | obj.m_vPosition.Z = north; 75 | 76 | try 77 | { 78 | 79 | m_List.Add( obj ); 80 | 81 | CGameEngine.QuadTree.AddObject((Object3D)obj); 82 | } 83 | catch (DirectXException d3de) 84 | { 85 | Console.AddLine("Unable to add billboard " + sName); 86 | Console.AddLine(d3de.ErrorString); 87 | } 88 | catch ( Exception e ) 89 | { 90 | Console.AddLine("Unable to add billboard " + sName); 91 | Console.AddLine(e.Message); 92 | } 93 | } 94 | 95 | public BillBoard(string sName, BillBoard other) : base( sName ) 96 | { 97 | m_sName = sName; 98 | Copy(other); 99 | } 100 | public BillBoard(string sName, string sTextureName, float fWidth, float fHeight) : base( sName ) 101 | { 102 | m_sName = sName; 103 | m_sTexture = sTextureName; 104 | 105 | m_fRadius = fWidth / 2.0f; 106 | 107 | // create the vertices for the box 108 | m_Corners = new CustomVertex.PositionNormalTextured[4]; 109 | 110 | m_Corners[0].X = m_fRadius; // upper left 111 | m_Corners[0].Y = fHeight; // upper left 112 | m_Corners[0].Z = 0.0f; // upper left 113 | m_Corners[0].Tu = 1.0f; 114 | m_Corners[0].Tv = 0.0f; 115 | m_Corners[0].Nx = 0.0f; 116 | m_Corners[0].Ny = 0.0f; 117 | m_Corners[0].Nz = -1.0f; 118 | m_Corners[1].X = -m_fRadius; // upper right 119 | m_Corners[1].Y = fHeight; // upper right 120 | m_Corners[1].Z = 0.0f; // upper right 121 | m_Corners[1].Tu = 0.0f; 122 | m_Corners[1].Tv = 0.0f; 123 | m_Corners[1].Nx = 0.0f; 124 | m_Corners[1].Ny = 0.0f; 125 | m_Corners[1].Nz = -1.0f; 126 | m_Corners[2].X = m_fRadius; // lower left 127 | m_Corners[2].Y = 0.0f; // lower left 128 | m_Corners[2].Z = 0.0f; // lower left 129 | m_Corners[2].Tu = 1.0f; 130 | m_Corners[2].Tv = 1.0f; 131 | m_Corners[2].Nx = 0.0f; 132 | m_Corners[2].Ny = 0.0f; 133 | m_Corners[2].Nz = -1.0f; 134 | m_Corners[3].X = -m_fRadius; // lower right 135 | m_Corners[3].Y = 0.0f; // lower right 136 | m_Corners[3].Z = 0.0f; // lower right 137 | m_Corners[3].Tu = 0.0f; 138 | m_Corners[3].Tv = 1.0f; 139 | m_Corners[3].Nx = 0.0f; 140 | m_Corners[3].Ny = 0.0f; 141 | m_Corners[3].Nz = -1.0f; 142 | 143 | // load the texture for the face 144 | try 145 | { 146 | m_Texture = GraphicsUtility.CreateTexture(CGameEngine.Device3D, sTextureName); 147 | m_bValid = true; 148 | } 149 | catch 150 | { 151 | Console.AddLine("Unable to create billboard texture for " + sName); 152 | } 153 | 154 | } 155 | 156 | private void Copy(BillBoard other) 157 | { 158 | m_sTexture = other.m_sTexture; 159 | 160 | m_fRadius = other.m_fRadius; 161 | 162 | // create the vertices for the box 163 | m_Corners = other.m_Corners; 164 | 165 | m_bValid = true; 166 | } 167 | 168 | public static void RenderAll( Camera cam ) 169 | { 170 | string currentTexture = ""; 171 | 172 | if ( m_List.Count > 0 ) 173 | { 174 | CGameEngine.Device3D.RenderState.CullMode = Microsoft.DirectX.Direct3D.Cull.Clockwise; 175 | 176 | // Set diffuse blending for alpha set in vertices. 177 | CGameEngine.Device3D.RenderState.AlphaBlendEnable = true; 178 | CGameEngine.Device3D.RenderState.SourceBlend = Blend.SourceAlpha; 179 | CGameEngine.Device3D.RenderState.DestinationBlend = Blend.InvSourceAlpha; 180 | 181 | // Enable alpha testing (skips pixels with less than a certain alpha.) 182 | if( CGameEngine.Device3D.DeviceCaps.AlphaCompareCaps.SupportsGreaterEqual ) 183 | { 184 | CGameEngine.Device3D.RenderState.AlphaTestEnable = true; 185 | CGameEngine.Device3D.RenderState.ReferenceAlpha = 0x08; 186 | CGameEngine.Device3D.RenderState.AlphaFunction = Compare.GreaterEqual; 187 | } 188 | 189 | SetupMatrix( cam ); 190 | 191 | CGameEngine.Device3D.VertexFormat = CustomVertex.PositionNormalTextured.Format; 192 | 193 | if ( m_VB == null ) 194 | { 195 | m_VB = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 196 | 4, CGameEngine.Device3D, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default ); 197 | } 198 | 199 | CGameEngine.Device3D.SetStreamSource( 0, m_VB, 0 ); 200 | 201 | foreach ( BillBoard obj in m_List ) 202 | { 203 | 204 | if ( currentTexture.CompareTo(obj.m_sTexture) != 0 ) 205 | { 206 | m_VB.SetData(obj.m_Corners, 0, 0); 207 | 208 | // Set the texture 209 | CGameEngine.Device3D.SetTexture(0, obj.m_Texture ); 210 | 211 | currentTexture = obj.m_sTexture; 212 | } 213 | 214 | obj.Render( cam ); 215 | } 216 | 217 | foreach ( BillBoard obj in m_List ) 218 | { 219 | obj.RenderChildren( cam ); 220 | } 221 | 222 | 223 | } 224 | } 225 | 226 | public override void Render( Camera cam ) 227 | { 228 | if ( Visible && m_bValid && !IsCulled ) 229 | { 230 | 231 | // Translate the billboard into place 232 | m_TheMatrix.M41 = m_vPosition.X; 233 | m_TheMatrix.M42 = m_vPosition.Y; 234 | m_TheMatrix.M43 = m_vPosition.Z; 235 | CGameEngine.Device3D.Transform.World = m_TheMatrix; 236 | 237 | // Render the face 238 | CGameEngine.Device3D.DrawPrimitives( PrimitiveType.TriangleStrip, 0, 2 ); 239 | } 240 | } 241 | 242 | public void RenderChildren( Camera cam ) 243 | { 244 | if ( Visible && m_bValid && !IsCulled ) 245 | { 246 | 247 | // Translate the billboard into place 248 | CGameEngine.Device3D.Transform.World = m_TheMatrix; 249 | 250 | Culled = true; 251 | if ( m_Children.Count > 0 ) 252 | { 253 | Object3D obj; 254 | for ( int i=0; i 0 ) 279 | { 280 | Object3D obj; 281 | for ( int i=0; i 9 | /// Summary description for Camera. 10 | /// 11 | public class Camera 12 | { 13 | #region // Cull State enumeration 14 | /// 15 | /// Each member of this enumeration is one possible culling result 16 | /// 17 | 18 | public enum CullState 19 | { 20 | /// 21 | /// The rectangle is completely within the viewing Frustum 22 | /// 23 | AllInside, 24 | /// 25 | /// The rectangle is completely outside the viewing Frustum 26 | /// 27 | AllOutside, 28 | /// 29 | /// The rectangle is partially within the viewing Frustum 30 | /// 31 | PartiallyIn, 32 | } 33 | #endregion 34 | 35 | #region Attributes 36 | private Object3D m_AttachedObject = null; 37 | private Object3D m_LookAtObject = null; 38 | private Vector3 m_Offset; 39 | private Attitude m_Attitude; 40 | private Matrix m_matProj; 41 | private Matrix m_matView; 42 | private float m_X = 1.0f; 43 | private float m_Y = 1.0f; 44 | private float m_Z = 1.0f; 45 | private Vector3[] vecFrustum; // corners of the view frustum 46 | private Plane[] planeFrustum; // planes of the view frustum 47 | private Vector3 m_Eye; 48 | private Vector3 m_LookAt; 49 | private string m_name = "default"; 50 | private float m_fFOV = (float)Math.PI/4.0f; 51 | private float m_fAspect = 1.33f; 52 | private float m_fNearPlane = 1.0f; 53 | private float m_fFarPlane = 800.0f; 54 | private ArrayList m_VisibleObjects = null; 55 | #endregion 56 | 57 | #region Properties 58 | public ArrayList VisibleObjects { get { return m_VisibleObjects; } } 59 | public float Heading { get { return (float)(m_Attitude.Heading*180.0/Math.PI); } } 60 | public float Pitch { get { return (float)(m_Attitude.Pitch*180.0/Math.PI); } } 61 | public string Name { get { return m_name; } } 62 | public float X { get { return m_X; } } 63 | public float Y { get { return m_Y; } } 64 | public float Z { get { return m_Z; } } 65 | public Matrix View { get { return m_matView; } } 66 | public Vector3 EyeVector { get { return m_Eye; } } 67 | public Vector3 LookAtVector { get { return m_LookAt; } } 68 | public float FieldOfView 69 | { 70 | set 71 | { 72 | m_fFOV = value; 73 | m_matProj = Matrix.PerspectiveFovLH( m_fFOV, m_fAspect, 74 | m_fNearPlane, m_fFarPlane ); 75 | } 76 | } 77 | public float AspectRatio 78 | { 79 | set 80 | { 81 | m_fAspect = value; 82 | m_matProj = Matrix.PerspectiveFovLH( m_fFOV, m_fAspect, 83 | m_fNearPlane, m_fFarPlane ); 84 | } 85 | } 86 | public float NearClipPlane 87 | { 88 | set 89 | { 90 | m_fNearPlane = value; 91 | m_matProj = Matrix.PerspectiveFovLH( m_fFOV, m_fAspect, 92 | m_fNearPlane, m_fFarPlane ); 93 | } 94 | } 95 | public float FarClipPlane 96 | { 97 | set 98 | { 99 | m_fFarPlane = value; 100 | m_matProj = Matrix.PerspectiveFovLH( m_fFOV, m_fAspect, 101 | m_fNearPlane, m_fFarPlane ); 102 | } 103 | } 104 | 105 | #endregion 106 | 107 | public Camera() 108 | { 109 | m_VisibleObjects = new ArrayList(); 110 | m_matView = Matrix.Identity; 111 | m_Offset = new Vector3(0.0f, 0.0f, 0.0f); 112 | vecFrustum = new Vector3[8]; // corners of the view frustum 113 | planeFrustum = new Plane[6]; // planes of the view frustum 114 | m_matProj = Matrix.PerspectiveFovLH( m_fFOV, m_fAspect, 115 | m_fNearPlane, m_fFarPlane ); 116 | } 117 | 118 | public Camera(string name) 119 | { 120 | m_VisibleObjects = new ArrayList(); 121 | m_matView = Matrix.Identity; 122 | m_Offset = new Vector3(0.0f, 0.0f, 0.0f);; 123 | vecFrustum = new Vector3[8]; // corners of the view frustum 124 | planeFrustum = new Plane[6]; // planes of the view frustum 125 | m_fFOV = (float)Math.PI/4.0f; 126 | m_fAspect = 1.0f; 127 | m_fNearPlane = .10f; 128 | m_fFarPlane = 800.0f; 129 | m_matProj = Matrix.PerspectiveFovLH( m_fFOV, m_fAspect, 130 | m_fNearPlane, m_fFarPlane ); 131 | m_name = name; 132 | } 133 | 134 | public void AdjustHeading( float deltaHeading ) 135 | { 136 | m_Attitude.Heading += (deltaHeading * (float)Math.PI / 180.0f); 137 | 138 | if ( m_Attitude.Heading > (2.0f * Math.PI) ) 139 | { 140 | m_Attitude.Heading -= (float)(2.0f * Math.PI); 141 | } 142 | 143 | if ( m_Attitude.Heading < 0.0f ) 144 | { 145 | m_Attitude.Heading += (float)(2.0f * Math.PI); 146 | } 147 | 148 | } 149 | 150 | public void AdjustPitch( float deltaPitch ) 151 | { 152 | m_Attitude.Pitch += (deltaPitch * (float)Math.PI / 180.0f); 153 | 154 | if ( m_Attitude.Pitch > (0.5f * Math.PI) ) 155 | { 156 | m_Attitude.Pitch = (float)(0.5f * Math.PI); 157 | } 158 | 159 | if ( m_Attitude.Pitch < (-0.5f * Math.PI) ) 160 | { 161 | m_Attitude.Pitch = (float)(-0.5f * Math.PI); 162 | } 163 | 164 | } 165 | 166 | public void MoveCamera( float x, float y, float z ) 167 | { 168 | float ty; 169 | m_X += x * (float)Math.Cos(m_Attitude.Heading) + z * (float)Math.Sin(m_Attitude.Heading); 170 | m_Y += y; 171 | m_Z += z * (float)Math.Cos(m_Attitude.Heading) + x * (float)Math.Sin(m_Attitude.Heading); 172 | try 173 | { 174 | ty = CGameEngine.Ground.HeightOfTerrain(new Vector3(m_X, m_Y, m_Z)); 175 | } 176 | catch {ty=0;} 177 | m_Y = ty + 1.0f; 178 | } 179 | 180 | public CullState CheckFrustum( Vector3 pos, float radius ) 181 | { 182 | 183 | float distance; 184 | int count = 0; 185 | 186 | for( int iPlane = 0; iPlane < 4; iPlane++ ) // don't check against top and bottom 187 | { 188 | distance = planeFrustum[iPlane].Dot( pos ); 189 | if( distance <= -radius ) 190 | { 191 | return CullState.AllOutside; 192 | } 193 | if ( distance > radius ) count++; 194 | } 195 | 196 | if ( count == 4 ) return CullState.AllInside; 197 | 198 | return CullState.PartiallyIn; 199 | } 200 | 201 | public CullState CheckFrustum( Object3D obj ) 202 | { 203 | 204 | float distance = 0.0f; 205 | int count = 0; 206 | 207 | for( int iPlane = 0; iPlane < 4; iPlane++ ) // don't check against top and bottom 208 | { 209 | distance = planeFrustum[iPlane].Dot( obj.Position ); 210 | if( distance <= -obj.Radius ) 211 | { 212 | return CullState.AllOutside; 213 | } 214 | if ( distance > obj.Radius ) count++; 215 | } 216 | 217 | if ( count == 4 ) return CullState.AllInside; 218 | 219 | return CullState.PartiallyIn; 220 | } 221 | 222 | public float GetDistance( Object3D obj ) 223 | { 224 | return planeFrustum[3].Dot( obj.Position ) + m_fNearPlane; 225 | } 226 | 227 | public void Attach( Object3D parent, Vector3 offset ) 228 | { 229 | m_AttachedObject = parent; 230 | m_Offset = offset; 231 | } 232 | 233 | public void LookAt( Object3D obj ) 234 | { 235 | m_LookAtObject = obj; 236 | } 237 | 238 | public void Render() 239 | { 240 | Vector3 Up = new Vector3(0.0f, 1.0f, 0.0f); 241 | if ( m_AttachedObject != null ) 242 | { 243 | if ( m_LookAtObject != null ) 244 | { 245 | m_LookAt = m_LookAtObject.Position; 246 | } 247 | else 248 | { 249 | m_LookAt = m_AttachedObject.Position; 250 | m_LookAt.X += (float)Math.Sin(m_Attitude.Heading)*10.0f; 251 | m_LookAt.Y += (float)Math.Sin(m_Attitude.Pitch)*10.0f; 252 | m_LookAt.Z += (float)Math.Cos(m_Attitude.Heading)*10.0f; 253 | } 254 | Matrix transpose = Matrix.Identity; 255 | 256 | m_Attitude.Heading = Attitude.Aepc(m_AttachedObject.Heading); 257 | m_Attitude.Pitch = m_AttachedObject.Pitch; 258 | m_Attitude.Roll = 0.0f; 259 | transpose.RotateYawPitchRoll(m_Attitude.Heading, 260 | m_Attitude.Pitch,m_Attitude.Roll); 261 | 262 | m_Eye = m_AttachedObject.Position + 263 | Vector3.TransformCoordinate(m_Offset, transpose); 264 | } 265 | else 266 | { 267 | m_Eye = new Vector3( m_X, m_Y, m_Z); 268 | if ( m_LookAtObject != null ) 269 | { 270 | m_LookAt = m_LookAtObject.Position; 271 | } 272 | else 273 | { 274 | m_LookAt = m_Eye; 275 | m_LookAt.X += (float)Math.Sin(m_Attitude.Heading)*10.0f; 276 | m_LookAt.Y += (float)Math.Sin(m_Attitude.Pitch)*10.0f; 277 | m_LookAt.Z += (float)Math.Cos(m_Attitude.Heading)*10.0f; 278 | } 279 | } 280 | // Set the app view matrix for normal viewing 281 | m_matView = Matrix.LookAtLH(m_Eye, m_LookAt, Up); 282 | 283 | CGameEngine.Device3D.Transform.View = m_matView; 284 | 285 | CGameEngine.Device3D.Transform.Projection = m_matProj; 286 | 287 | Matrix mat = Matrix.Multiply(m_matView, m_matProj); 288 | mat.Invert(); 289 | 290 | vecFrustum[0] = new Vector3(-1.0f, -1.0f, 0.0f); // xyz 291 | vecFrustum[1] = new Vector3( 1.0f, -1.0f, 0.0f); // Xyz 292 | vecFrustum[2] = new Vector3(-1.0f, 1.0f, 0.0f); // xYz 293 | vecFrustum[3] = new Vector3( 1.0f, 1.0f, 0.0f); // XYz 294 | vecFrustum[4] = new Vector3(-1.0f, -1.0f, 1.0f); // xyZ 295 | vecFrustum[5] = new Vector3( 1.0f, -1.0f, 1.0f); // XyZ 296 | vecFrustum[6] = new Vector3(-1.0f, 1.0f, 1.0f); // xYZ 297 | vecFrustum[7] = new Vector3( 1.0f, 1.0f, 1.0f); // XYZ 298 | 299 | for( int i = 0; i < 8; i++ ) 300 | vecFrustum[i] = Vector3.TransformCoordinate(vecFrustum[i],mat); 301 | 302 | planeFrustum[0] = Plane.FromPoints(vecFrustum[7], 303 | vecFrustum[3],vecFrustum[5]); // Right 304 | planeFrustum[1] = Plane.FromPoints(vecFrustum[2], 305 | vecFrustum[6],vecFrustum[4]); // Left 306 | planeFrustum[2] = Plane.FromPoints(vecFrustum[6], 307 | vecFrustum[7],vecFrustum[5]); // Far 308 | planeFrustum[3] = Plane.FromPoints(vecFrustum[0], 309 | vecFrustum[1],vecFrustum[2]); // Near 310 | planeFrustum[4] = Plane.FromPoints(vecFrustum[2], 311 | vecFrustum[3],vecFrustum[6]); // Top 312 | planeFrustum[5] = Plane.FromPoints(vecFrustum[1], 313 | vecFrustum[0],vecFrustum[4]); // Bottom 314 | } 315 | 316 | public void Reset() 317 | { 318 | m_VisibleObjects.Clear(); 319 | } 320 | 321 | public void AddVisibleObject( Object3D obj ) 322 | { 323 | if ( ! (obj is TerrainQuad) ) 324 | { 325 | m_VisibleObjects.Add( obj ); 326 | } 327 | } 328 | 329 | } 330 | } 331 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Copy of hud.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.Direct3D; 5 | 6 | namespace GameEngine 7 | { 8 | /// 9 | /// Summary description for hud. 10 | /// 11 | public class Hud : IDisposable 12 | { 13 | /// 14 | /// Custom vertex type for the HudPoint 15 | /// 16 | public struct HUDPOINTVERTEX 17 | { 18 | public Vector3 p; 19 | public float rhw; 20 | public int color; 21 | 22 | public const VertexFormats Fvf = VertexFormats.PositionW | VertexFormats.Diffuse; 23 | }; 24 | 25 | private CustomVertex.TransformedColored[] m_Points; 26 | private VertexBuffer m_VB = null; // Vertex buffer 27 | private int m_xSize; 28 | private int m_ySize; 29 | private int m_numPoints; 30 | 31 | public Hud(int xSize, int ySize) 32 | { 33 | m_xSize = xSize; 34 | m_ySize = ySize; 35 | m_numPoints = xSize * ySize; 36 | 37 | m_Points = new CustomVertex.TransformedColored[m_numPoints]; 38 | 39 | for ( int i=0; i 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | text/microsoft-resx 32 | 33 | 34 | 1.0.0.0 35 | 36 | 37 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 38 | 39 | 40 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 41 | 42 | 43 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/D3DSettingsForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | text/microsoft-resx 89 | 90 | 91 | 1.3 92 | 93 | 94 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 95 | 96 | 97 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 98 | 99 | 100 | D3DSettingsForm 101 | 102 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/DXUtil.cs: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // File: DXUtil.cs 3 | // 4 | // Desc: Shortcut macros and functions for using DX objects 5 | // 6 | // Copyright (c) 2001-2002 Microsoft Corporation. All rights reserved 7 | //----------------------------------------------------------------------------- 8 | using System; 9 | using System.IO; 10 | using System.Runtime.InteropServices; 11 | public enum TIMER 12 | { 13 | RESET, 14 | START, 15 | STOP, 16 | ADVANCE, 17 | GETABSOLUTETIME, 18 | GETAPPTIME, 19 | GETELAPSEDTIME 20 | }; 21 | 22 | public class DXUtil 23 | { 24 | #region Timer Internal Stuff 25 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously 26 | [DllImport("kernel32")] 27 | private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency); 28 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously 29 | [DllImport("kernel32")] 30 | private static extern bool QueryPerformanceCounter(ref long PerformanceCount); 31 | [System.Security.SuppressUnmanagedCodeSecurity] // We won't use this maliciously 32 | [DllImport("winmm.dll")] 33 | public static extern int timeGetTime(); 34 | private static bool m_bTimerInitialized = false; 35 | private static bool m_bUsingQPF = false; 36 | private static bool m_bTimerStopped = true; 37 | private static long m_llQPFTicksPerSec = 0; 38 | private static long m_llStopTime = 0; 39 | private static long m_llLastElapsedTime = 0; 40 | private static long m_llBaseTime = 0; 41 | private static double m_fLastElapsedTime = 0.0; 42 | private static double m_fBaseTime = 0.0; 43 | private static double m_fStopTime = 0.0; 44 | #endregion 45 | 46 | // Constants for SDK Path registry keys 47 | private const string g_sSDKPath = "Software\\Microsoft\\DirectX SDK"; 48 | private const string g_sSDKKey = "DX9SDK Samples Path"; 49 | 50 | private DXUtil() { /* Private Constructor */ } 51 | 52 | 53 | 54 | //----------------------------------------------------------------------------- 55 | // Name: DXUtil.GetDXSDKMediaPath() 56 | // Desc: Returns the DirectX SDK media path 57 | //----------------------------------------------------------------------------- 58 | public static string GetDXSDKMediaPath() 59 | { 60 | Microsoft.Win32.RegistryKey rKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(g_sSDKPath); 61 | string sReg = null; 62 | if (rKey != null) 63 | { 64 | sReg = (string)rKey.GetValue(g_sSDKKey); 65 | rKey.Close(); 66 | } 67 | if (sReg != null) 68 | sReg += @"\Media\"; 69 | else 70 | return null; 71 | 72 | return sReg; 73 | } 74 | 75 | 76 | 77 | //----------------------------------------------------------------------------- 78 | // Name: DXUtil.Timer() 79 | // Desc: Performs timer opertations. Use the following commands: 80 | // TIMER.RESET - to reset the timer 81 | // TIMER.START - to start the timer 82 | // TIMER.STOP - to stop (or pause) the timer 83 | // TIMER.ADVANCE - to advance the timer by 0.001 seconds 84 | // TIMER.GETABSOLUTETIME - to get the absolute system time 85 | // TIMER.GETAPPTIME - to get the current time 86 | // TIMER.GETELAPSEDTIME - to get the time that elapsed between 87 | // TIMER_GETELAPSEDTIME calls 88 | //----------------------------------------------------------------------------- 89 | public static float Timer(TIMER command) 90 | { 91 | if( !m_bTimerInitialized ) 92 | { 93 | m_bTimerInitialized = true; 94 | 95 | // Use QueryPerformanceFrequency() to get frequency of timer. If QPF is 96 | // not supported, we will timeGetTime() which returns milliseconds. 97 | long qwTicksPerSec = 0; 98 | m_bUsingQPF = QueryPerformanceFrequency( ref qwTicksPerSec ); 99 | if( m_bUsingQPF ) 100 | m_llQPFTicksPerSec = qwTicksPerSec; // in msec 101 | } 102 | if( m_bUsingQPF ) 103 | { 104 | double fTime; 105 | double fElapsedTime; 106 | long qwTime = 0; 107 | 108 | // Get either the current time or the stop time, depending 109 | // on whether we're stopped and what command was sent 110 | if( m_llStopTime != 0 && command != TIMER.START && command != TIMER.GETABSOLUTETIME) 111 | qwTime = m_llStopTime; 112 | else 113 | QueryPerformanceCounter( ref qwTime ); 114 | 115 | // Return the elapsed time 116 | if( command == TIMER.GETELAPSEDTIME ) 117 | { 118 | fElapsedTime = (double) ( qwTime - m_llLastElapsedTime ) / (double) m_llQPFTicksPerSec; 119 | m_llLastElapsedTime = qwTime; 120 | return (float)fElapsedTime; 121 | } 122 | 123 | // Return the current time 124 | if( command == TIMER.GETAPPTIME ) 125 | { 126 | double fAppTime = (double) ( qwTime - m_llBaseTime ) / (double) m_llQPFTicksPerSec; 127 | return (float)fAppTime; 128 | } 129 | 130 | // Reset the timer 131 | if( command == TIMER.RESET ) 132 | { 133 | m_llBaseTime = qwTime; 134 | m_llLastElapsedTime = qwTime; 135 | m_llStopTime = 0; 136 | m_bTimerStopped = false; 137 | return 0.0f; 138 | } 139 | 140 | // Start the timer 141 | if( command == TIMER.START ) 142 | { 143 | if( m_bTimerStopped ) 144 | m_llBaseTime += qwTime - m_llStopTime; 145 | m_llStopTime = 0; 146 | m_llLastElapsedTime = qwTime; 147 | m_bTimerStopped = false; 148 | return 0.0f; 149 | } 150 | 151 | // Stop the timer 152 | if( command == TIMER.STOP ) 153 | { 154 | m_llStopTime = qwTime; 155 | m_llLastElapsedTime = qwTime; 156 | m_bTimerStopped = true; 157 | return 0.0f; 158 | } 159 | 160 | // Advance the timer by millisecond 161 | if( command == TIMER.ADVANCE ) 162 | { 163 | m_llStopTime += m_llQPFTicksPerSec/1000; 164 | return 0.0f; 165 | } 166 | 167 | if( command == TIMER.GETABSOLUTETIME ) 168 | { 169 | fTime = qwTime / (double) m_llQPFTicksPerSec; 170 | return (float)fTime; 171 | } 172 | 173 | return -1.0f; // Invalid command specified 174 | } 175 | else 176 | { 177 | // Get the time using timeGetTime() 178 | double fTime; 179 | double fElapsedTime; 180 | 181 | // Get either the current time or the stop time, depending 182 | // on whether we're stopped and what command was sent 183 | if( m_fStopTime != 0.0 && command != TIMER.START && command != TIMER.GETABSOLUTETIME) 184 | fTime = m_fStopTime; 185 | else 186 | fTime = timeGetTime(); 187 | 188 | // Return the elapsed time 189 | if( command == TIMER.GETELAPSEDTIME ) 190 | { 191 | fElapsedTime = (double) (fTime - m_fLastElapsedTime); 192 | m_fLastElapsedTime = fTime; 193 | return (float) fElapsedTime; 194 | } 195 | 196 | // Return the current time 197 | if( command == TIMER.GETAPPTIME ) 198 | { 199 | return (float) (fTime - m_fBaseTime); 200 | } 201 | 202 | // Reset the timer 203 | if( command == TIMER.RESET ) 204 | { 205 | m_fBaseTime = fTime; 206 | m_fLastElapsedTime = fTime; 207 | m_fStopTime = 0; 208 | m_bTimerStopped = false; 209 | return 0.0f; 210 | } 211 | 212 | // Start the timer 213 | if( command == TIMER.START ) 214 | { 215 | if( m_bTimerStopped ) 216 | m_fBaseTime += fTime - m_fStopTime; 217 | m_fStopTime = 0.0f; 218 | m_fLastElapsedTime = fTime; 219 | m_bTimerStopped = false; 220 | return 0.0f; 221 | } 222 | 223 | // Stop the timer 224 | if( command == TIMER.STOP ) 225 | { 226 | m_fStopTime = fTime; 227 | m_fLastElapsedTime = fTime; 228 | m_bTimerStopped = true; 229 | return 0.0f; 230 | } 231 | 232 | // Advance the timer by 1/10th second 233 | if( command == TIMER.ADVANCE ) 234 | { 235 | m_fStopTime += 0.1f; 236 | return 0.0f; 237 | } 238 | 239 | if( command == TIMER.GETABSOLUTETIME ) 240 | { 241 | return (float) fTime; 242 | } 243 | 244 | return -1.0f; // Invalid command specified 245 | } 246 | } 247 | 248 | 249 | 250 | //----------------------------------------------------------------------------- 251 | // Name: DXUtil.FindMediaFile() 252 | // Desc: Returns a valid path to a DXSDK media file 253 | //----------------------------------------------------------------------------- 254 | public static string FindMediaFile( string sPath, string sFilename ) 255 | { 256 | // First try to load the file in the full path 257 | if (sPath != null) 258 | { 259 | if (File.Exists(AppendDirSep(sPath) + sFilename)) 260 | return AppendDirSep(sPath) + sFilename; 261 | } 262 | 263 | // if not try to find the filename in the current folder. 264 | if (File.Exists(sFilename)) 265 | return AppendDirSep(Directory.GetCurrentDirectory()) + sFilename; 266 | 267 | // last, check if the file exists in the media directory 268 | if (File.Exists(AppendDirSep(GetDXSDKMediaPath()) + sFilename)) 269 | return AppendDirSep(GetDXSDKMediaPath()) + sFilename; 270 | 271 | throw new FileNotFoundException("Could not find this file.", sFilename); 272 | } 273 | 274 | 275 | 276 | //----------------------------------------------------------------------------- 277 | // Name: DXUtil.AppendDirSep() 278 | // Desc: Returns a valid string with a directory separator at the end. 279 | //----------------------------------------------------------------------------- 280 | private static string AppendDirSep(string sFile) 281 | { 282 | if (!sFile.EndsWith(@"\")) 283 | return sFile + @"\"; 284 | 285 | return sFile; 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/GameCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace GameEngine 5 | { 6 | /// 7 | /// Summary description for GameCommand. 8 | /// 9 | public delegate void CommandFunction( string sData ); 10 | 11 | public class GameCommand 12 | { 13 | 14 | private string m_sCommand = null; 15 | private string m_sHelp = null; 16 | private CommandFunction m_Function = null; 17 | 18 | public string Command { get { return m_sCommand; } } 19 | public string Help { get { return m_sHelp; } } 20 | 21 | /// 22 | /// Constructor 23 | /// 24 | /// 25 | /// 26 | /// 27 | public GameCommand(string sCmd, string sHelp, CommandFunction pFunc ) 28 | { 29 | m_sCommand = sCmd; 30 | m_sHelp = sHelp; 31 | m_Function = pFunc; 32 | } 33 | 34 | /// 35 | /// Execute the attached delegate function 36 | /// 37 | /// 38 | public void Execute( string sData ) 39 | { 40 | if ( m_Function != null ) 41 | { 42 | m_Function(sData); 43 | } 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/GameEngine.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 37 | 38 | 39 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/GameEngine.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 7.00 2 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarLib", "..\CarLib\CarLib.csproj", "{FB9F633D-97DA-4E1A-A860-554F227081BE}" 3 | EndProject 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameAI", "..\GameAI\GameAI.csproj", "{730364D6-9306-4DF9-B72F-8C26E616D29E}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameEngine", "GameEngine.csproj", "{B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleGame", "..\SampleGame\SampleGame.csproj", "{34B5395F-E85C-45A6-B2BA-AABE3417DEB2}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfiguration) = preSolution 12 | ConfigName.0 = Debug 13 | ConfigName.1 = Release 14 | EndGlobalSection 15 | GlobalSection(ProjectDependencies) = postSolution 16 | EndGlobalSection 17 | GlobalSection(ProjectConfiguration) = postSolution 18 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Debug.ActiveCfg = Debug|.NET 19 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Debug.Build.0 = Debug|.NET 20 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Release.ActiveCfg = Release|.NET 21 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Release.Build.0 = Release|.NET 22 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Debug.ActiveCfg = Debug|.NET 23 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Debug.Build.0 = Debug|.NET 24 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Release.ActiveCfg = Release|.NET 25 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Release.Build.0 = Release|.NET 26 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Debug.ActiveCfg = Debug|.NET 27 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Debug.Build.0 = Debug|.NET 28 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Release.ActiveCfg = Release|.NET 29 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Release.Build.0 = Release|.NET 30 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Debug.ActiveCfg = Debug|.NET 31 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Debug.Build.0 = Debug|.NET 32 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Release.ActiveCfg = Release|.NET 33 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Release.Build.0 = Release|.NET 34 | EndGlobalSection 35 | GlobalSection(SolutionItems) = postSolution 36 | EndGlobalSection 37 | GlobalSection(ExtensibilityGlobals) = postSolution 38 | EndGlobalSection 39 | GlobalSection(ExtensibilityAddIns) = postSolution 40 | EndGlobalSection 41 | EndGlobal 42 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/GameEngine.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/GameEngine/GameEngine.suo -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Interfaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.DirectX; 3 | 4 | namespace GameEngine 5 | { 6 | /// Basic structures used in the game 7 | public struct Attitude 8 | { 9 | public float Pitch; 10 | public float Heading; 11 | public float Roll; 12 | 13 | public Attitude( float pitch, float heading, float roll ) 14 | { 15 | Pitch = pitch; 16 | Heading = heading; 17 | Roll = roll; 18 | } 19 | public static float Aepc( float angle ) 20 | { 21 | if ( angle > (2.0*Math.PI) ) 22 | { 23 | angle -= (float)(2.0*Math.PI); 24 | } 25 | if ( angle < 0.0f ) 26 | { 27 | angle += (float)(2.0*Math.PI); 28 | } 29 | return angle; 30 | } 31 | public static float Aepc2( float angle ) 32 | { 33 | if ( angle > Math.PI ) 34 | { 35 | angle -= (float)(2.0*Math.PI); 36 | } 37 | if ( angle < -Math.PI ) 38 | { 39 | angle += (float)(2.0*Math.PI); 40 | } 41 | return angle; 42 | } 43 | } 44 | 45 | /// 46 | /// Interfaces used in the game engine. 47 | /// 48 | public interface IRenderable 49 | { 50 | void Render(Camera cam); 51 | } 52 | 53 | public interface ICullable 54 | { 55 | bool Culled { set; } 56 | bool IsCulled { get; } 57 | } 58 | 59 | public interface ICollidable 60 | { 61 | Vector3 CenterOfMass { get; } 62 | float BoundingRadius { get; } 63 | bool CollideSphere ( Object3D other ); 64 | bool CollidePolygon ( Vector3 Point1, Vector3 Point2, Vector3 Point3 ); 65 | } 66 | 67 | public interface IDynamic 68 | { 69 | void Update( float DeltaT ); 70 | } 71 | 72 | public interface ITerrainInfo 73 | { 74 | float HeightOfTerrain( Vector3 Position ); 75 | float HeightAboveTerrain( Vector3 Position ); 76 | bool InLineOfSight( Vector3 Position1, Vector3 Position2 ); 77 | Attitude GetSlope( Vector3 Position, float Heading ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Lights.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.Direct3D; 5 | using System.Collections; 6 | 7 | namespace GameEngine 8 | { 9 | /// 10 | /// Summary description for GameLights. 11 | /// 12 | public class GameLights : Object3D, IDisposable, IDynamic, IComparable 13 | { 14 | #region Attributes 15 | private LightType m_Type = LightType.Point; 16 | private Vector3 m_Direction = new Vector3(0.0f,0.0f,0.0f); 17 | private Vector3 m_DirectionOffset = new Vector3(0.0f,0.0f,0.0f); 18 | private Vector3 m_PositionOffset = new Vector3(0.0f,0.0f,0.0f); 19 | private Color m_Diffuse = Color.White; 20 | private Color m_Specular = Color.White; 21 | private float m_EffectiveRange = 1000.0f; 22 | private float m_Attenuation0 = 0.0f; 23 | private float m_Attenuation1 = 1.0f; 24 | private float m_Attenuation2 = 0.0f; 25 | private float m_FallOff = 1.0f; 26 | private float m_InnerConeAngle = 0.5f; 27 | private float m_OuterConeAngle = 1.0f; 28 | private bool m_Deferred = true; 29 | private bool m_Enabled = true; 30 | 31 | // a static array that will hold all lights 32 | private static Color m_Ambient = Color.White; 33 | private static ArrayList m_ActiveLights = new ArrayList(); 34 | private static ArrayList m_InactiveLights = new ArrayList(); 35 | private static int m_max_lights = 1; 36 | private static int m_num_activated = 0; 37 | #endregion 38 | 39 | #region Properties 40 | public LightType Type { get { return m_Type; } } 41 | public Vector3 Direction { get { return m_Direction; } set { m_Direction = value; }} 42 | public Vector3 DirectionOffset { get { return m_DirectionOffset; } set { m_DirectionOffset = value; }} 43 | public Vector3 PositionOffset { get { return m_PositionOffset; } set { m_PositionOffset = value; }} 44 | public Color Diffuse { get { return m_Diffuse; } set { m_Diffuse = value; }} 45 | public Color Specular { get { return m_Specular; } set { m_Specular = value; }} 46 | public float EffectiveRange { get { return m_EffectiveRange; } set { m_EffectiveRange = value; }} 47 | public float Attenuation0 { get { return m_Attenuation0; } set { m_Attenuation0 = value; }} 48 | public float Attenuation1 { get { return m_Attenuation1; } set { m_Attenuation1 = value; }} 49 | public float Attenuation2 { get { return m_Attenuation2; } set { m_Attenuation2 = value; }} 50 | public float FallOff { get { return m_FallOff; } set { m_FallOff = value; }} 51 | public float InnerConeAngle { get { return m_InnerConeAngle; } set { m_InnerConeAngle = value; }} 52 | public float OuterConeAngle { get { return m_OuterConeAngle; } set { m_OuterConeAngle = value; }} 53 | public bool Deferred { get { return m_Deferred; } set { m_Deferred = value; }} 54 | public bool Enabled 55 | { 56 | get { return m_Enabled; } 57 | set 58 | { 59 | m_Enabled = value; 60 | // remove from both list to ensure it does not get onto a list twice 61 | m_ActiveLights.Remove( this ); 62 | m_InactiveLights.Remove( this ); 63 | if ( m_Enabled ) // move from inactive list to active list 64 | { 65 | m_ActiveLights.Add( this ); 66 | } 67 | else // move from active list to inactive list 68 | { 69 | m_InactiveLights.Add( this ); 70 | } 71 | } 72 | } 73 | 74 | public static Color Ambient { get { return m_Ambient; } set { m_Ambient = value; } } 75 | #endregion 76 | 77 | public GameLights(string name) :base(name) 78 | { 79 | m_EffectiveRange = 1000.0f; 80 | m_fRadius = m_EffectiveRange; 81 | } 82 | 83 | public int CompareTo( object other ) 84 | { 85 | GameLights other_light = (GameLights)other; 86 | return (int)(Range - other_light.Range); 87 | } 88 | 89 | public static GameLights GetLight( string name ) 90 | { 91 | GameLights light_found = null; 92 | foreach ( GameLights light in m_ActiveLights ) 93 | { 94 | if ( light.Name == name ) 95 | { 96 | light_found = light; 97 | } 98 | } 99 | foreach ( GameLights light in m_InactiveLights ) 100 | { 101 | if ( light.Name == name ) 102 | { 103 | light_found = light; 104 | } 105 | } 106 | return light_found; 107 | } 108 | 109 | public static GameLights AddDirectionalLight(Vector3 direction, Color color, string name) 110 | { 111 | GameLights light = new GameLights(name); 112 | light.m_Diffuse = color; 113 | light.m_Direction = direction; 114 | light.m_Type = LightType.Directional; 115 | m_ActiveLights.Add( light ); 116 | return light; 117 | } 118 | 119 | public static GameLights AddPointLight(Vector3 position, Color color, string name) 120 | { 121 | GameLights light = new GameLights(name); 122 | light.m_Diffuse = color; 123 | light.Position = position; 124 | light.m_Type = LightType.Point; 125 | m_ActiveLights.Add( light ); 126 | return light; 127 | } 128 | 129 | public static GameLights AddSpotLight(Vector3 position, Vector3 direction, Color color, string name) 130 | { 131 | GameLights light = new GameLights(name); 132 | light.m_Diffuse = color; 133 | light.m_Direction = direction; 134 | light.Position = position; 135 | light.m_Type = LightType.Spot; 136 | light.Attenuation0 = 0.0f; 137 | light.Attenuation1 = 1.0f; 138 | m_ActiveLights.Add( light ); 139 | return light; 140 | } 141 | 142 | public static void InitializeLights() 143 | { 144 | m_max_lights = CGameEngine.Device3D.DeviceCaps.MaxActiveLights; 145 | } 146 | 147 | public static void DeactivateLights() 148 | { 149 | try 150 | { 151 | for ( int i=0; i< m_num_activated; i++ ) 152 | { 153 | CGameEngine.Device3D.Lights[i].Enabled = false; 154 | CGameEngine.Device3D.Lights[i].Commit(); 155 | } 156 | } 157 | catch (DirectXException d3de) 158 | { 159 | Console.AddLine("Unable to Deactivate lights "); 160 | Console.AddLine(d3de.ErrorString); 161 | } 162 | catch ( Exception e ) 163 | { 164 | Console.AddLine("Unable to Deactivate lights "); 165 | Console.AddLine(e.Message); 166 | } 167 | } 168 | 169 | public static void SetupLights() 170 | { 171 | int num_active_lights = 0; 172 | 173 | CGameEngine.Device3D.RenderState.Lighting = true; 174 | CGameEngine.Device3D.RenderState.Ambient = m_Ambient; 175 | CGameEngine.Device3D.RenderState.SpecularEnable = true; 176 | 177 | // sort lights to be in range order from closest to farthest 178 | 179 | m_ActiveLights.Sort(); 180 | 181 | try 182 | { 183 | 184 | foreach ( GameLights light in m_ActiveLights ) 185 | { 186 | if ( !light.IsCulled && num_active_lights < m_max_lights ) 187 | { 188 | Light this_light = CGameEngine.Device3D.Lights[num_active_lights]; 189 | this_light.Deferred = light.m_Deferred; 190 | this_light.Type = light.m_Type; 191 | this_light.Position = light.m_vPosition; 192 | this_light.Direction = light.m_Direction; 193 | this_light.Diffuse = light.m_Diffuse; 194 | this_light.Specular = light.m_Specular; 195 | this_light.Attenuation0 = light.m_Attenuation0; 196 | this_light.Attenuation1 = light.m_Attenuation1; 197 | this_light.Attenuation2 = light.m_Attenuation2; 198 | this_light.InnerConeAngle = light.m_InnerConeAngle; 199 | this_light.OuterConeAngle = light.m_OuterConeAngle; 200 | this_light.Range = light.m_EffectiveRange; 201 | this_light.Falloff = light.FallOff; 202 | this_light.Enabled = true; 203 | this_light.Commit(); 204 | num_active_lights++; 205 | } 206 | } 207 | 208 | if ( m_num_activated > num_active_lights ) 209 | { 210 | for ( int i=0; i< (m_num_activated - num_active_lights); i++ ) 211 | { 212 | Light this_light = CGameEngine.Device3D.Lights[num_active_lights+i]; 213 | this_light.Enabled = false; 214 | this_light.Commit(); 215 | } 216 | } 217 | m_num_activated = num_active_lights; 218 | } 219 | catch (DirectXException d3de) 220 | { 221 | Console.AddLine("dx Unable to setup lights "); 222 | Console.AddLine(d3de.ErrorString); 223 | } 224 | catch ( Exception e ) 225 | { 226 | Console.AddLine("Unable to setup lights " ); 227 | Console.AddLine(e.Message); 228 | } 229 | } 230 | 231 | public static void CheckCulling ( Camera cam ) 232 | { 233 | foreach ( GameLights light in m_ActiveLights ) 234 | { 235 | if ( light.m_Type == LightType.Directional ) 236 | { 237 | light.Culled = false; // can't cull a directional light 238 | light.Range = 0.0f; 239 | } 240 | else 241 | { 242 | if ( cam.CheckFrustum( light ) != Camera.CullState.AllOutside ) 243 | { 244 | light.Culled = false; 245 | 246 | // we want the absolute value of the range 247 | light.m_fRange = Math.Abs(light.m_fRange); 248 | } 249 | else 250 | { 251 | light.Culled = true; 252 | light.Range = 1000000000.0f; // big range to sort to end of list 253 | } 254 | } 255 | } 256 | } 257 | 258 | public override void Update( float DeltaT ) 259 | { 260 | m_fRadius = m_EffectiveRange; 261 | 262 | if ( m_Parent != null ) 263 | { 264 | Matrix matrix = Matrix.Identity; 265 | 266 | matrix.RotateYawPitchRoll(m_Parent.Heading, 267 | m_Parent.Pitch,m_Parent.Roll); 268 | Vector3 pos_offset = Vector3.TransformCoordinate(m_PositionOffset,matrix); 269 | // Console.AddLine("light offset " + pos_offset); 270 | m_vPosition = m_Parent.Position + pos_offset; 271 | m_Direction.X = (float)Math.Sin(m_Parent.Attitude.Heading); 272 | m_Direction.Y = (float)Math.Sin(m_Parent.Attitude.Pitch); 273 | m_Direction.Z = (float)Math.Cos(m_Parent.Attitude.Heading); 274 | m_Direction += Vector3.TransformCoordinate(m_DirectionOffset,matrix); 275 | } 276 | } 277 | } 278 | } 279 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Listener.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.DirectSound; 5 | using Sound = Microsoft.DirectX.DirectSound; 6 | using Buffer = Microsoft.DirectX.DirectSound.Buffer; 7 | 8 | namespace GameEngine 9 | { 10 | /// 11 | /// Summary description for Listener. 12 | /// 13 | public class Listener : IDisposable 14 | { 15 | 16 | #region Attributes 17 | private Sound.Listener3DSettings listenerParameters = new Sound.Listener3DSettings(); 18 | private Sound.Listener3D applicationListener = null; 19 | private Object3D m_listener = null; 20 | 21 | private static Sound.Device applicationDevice = new Sound.Device(); 22 | #endregion 23 | 24 | #region Properties 25 | public static Sound.Device Device { get { return applicationDevice; } } 26 | #endregion 27 | 28 | public Listener(System.Windows.Forms.Form form, Object3D object_listening) 29 | { 30 | m_listener = object_listening; 31 | Sound.BufferDescription description = new Sound.BufferDescription(); 32 | Sound.WaveFormat fmt = new Sound.WaveFormat(); 33 | description.PrimaryBuffer = true; 34 | description.Control3D = true; 35 | Sound.Buffer buff = null; 36 | 37 | fmt.FormatTag = Sound.WaveFormatTag.Pcm; 38 | fmt.Channels = 2; 39 | fmt.SamplesPerSecond = 22050; 40 | fmt.BitsPerSample = 16; 41 | fmt.BlockAlign = (short)(fmt.BitsPerSample / 8 * fmt.Channels); 42 | fmt.AverageBytesPerSecond = fmt.SamplesPerSecond * fmt.BlockAlign; 43 | 44 | applicationDevice.SetCooperativeLevel( form, Sound.CooperativeLevel.Priority); 45 | 46 | // Get the primary buffer and set the format. 47 | buff = new Buffer(description, Device); 48 | buff.Format = fmt; 49 | 50 | applicationListener = new Listener3D(buff); 51 | listenerParameters = applicationListener.AllParameters; 52 | } 53 | 54 | public void Update() 55 | { 56 | if ( m_listener != null ) 57 | { 58 | listenerParameters.Position = m_listener.Position; 59 | 60 | Vector3 front = new Vector3( 0.0f, 0.0f, 1.0f ); 61 | Vector3 top = new Vector3( 0.0f, 1.0f, 0.0f ); 62 | 63 | Matrix transform = Matrix.RotationYawPitchRoll( 64 | m_listener.Attitude.Heading, 65 | m_listener.Attitude.Pitch, 66 | m_listener.Attitude.Roll); 67 | 68 | listenerParameters.OrientFront = 69 | Vector3.TransformCoordinate( front, transform ); 70 | listenerParameters.OrientTop = 71 | Vector3.TransformCoordinate( top, transform ); 72 | } 73 | applicationListener.CommitDeferredSettings(); 74 | 75 | } 76 | 77 | public void Dispose() 78 | { 79 | applicationListener.Dispose(); 80 | applicationDevice.Dispose(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Math.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.Direct3D; 5 | 6 | namespace GameEngine 7 | { 8 | /// 9 | /// Summary description for GameMath. 10 | /// 11 | public class GameMath 12 | { 13 | public GameMath() 14 | { 15 | // 16 | // TODO: Add constructor logic here 17 | // 18 | } 19 | 20 | public static Vector3 ComputeFaceNormal( Vector3 p1, Vector3 p2, Vector3 p3 ) 21 | { 22 | Vector3 Normal; 23 | 24 | Vector3 V1 = Vector3.Subtract(p1,p2); 25 | Vector3 V2 = Vector3.Subtract(p3,p1); 26 | Normal = Vector3.Cross( V1, V2 ); 27 | Normal.Normalize(); 28 | 29 | return Normal; 30 | } 31 | 32 | public static bool InRect( Rectangle rect, Vector3 pt) 33 | { 34 | bool inside = pt.X >= rect.Left && pt.X <= rect.Right && 35 | pt.Z >= rect.Bottom && pt.Z <= rect.Top; 36 | 37 | return inside; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Music.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.AudioVideoPlayback; 5 | 6 | namespace GameEngine 7 | { 8 | /// 9 | /// Summary description for Music. 10 | /// 11 | public class Music : Microsoft.DirectX.AudioVideoPlayback.Audio 12 | { 13 | #region Attributes 14 | private bool loop = false; 15 | #endregion 16 | 17 | #region Properties 18 | public bool Loop { get { return loop; } set { loop = value; } } 19 | public float MusicVolume { set { base.Volume = (int)(-4000 * (1.0f - value)); } } 20 | #endregion 21 | 22 | /// 23 | /// Music constructor 24 | /// 25 | public Music( string filename ) : base(filename) 26 | { 27 | try 28 | { 29 | Ending += new System.EventHandler(this.ClipEnded); 30 | } 31 | catch (DirectXException d3de) 32 | { 33 | Console.AddLine("Unable to create music "); 34 | Console.AddLine(d3de.ErrorString); 35 | } 36 | catch ( Exception e ) 37 | { 38 | Console.AddLine("Unable to create music "); 39 | Console.AddLine(e.Message); 40 | } 41 | } 42 | 43 | private void ClipEnded(object sender, System.EventArgs e) 44 | { 45 | // The clip has ended, stop and restart it 46 | if ( loop ) 47 | { 48 | Stop(); 49 | Play(); 50 | } 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Object3D.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Diagnostics; 4 | using System.Drawing; 5 | using Microsoft.DirectX; 6 | using Microsoft.DirectX.Direct3D; 7 | 8 | namespace GameEngine 9 | { 10 | /// 11 | /// delegate used for specifying the update method for the object 12 | /// 13 | public delegate void ObjectUpdate( Object3D Obj, float DeltaT ); 14 | 15 | /// 16 | /// Summary description for Object3D. 17 | /// 18 | abstract public class Object3D : IDisposable, IRenderable, ICullable, ICollidable, IDynamic 19 | { 20 | 21 | #region Attributes 22 | protected string m_sName; 23 | protected Vector3 m_vPosition; 24 | protected Vector3 m_vVelocity; 25 | protected Attitude m_vOrientation; 26 | protected bool m_bVisible = true; // visible by default 27 | protected bool m_bCulled; 28 | protected bool m_bHasMoved = false; 29 | protected Object3D m_Parent; 30 | protected SortedList m_Children = new SortedList(); 31 | protected float m_fRadius; // bounding circle 32 | protected float m_fRange; // distance from view point 33 | protected Matrix m_Matrix; 34 | protected ObjectUpdate m_UpdateMethod = null; 35 | 36 | public ArrayList m_Quads = new ArrayList(); 37 | 38 | public string Name { get { return m_sName; } } 39 | public Vector3 Position { get { return m_vPosition; } set { m_vPosition = value; m_bHasMoved = true;} } 40 | public Vector3 Velocity { get { return m_vVelocity; } set { m_vVelocity = value; } } 41 | public float VelocityX { get { return m_vVelocity.X; } set { m_vVelocity.X = value; m_bHasMoved = true;} } 42 | public float VelocityY { get { return m_vVelocity.Y; } set { m_vVelocity.Y = value; m_bHasMoved = true;} } 43 | public float VelocityZ { get { return m_vVelocity.Z; } set { m_vVelocity.Z = value; m_bHasMoved = true;} } 44 | public Attitude Attitude { get { return m_vOrientation; } set { m_vOrientation = value; } } 45 | public virtual float North { get { return m_vPosition.Z; } set { m_vPosition.Z = value; m_bHasMoved = true;} } 46 | public virtual float East { get { return m_vPosition.X; } set { m_vPosition.X = value; m_bHasMoved = true;} } 47 | public virtual float Height { get { return m_vPosition.Y; } set { m_vPosition.Y = value; m_bHasMoved = true;} } 48 | public virtual float Roll { get { return m_vOrientation.Roll; } set { m_vOrientation.Roll = value; } } 49 | public virtual float Pitch { get { return m_vOrientation.Pitch; } set { m_vOrientation.Pitch = value; } } 50 | public virtual float Heading { get { return m_vOrientation.Heading; } set { m_vOrientation.Heading = value; } } 51 | public float Range { get { return m_fRange; } set { m_fRange = value; } } 52 | public float Radius { get { return m_fRadius; } set { m_fRadius = value; } } 53 | public Matrix WorldMatrix { get { return m_Matrix; } } 54 | public bool Visible { get { return m_bVisible; } set { m_bVisible = value; } } 55 | #endregion 56 | 57 | public Object3D( string sName ) 58 | { 59 | m_sName = sName; 60 | m_bCulled = false; 61 | m_bVisible = true; 62 | m_Matrix = Matrix.Identity; 63 | } 64 | 65 | public void SetUpdateMethod( ObjectUpdate method ) 66 | { 67 | m_UpdateMethod = method; 68 | } 69 | 70 | public virtual bool InRect( Rectangle rect ) 71 | { 72 | // check to see if the object is within this rectangle 73 | return false; 74 | } 75 | 76 | public virtual bool Collide( Object3D Other ) { return false; } 77 | 78 | public virtual void Render() { } 79 | 80 | public virtual void Dispose() 81 | { 82 | Debug.WriteLine("Disposing of " + Name + " in Object3D"); 83 | } 84 | public virtual void Render( Camera cam ){} 85 | public virtual void Update( float DeltaT ){} 86 | public virtual bool Culled { set { m_bCulled = value; } } 87 | public virtual bool IsCulled { get { return m_bCulled; } } 88 | public Vector3 CenterOfMass { get { return m_vPosition; }} 89 | public float BoundingRadius { get { return m_fRadius; } } 90 | public virtual bool CollideSphere ( Object3D other ){ return false; } 91 | public virtual bool CollidePolygon ( Vector3 Point1, Vector3 Point2, Vector3 Point3 ){ return false; } 92 | 93 | public void AddChild( Object3D child ) 94 | { 95 | m_Children.Add(child.Name, child); 96 | child.m_Parent = this; 97 | } 98 | 99 | public void RemoveChild( string name ) 100 | { 101 | Object3D obj = (Object3D)m_Children.GetByIndex(m_Children.IndexOfKey(name)); 102 | obj.m_Parent = null; 103 | m_Children.Remove(name); 104 | } 105 | 106 | public Object3D GetChild( string name ) 107 | { 108 | try 109 | { 110 | return (Object3D)m_Children.GetByIndex(m_Children.IndexOfKey(name)); 111 | } 112 | catch 113 | { 114 | return null; 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/Quad.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Drawing; 4 | using Microsoft.DirectX; 5 | using Microsoft.DirectX.Direct3D; 6 | 7 | namespace GameEngine 8 | { 9 | /// 10 | /// The basic structure for building a Quadtree 11 | /// 12 | public class Quad : IDisposable 13 | { 14 | private Rectangle m_Bounds; 15 | private Quad m_NorthEast = null; 16 | private Quad m_NorthWest = null; 17 | private Quad m_SouthWest = null; 18 | private Quad m_SouthEast = null; 19 | private Quad m_Parent = null; 20 | private int m_nLevel; 21 | private SortedList m_Objects; 22 | private float m_fRadius; 23 | private Vector3 m_vPosition; 24 | private string m_sName; 25 | private static Quad m_BaseQuad = null; 26 | 27 | public String Name { get { return m_sName; } } 28 | 29 | public Rectangle Bounds { get { return m_Bounds; } } 30 | 31 | public Quad(Rectangle bounds, int level, int maxlevel, Quad parent ) 32 | { 33 | if ( m_BaseQuad == null ) 34 | { 35 | m_BaseQuad = this; 36 | } 37 | 38 | m_Bounds = bounds; 39 | m_nLevel = level; 40 | m_Parent = parent; 41 | m_Objects = new SortedList(); 42 | 43 | m_sName = "L" + level + ":X" + bounds.Left + "Y" + bounds.Top; 44 | 45 | m_vPosition.X = (bounds.Left + bounds.Right) / 2.0f; 46 | m_vPosition.Y = 0.0f; 47 | m_vPosition.Z = (bounds.Top + bounds.Bottom) / 2.0f; 48 | 49 | double dx = bounds.Width; 50 | double dz = bounds.Height; 51 | m_fRadius = (float)Math.Sqrt( dx * dx + dz * dz ) / 2.0f; 52 | 53 | if ( level < maxlevel ) 54 | { 55 | int nHalfHeight = (int)dz / 2; 56 | int nHalfWidth = (int)dx / 2; 57 | m_NorthEast = new Quad ( 58 | new Rectangle(bounds.Left + nHalfWidth, bounds.Top, nHalfWidth, nHalfHeight), 59 | level+1, maxlevel, this ); 60 | m_NorthWest = new Quad ( 61 | new Rectangle(bounds.Left, bounds.Top, nHalfWidth, nHalfHeight), 62 | level+1, maxlevel, this); 63 | m_SouthWest = new Quad ( 64 | new Rectangle(bounds.Left, bounds.Top + nHalfHeight, nHalfWidth, nHalfHeight), 65 | level+1, maxlevel, this); 66 | m_SouthEast = new Quad ( 67 | new Rectangle(bounds.Left + nHalfWidth, bounds.Top + nHalfHeight, nHalfWidth, nHalfHeight), 68 | level+1, maxlevel, this); 69 | } 70 | } 71 | 72 | public void AddObject( Object3D obj ) 73 | { 74 | try 75 | { 76 | if ( obj != null ) 77 | { 78 | if ( obj.InRect( m_Bounds ) ) 79 | { 80 | int nIndex = m_Objects.IndexOfKey( obj.Name ); 81 | try 82 | { 83 | if ( nIndex < 0 ) // add object if we don't have it yet 84 | { 85 | m_Objects.Add(obj.Name, obj ); 86 | obj.m_Quads.Add(this); 87 | // if ( !obj.Name.StartsWith("Quad") && !obj.Name.StartsWith("tree") && !obj.Name.StartsWith("red")&& !obj.Name.StartsWith("blue")) 88 | // { 89 | // Console.AddLine(obj.Name + " added to " + Name ); 90 | // } 91 | if ( m_NorthEast != null && obj.InRect( m_NorthEast.Bounds ) ) 92 | { 93 | m_NorthEast.AddObject( obj ); 94 | } 95 | if ( m_NorthWest != null && obj.InRect( m_NorthWest.Bounds ) ) 96 | { 97 | m_NorthWest.AddObject( obj ); 98 | } 99 | if ( m_SouthWest != null && obj.InRect( m_SouthWest.Bounds ) ) 100 | { 101 | m_SouthWest.AddObject( obj ); 102 | } 103 | if ( m_SouthEast != null && obj.InRect( m_SouthEast.Bounds ) ) 104 | { 105 | m_SouthEast.AddObject( obj ); 106 | } 107 | } 108 | else 109 | { 110 | // Console.AddLine("Attempt to add another " + obj.Name ); 111 | } 112 | } 113 | catch (DirectXException d3de) 114 | { 115 | Console.AddLine("Unable to add object" ); 116 | Console.AddLine(d3de.ErrorString); 117 | } 118 | catch ( Exception e ) 119 | { 120 | Console.AddLine("Unable to add object" ); 121 | Console.AddLine(e.Message); 122 | } 123 | } 124 | else 125 | { 126 | int nIndex = m_Objects.IndexOfKey( obj.Name ); 127 | if ( nIndex >= 0 ) // remove the object if we have it 128 | { 129 | RemoveObject( obj ); 130 | if ( m_Parent != null ) 131 | { 132 | m_Parent.AddObject( obj ); 133 | } 134 | } 135 | } 136 | } 137 | } 138 | catch 139 | { 140 | Console.AddLine("fails in Quad AddObject"); 141 | } 142 | } 143 | 144 | public void RemoveObject( Object3D obj ) 145 | { 146 | try 147 | { 148 | if ( obj != null ) 149 | { 150 | int nIndex = m_Objects.IndexOfKey( obj.Name ); 151 | if ( nIndex >= 0 ) 152 | { 153 | try 154 | { 155 | m_Objects.Remove( obj.Name ); 156 | } 157 | catch 158 | { 159 | Console.AddLine("failing while removing object from quad object list" ); 160 | } 161 | try 162 | { 163 | if ( obj.m_Quads.Count > 0 ) 164 | { 165 | obj.m_Quads.Clear(); 166 | } 167 | } 168 | catch 169 | { 170 | Console.AddLine("failing while clearing objects quad list"); 171 | } 172 | if ( m_NorthEast != null ) 173 | { 174 | m_NorthEast.RemoveObject( obj ); 175 | } 176 | if ( m_NorthWest != null ) 177 | { 178 | m_NorthWest.RemoveObject( obj ); 179 | } 180 | if ( m_SouthWest != null ) 181 | { 182 | m_SouthWest.RemoveObject( obj ); 183 | } 184 | if ( m_SouthEast != null ) 185 | { 186 | m_SouthEast.RemoveObject( obj ); 187 | } 188 | } 189 | } 190 | } 191 | catch (DirectXException d3de) 192 | { 193 | Console.AddLine("Unable to remove object" ); 194 | Console.AddLine(d3de.ErrorString); 195 | } 196 | catch ( Exception e ) 197 | { 198 | Console.AddLine("Unable to remove object" ); 199 | Console.AddLine(e.Message); 200 | } 201 | } 202 | 203 | public void Cull( Camera cam ) 204 | { 205 | Object3D obj; 206 | int i; 207 | 208 | cam.Reset(); 209 | 210 | if ( m_Objects.Count > 0 ) 211 | { 212 | 213 | try 214 | { 215 | switch ( cam.CheckFrustum( m_vPosition, m_fRadius ) ) 216 | { 217 | case Camera.CullState.AllInside: 218 | for ( i = 0; i < m_Objects.Count; i++ ) 219 | { 220 | obj = (Object3D)m_Objects.GetByIndex(i); 221 | obj.Range = cam.GetDistance( obj ); 222 | obj.Culled = false; 223 | m_Objects.SetByIndex(i, obj); 224 | cam.AddVisibleObject( obj ); 225 | } 226 | break; 227 | case Camera.CullState.AllOutside: 228 | if ( m_Parent == null ) // i.e. if this is the root quad 229 | { 230 | goto case Camera.CullState.PartiallyIn; 231 | } 232 | // do nothing since the default state is true (reset after each render) 233 | break; 234 | case Camera.CullState.PartiallyIn: 235 | if ( m_NorthEast != null ) 236 | { 237 | m_NorthEast.Cull( cam ); 238 | m_NorthWest.Cull( cam ); 239 | m_SouthWest.Cull( cam ); 240 | m_SouthEast.Cull( cam ); 241 | } 242 | else // if partially in at the bottom level treat as in 243 | { 244 | for ( i = 0; i < m_Objects.Count; i++ ) 245 | { 246 | obj = (Object3D)m_Objects.GetByIndex(i); 247 | obj.Culled = false; 248 | m_Objects.SetByIndex(i, obj); 249 | cam.AddVisibleObject( obj ); 250 | } 251 | } 252 | break; 253 | } 254 | } 255 | catch (DirectXException d3de) 256 | { 257 | Console.AddLine("Unable to cull object" ); 258 | Console.AddLine(d3de.ErrorString); 259 | } 260 | catch ( Exception e ) 261 | { 262 | Console.AddLine("Unable to cull object" ); 263 | Console.AddLine(e.Message); 264 | } 265 | } 266 | } 267 | 268 | 269 | public void Update ( Object3D obj ) 270 | { 271 | bool bResetNeeded = false; 272 | 273 | try 274 | { 275 | 276 | // only need to reset the quad for the object if it is no longer in one of the quads 277 | try 278 | { 279 | foreach ( Quad q in obj.m_Quads ) 280 | { 281 | try 282 | { 283 | if ( !obj.InRect( q.m_Bounds ) ) 284 | { 285 | bResetNeeded = true; 286 | } 287 | } 288 | catch 289 | { 290 | Console.AddLine("invalid quad in object quad list"); 291 | } 292 | } 293 | } 294 | catch 295 | { 296 | Console.AddLine("fails in foreach"); 297 | } 298 | try 299 | { 300 | if ( bResetNeeded ) 301 | { 302 | m_BaseQuad.RemoveObject( obj ); 303 | m_BaseQuad.AddObject( obj ); 304 | } 305 | } 306 | catch 307 | { 308 | Console.AddLine("fails in reset needed"); 309 | } 310 | } 311 | catch (DirectXException d3de) 312 | { 313 | Console.AddLine("Unable to update a Quad " + Name); 314 | Console.AddLine(d3de.ErrorString); 315 | } 316 | catch ( Exception e ) 317 | { 318 | Console.AddLine("Unable to update a Quad " + Name); 319 | Console.AddLine(e.Message); 320 | } 321 | 322 | } 323 | 324 | public void Dispose() 325 | { 326 | if ( m_NorthEast != null ) m_NorthEast.Dispose(); 327 | if ( m_NorthWest != null ) m_NorthWest.Dispose(); 328 | if ( m_SouthWest != null ) m_SouthWest.Dispose(); 329 | if ( m_SouthEast != null ) m_SouthEast.Dispose(); 330 | } 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/SoundEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.DirectSound; 5 | using Sound = Microsoft.DirectX.DirectSound; 6 | using Buffer = Microsoft.DirectX.DirectSound.Buffer; 7 | 8 | namespace GameEngine 9 | { 10 | /// 11 | /// Summary description for SoundEffect. 12 | /// 13 | public class SoundEffect : IDisposable 14 | { 15 | #region Attributes 16 | private SecondaryBuffer soundBuffer = null; 17 | private Buffer3D soundBuffer3D = null; 18 | private Object3D m_source = null; 19 | private string m_FileName; 20 | private bool looping = false; 21 | private int min_freq = 22050; 22 | private int max_freq = 22050; 23 | private float current_freq = 0.0f; 24 | 25 | private static int master_volume = 0; 26 | #endregion 27 | 28 | #region Properties 29 | public bool Looping { set { looping = value; } get { return looping; } } 30 | public int MinFreq { set { min_freq = value; } get { return min_freq; } } 31 | public int MaxFreq { set { max_freq = value; } get { return max_freq; } } 32 | public float Frequency { 33 | set { 34 | current_freq = value; 35 | if ( current_freq > 1.0 ) current_freq = 1.0f; 36 | if ( current_freq < 0.0 ) current_freq = 0.0f; 37 | } get { return current_freq; } } 38 | public float MinDistance { set { soundBuffer3D.MinDistance = value; } get { return soundBuffer3D.MinDistance; } } 39 | public float MaxDistance { set { soundBuffer3D.MaxDistance = value; } get { return soundBuffer3D.MaxDistance; } } 40 | 41 | public static float Volume { set { master_volume = (int)(-4000 * (1.0f - value)); } } 42 | 43 | private static int MasterVolume { get { return master_volume; } } 44 | #endregion 45 | 46 | public SoundEffect( string FileName) 47 | { 48 | m_FileName = FileName; 49 | LoadSoundFile(); 50 | 51 | } 52 | 53 | private void LoadSoundFile() 54 | { 55 | 56 | BufferDescription description = new BufferDescription(); 57 | 58 | description.Guid3DAlgorithm = DSoundHelper.Guid3DAlgorithmHrtfLight; 59 | description.Control3D = true; 60 | description.ControlFrequency = true; 61 | description.ControlVolume = true; 62 | 63 | if (null != soundBuffer) 64 | { 65 | soundBuffer.Stop(); 66 | soundBuffer.SetCurrentPosition(0); 67 | } 68 | 69 | // Load the wave file into a DirectSound buffer 70 | try 71 | { 72 | soundBuffer = new SecondaryBuffer(m_FileName, description, Listener.Device); 73 | soundBuffer3D = new Buffer3D(soundBuffer); 74 | } 75 | catch ( Exception e ) 76 | { 77 | GameEngine.Console.AddLine("Exception on loading " + m_FileName + ". Ensure file is Mono"); 78 | GameEngine.Console.AddLine(e.Message); 79 | } 80 | 81 | if (WaveFormatTag.Pcm != (WaveFormatTag.Pcm & description.Format.FormatTag)) 82 | { 83 | GameEngine.Console.AddLine("Wave file must be PCM for 3D control."); 84 | if (null != soundBuffer) 85 | soundBuffer.Dispose(); 86 | soundBuffer = null; 87 | } 88 | } 89 | 90 | private bool RestoreBuffer() 91 | { 92 | if (false == soundBuffer.Status.BufferLost) 93 | return false; 94 | 95 | while(true == soundBuffer.Status.BufferLost) 96 | { 97 | soundBuffer.Restore(); 98 | } 99 | return true; 100 | } 101 | 102 | public void PlaySound() 103 | { 104 | try 105 | { 106 | BufferPlayFlags flags; 107 | if ( looping ) 108 | { 109 | flags = BufferPlayFlags.Looping; 110 | } 111 | else 112 | { 113 | flags = BufferPlayFlags.Default; 114 | } 115 | 116 | if (RestoreBuffer()) 117 | { 118 | LoadSoundFile(); 119 | soundBuffer.SetCurrentPosition(0); 120 | } 121 | soundBuffer.Play(0, flags); 122 | } 123 | catch ( Exception e ) 124 | { 125 | GameEngine.Console.AddLine("Exception on playing " + m_FileName); 126 | GameEngine.Console.AddLine(e.Message); 127 | } 128 | } 129 | 130 | public void StopSound() 131 | { 132 | try 133 | { 134 | soundBuffer.Stop(); 135 | soundBuffer.SetCurrentPosition(0); 136 | } 137 | catch ( Exception e ) 138 | { 139 | GameEngine.Console.AddLine("Exception on stopping " + m_FileName); 140 | GameEngine.Console.AddLine(e.Message); 141 | } 142 | } 143 | 144 | public void Update() 145 | { 146 | try 147 | { 148 | int freq_range = max_freq - min_freq; 149 | 150 | if ( freq_range > 0 ) 151 | { 152 | soundBuffer.Frequency = 153 | min_freq + (int)(freq_range * current_freq); 154 | } 155 | 156 | soundBuffer.Volume = MasterVolume; 157 | 158 | if ( m_source != null ) 159 | { 160 | soundBuffer3D.Position = m_source.Position; 161 | } 162 | } 163 | catch ( Exception e ) 164 | { 165 | GameEngine.Console.AddLine("Exception while updating " + m_FileName); 166 | GameEngine.Console.AddLine(e.Message); 167 | } 168 | } 169 | 170 | public void Dispose() 171 | { 172 | try 173 | { 174 | soundBuffer.Dispose(); 175 | soundBuffer3D.Dispose(); 176 | } 177 | catch 178 | { 179 | // do nothing - if this failed there was probably nothing to dispose of 180 | } 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /1590590813-1225/GameEngine/hud.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using Microsoft.DirectX; 4 | using Microsoft.DirectX.Direct3D; 5 | 6 | namespace GameEngine 7 | { 8 | /// 9 | /// Summary description for hud. 10 | /// 11 | public class Hud : IDisposable 12 | { 13 | /// 14 | /// Custom vertex type for the HudPoint 15 | /// 16 | public struct HUDPOINTVERTEX 17 | { 18 | public Vector3 p; 19 | public float rhw; 20 | public int color; 21 | 22 | public const VertexFormats Fvf = VertexFormats.PositionW | VertexFormats.Diffuse; 23 | }; 24 | 25 | private CustomVertex.TransformedColored[] m_Points; 26 | private VertexBuffer m_VB = null; // Vertex buffer 27 | private int m_xSize; 28 | private int m_ySize; 29 | private int m_numPoints; 30 | 31 | public Hud(int xSize, int ySize) 32 | { 33 | m_xSize = xSize; 34 | m_ySize = ySize; 35 | m_numPoints = xSize * ySize; 36 | 37 | m_Points = new CustomVertex.TransformedColored[m_numPoints]; 38 | 39 | for ( int i=0; i 10 | /// Summary description for Jukebox. 11 | /// 12 | public class Jukebox : IDisposable 13 | { 14 | #region Attributes 15 | private ArrayList playlist = null; 16 | private int current_song = 0; 17 | private int volume = 0; 18 | #endregion 19 | 20 | #region Properties 21 | public float Volume { set { volume = (int)(-4000 * (1.0f - value)); } } 22 | #endregion 23 | 24 | /// 25 | /// Jukebox constructor 26 | /// 27 | public Jukebox( ) 28 | { 29 | playlist = new ArrayList(); 30 | } 31 | 32 | public void AddSong( string filename ) 33 | { 34 | try 35 | { 36 | Music song = new Music(filename); 37 | song.Ending += new System.EventHandler(this.ClipEnded); 38 | playlist.Add(song); 39 | } 40 | catch (DirectXException d3de) 41 | { 42 | Console.AddLine("Unable to add " + filename + " to the jukebox playlist "); 43 | Console.AddLine(d3de.ErrorString); 44 | } 45 | catch ( Exception e ) 46 | { 47 | Console.AddLine("Unable to add " + filename + " to the jukebox playlist "); 48 | Console.AddLine(e.Message); 49 | } 50 | } 51 | 52 | public void Play() 53 | { 54 | if ( current_song < playlist.Count ) 55 | { 56 | Music song = (Music)(playlist[current_song]); 57 | song.Ending += new System.EventHandler(this.ClipEnded); 58 | song.Volume = volume; 59 | song.Play(); 60 | } 61 | } 62 | 63 | public void Stop() 64 | { 65 | Next(); 66 | } 67 | 68 | public void Next() 69 | { 70 | Music song = (Music)(playlist[current_song]); 71 | song.Stop(); 72 | song.SeekCurrentPosition(0.0, SeekPositionFlags.AbsolutePositioning ); 73 | current_song++; 74 | if ( current_song >= playlist.Count ) 75 | { 76 | current_song = 0; 77 | } 78 | } 79 | 80 | private void ClipEnded(object sender, System.EventArgs e) 81 | { 82 | Next(); 83 | Play(); 84 | } 85 | 86 | public void Dispose() 87 | { 88 | foreach ( Music song in playlist ) 89 | { 90 | song.Dispose(); 91 | } 92 | } 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /1590590813-1225/Readme.txt: -------------------------------------------------------------------------------- 1 | The source and resources for the sample game from Introduction to 3D game Engine Design is packaged in two files. be sure to douwnload and unzip both. There are issues in the car physics code that were discovered after the book was printed. Although some of the issues have been addressed and the car is now driveable there will be additional corrections coming in the next week or so. 2 | 3 | Check back for updated files in the Apress download site or at http://home.stny.rr.com/lynnharrison. I can be contacted on the Apress forum at www.forums.apress.com on the game development forum. 4 | 5 | The SampleGame solution file is the primary solution for the game project. It includes the other solutions as sub-projects. They build DLLs that are used by the game application. 6 | 7 | Lynn T. Harrison -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/App.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/App.ico -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("")] 14 | [assembly: AssemblyCopyright("")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("1.0.*")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Car.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Microsoft.DirectX; 4 | using GameEngine; 5 | using GameAI; 6 | using VehicleDynamics; 7 | 8 | namespace SampleGame 9 | { 10 | /// 11 | /// Summary description for Car. 12 | /// 13 | public class Car : Model 14 | { 15 | #region Attributes 16 | private CarDynamics m_dynamics; 17 | private float steering_wheel = 0.0f; 18 | private float brake_pedal = 0.0f; 19 | private float gas_pedal = 0.0f; 20 | private float terrain_limit = 2000.0f; 21 | #endregion 22 | 23 | #region Properties 24 | public CarDynamics Dynamics { get { return m_dynamics; } } 25 | public float Steering { set { steering_wheel = value; } get { return steering_wheel; } } 26 | public float Brake { set { brake_pedal = value; } get { return brake_pedal; } } 27 | public float Gas { set { gas_pedal = value; } get { return gas_pedal; } } 28 | public override float North { get { return m_vPosition.Z; } set { m_vPosition.Z = value; m_dynamics.North = value; m_bHasMoved = true;} } 29 | public override float East { get { return m_vPosition.X; } set { m_vPosition.X = value; m_dynamics.East = value; m_bHasMoved = true;} } 30 | public override float Height { get { return m_vPosition.Y; } set { m_vPosition.Y = value; m_dynamics.Height = value; m_bHasMoved = true;} } 31 | public override float Roll { get { return m_vOrientation.Roll; } set { m_vOrientation.Roll = value; m_dynamics.Roll = value; } } 32 | public override float Pitch { get { return m_vOrientation.Pitch; } set { m_vOrientation.Pitch = value; m_dynamics.Pitch = value; } } 33 | public override float Heading { get { return m_vOrientation.Heading; } set { m_vOrientation.Heading = value; m_dynamics.Heading = value; } } 34 | public int MPH { get { return (int)(m_dynamics.MPH); } } 35 | public int RPM { get { return (int)(m_dynamics.EngineRPM); } } 36 | public double ForwardVelocity { get { return m_dynamics.ForwardVelocity; } } 37 | public double SidewaysVelocity { get { return m_dynamics.SidewaysVelocity; } } 38 | public bool Driving { 39 | set { 40 | if ( value ) m_dynamics.Gear = CarDynamics.GearState.Drive; 41 | else m_dynamics.Gear = CarDynamics.GearState.Park; 42 | } 43 | } 44 | #endregion 45 | 46 | public Car(string name, string meshFile, Vector3 offset, Attitude adjust ) 47 | : base (name, meshFile, offset, adjust) 48 | { 49 | m_dynamics = new CarDynamics(); 50 | 51 | // start the engine 52 | // m_dynamics.Gear = CarDynamics.GearState.Park; 53 | m_dynamics.Ignition = CarDynamics.IgnitionState.IgnitionStart; 54 | m_dynamics.Gear = CarDynamics.GearState.Drive; 55 | } 56 | public override void Update( float DeltaT ) 57 | { 58 | // System.Diagnostics.Debug.WriteLine("car update"); 59 | 60 | m_dynamics.Brake = brake_pedal; 61 | m_dynamics.SteeringWheel = steering_wheel; 62 | m_dynamics.Throttle = gas_pedal; 63 | 64 | float tire_north = m_dynamics.WheelNorth(WhichWheel.LeftFront) + North; 65 | float tire_east = m_dynamics.WheelEast(WhichWheel.LeftFront) + East; 66 | float tire_altitude = CGameEngine.Ground.TerrainHeight( tire_east, tire_north ); 67 | m_dynamics.SetWheelAltitude( WhichWheel.LeftFront, tire_altitude ); 68 | // GameEngine.Console.AddLine( Name + " LeftFront height " + tire_altitude + " at n="+tire_north+" e="+tire_east); 69 | 70 | tire_north = m_dynamics.WheelNorth(WhichWheel.LeftRear) + North; 71 | tire_east = m_dynamics.WheelEast(WhichWheel.LeftRear) + East; 72 | tire_altitude = CGameEngine.Ground.TerrainHeight( tire_east, tire_north ); 73 | m_dynamics.SetWheelAltitude( WhichWheel.LeftRear, tire_altitude ); 74 | // GameEngine.Console.AddLine( Name + " LeftRear height " + tire_altitude + " at n="+tire_north+" e="+tire_east); 75 | 76 | tire_north = m_dynamics.WheelNorth(WhichWheel.RightRear) + North; 77 | tire_east = m_dynamics.WheelEast(WhichWheel.RightRear) + East; 78 | tire_altitude = CGameEngine.Ground.TerrainHeight( tire_east, tire_north ); 79 | m_dynamics.SetWheelAltitude( WhichWheel.RightRear, tire_altitude ); 80 | // GameEngine.Console.AddLine( Name + " RightRear height " + tire_altitude + " at n="+tire_north+" e="+tire_east); 81 | 82 | tire_north = m_dynamics.WheelNorth(WhichWheel.RightFront) + North; 83 | tire_east = m_dynamics.WheelEast(WhichWheel.RightFront) + East; 84 | tire_altitude = CGameEngine.Ground.TerrainHeight( tire_east, tire_north ); 85 | m_dynamics.SetWheelAltitude( WhichWheel.RightFront, tire_altitude ); 86 | // GameEngine.Console.AddLine( Name + " RightFront height " + tire_altitude + " at n="+tire_north+" e="+tire_east); 87 | 88 | if ( (float)m_dynamics.North > 10.0 && (float)m_dynamics.North < (terrain_limit-10.0f) ) 89 | { 90 | m_vPosition.Z = (float)m_dynamics.North; 91 | } 92 | else 93 | { 94 | m_dynamics.North = m_vPosition.Z; 95 | } 96 | if ( (float)m_dynamics.East > 10.0 && (float)m_dynamics.East < (terrain_limit-10.0f) ) 97 | { 98 | m_vPosition.X = (float)m_dynamics.East; 99 | } 100 | else 101 | { 102 | m_dynamics.East = m_vPosition.X; 103 | } 104 | 105 | Heading = (float)m_dynamics.Heading; 106 | Pitch = (float)m_dynamics.Pitch; 107 | Roll = (float)m_dynamics.Roll; 108 | 109 | base.VelocityX = (float)m_dynamics.EastVelocity; 110 | base.VelocityZ = (float)m_dynamics.NorthVelocity; 111 | base.VelocityY = (float)m_dynamics.VerticalVelocity; 112 | 113 | m_bHasMoved = true; 114 | 115 | base.Update( DeltaT ); 116 | } 117 | 118 | public override void Dispose() 119 | { 120 | Debug.WriteLine("Disposing of " + Name + " in Car"); 121 | m_dynamics.Dispose(); 122 | base.Dispose(); 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Opponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.DirectX; 3 | using GameEngine; 4 | using GameAI; 5 | using VehicleDynamics; 6 | using System.Collections; 7 | using System.Diagnostics; 8 | 9 | namespace SampleGame 10 | { 11 | /// 12 | /// Summary description for Opponent. 13 | /// 14 | public class Opponent : Car 15 | { 16 | #region Attributes 17 | private Thinker m_thinker; 18 | private Camera m_camera; 19 | #endregion 20 | 21 | #region Properties 22 | public Camera Eyes { get { return m_camera; } } 23 | #endregion 24 | 25 | public Opponent(string name, string meshFile, Vector3 offset, Attitude adjust, 26 | string knowledge ) : base (name, meshFile, offset, adjust) 27 | { 28 | m_camera = new Camera(name + " cam"); 29 | m_camera.Attach( this, new Vector3(0.0f, 0.0f, 0.0f )); 30 | 31 | Thinker.AddAction( "SteerLeft", new Thinker.ActionMethod( SteerLeft ) ); 32 | Thinker.AddAction( "SteerStraight", new Thinker.ActionMethod( SteerStraight ) ); 33 | Thinker.AddAction( "SteerRight", new Thinker.ActionMethod( SteerRight ) ); 34 | Thinker.AddAction( "HitTheBrakes", new Thinker.ActionMethod( HitTheBrakes ) ); 35 | Thinker.AddAction( "Accelerate", new Thinker.ActionMethod( Accelerate ) ); 36 | 37 | m_thinker = new Thinker( this ); 38 | 39 | m_thinker.AddSensorMethod( new Thinker.SensorMethod( DriverView) ); 40 | 41 | m_thinker.Read( knowledge ); 42 | } 43 | 44 | public void DriverView( Thinker thinker ) 45 | { 46 | ArrayList objects = new ArrayList(); 47 | 48 | Opponent self = (Opponent)thinker.Self; 49 | Camera eyes = self.Eyes; 50 | 51 | // get a local copy of the objects that the camera can see 52 | objects.Clear(); 53 | foreach ( Object3D obj in eyes.VisibleObjects ) 54 | { 55 | objects.Add( obj ); 56 | } 57 | 58 | float range_to_nearest = 10000.0f; 59 | float bearing_to_nearest = 0.0f; 60 | Object3D nearest_object = null; 61 | 62 | // nearest red post 63 | foreach ( Object3D obj in objects ) 64 | { 65 | if ( obj.Name.Substring(0,3) == "red" ) 66 | { 67 | float range = eyes.GetDistance(obj); 68 | if ( range < range_to_nearest ) 69 | { 70 | range_to_nearest = range; 71 | nearest_object = obj; 72 | } 73 | } 74 | } 75 | if ( nearest_object != null ) 76 | { 77 | bearing_to_nearest = GetBearing( self, nearest_object ); 78 | thinker.SetFact("red_post_in_sight", 1.0f ); 79 | thinker.SetFact("red_post_range", range_to_nearest ); 80 | thinker.SetFact("red_post_bearing", bearing_to_nearest ); 81 | } 82 | else 83 | { 84 | thinker.SetFact("red_post_in_sight", 0.0f ); 85 | } 86 | 87 | // nearest blue post 88 | range_to_nearest = 10000.0f; 89 | foreach ( Object3D obj in objects ) 90 | { 91 | if ( obj.Name.Substring(0,4) == "blue" ) 92 | { 93 | float range = eyes.GetDistance(obj); 94 | if ( range < range_to_nearest ) 95 | { 96 | range_to_nearest = range; 97 | nearest_object = obj; 98 | } 99 | } 100 | } 101 | if ( nearest_object != null ) 102 | { 103 | bearing_to_nearest = GetBearing( self, nearest_object ); 104 | thinker.SetFact("blue_post_in_sight", 1.0f ); 105 | thinker.SetFact("blue_post_range", range_to_nearest ); 106 | thinker.SetFact("blue_post_bearing", bearing_to_nearest ); 107 | } 108 | else 109 | { 110 | thinker.SetFact("blue_post_in_sight", 0.0f ); 111 | } 112 | 113 | // nearest obstacle (vehicles and trees) 114 | range_to_nearest = 10000.0f; 115 | foreach ( Object3D obj in objects ) 116 | { 117 | if ( obj.Name.Substring(0,4) == "tree" || 118 | obj.Name.Substring(0,3) == "car" ) 119 | { 120 | float bearing = GetBearing( self, nearest_object ); 121 | float range = eyes.GetDistance(obj); 122 | 123 | // only accept nearest object within +/- 5 degrees 124 | if ( Math.Abs(bearing) < 0.087266462599716478846184538424431 && range < range_to_nearest ) 125 | { 126 | range_to_nearest = range; 127 | nearest_object = obj; 128 | bearing_to_nearest = bearing; 129 | } 130 | } 131 | } 132 | if ( nearest_object != null ) 133 | { 134 | thinker.SetFact("obstacle_in_sight", 1.0f ); 135 | thinker.SetFact("obstacle_range", range_to_nearest ); 136 | thinker.SetFact("obstacle_bearing", bearing_to_nearest ); 137 | } 138 | else 139 | { 140 | thinker.SetFact("obstacle_in_sight", 0.0f ); 141 | } 142 | } 143 | 144 | void SteerLeft( Thinker thinker ) 145 | { 146 | Opponent self = (Opponent)thinker.Self; 147 | 148 | if ( self.Steering > -1.0 ) self.Steering = self.Steering - 0.01f; 149 | } 150 | 151 | void SteerStraight( Thinker thinker ) 152 | { 153 | Opponent self = (Opponent)thinker.Self; 154 | 155 | if ( self.Steering > 0.0 ) self.Steering = self.Steering - 0.01f; 156 | else if ( self.Steering < 0.0 ) self.Steering = self.Steering + 0.01f; 157 | } 158 | 159 | void SteerRight( Thinker thinker ) 160 | { 161 | Opponent self = (Opponent)thinker.Self; 162 | 163 | if ( self.Steering < 1.0 ) self.Steering = self.Steering + 0.01f; 164 | } 165 | 166 | void HitTheBrakes( Thinker thinker ) 167 | { 168 | Opponent self = (Opponent)thinker.Self; 169 | 170 | self.Gas = 0.0f; 171 | 172 | if ( self.Brake < 1.0 ) self.Brake = self.Brake + 0.1f; 173 | } 174 | 175 | void Accelerate( Thinker thinker ) 176 | { 177 | Opponent self = (Opponent)thinker.Self; 178 | 179 | self.Brake = 0.0f; 180 | 181 | if ( self.Gas < 1.0 ) self.Gas = self.Gas + 0.1f; 182 | } 183 | 184 | float GetBearing( Object3D self, Object3D other ) 185 | { 186 | float bearing = 0.0f; 187 | 188 | Vector3 direction = other.Position - self.Position; 189 | if ( direction.X != 0.0 ) 190 | { 191 | bearing = (float)Math.Atan(direction.Z / direction.X); 192 | } 193 | else 194 | { 195 | if ( direction.Z > 0.0 ) 196 | { 197 | bearing = 0.0f; 198 | } 199 | else 200 | { 201 | bearing = (float)Math.PI; 202 | } 203 | } 204 | return bearing; 205 | } 206 | 207 | public override void Dispose() 208 | { 209 | Debug.WriteLine("disposing of " + Name + " in opponent"); 210 | m_thinker.Dispose(); 211 | base.Dispose(); 212 | } 213 | } 214 | 215 | } 216 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Ownship.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Microsoft.DirectX; 4 | using GameEngine; 5 | using GameAI; 6 | using VehicleDynamics; 7 | using Microsoft.DirectX.DirectInput; 8 | 9 | namespace SampleGame 10 | { 11 | /// 12 | /// Summary description for Ownship. 13 | /// 14 | public class Ownship : Car 15 | { 16 | #region Attributes 17 | private float ownship_speed = 0.0f; 18 | private float wheel = 0.0f; 19 | private float gas = 0.0f; 20 | private Listener ears = null; 21 | private SoundEffect engine_sound = null; 22 | private SoundEffect thump = null; 23 | private SoundEffect crash = null; 24 | private bool first_pass = true; 25 | private bool m_bUsingJoystick = false; 26 | private bool m_bUsingMouse = false; 27 | private bool m_bUsingKeyboard = false; 28 | #endregion 29 | 30 | #region Properties 31 | public bool UseJoystick { set { m_bUsingJoystick = value; } } 32 | public bool UseMouse { set { m_bUsingMouse = value; } } 33 | public bool UseKeyboard { set { m_bUsingKeyboard = value; } } 34 | #endregion 35 | 36 | public Ownship(System.Windows.Forms.Form form, string name, string meshFile, Vector3 offset, Attitude adjust ) 37 | : base (name, meshFile, offset, adjust) 38 | { 39 | ears = new Listener(form, this); 40 | engine_sound = new SoundEffect(@"..\..\Resources\car_idle.wav"); 41 | engine_sound.Looping = true; 42 | engine_sound.MinFreq = 9700; 43 | engine_sound.MaxFreq = 13500; 44 | thump = new SoundEffect(@"..\..\Resources\thump.wav"); 45 | crash = new SoundEffect(@"..\..\Resources\crash.wav"); 46 | } 47 | public override void Update( float DeltaT ) 48 | { 49 | float delta_x_velocity; 50 | float delta_y_velocity; 51 | float delta_z_velocity; 52 | float delta_x_position; 53 | float delta_y_position; 54 | float delta_z_position; 55 | 56 | if ( first_pass ) 57 | { 58 | first_pass = false; 59 | 60 | engine_sound.PlaySound(); 61 | } 62 | 63 | ears.Update(); 64 | 65 | // System.Diagnostics.Debug.WriteLine("ownship update"); 66 | // North = North + ownship_speed * (float)Math.Cos(Heading) * DeltaT; 67 | // East = East + ownship_speed * (float)Math.Sin(Heading) * DeltaT; 68 | 69 | if ( m_bUsingJoystick ) 70 | { 71 | Steering = (CGameEngine.Inputs.GetJoystickNormalX()-1.0f); 72 | gas = (1.0f - (float)CGameEngine.Inputs.GetJoystickNormalY()); 73 | } 74 | else if ( m_bUsingMouse ) 75 | { 76 | try 77 | { 78 | gas += (float)CGameEngine.Inputs.GetMouseZ() * 0.1f; 79 | if ( CGameEngine.Inputs.IsKeyPressed(Key.DownArrow) ) 80 | { 81 | gas -= 0.1f; 82 | } 83 | else if ( CGameEngine.Inputs.IsKeyPressed(Key.UpArrow) ) 84 | { 85 | gas += 0.1f; 86 | } 87 | if ( gas > 1.0 ) 88 | { 89 | gas = 1.0f; 90 | } 91 | else if ( gas < -1.0f ) 92 | { 93 | gas = -1.0f; 94 | } 95 | float x = (float)CGameEngine.Inputs.GetMouseX(); 96 | wheel += (x * .10f)*DeltaT; 97 | if ( wheel > 1.0 ) 98 | { 99 | wheel = 1.0f; 100 | } 101 | else if ( wheel < -1.0f ) 102 | { 103 | wheel = -1.0f; 104 | } 105 | 106 | Steering = wheel; 107 | } 108 | catch ( Exception e ) 109 | { 110 | GameEngine.Console.AddLine("Exception"); 111 | GameEngine.Console.AddLine(e.Message); 112 | } 113 | } 114 | else if ( m_bUsingKeyboard ) 115 | { 116 | if ( CGameEngine.Inputs.IsKeyPressed(Key.LeftArrow) ) 117 | { 118 | Heading = Heading - .50f * DeltaT; 119 | } 120 | else if ( CGameEngine.Inputs.IsKeyPressed(Key.RightArrow) ) 121 | { 122 | Heading = Heading + .50f * DeltaT; 123 | } 124 | if ( CGameEngine.Inputs.IsKeyPressed(Key.DownArrow) ) 125 | { 126 | ownship_speed -= 0.1f; 127 | } 128 | else if ( CGameEngine.Inputs.IsKeyPressed(Key.UpArrow) ) 129 | { 130 | ownship_speed += 0.1f; 131 | } 132 | } 133 | 134 | if ( gas >= 0.0f ) 135 | { 136 | Gas = gas; 137 | Brake = 0.0f; 138 | } 139 | if ( gas <= 0.0f ) 140 | { 141 | Gas = 0.0f; 142 | Brake = -gas; 143 | } 144 | // GameEngine.Console.AddLine("Steering " + wheel + " gas " + gas ); 145 | engine_sound.Frequency = Gas; 146 | engine_sound.Update(); 147 | 148 | foreach ( Object3D test_obj in CGameApplication.Engine.Objects ) 149 | { 150 | if ( test_obj != this ) 151 | { 152 | if ( Collide(test_obj) ) 153 | { 154 | delta_x_velocity = test_obj.VelocityX - VelocityX; 155 | delta_y_velocity = test_obj.VelocityY - VelocityY; 156 | delta_z_velocity = test_obj.VelocityZ - VelocityZ; 157 | delta_x_position= test_obj.Position.X; 158 | delta_y_position= test_obj.Position.X; 159 | delta_z_position= test_obj.Position.X; 160 | // GameEngine.Console.AddLine( Name + " collided with " + test_obj.Name); 161 | if ( test_obj.Name.Substring(0,3) == "red" || 162 | test_obj.Name.Substring(0,4) == "blue" || 163 | test_obj.Name.Substring(0,6) == "cactus" ) 164 | { 165 | thump.PlaySound(); 166 | Dynamics.MinorCollision(); 167 | } 168 | else 169 | { 170 | crash.PlaySound(); 171 | Dynamics.MajorCollision(delta_x_velocity, delta_y_velocity, delta_z_velocity, delta_x_position, delta_y_position, delta_z_position); 172 | } 173 | } 174 | } 175 | } 176 | foreach ( Object3D test_obj in GameEngine.BillBoard.Objects ) 177 | { 178 | if ( test_obj != this ) 179 | { 180 | if ( Collide(test_obj) ) 181 | { 182 | delta_x_velocity = test_obj.VelocityX - VelocityX; 183 | delta_y_velocity = test_obj.VelocityY - VelocityY; 184 | delta_z_velocity = test_obj.VelocityZ - VelocityZ; 185 | delta_x_position= test_obj.Position.X; 186 | delta_y_position= test_obj.Position.X; 187 | delta_z_position= test_obj.Position.X; 188 | // GameEngine.Console.AddLine( Name + " collided with " + test_obj.Name); 189 | if ( test_obj.Name.Substring(0,3) == "red" || 190 | test_obj.Name.Substring(0,4) == "blue" || 191 | test_obj.Name.Substring(0,6) == "cactus" ) 192 | { 193 | thump.PlaySound(); 194 | Dynamics.MinorCollision(); 195 | } 196 | else 197 | { 198 | crash.PlaySound(); 199 | Dynamics.MajorCollision(delta_x_velocity, delta_y_velocity, delta_z_velocity, delta_x_position, delta_y_position, delta_z_position); 200 | } 201 | } 202 | } 203 | } 204 | base.Update( DeltaT ); 205 | // Height = CGameEngine.Ground.HeightOfTerrain(Position) + Offset.Y; 206 | Height = (float)Dynamics.Height; 207 | // GameEngine.Console.AddLine( " height " + Height); 208 | // Attitude = CGameEngine.Ground.GetSlope(Position, Heading ); 209 | } 210 | 211 | public override void Dispose() 212 | { 213 | Debug.WriteLine(" disposing of " + Name + " in Ownship"); 214 | base.Dispose(); 215 | } 216 | 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Beethoven9.wma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Beethoven9.wma -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Console.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Console.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/DevSplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/DevSplash.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Dunes_Back.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Dunes_Back.tga -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Dunes_Bottom.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Dunes_Bottom.tga -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Dunes_Front.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Dunes_Front.tga -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Dunes_Left.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Dunes_Left.tga -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Dunes_Right.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Dunes_Right.tga -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Dunes_Top.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Dunes_Top.tga -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/GameSplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/GameSplash.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Options1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Options1.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Options2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Options2.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayHover.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayHover.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayHover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayHover.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayHover.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayHover.tif -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayOff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayOff.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayOff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayOff.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayOn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayOn.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/PlayOn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/PlayOn.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/QuitHover.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/QuitHover.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/QuitHover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/QuitHover.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/QuitOff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/QuitOff.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/QuitOff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/QuitOff.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Quiton.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Quiton.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Quiton.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Quiton.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/SprintRacer.x: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/SprintRacer.x -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/Thump.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/Thump.wav -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/bluepost.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/bluepost.dds -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/cactus.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/cactus.dds -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/canyon.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/canyon.mid -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/car_idle.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/car_idle.wav -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/carbody.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/carbody.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/crash.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/crash.wav -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/cursor.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/cursor.dds -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/flag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/flag.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/heightmap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/heightmap.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/knowledge.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | race started 4 | 0.0 5 | 6 | 7 | collision ahead 8 | 0.0 9 | 10 | 11 | race over 12 | 0.0 13 | 14 | 15 | Idle 16 | 17 | 18 | Race 19 | 20 | 21 | Evade 22 | 23 | 24 | Idle 25 | 26 | Race 27 | 28 | true 29 | 30 | race started 31 | True 32 | null 33 | 34 | 35 | 36 | 37 | 38 | Race 39 | 40 | Idle 41 | 42 | true 43 | 44 | race over 45 | True 46 | null 47 | 48 | 49 | 50 | 51 | Evade 52 | 53 | true 54 | 55 | collision ahead 56 | True 57 | null 58 | 59 | 60 | race started 61 | True 62 | null 63 | 64 | 65 | race over 66 | False 67 | null 68 | 69 | 70 | 71 | 72 | 73 | Evade 74 | 75 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/palmtree.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/palmtree.dds -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/particle.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/particle.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/redpost.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/redpost.dds -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/sand1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/sand1.jpg -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/small_crash.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/small_crash.wav -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/Resources/tire.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/Resources/tire.bmp -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/SampleGame.csproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 22 | 40 | 58 | 59 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 136 | 137 | 138 | 139 | 144 | 148 | 153 | 158 | 163 | 168 | 173 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/SampleGame.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 37 | 38 | 39 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/SampleGame.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 7.00 2 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleGame", "SampleGame.csproj", "{34B5395F-E85C-45A6-B2BA-AABE3417DEB2}" 3 | EndProject 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameEngine", "..\GameEngine\GameEngine.csproj", "{B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameAI", "..\GameAI\GameAI.csproj", "{730364D6-9306-4DF9-B72F-8C26E616D29E}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarLib", "..\CarLib\CarLib.csproj", "{FB9F633D-97DA-4E1A-A860-554F227081BE}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfiguration) = preSolution 12 | ConfigName.0 = Debug 13 | ConfigName.1 = Release 14 | EndGlobalSection 15 | GlobalSection(ProjectDependencies) = postSolution 16 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.0 = {FB9F633D-97DA-4E1A-A860-554F227081BE} 17 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.1 = {730364D6-9306-4DF9-B72F-8C26E616D29E} 18 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.2 = {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E} 19 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.0 = {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E} 20 | EndGlobalSection 21 | GlobalSection(ProjectConfiguration) = postSolution 22 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Debug.ActiveCfg = Debug|.NET 23 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Debug.Build.0 = Debug|.NET 24 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Release.ActiveCfg = Release|.NET 25 | {34B5395F-E85C-45A6-B2BA-AABE3417DEB2}.Release.Build.0 = Release|.NET 26 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Debug.ActiveCfg = Debug|.NET 27 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Debug.Build.0 = Debug|.NET 28 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Release.ActiveCfg = Release|.NET 29 | {B8B1DDFF-29F9-4088-BA75-05B2D7CE0C8E}.Release.Build.0 = Release|.NET 30 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Debug.ActiveCfg = Debug|.NET 31 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Debug.Build.0 = Debug|.NET 32 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Release.ActiveCfg = Release|.NET 33 | {730364D6-9306-4DF9-B72F-8C26E616D29E}.Release.Build.0 = Release|.NET 34 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Debug.ActiveCfg = Debug|.NET 35 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Debug.Build.0 = Debug|.NET 36 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Release.ActiveCfg = Release|.NET 37 | {FB9F633D-97DA-4E1A-A860-554F227081BE}.Release.Build.0 = Release|.NET 38 | EndGlobalSection 39 | GlobalSection(ExtensibilityGlobals) = postSolution 40 | EndGlobalSection 41 | GlobalSection(ExtensibilityAddIns) = postSolution 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/SampleGame.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/1590590813-1225/SampleGame/SampleGame.suo -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/SelectControls.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Collections; 4 | using System.ComponentModel; 5 | using System.Windows.Forms; 6 | 7 | namespace SampleGame 8 | { 9 | /// 10 | /// Summary description for SelectControls. 11 | /// 12 | public class SelectControls : System.Windows.Forms.Form 13 | { 14 | public System.Windows.Forms.RadioButton UseKeyboard; 15 | public System.Windows.Forms.RadioButton UseJoystick; 16 | public System.Windows.Forms.RadioButton UseMouse; 17 | private new System.Windows.Forms.Button Close; 18 | /// 19 | /// Required designer variable. 20 | /// 21 | private System.ComponentModel.Container components = null; 22 | 23 | public SelectControls() 24 | { 25 | // 26 | // Required for Windows Form Designer support 27 | // 28 | InitializeComponent(); 29 | 30 | // 31 | // TODO: Add any constructor code after InitializeComponent call 32 | // 33 | } 34 | 35 | /// 36 | /// Clean up any resources being used. 37 | /// 38 | protected override void Dispose( bool disposing ) 39 | { 40 | if( disposing ) 41 | { 42 | if(components != null) 43 | { 44 | components.Dispose(); 45 | } 46 | } 47 | base.Dispose( disposing ); 48 | } 49 | 50 | #region Windows Form Designer generated code 51 | /// 52 | /// Required method for Designer support - do not modify 53 | /// the contents of this method with the code editor. 54 | /// 55 | private void InitializeComponent() 56 | { 57 | this.UseKeyboard = new System.Windows.Forms.RadioButton(); 58 | this.UseJoystick = new System.Windows.Forms.RadioButton(); 59 | this.UseMouse = new System.Windows.Forms.RadioButton(); 60 | this.Close = new System.Windows.Forms.Button(); 61 | this.SuspendLayout(); 62 | // 63 | // UseKeyboard 64 | // 65 | this.UseKeyboard.Location = new System.Drawing.Point(37, 38); 66 | this.UseKeyboard.Name = "UseKeyboard"; 67 | this.UseKeyboard.Size = new System.Drawing.Size(95, 23); 68 | this.UseKeyboard.TabIndex = 0; 69 | this.UseKeyboard.Text = "Keyboard"; 70 | // 71 | // UseJoystick 72 | // 73 | this.UseJoystick.Location = new System.Drawing.Point(37, 98); 74 | this.UseJoystick.Name = "UseJoystick"; 75 | this.UseJoystick.Size = new System.Drawing.Size(95, 23); 76 | this.UseJoystick.TabIndex = 1; 77 | this.UseJoystick.Text = "Joystick"; 78 | // 79 | // UseMouse 80 | // 81 | this.UseMouse.Checked = true; 82 | this.UseMouse.Location = new System.Drawing.Point(37, 68); 83 | this.UseMouse.Name = "UseMouse"; 84 | this.UseMouse.Size = new System.Drawing.Size(95, 23); 85 | this.UseMouse.TabIndex = 2; 86 | this.UseMouse.TabStop = true; 87 | this.UseMouse.Text = "Mouse"; 88 | // 89 | // Close 90 | // 91 | this.Close.DialogResult = System.Windows.Forms.DialogResult.OK; 92 | this.Close.Location = new System.Drawing.Point(44, 151); 93 | this.Close.Name = "Close"; 94 | this.Close.Size = new System.Drawing.Size(68, 22); 95 | this.Close.TabIndex = 3; 96 | this.Close.Text = "Close"; 97 | this.Close.Click += new System.EventHandler(this.Close_Click); 98 | // 99 | // SelectControls 100 | // 101 | this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 102 | this.ClientSize = new System.Drawing.Size(211, 204); 103 | this.Controls.AddRange(new System.Windows.Forms.Control[] { 104 | this.Close, 105 | this.UseMouse, 106 | this.UseJoystick, 107 | this.UseKeyboard}); 108 | this.Name = "SelectControls"; 109 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 110 | this.Text = "SelectControls"; 111 | this.ResumeLayout(false); 112 | 113 | } 114 | #endregion 115 | 116 | private void Close_Click(object sender, System.EventArgs e) 117 | { 118 | Dispose(); 119 | } 120 | 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /1590590813-1225/SampleGame/SelectControls.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | text/microsoft-resx 89 | 90 | 91 | 1.3 92 | 93 | 94 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 95 | 96 | 97 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 98 | 99 | 100 | Public 101 | 102 | 103 | Public 104 | 105 | 106 | Public 107 | 108 | 109 | SelectControls 110 | 111 | -------------------------------------------------------------------------------- /719.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/719.html -------------------------------------------------------------------------------- /9781590590812.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/9781590590812.jpg -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/intro-to-3d-game-engine-design-using-directx-9-csharp/500c3efa363d5f382fae712b44e643014cc8fde6/LICENSE.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Introduction to 3D Game Engine Design Using DirectX 9 and C#*](http://www.apress.com/9781590590812) by Marshall Harrison (Apress, 2003). 4 | 5 | ![Cover image](9781590590812.jpg) 6 | 7 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 8 | 9 | ## Releases 10 | 11 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 12 | 13 | ## Contributions 14 | 15 | See the file Contributing.md for more information on how you can contribute to this repository. 16 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! --------------------------------------------------------------------------------