Esempio n. 1
0
 // this is gonna be awesome
 public static List<InstancedMesh3d> FromMesh3dList(List<Mesh3d> meshes)
 {
     List<InstancedMesh3d> result = new List<InstancedMesh3d>();
     meshes.Sort((a, b) => a.MainObjectInfo.GetHash() - b.MainObjectInfo.GetHash());
     var first = meshes[0];
     InstancedMesh3d current = new InstancedMesh3d(first.MainObjectInfo, first.MainMaterial);
     int lastHash = first.MainObjectInfo.GetHash();
     foreach(var m in meshes)
     {
         if(lastHash == m.MainObjectInfo.GetHash())
         {
             current.Transformations.Add(m.Transformation);
             current.Instances++;
         }
         else
         {
             current.UpdateMatrix();
             result.Add(current);
             current = new InstancedMesh3d(m.MainObjectInfo, m.MainMaterial);
             current.Transformations.Add(m.Transformation);
             current.Instances++;
         }
     }
     result.Add(current);
     return result;
 }
Esempio n. 2
0
 // this is gonna be awesome
 public static InstancedMesh3d FromSimilarMesh3dList(List<Mesh3d> meshes)
 {
     var first = meshes[0];
     InstancedMesh3d result = new InstancedMesh3d(first.MainObjectInfo, first.MainMaterial);
     foreach(var m in meshes)
     {
         result.Transformations.Add(m.Transformation);
         result.Instances++;
     }
     result.UpdateMatrix();
     return result;
 }
