- Code: Select all
using System.Drawing;
using Brume;
namespace BrumeTutorials
{
/// <summary>
/// Camera Move
/// </summary>
class TutorialCameraMove : Brume.Brume
{
// physics
BrumePhysicsCar physicsCar = null;
BrumeCubeTextured chassis;
public TutorialCameraMove() : base()
{
this.Text = "Brume - Camera Move";
//this.InitStates.Mode = BrumeInitParams.MODE_FULLSCREEN;
BrumeFileManager.AddDirForAll("../../../Data");
}
override protected void GameInit()
{
// camera setup
BrumeVector cameraPos = new BrumeVector(3.0f, 0.0f, -3.0f);
BrumeVector cameraDir = new BrumeVector(-0.7f, 0.0f, 0.7f);
BrumeVector cameraUp = new BrumeVector(0.0f, 1.0f, 0.0f);
BrumeFPSCamera camera = new BrumeFPSCamera(this, "camera", cameraPos, cameraDir, cameraUp);
this.SetActiveCamera(camera);
// buffer clear color setup
this.BufferClearColor = Color.Black;
// a simple cube
//BrumeCubeColored theCube = new BrumeCubeColored(this, "The Cube", Color.Blue, Color.Red, Color.Green);
SetupPhysicsFloor();
TestPhysicsCar();
}
private float moveSpeed = 100.0f;
protected override void MoveScene(float fElapsedTime)
{
// retreives active camera
BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;
// if camera present and not in full console mode
if (camera != null && this.DebugConsole.debugLevel != 2)
{
// orient
camera.FPSOrient((float)this.MouseDeltaX / (float)2, (float)this.MouseDeltaY / (float)2);
// move speed
if (MouseDeltaZ > 0.0f)
moveSpeed *= 0.5f;
else
if (MouseDeltaZ < 0.0f)
moveSpeed /= 0.5f;
// move
if (BrumeKeyboard.IsPressed(BrumeKey.W))
camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.S))
camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.D))
camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
if (BrumeKeyboard.IsPressed(BrumeKey.A))
camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
}
if (physicsCar != null)
{
// TODO : compute max Forces in auto
float fMax = 50.0f;
float fMax2 = 10.0f;
// TODO : Speed + inertia
float speed = 50.0f;
physicsCar.Speed = 0.0f;
physicsCar.SpeedForce = fMax2;
if (BrumeKeyboard.IsPressed(BrumeKey.UpArrow))
{
physicsCar.Speed = -speed;
}
if (BrumeKeyboard.IsPressed(BrumeKey.DownArrow))
{
physicsCar.Speed = speed;
}
physicsCar.Left = false;
physicsCar.Right = false;
physicsCar.SteeringForce = fMax;
if (BrumeKeyboard.IsPressed(BrumeKey.LeftArrow))
{
physicsCar.Left = true;
}
if (BrumeKeyboard.IsPressed(BrumeKey.RightArrow))
{
physicsCar.Right = true;
}
if (BrumeKeyboard.IsPressed(BrumeKey.Space))
{
physicsCar.Handbrake = true;
}
else
{
physicsCar.Handbrake = false;
}
physicsCar.Move(fElapsedTime);
}
}
protected override void AfterRendering()
{
base.AfterRendering();
// exit ?
if (BrumeKeyboard.IsPressed(BrumeKey.Escape))
{
this.Close();
return;
}
}
public static void Main()
{
using (TutorialCameraMove game = new TutorialCameraMove())
{
game.Play();
}
}
private void SetupPhysicsFloor()
{
BrumeSplashScreen.SetStatus("Loading Physics Floor...");
// PHYSICS & COLLISION (based on ODE)
this.PhysicsWorld.SetGravity(0, -9.8f, 0);
// floor
BrumeCollisionPlane floor = new BrumeCollisionPlane(this, 0, 1, 0, -0.5f, null);
floor.SufacePhysics.Bouncy = true;
floor.SufacePhysics.BounceValue = 0.1f;
floor.SufacePhysics.MinimumBounceVelocity = 0.1f;
floor.SufacePhysics.Friction = float.MaxValue;
floor.SufacePhysics.Slip = 0.0f;
}
private void TestPhysicsCar()
{
BrumeSplashScreen.SetStatus("Loading Physics Car...");
// car
BrumeVector carPos = new BrumeVector(0.0f, 0.0f, 0.0f);
float carWidth = 0.5f;
float carHeight = 0.3f;
float carLength = 1.0f;
float wheelSize = 0.3f;
chassis = new BrumeCubeTextured(this, "chassis");
// chassis will be multi textured
chassis.RenderStates.Texture[0] = this.GetTexture("multitex2.tga");
chassis.RenderStates.Texture[1] = this.GetTexture("shine3.png");
chassis.RenderStates.TextureStates[1].ColorArg2 = BrumeTextureParams.ARG_CURRENT;
chassis.RenderStates.TextureStates[1].ColorOperation = BrumeTextureParams.OP_BLEND_CURRENT_ALPHA;
chassis.Pos = carPos;
chassis.HasGlobalSize = false;
chassis.XSize = carWidth;
chassis.YSize = carHeight;
chassis.ZSize = carLength;
BrumeSphereTextured lfWheel = new BrumeSphereTextured(this, "lfWheel");
lfWheel.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");
lfWheel.Pos = new BrumeVector(chassis.Pos.X - carWidth / 2.0f, chassis.Pos.Y - carHeight / 2, chassis.Pos.Z + carLength / 2.0f);
lfWheel.Size = wheelSize;
BrumeSphereTextured rfWheel = new BrumeSphereTextured(this, "rfWheel");
rfWheel.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");
rfWheel.Pos = new BrumeVector(chassis.Pos.X + carWidth / 2.0f, chassis.Pos.Y - carHeight / 2, chassis.Pos.Z + carLength / 2.0f);
rfWheel.Size = wheelSize;
BrumeSphereTextured lbWheel = new BrumeSphereTextured(this, "lbWheel");
lbWheel.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");
lbWheel.Pos = new BrumeVector(chassis.Pos.X - carWidth / 2.0f, chassis.Pos.Y - carHeight / 2, chassis.Pos.Z - carLength / 2.0f);
lbWheel.Size = wheelSize;
BrumeSphereTextured rbWheel = new BrumeSphereTextured(this, "rbWheel");
rbWheel.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");
rbWheel.Pos = new BrumeVector(chassis.Pos.X + carWidth / 2.0f, chassis.Pos.Y - carHeight / 2, chassis.Pos.Z - carLength / 2.0f);
rbWheel.Size = wheelSize;
physicsCar = new BrumePhysicsCar(this, chassis, lfWheel, rfWheel, lbWheel, rbWheel);
physicsCar.SteeringSmoothFactor = 0.9f;
physicsCar.SteeringAngle = 0.5f;
physicsCar.BackSuspensionCFM = 0.1f;
physicsCar.BackSuspensionERP = 0.5f;
physicsCar.FrontSuspensionCFM = 0.1f;
physicsCar.FrontSuspensionERP = 0.5f;
physicsCar.AngularVelocityReduction = 0.00001f; //0.8f
physicsCar.AddGear(0, float.NegativeInfinity, 2.0f);
physicsCar.AddGear(1, 2.0f, 5.0f);
physicsCar.AddGear(2, 5.0f, 10.0f);
physicsCar.AddGear(3, 10.0f, 17.0f);
physicsCar.AddGear(4, 17.0f, float.PositiveInfinity);
physicsCar.CurrentGear = 0;
}
}
}
but i have a problem, when i execute the program it run for a minute and then i got this error window http://img300.imageshack.us/my.php?image=errorxi7.jpg. Sry for my english im from Argentina. Greetings