示例#1
0
        public override void Update(Window window, Camera camera, Input input, float dt)
        {
            if (input.WasPushed(OpenTK.Input.Key.Z))
            {
                //INVEST TODAY FOR INCREDIBLE RETURNS DON'T MISS OUT LOOK AT THE COINS THERE ARE A LOT OF THEM AND THEY COULD BE YOURS
                var origin = new Vector3(-30, 5, -30) + new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()) * new Vector3(60, 30, 60);
                for (int i = 0; i < 128; ++i)
                {
                    var direction = new Vector3(-1) + 2 * new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
                    var length    = direction.Length();
                    if (length > 1e-7f)
                    {
                        direction /= length;
                    }
                    else
                    {
                        direction = new Vector3(0, 1, 0);
                    }

                    coinDescription.Pose.Position    = origin + direction * 10 * (float)random.NextDouble();
                    coinDescription.Pose.Orientation = Quaternion.Normalize(new Quaternion(0.01f + (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()));
                    coinDescription.Velocity.Linear  = direction * (5 + 30 * (float)random.NextDouble());
                    Simulation.Bodies.Add(coinDescription);
                }
            }
            base.Update(window, camera, input, dt);
        }
示例#2
0
            public void Test(Random random, int innerIterations)
            {
                Quaternion q;

                q.X = (float)random.NextDouble() * 2 - 1;
                q.Y = (float)random.NextDouble() * 2 - 1;
                q.Z = (float)random.NextDouble() * 2 - 1;
                q.W = (float)random.NextDouble() * 2 - 1;

                Quaternion.Normalize(ref q);

                for (int i = 0; i < innerIterations; ++i)
                {
                    Matrix3x3.CreateFromQuaternion(ref q, out var r);
                    Quaternion.CreateFromRotationMatrix(ref r, out var qTest);

#if DEBUG
                    const float epsilon = 1e-6f;
                    var         lengthX = r.X.Length();
                    var         lengthY = r.Y.Length();
                    var         lengthZ = r.Z.Length();
                    Debug.Assert(
                        Math.Abs(1 - lengthX) < epsilon &&
                        Math.Abs(1 - lengthY) < epsilon &&
                        Math.Abs(1 - lengthZ) < epsilon);


                    if (qTest.X * q.X < 0)
                    {
                        Quaternion.Negate(ref qTest, out qTest);
                    }
                    Debug.Assert(
                        Math.Abs(qTest.X - q.X) < epsilon &&
                        Math.Abs(qTest.Y - q.Y) < epsilon &&
                        Math.Abs(qTest.Z - q.Z) < epsilon &&
                        Math.Abs(qTest.W - q.W) < epsilon);
#endif
                }
            }