Esempio n. 3
0
        public FortressScene()
        {
            Object3dInfo skydomeInfo = Object3dInfo.LoadFromObjSingle(Media.Get("usky.obj"));
            var skydomeMaterial = GenericMaterial.FromMedia("skyreal.png");
            var skydome = new Mesh3d(skydomeInfo, skydomeMaterial);
            skydome.Scale(55000);
            skydome.Translate(0, -100, 0);
            //skydome.IgnoreLighting = true;
            //skydome.DiffuseComponent = 0.2f;
            Add(skydome);
               /* var sun = new Sun(new Vector3(0.1f, -1, 0).ToQuaternion(Vector3.UnitY), new Vector4(1, 0.97f, 0.92f, 120), 300, 100, 70, 40, 10, 1);
            GLThread.OnUpdate += (o, e) =>
            {
                var kb = OpenTK.Input.Keyboard.GetState();
                if(kb.IsKeyDown(OpenTK.Input.Key.U))
                {
                    var quat = Quaternion.FromAxisAngle(sun.Orientation.GetTangent(MathExtensions.TangentDirection.Left), -0.01f);
                    sun.Orientation = Quaternion.Multiply(sun.Orientation, quat);
                }
                if(kb.IsKeyDown(OpenTK.Input.Key.J))
                {
                    var quat = Quaternion.FromAxisAngle(sun.Orientation.GetTangent(MathExtensions.TangentDirection.Left), 0.01f);
                    sun.Orientation = Quaternion.Multiply(sun.Orientation, quat);
                }
                if(kb.IsKeyDown(OpenTK.Input.Key.H))
                {
                    var quat = Quaternion.FromAxisAngle(Vector3.UnitY, -0.01f);
                    sun.Orientation = Quaternion.Multiply(sun.Orientation, quat);
                }
                if(kb.IsKeyDown(OpenTK.Input.Key.K))
                {
                    var quat = Quaternion.FromAxisAngle(Vector3.UnitY, 0.01f);
                    sun.Orientation = Quaternion.Multiply(sun.Orientation, quat);
                }
            };*/

            List<Mesh3d> nodes1 = new List<Mesh3d>();
            List<Mesh3d> leaves1 = new List<Mesh3d>();
            Random rand = new Random();
            for(int x = 0; x < 3; x++)
            {
                for(int z = 0; z < 3; z++)
                {
                    var tree = TreeGenerator.CreateTree(MathHelper.DegreesToRadians(30), MathHelper.DegreesToRadians(45), 4, 4, 6666, 0.3f, true);
                    var scale = (float)rand.NextDouble() * 2 + 1;
                    var tx = (float)rand.NextDouble() * 2 + 4;
                    var ty = (float)rand.NextDouble() * 2 + 4;
                    var mergedNodes = tree[0].Merge();
                    mergedNodes.Translate(x * 5 + tx, 0, z * 5 + ty);
                    mergedNodes.Scale(scale);
                    nodes1.Add(mergedNodes);

                    var mergedLeaves = tree[1].Merge();
                    mergedLeaves.Translate(x * 5 + tx, 0, z * 5 + ty);
                    mergedLeaves.Scale(scale);
                    leaves1.Add(mergedLeaves);

                    //tree[0].ObjectInfo.FreeCPUMemory();
                    //tree[1].ObjectInfo.FreeCPUMemory();
                }
            }
            Mesh3d singleNodes = Mesh3d.Merge(nodes1);
            Mesh3d singleLeaves = Mesh3d.Merge(leaves1);
            foreach(var o in nodes1)
                o.MainObjectInfo.FreeCPUMemory();
            foreach(var o in leaves1)
                o.MainObjectInfo.FreeCPUMemory();

            InstancedMesh3d nodes = new InstancedMesh3d(singleNodes.MainObjectInfo, singleNodes.MainMaterial);
            InstancedMesh3d leaves = new InstancedMesh3d(singleLeaves.MainObjectInfo, singleLeaves.MainMaterial);
            for(int x = 0; x < 1; x++)
            {
                for(int z = 0; z < 1; z++)
                {
                    nodes.Transformations.Add(new TransformationManager(new Vector3(x * 50, 0, z * 50)));
                    leaves.Transformations.Add(new TransformationManager(new Vector3(x * 50, 0, z * 50)));
                }
            }
            nodes.UpdateMatrix();
            leaves.UpdateMatrix();
            Add(nodes);
            Add(leaves);

            /*GLThread.CreateTimer(() =>
            {
                GLThread.Invoke(() => read());

            }, 2000).Start();*/
            Object3dInfo waterInfo = Object3dGenerator.CreateTerrain(new Vector2(-200, -200), new Vector2(200, 200), new Vector2(100, 100), Vector3.UnitY, 333, (x, y) => 0);

            var color = GenericMaterial.FromMedia("checked.png");
            //color.SetBumpMapFromMedia("lightref.png");
            Mesh3d water = new Mesh3d(waterInfo, color);
            water.SetMass(0);
            water.Translate(0, 0, 0);
            water.SetCollisionShape(new BulletSharp.StaticPlaneShape(Vector3.UnitY, 0));
            Add(water);
        }
Esempio n. 4
0
        public ComputeBallsScene()
        {
            int instancesAxis = 10;
            int instances = instancesAxis * instancesAxis * instancesAxis;
            var ballInfo = Object3dInfo.LoadFromObjSingle(Media.Get("star3d.obj"));
               // var cb = Object3dGenerator.CreateCube(new Vector3(1000, 1000, 1000), new Vector2(1, 1));
               // cb.FlipFaces();
               // var sky = new Mesh3d(cb, new GenericMaterial(Color.Black));
               // Add(sky);
            ballInfo.Normalize();
            var instanced = new InstancedMesh3d(ballInfo, new GenericMaterial(new Vector4(0, 1, 0, 1)));
            var instanced2 = new InstancedMesh3d(ballInfo, new GenericMaterial(Color.Green));
            //var model = Object3dInfo.LoadFromObjSingle(Media.Get("monkey.obj"));
            //var vrts = model.GetOrderedVertices();
            //vrts = vrts.Distinct().ToList();
            var bts3 = new List<Vector4>();
            for(int x = 0; x < 20; x++)
                for(int y = 60; y > 0; y--)
            {
                bts3.Add(new Vector4(x, y, 0, 1));
            }
            instanced2.UpdateMatrix();
            Add(instanced2);

            instanced.Instances = instances;
            var SBuffer = new ShaderStorageBuffer();
            var VBuffer = new ShaderStorageBuffer();
            var PBuffer = new ShaderStorageBuffer();
            GLThread.Invoke(() =>
            {
                var cshader = new ComputeShader("AIPathFollower.compute.glsl");
                var bts = new List<Vector4>();
                var bts2 = new List<Vector4>();
                var rand = new Random();
                PBuffer.MapData(bts3.ToArray());
                for(int x = 0; x < 12; x++)
                {
                    for(int y = 0; y < 90; y++)
                    {
                        for(int z = 0; z < 12; z++)
                        {
                            instanced.Transformations.Add(new TransformationManager(new Vector3(x * 5, y + 300, z * 5), Quaternion.Identity, 1.5f));
                            bts.Add(new Vector4(x * 5, y + 300, z * 5, 1));
                            bts2.Add(new Vector4(0, 0, 0, 1));
                        }
                    }
                }

                SBuffer.MapData(bts.ToArray());
                VBuffer.MapData(bts2.ToArray());
                instanced.UpdateMatrix();
                GLThread.OnBeforeDraw += (o, e) =>
                {
                    cshader.Use();
                    instanced.ModelMatricesBuffer.Use(0);
                    SBuffer.Use(1);
                    VBuffer.Use(2);
                    PBuffer.Use(3);
                    cshader.SetUniform("BallsCount", instances);
                    cshader.SetUniform("PathPointsCount", bts3.Count);
                    cshader.SetUniform("Time", (float)(DateTime.Now - GLThread.StartTime).TotalMilliseconds / 1000);
                    cshader.Dispatch(12, 90, 12);
                };
            });
            Add(instanced);
        }
