Esempio n. 1
0
    void FixedPointCSTest_Matrix2()
    {
        //MoveObject obj = new MoveObject();
        //F64Vec2 pos = F64Vec2.Zero;
        //F64Vec2 heading = F64Vec2.Right; //1,0
        //F64Vec2 side = F64Vec2.Up; //0,1

        F64Matrix3x3 m = new F64Matrix3x3();
        //F64Vec2 point = F64Vec2.FromFloat(2, 3);
        //F64Vec2 point2 = m.PointToLocalSpace(point,
        //                        heading,
        //                        side,
        //                        pos);
        //Debug.LogError(point2.X.Float + " " + point2.Y.Float);

        MoveObject obj = new MoveObject();

        obj.SetPos(F64Vec3.Zero);
        obj.SetDir(new F64Vec3(1, 0, 0));
        //var f = F64Vec3.RotateY(obj.forward, new FixMath.F64(-90));
        //Debug.LogError(obj.forward + " " + F64Vec3.Normalize(f).ToUnityVector3());

        F64Vec3 check = new F64Vec3(2, 0, 3);
        var     r3    = F64Vec3.PointToLocalSpace2D(check, obj.forward, obj.left, obj.GetPos());

        //Debug.LogError(check2.X.Float + " " + check2.Y.Float);
        Debug.LogError(r3);
    }
Esempio n. 2
0
    void TestFCS_P2()
    {
        Vector3 av = new Vector3(100, 0, 20);

        MoveObject obj = new MoveObject();

        obj.SetPos(F64Vec3.Zero);
        obj.SetDir(new F64Vec3(0, 0, 1));
        obj.moveData.detectionLen   = new F64(5);
        obj.moveData.detectionWidth = new F64(0.8);

        GameObjectGetter tankGetter = ResHelper.LoadGameObject("prefabs/tank");
        GameObject       tankGo     = tankGetter.Get();

        tankGo.transform.position = obj.GetPos().ToUnityVector3();
        tankGo.transform.forward  = obj.GetDir().ToUnityVector3();
        GameObject.Instantiate <GameObject>(tankGo);

        for (int i = 0; i < 3; i++)
        {
            F64Vec3 newDir = F64Vec3.RotateY(obj.GetDir(), new F64(30));
            obj.SetDir(F64Vec3.Normalize(newDir));
            obj.SetPos(obj.GetPos() + (newDir * new F64(5)));
            tankGo.transform.position = obj.GetPos().ToUnityVector3();
            tankGo.transform.forward  = obj.GetDir().ToUnityVector3();
            GameObject.Instantiate <GameObject>(tankGo);
        }
        Debug.LogError("Tank " + obj.GetPos() + " " + obj.GetPos().ToUnityVector3());

        F64Vec3 localAv = F64Vec3.PointToLocalSpace2D(F64Vec3.FromUnityVector3(av),
                                                      obj.forward, obj.left, obj.GetPos());
        F64Matrix3x3 m = new F64Matrix3x3();

        F64Vec2 worldAv = m.PointToWorldSpace(new F64Vec2(localAv.X, localAv.Z),
                                              new F64Vec2(obj.forward.X, obj.forward.Z),
                                              new F64Vec2(obj.left.X, obj.left.Z),
                                              new F64Vec2(obj.GetPos().X, obj.GetPos().Z));
        F64Vec3 worldAv3 = new F64Vec3(worldAv.X, F64.Zero, worldAv.Y);

        Debug.LogError("worldAv " + worldAv + " " + worldAv3.ToUnityVector3());

        F64Vec3 nworldAv3 = F64Vec3.PointToWorldSpace2D(localAv, obj.forward, obj.left, obj.GetPos());

        Debug.LogError("nworldAv3 " + nworldAv3 + " " + nworldAv3.ToUnityVector3());
    }
Esempio n. 3
0
    void FixedPointCSTest_Matrix()
    {
        //MoveObject obj = new MoveObject();
        F64Vec2 pos     = F64Vec2.Zero;
        F64Vec2 heading = F64Vec2.Right; //1,0
        F64Vec2 side    = F64Vec2.Up;    //0,1

        F64Matrix3x3 m      = new F64Matrix3x3();
        F64Vec2      point  = F64Vec2.FromFloat(2, 3);
        F64Vec2      point2 = m.PointToLocalSpace(point,
                                                  heading,
                                                  side,
                                                  pos);

        Debug.LogError(point2.X.Float + " " + point2.Y.Float);

        F64Vec3 forward = new F64Vec3(1, 0, 0);
        F64Vec3 right   = F64Vec3.RotateY(forward, new FixMath.F64(90));

        Debug.LogError(forward.ToUnityVector3() + " " + F64Vec3.Normalize(right).ToUnityVector3());
        Debug.LogError(F64Vec3.Normalize(F64Vec3.Cross(forward, right)).ToUnityVector3());

        MoveObject obj = new MoveObject();

        obj.SetPos(F64Vec3.Zero);
        obj.SetDir(new F64Vec3(1, 0, 0));
        var f = F64Vec3.RotateY(obj.forward, new FixMath.F64(90));

        Debug.LogError(obj.forward + " " + F64Vec3.Normalize(f).ToUnityVector3());

        F64Vec3 check = F64Vec3.FromFloat(2, 0, 3);
        //var r = obj.PointToLocalSpace2D(check);
        F64Vec2 check2 = m.PointToLocalSpace(new F64Vec2(check.X, check.Z),
                                             new F64Vec2(obj.forward.X, obj.forward.Z),
                                             new F64Vec2(f.X, f.Z),
                                             new F64Vec2(obj.GetPos().X, obj.GetPos().Y));

        Debug.LogError(check2.X.Float + " " + check2.Y.Float);

        //Debug.LogError(check2.X.Float + " " + check2.Y.Float);
    }
Esempio n. 4
0
    void TestTurn()
    {
        Debug.LogError(new F64(1.3d) + new F64(0.1d));
        Debug.LogError(new F64(0d));

        MoveObject obj = new MoveObject();

        obj.SetPos(F64Vec3.Zero);
        obj.SetDir(new F64Vec3(0, 0, 1));
        obj.moveData.detectionLen   = new F64(5);
        obj.moveData.detectionWidth = new F64(0.8);

        GameObjectGetter tankGetter = ResHelper.LoadGameObject("prefabs/tank");
        GameObject       tankGo     = tankGetter.Get();

        tankGo.transform.position = obj.GetPos().ToUnityVector3();
        tankGo.transform.forward  = obj.GetDir().ToUnityVector3();
        GameObject.Instantiate <GameObject>(tankGo);

        for (int i = 0; i < 3; i++)
        {
            F64Vec3 newDir = F64Vec3.RotateY(obj.GetDir(), new F64(30));
            obj.SetDir(F64Vec3.Normalize(newDir));
            obj.SetPos(obj.GetPos() + (newDir * new F64(5)));
            tankGo.transform.position = obj.GetPos().ToUnityVector3();
            tankGo.transform.forward  = obj.GetDir().ToUnityVector3();
            GameObject.Instantiate <GameObject>(tankGo);
        }

        Vector3 av      = new Vector3(100, 0, 20);
        F64Vec3 localAv = F64Vec3.PointToLocalSpace2D(F64Vec3.FromUnityVector3(av),
                                                      obj.forward, obj.left, obj.GetPos());

        Debug.LogError("world obj=" + obj.GetPos().ToUnityVector3() + "world av=" + av + "loc av " + localAv.ToUnityVector3());

        F64Matrix3x3 m = new F64Matrix3x3();
        //F64Vec2 localAv2 = localAv.ToF64Vec2();
        //F64Vec2 forward2 = obj.forward.ToF64Vec2();
        //F64Vec2 left2 = obj.left.ToF64Vec2();
        F64Vec2 localAv2 = F64Vec2.FromFloat(88.2f, 13.2f);
        F64Vec2 forward2 = F64Vec2.FromFloat(1f, 0f);
        F64Vec2 left2    = F64Vec2.FromFloat(0f, 1f);
        F64Vec2 worldAv2 = m.VectorToWorldSpace(localAv2, forward2, left2);
        F64Vec3 worldAv3 = F64Vec3.FromF64Vec2(worldAv2);

        Debug.LogError("m convt to world " + worldAv3.ToUnityVector3() + " " + worldAv3);

        GameObject cube     = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        F64        radius   = F64.Half;
        F64        foffsetX = F64.One;
        F64        foffsetZ = obj.moveData.detectionWidth + radius + new F64(-0.1);
        F64Vec3    fcubePos = new F64Vec3(obj.GetPos().X + foffsetX, obj.GetPos().Y, obj.GetPos().Z + foffsetZ);

        cube.transform.position = fcubePos.ToUnityVector3();
        F64Vec3 flocalCube = F64Vec3.PointToLocalSpace2D(fcubePos,
                                                         obj.forward, obj.left, obj.GetPos());

        Debug.LogError("world obj=" + obj.GetPos().ToUnityVector3() + "world cube=" + fcubePos + "loc cubePos " + flocalCube.ToUnityVector3());
        Debug.LogError("world obj=" + obj.GetPos().ToUnityVector3() + "world cube=" + fcubePos + "loc cubePos " + flocalCube);
        fff(obj, fcubePos, F64.Half);

        //Mathf.Approximately()
    }