Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        //importing section for Electromagnetic Effects
        cam                   = Camera.main;
        cameraMove2           = cam.GetComponent <cameraMove2>();
        cubeMove2             = this.GetComponent <cubeMove2>();
        cubeMove2pointcharge1 = GameObject.Find("Point_charge").GetComponent <cubeMove2>();
        cubeMove2pointcharge2 = GameObject.Find("Point_charge2").GetComponent <cubeMove2>();

        //Update the latest positions of Each point source
        pointchargeposworldframe3  = cubeMove2pointcharge1.objposworldframe3;
        pointcharge2posworldframe3 = cubeMove2pointcharge2.objposworldframe3;

        //Electric charge of the point source.
        q1 = 1.0f;
        q2 = 0.0f;
        m1 = 0.0f;
        m2 = 0.0f;
        //an Arrow's Position Vector mesured from Each point source in World frame
        Vector3 r = cubeMove2pointcharge1.Lobject * rR(cubeMove2.objposworldframe3, pointchargeposworldframe3);
        Vector3 R = cubeMove2pointcharge2.Lobject * rR(cubeMove2.objposworldframe3, pointcharge2posworldframe3);

        //Player's Position Vector mesured from Each point source in World frame
        Vector3 rp = cubeMove2pointcharge1.Lobject * rR(cameraMove2.playrposworldframe3, pointchargeposworldframe3);
        Vector3 Rp = cubeMove2pointcharge2.Lobject * rR(cameraMove2.playrposworldframe3, pointcharge2posworldframe3);

        //Creating Electromagnetic Tensor for an Arrow's position in world frame
        Matrix4x4 F1 = cubeMove2pointcharge1.Lobject.inverse * K(field(cubeMove2pointcharge1.Lobject * r, q1), field(cubeMove2pointcharge1.Lobject * r, m1)) * cubeMove2pointcharge1.Lobject.inverse;
        Matrix4x4 F2 = cubeMove2pointcharge2.Lobject.inverse * K(field(cubeMove2pointcharge1.Lobject * R, q2), field(cubeMove2pointcharge1.Lobject * R, m2)) * cubeMove2pointcharge2.Lobject.inverse;

        F = Sum(F1, F2);
        //Creating Electromagnetic Tensor for an Arrow's position in Player's rest frame
        Matrix4x4 f = cameraMove2.Lplayer * F * cameraMove2.Lplayer;

        efield = new Vector3(f.m03, f.m13, f.m23);
        this.transform.localScale = new Vector3(1, efield.magnitude / 20, 1);

        if (vp(efield, new Vector3(0, 0, 1)) == new Vector3(0, 0, 0))
        {
            Vector3 up1 = vp(efield, new Vector3(0, 1, 0));
            // 方向を、回転情報に変換
            Quaternion erotation = Quaternion.LookRotation(up1, efield);
            transform.rotation = erotation;
        }
        else
        {
            Vector3 up1 = vp(efield, new Vector3(0, 0, 1));
            // 方向を、回転情報に変換
            Quaternion erotation = Quaternion.LookRotation(up1, efield);
            transform.rotation = erotation;
        }

        //Creating Electromagnetic Tensor for Player's position in world frame
        Matrix4x4 G1 = cubeMove2pointcharge1.Lobject.inverse * K(field(cameraMove2.LTrans(cubeMove2pointcharge1.objvelworldframe3) * rp, q1), field(cameraMove2.LTrans(cubeMove2pointcharge1.objvelworldframe3) * rp, m1)) * cubeMove2pointcharge1.Lobject.inverse;
        Matrix4x4 G2 = cubeMove2pointcharge2.Lobject.inverse * K(field(cameraMove2.LTrans(cubeMove2pointcharge1.objvelworldframe3) * Rp, q2), field(cameraMove2.LTrans(cubeMove2pointcharge1.objvelworldframe3) * Rp, m2)) * cubeMove2pointcharge2.Lobject.inverse;

        G = Sum(G1, G2);
    }
Ejemplo n.º 2
0
    private Vector3 objectposworldframe4;     //object's world frame position

    public void Awake()
    {
        Quaternion q = centralObject.transform.rotation.normalized;

        //Defining Rotation Matrix by using Quartanion
        R     = Matrix4x4.identity;
        R.m00 = q.x * q.x - q.y * q.y - q.z * q.z + q.w * q.w;
        R.m01 = 2 * (q.x * q.y - q.z * q.w);
        R.m02 = 2 * (q.x * q.z + q.y * q.w);
        R.m10 = 2 * (q.x * q.z + q.y * q.w);
        R.m11 = -q.x * q.x + q.y * q.y - q.z * q.z + q.w * q.w;
        R.m12 = 2 * (q.y * q.z - q.x * q.w);
        R.m20 = 2 * (q.x * q.z - q.y * q.w);
        R.m21 = 2 * (q.y * q.z + q.x * q.w);
        R.m22 = -q.x * q.x - q.y * q.y + q.z * q.z + q.w * q.w;

        cam         = Camera.main;
        cameraMove2 = cam.GetComponent <cameraMove2>();
        cubeMove2   = centralObject.GetComponent <cubeMove2>();

        //importing the position of central object in world frame from cubeMove's four vector x4
        centralobjectposworldframe4 = cubeMove2.objposworldframe4;
        centralobjectposworldframe3 = centralobjectposworldframe4;

        //importing Lorentz transformation(Lplayer) and its inverse transformation from cameraMove
        Lplayer        = cameraMove2.Lplayer;
        Lplayerinverse = cameraMove2.Lplayer.inverse;

        //importing basic meshdata(vertex list)
        this.meshFilter       = this.GetComponent <MeshFilter>();
        this.originalvertices = this.meshFilter.mesh.vertices;
        this.vertices         = this.meshFilter.mesh.vertices;

        //objectposworldframe4 = Lplayerinverse * centralobjectposworldframe4;//body's position in world frame

        centralobjectvelworld3   = new Vector3(0.0f, 0.0f, 0.0f);
        centralobjectvelworld4   = centralobjectvelworld3;
        centralobjectvelworld4.w = 1.0f;
    }