Esempio n. 5
0
        public ManyCubesScene()
        {
            Object3dInfo wall = Object3dGenerator.CreateCube(new Vector3(10.0f, 10.0f, 1.0f), new Vector2(1, 1));
            InstancedMesh3d wallsInst = new InstancedMesh3d(wall, new GenericMaterial(Color.Red));
            wallsInst.Transformations.Add(new TransformationManager(new Vector3(0, 5, 10), Quaternion.Identity, 1));
            wallsInst.Transformations.Add(new TransformationManager(new Vector3(0, 5, -10), Quaternion.Identity, 1));
            wallsInst.Transformations.Add(new TransformationManager(new Vector3(10, 5, 0), Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.PiOver2), 1));
            wallsInst.Transformations.Add(new TransformationManager(new Vector3(-10, 5, 0), Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.PiOver2), 1));
            wallsInst.Instances = 4;
            wallsInst.UpdateMatrix();
            World.Root.CreateRigidBody(0, wallsInst.Transformations[0].GetWorldTransform(), new BulletSharp.BoxShape(wall.GetAxisAlignedBox()/2), null);
            World.Root.CreateRigidBody(0, wallsInst.Transformations[1].GetWorldTransform(), new BulletSharp.BoxShape(wall.GetAxisAlignedBox() / 2), null);
            World.Root.CreateRigidBody(0, wallsInst.Transformations[2].GetWorldTransform(), new BulletSharp.BoxShape(wall.GetAxisAlignedBox() / 2), null);
            World.Root.CreateRigidBody(0, wallsInst.Transformations[3].GetWorldTransform(), new BulletSharp.BoxShape(wall.GetAxisAlignedBox() / 2), null);
            Add(wallsInst);

            World.Root.CreateRigidBody(0, Matrix4.Identity, new BulletSharp.StaticPlaneShape(Vector3.UnitY, 0), null);
            /*
            var roadtile = Object3dGenerator.CreateGround(new Vector2(-0.47f, -0.5f) * 20, new Vector2(0.47f, 0.5f) * 20, new Vector2(1, 1), Vector3.UnitY);
            var roadsInstances = new InstancedMesh3d(roadtile, GenericMaterial.FromMedia("roadtex.png", "roadnormaltex.png"));
            var advancer = new Vector3(0, 0, (roadtile.GetAxisAlignedBox() * 2).Z);
            roadsInstances.Transformations.Add(new TransformationManager(new Vector3(0, 0.1f, 0)));
            for(int i = 0; i < 120; i++)
            {
                roadsInstances.Transformations.Add(new TransformationManager(new Vector3(0, 0.1f, 0) + advancer * i));
            }
            roadsInstances.UpdateMatrix();
            Add(roadsInstances);*/

            //Object3dInfo cube = Object3dGenerator.CreateCube(new Vector3(1, 1, 1), new Vector2(1, 1));
            var cube = Object3dInfo.LoadFromObjSingle(Media.Get("portalcube.obj"));
            cube.MakeDoubleFaced();
            GenericMaterial material = new GenericMaterial(new Vector4(1, 1, 1, 1.000f));
            int allCount = 0;
            var meshes = new List<Mesh3d>();
            Mesh3d lastmesh = null;
            var rand = new Random();
            var sphere3dInfo = Object3dInfo.LoadFromObjSingle(Media.Get("lightsphere.obj"));
            sphere3dInfo.Normalize();
            for(int y = 0; y < 100; y++)
            {
                Mesh3d mesh = new Mesh3d(cube, material);
                mesh.DisableDepthWrite = true;
                mesh.Transformation.SetPosition(new Vector3(0, (y + 10.0f) * 12.0f, 0));
                Vector3 scaleRand = new Vector3((float)rand.NextDouble() * 6.0f + 5.0f, (float)rand.NextDouble() * 6.0f + 5.0f, (float)rand.NextDouble() * 6.0f + 5.0f);
                mesh.SetMass(11.0f);
                mesh.Transformation.Scale(1);
                mesh.SetCollisionShape(new BulletSharp.BoxShape(cube.GetAxisAlignedBox() / 2));
                meshes.Add(mesh);
                World.Root.PhysicalWorld.AddCollisionObject(mesh.CreateRigidBody());
                if(lastmesh != null)
                {
                    //var offset = (mesh.Transformation.GetPosition() - lastmesh.Transformation.GetPosition()) / 2;
                    //var cst = new BulletSharp.FixedConstraint(mesh.PhysicalBody, lastmesh.PhysicalBody, (-offset).ToMatrix(), offset.ToMatrix());
                    //World.Root.PhysicalWorld.AddConstraint(cst, true);
                }

                lastmesh = mesh;
            }

            var inst = InstancedMesh3d.FromSimilarMesh3dList(meshes);
            GLThread.OnUpdate += (o, e) =>
            {
                inst.UpdateMatrix();
                //wallsInst.UpdateMatrix();
            };
            Add(inst);
            Console.WriteLine("allCount " + allCount);
        }
