Problems with Physic Car

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

Problems with Physic Car

Postby estu91 on Sun Nov 16, 2008 2:33 am

Hi, i found Brume searching in google, i have to say that its very good and simple. I was looking the brume src when i saw the physic car feature, i tried to use it in the tutorial Camera Move so i did this
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
estu91
Brume Rookie
 
Posts: 4
Joined: Sun Nov 16, 2008 2:26 am

Re: Problems with Physic Car

Postby Silmaryls on Tue Nov 25, 2008 10:08 pm

Hi,

This is a known issue with my ODE Wrapper (which I found on the web a long time ago) : viewtopic.php?f=3&t=140
It happens on multi-core CPUs.
I refactored the physics code to use the official ODE.NET wrapper for next release as there is no workaround for this.

Silmaryls
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Re: Problems with Physic Car

Postby estu91 on Sat Dec 13, 2008 12:52 am

Thanks for your answer Silmaryls, so the problem it's in ODE. When is the next release going to be release?. Greetings (sry for my english)
estu91
Brume Rookie
 
Posts: 4
Joined: Sun Nov 16, 2008 2:26 am

Re: Problems with Physic Car

Postby Silmaryls on Wed Jan 07, 2009 8:50 pm

Well for the moment I am still finalizing DX10 features (my todo list tells me 82% achieved :wink: ).
I hope to release in the first quarter of 2009. But nothing sure yet.
I try to keep a clean working copy under SVN so you can already test some new features.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron