#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion
namespace Car_Drift_OSF
{
///
/// This is a game component that implements IUpdateable.
///
public partial class AudiComponent : Microsoft.Xna.Framework.DrawableGameComponent
{
public Model model;
public Vector3 modelPosition;
public Vector3 modelVelocity;
public float modelRotationY;
public ICamera camera;
public AudiComponent(Demo game)
: base(game)
{
// TODO: Construct any child components here
}
///
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
///
public override void Initialize()
{
model = Demo.content.Load("Content\\Models\\audi");
base.Initialize();
}
///
/// Allows the game component to update itself.
///
/// Provides a snapshot of timing values.
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
UpdateInput();
modelPosition += modelVelocity;
modelVelocity *= 0.95f;
base.Update(gameTime);
}
private void UpdateInput()
{
GamePadState currentGamePadState = GamePad.GetState(PlayerIndex.One);
KeyboardState keyb = Keyboard.GetState();
if (currentGamePadState.IsConnected)
{
if (Math.Abs(modelVelocity.X) > 40 || Math.Abs(modelVelocity.Z) > 40)
modelRotationY -= currentGamePadState.ThumbSticks.Left.X * 0.02f;
Vector3 modelVelocityAdd = Vector3.Zero;
modelVelocityAdd.X = -(float)Math.Sin(modelRotationY);
modelVelocityAdd.Z = -(float)Math.Cos(modelRotationY);
modelVelocityAdd *= (currentGamePadState.Triggers.Right * 10);
modelVelocity += modelVelocityAdd;
//GamePad.SetVibration(PlayerIndex.One, currentGamePadState.Triggers.Right,
// currentGamePadState.Triggers.Right);
//Reset
if (currentGamePadState.Buttons.Start == ButtonState.Pressed)
modelPosition = new Vector3(0, 800, 10000);
// Allows the default game to exit on Xbox 360 and Windows
if (currentGamePadState.Buttons.Back == ButtonState.Pressed)
Game.Exit();
}
else
{
if (Math.Abs(modelVelocity.X) > 120 || Math.Abs(modelVelocity.Z) > 110)
{
if (keyb.IsKeyDown(Keys.Left))
modelRotationY += 0.1f;
else
{
Vector3 modelVelocityAdd = Vector3.Zero;
modelVelocityAdd.X = -(float)Math.Sin(modelRotationY);
modelVelocityAdd.Z = -(float)Math.Cos(modelRotationY);
modelVelocityAdd *= 50f;
modelVelocity += modelVelocityAdd;
}
if (keyb.IsKeyDown(Keys.Right))
modelRotationY -= 0.1f;
else
{
Vector3 modelVelocityAdd = Vector3.Zero;
modelVelocityAdd.X = +(float)Math.Sin(modelRotationY);
modelVelocityAdd.Z = +(float)Math.Cos(modelRotationY);
modelVelocityAdd *= 20f;
modelVelocity -= modelVelocityAdd;
}
}
if (keyb.IsKeyDown(Keys.Up))
{
Vector3 modelVelocityAdd = Vector3.Zero;
modelVelocityAdd.X = -(float)Math.Sin(modelRotationY);
modelVelocityAdd.Z = -(float)Math.Cos(modelRotationY);
modelVelocityAdd *= 20f;
modelVelocity += modelVelocityAdd;
}
if(keyb.IsKeyDown(Keys.R))
modelPosition = new Vector3(0, 800, 10000);
if (keyb.IsKeyDown(Keys.Escape))
Game.Exit();
}
}
public override void Draw(GameTime gameTime)
{
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index]
* Matrix.CreateRotationY(modelRotationY + MathHelper.Pi)
* Matrix.CreateTranslation(modelPosition);
effect.View = camera.View;
effect.Projection = camera.Projection;
}
mesh.Draw();
}
}
}
}
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
namespace Car_Drift_OSF
{
///
/// This is the main type for your game
///
public class Demo : Microsoft.Xna.Framework.Game
{
public static GraphicsDeviceManager graphics;
public static ContentManager content;
private ReplayCamera camera;
FloorComponent floor;
AudiComponent audi;
public Demo()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
///
protected override void Initialize()
{
camera = new ReplayCamera(this);
camera.CameraPosition = new Vector3(0, 5000, 0);
floor = new FloorComponent(this);
floor.camera = camera;
audi = new AudiComponent(this);
audi.modelPosition = new Vector3(0, 800, 10000);
audi.camera = camera;
this.Components.Add(camera);
this.Components.Add(floor);
this.Components.Add(audi);
this.Window.Title = "Car Physic Dynamic Animation With Programming OSF ";
base.Initialize();
}
///
/// Load your graphics content. If loadAllContent is true, you should
/// load content from both ResourceManagementMode pools. Otherwise, just
/// load ResourceManagementMode.Manual content.
///
/// Which type of content to load.
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
}
// TODO: Load any ResourceManagementMode.Manual content
}
///
/// Unload your graphics content. If unloadAllContent is true, you should
/// unload content from both ResourceManagementMode pools. Otherwise, just
/// unload ResourceManagementMode.Manual content. Manual content will get
/// Disposed by the GraphicsDevice during a Reset.
///
/// Which type of content to unload.
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent == true)
{
content.Unload();
}
}
///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input and playing audio.
///
/// Provides a snapshot of timing values.
protected override void Update(GameTime gameTime)
{
camera.CameraLookat = audi.modelPosition;
base.Update(gameTime);
}
///
/// This is called when the game should draw itself.
///
/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion
namespace Car_Drift_OSF
{
///
/// This is a game component that implements IUpdateable.
///
public partial class FloorComponent : Microsoft.Xna.Framework.DrawableGameComponent
{
public Model model;
public ICamera camera;
public FloorComponent(Demo game)
: base(game)
{
// TODO: Construct any child components here
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
model = Demo.content.Load("Content\\Models\\floor");
}
///
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
///
public override void Initialize()
{
// TODO: Add your initialization code here
base.Initialize();
}
///
/// Allows the game component to update itself.
///
/// Provides a snapshot of timing values.
public override void Update(GameTime gameTime)
{
// TODO: Add your update code here
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index];
effect.View = camera.View;
effect.Projection = camera.Projection;
}
mesh.Draw();
}
}
}
}
وفي 03 مارس 2009 06:17 ص، قال عمر متحمساً:
هذا هو المشروع ولكن ليس كاملاً