Esempio n. 6
0
        public CarScene()
        {
            Object3dInfo waterInfo = Object3dGenerator.CreateGround(new Vector2(-200, -200), new Vector2(200, 200), new Vector2(100, 100), Vector3.UnitY);

            var color = GenericMaterial.FromMedia("checked.png", "183_norm.JPG");
            Mesh3d water = new Mesh3d(waterInfo, color);
            water.SetMass(0);
            water.Translate(0, -10, 0);
            water.SetCollisionShape(new BulletSharp.StaticPlaneShape(Vector3.UnitY, 0));
            World.Root.Add(water);

            var lod1 = Object3dInfo.LoadFromRaw(Media.Get("lucy_lod1.vbo.raw"), Media.Get("lucy_lod1.indices.raw"));
            var mat = new GenericMaterial(new Vector4(0, 0, 1, 1f));
            var dragon = new Mesh3d(lod1, mat);
            dragon.Transformation.Scale(2);
            Add(dragon);

            var rand = new Random();
            var grasslod0 = Object3dInfo.LoadFromObjSingle(Media.Get("grasslod1.obj"));
            var grasslod1 = Object3dInfo.LoadFromObjSingle(Media.Get("grasslod1.obj"));
            var grasslod2 = Object3dInfo.LoadFromObjSingle(Media.Get("grasslod2.obj"));
            var grasslod3 = Object3dInfo.LoadFromObjSingle(Media.Get("grasslod3.obj"));
            var grasscolor = new GenericMaterial(Color.DarkGreen);
            var grassInstanced = new InstancedMesh3d(grasslod2, grasscolor);
            for(int x = -15; x < 15; x++)
            {
                for(int y = -15; y < 15; y++)
                {
                    grassInstanced.Transformations.Add(new TransformationManager(new Vector3(x, 0, y), Quaternion.FromAxisAngle(Vector3.UnitY, (float)rand.NextDouble() * MathHelper.Pi), new Vector3(1, 1, 1)));
                    grassInstanced.Instances++;
                }
            }
            grassInstanced.UpdateMatrix();
            Add(grassInstanced);

            ProjectionLight redConeLight = new ProjectionLight(new Vector3(1, 25, 1), Quaternion.Identity, 5000, 5000, MathHelper.PiOver2, 1.0f, 10000.0f);
            redConeLight.LightColor = new Vector4(1, 1, 1, 1);
            redConeLight.BuildOrthographicProjection(500, 500, -100, 100);
            redConeLight.camera.LookAt(Vector3.Zero);

            LightPool.Add(redConeLight);

            var wheel3dInfo = Object3dInfo.LoadFromObjSingle(Media.Get("fcarwheel.obj"));
            var car3dInfo = Object3dInfo.LoadFromObjSingle(Media.Get("fcarbody.obj"));

            var car = new Mesh3d(car3dInfo, new GenericMaterial(Color.LightGreen));
            car.SetMass(200);
            //car.Translate(0, 3.76f, 0);
            car.SetCollisionShape(new BoxShape(0.5f, 0.5f, 0.5f));
            car.CreateRigidBody(new Vector3(0, -25, 0), true);
            car.PhysicalBody.SetSleepingThresholds(0, 0);
            car.PhysicalBody.ContactProcessingThreshold = 0;
            car.PhysicalBody.CcdMotionThreshold = 0;
            CurrentCar = car;
            World.Root.Add(car);

            GLThread.OnUpdate += (o, e) =>
            {
                redConeLight.SetPosition(car.GetPosition() + new Vector3(0, 15, 0));
            };

            var shape = new SphereShape(0.5f);
            //var shape = wheel3dInfo.GetAccurateCollisionShape();
            var wheelLF = new Mesh3d(wheel3dInfo, new GenericMaterial(Color.White));
            wheelLF.SetMass(100);
            wheelLF.Translate(1.640539f, 0.48866f, -1.94906f);
            wheelLF.SetCollisionShape(shape);
            wheelLF.CreateRigidBody();
            World.Root.Add(wheelLF);
            var wheelRF = new Mesh3d(wheel3dInfo, new GenericMaterial(Color.White));
            wheelRF.SetMass(100);
            wheelRF.Translate(1.640539f, 0.48866f, 1.94906f);
            wheelRF.SetCollisionShape(shape);
            wheelRF.CreateRigidBody();
            World.Root.Add(wheelRF);
            var wheelLR = new Mesh3d(wheel3dInfo, new GenericMaterial(Color.White));
            wheelLR.SetMass(100);
            wheelLR.Translate(-1.640539f, 0.48866f, -1.94906f);
            wheelLR.SetCollisionShape(shape);
            wheelLR.CreateRigidBody();
            World.Root.Add(wheelLR);
            var wheelRR = new Mesh3d(wheel3dInfo, new GenericMaterial(Color.White));
            wheelRR.SetMass(100);
            wheelRR.Translate(-1.640539f, 0.48866f, 1.94906f);
            wheelRR.SetCollisionShape(shape);
            wheelRR.CreateRigidBody();
            World.Root.Add(wheelRR);

            wheelLF.PhysicalBody.SetSleepingThresholds(0, 0);
            wheelLF.PhysicalBody.ContactProcessingThreshold = 0;
            wheelLF.PhysicalBody.CcdMotionThreshold = 0;

            wheelRF.PhysicalBody.SetSleepingThresholds(0, 0);
            wheelRF.PhysicalBody.ContactProcessingThreshold = 0;
            wheelRF.PhysicalBody.CcdMotionThreshold = 0;

            wheelLR.PhysicalBody.SetSleepingThresholds(0, 0);
            wheelLR.PhysicalBody.ContactProcessingThreshold = 0;
            wheelLR.PhysicalBody.CcdMotionThreshold = 0;

            wheelLR.PhysicalBody.SetSleepingThresholds(0, 0);
            wheelLR.PhysicalBody.ContactProcessingThreshold = 0;
            wheelLR.PhysicalBody.CcdMotionThreshold = 0;

            wheelRR.PhysicalBody.SetSleepingThresholds(0, 0);
            wheelRR.PhysicalBody.ContactProcessingThreshold = 0;
            wheelRR.PhysicalBody.CcdMotionThreshold = 0;

            wheelLF.PhysicalBody.Friction = 1200;
            wheelRF.PhysicalBody.Friction = 1200;
            wheelLR.PhysicalBody.Friction = 1200;
            wheelRR.PhysicalBody.Friction = 1200;

            car.PhysicalBody.SetIgnoreCollisionCheck(wheelLF.PhysicalBody, true);
            car.PhysicalBody.SetIgnoreCollisionCheck(wheelRF.PhysicalBody, true);
            car.PhysicalBody.SetIgnoreCollisionCheck(wheelLR.PhysicalBody, true);
            car.PhysicalBody.SetIgnoreCollisionCheck(wheelRR.PhysicalBody, true);

            // location left rear x -5.27709 y 1.56474 z -3.13906
            // location right rear x -5.27709 y 1.56474 z 3.13906
            // location left front x 5.500539 y 1.56474 z -3.13906
            // location right front x 5.500539 y 1.56474 z 3.13906
            //public HingeConstraint(RigidBody rigidBodyA, RigidBody rigidBodyB, Vector3 pivotInA, Vector3 pivotInB, Vector3 axisInA, Vector3 axisInB);

            var frontAxis = new HingeConstraint(wheelLF.PhysicalBody, wheelRF.PhysicalBody,
                new Vector3(1.640539f, 0.48866f, 1.94906f), new Vector3(1.640539f, 0.48866f, -1.94906f), Vector3.UnitZ, Vector3.UnitZ);

            var rearAxis = new HingeConstraint(wheelLR.PhysicalBody, wheelRR.PhysicalBody,
                new Vector3(-1.640539f, 0.48866f, 1.94906f), new Vector3(-1.640539f, 0.48866f, -1.94906f), Vector3.UnitZ, Vector3.UnitZ);

            var centerAxis1 = new HingeConstraint(car.PhysicalBody, wheelLF.PhysicalBody,
                new Vector3(1.640539f, -0.48866f, -1.94906f), new Vector3(0), Vector3.UnitZ, Vector3.UnitZ);
            var centerAxis2 = new HingeConstraint(car.PhysicalBody, wheelRF.PhysicalBody,
                new Vector3(1.640539f, -0.48866f, 1.94906f), new Vector3(0), Vector3.UnitZ, Vector3.UnitZ);

            var centerAxis3 = new HingeConstraint(car.PhysicalBody, wheelLR.PhysicalBody,
                new Vector3(-1.640539f, -0.48866f, 1.94906f), new Vector3(0), Vector3.UnitZ, Vector3.UnitZ);
            var centerAxis4 = new HingeConstraint(car.PhysicalBody, wheelRR.PhysicalBody,
                new Vector3(-1.640539f, -0.48866f, -1.94906f), new Vector3(0), Vector3.UnitZ, Vector3.UnitZ);

            centerAxis1.SetLimit(0, 10, 0, 0, 0);
            centerAxis2.SetLimit(0, 10, 0, 0, 0);
            centerAxis3.SetLimit(0, 10, 0, 0, 0);
            centerAxis4.SetLimit(0, 10, 0, 0, 0);

            //World.Root.PhysicalWorld.AddConstraint(frontAxis);
            // World.Root.PhysicalWorld.AddConstraint(rearAxis);
              //  centerAxis1.SetLimit(0, 0.01f);
               // centerAxis2.SetLimit(0, 0.01f);
            //centerAxis3.SetLimit(0, 0.01f);
            //centerAxis4.SetLimit(0, 0.01f);
            World.Root.PhysicalWorld.AddConstraint(centerAxis1);
            World.Root.PhysicalWorld.AddConstraint(centerAxis2);
            World.Root.PhysicalWorld.AddConstraint(centerAxis3);
            World.Root.PhysicalWorld.AddConstraint(centerAxis4);

            GLThread.OnKeyDown += (object sender, OpenTK.Input.KeyboardKeyEventArgs e) =>
            {
                if(e.Key == OpenTK.Input.Key.R)
                {
                    car.SetOrientation(Quaternion.Identity);
                }
                if(e.Key == OpenTK.Input.Key.Space)
                {
                    centerAxis1.EnableMotor = false;
                    centerAxis2.EnableMotor = false;
                }
                if(e.Key == OpenTK.Input.Key.Up)
                {
                    centerAxis1.EnableMotor = true;
                    centerAxis1.EnableAngularMotor(true, -100.0f, 10.0f);
                    centerAxis2.EnableMotor = true;
                    centerAxis2.EnableAngularMotor(true, -100.0f, 10.0f);
                }
                if(e.Key == OpenTK.Input.Key.Down)
                {

                    centerAxis1.EnableMotor = true;
                    centerAxis1.EnableAngularMotor(true, 100.0f, 6.0f);
                    centerAxis2.EnableMotor = true;
                    centerAxis2.EnableAngularMotor(true, 100.0f, 6.0f);
                }
                if(e.Key == OpenTK.Input.Key.Left)
                {
                    float angle = 0.6f / (car.PhysicalBody.LinearVelocity.Length + 1.0f);
                    centerAxis3.SetFrames(Matrix4.CreateRotationY(angle) * Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, 1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    centerAxis4.SetFrames(Matrix4.CreateRotationY(angle) * Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, -1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    //centerAxis3.SetAxis(new Vector3(1, 0, 1));
                    //centerAxis4.SetAxis(new Vector3(1, 0, 1));
                }
                if(e.Key == OpenTK.Input.Key.Right)
                {
                    float angle = 0.6f / (car.PhysicalBody.LinearVelocity.Length + 1.0f);
                    centerAxis3.SetFrames(Matrix4.CreateRotationY(-angle) * Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, 1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    centerAxis4.SetFrames(Matrix4.CreateRotationY(-angle) * Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, -1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    //centerAxis3.SetAxis(new Vector3(-1, 0, 1));
                    //centerAxis4.SetAxis(new Vector3(-1, 0, 1));
                }
            };
            GLThread.OnKeyUp += (object sender, OpenTK.Input.KeyboardKeyEventArgs e) =>
            {
                if(e.Key == OpenTK.Input.Key.Up)
                {

                    centerAxis1.EnableMotor = false;
                    centerAxis2.EnableMotor = false;
                }
                if(e.Key == OpenTK.Input.Key.Down)
                {

                    centerAxis1.EnableMotor = false;
                    centerAxis2.EnableMotor = false;
                }
                if(e.Key == OpenTK.Input.Key.Left)
                {
                    centerAxis3.SetFrames(Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, 1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    centerAxis4.SetFrames(Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, -1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    //centerAxis3.SetAxis(new Vector3(0, 0, 1));
                    //centerAxis4.SetAxis(new Vector3(0, 0, 1));
                }
                if(e.Key == OpenTK.Input.Key.Right)
                {
                    centerAxis3.SetFrames( Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, 1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    centerAxis4.SetFrames(Matrix4.CreateTranslation(new Vector3(-1.640539f, -0.48866f, -1.94906f)), Matrix4.CreateTranslation(new Vector3(0)));
                    //centerAxis3.SetAxis(new Vector3(0, 0, 1));
                    //centerAxis4.SetAxis(new Vector3(0, 0, 1));
                }
            };
        }