// Update object and camera positions based on the positions sent by ZMQ.
    void updateObjectPositions()
    {
        if (internal_state.readyToRender)
        {
            // Update camera positions

            internal_state.uavCenterOfMass = new Vector3();

            foreach (Camera_t obj_state in state.cameras)
            {
                // Get camera game object
                GameObject obj = internal_state.getGameobject(obj_state.ID, camera_template);
                // Apply translation and rotation
                Vector3 pos = ListToVector3(obj_state.position);
                obj.transform.SetPositionAndRotation(pos, ListToQuaternion(obj_state.rotation));

                // Calculate center of mass
                internal_state.uavCenterOfMass += pos;
            }

            // Adjust camera colliders such that camera colliders are at the center of mass.
            internal_state.uavCenterOfMass /= state.numCameras;

            // Get camera to cast from
            ObjectState_t internal_object_state = internal_state.getWrapperObject(state.cameras[0].ID, camera_template);

            // Get camera collider
            SphereCollider cameraCollider = internal_object_state.gameObj.GetComponent <SphereCollider>();
            // Set collider global pos to center of mass.
            cameraCollider.center = internal_state.uavCenterOfMass - internal_object_state.gameObj.transform.position;


            // Update Window positions
            foreach (Object_t obj_state in state.objects)
            {
                // Get game object
                GameObject obj = internal_state.getGameobject(obj_state.ID, obj_state.prefabID);

                // Apply translation and rotation
                obj.transform.SetPositionAndRotation(ListToVector3(obj_state.position), ListToQuaternion(obj_state.rotation));
            }
        }
    }
Exemplo n.º 2
0
    // Update window and camera positions based on the positions sent by ZMQ.
    void updateObjectPositions()
    {
        if (internal_state.readyToRender)
        {
            // Update camera positions
            foreach (Camera_t obj_state in state.cameras)
            {
                // Get camera game object
                GameObject obj = internal_state.getGameobject(obj_state.ID, camera_template);
                // Apply translation and rotation
                obj.transform.SetPositionAndRotation(ListToVector3(obj_state.position), ListToQuaternion(obj_state.rotation));
            }

            // Update Window positions
            foreach (Window_t obj_state in state.windows)
            {
                // Get camera game object
                GameObject obj = internal_state.getGameobject(obj_state.ID, window_template);
                // Apply translation and rotation
                obj.transform.SetPositionAndRotation(ListToVector3(obj_state.position), ListToQuaternion(obj_state.rotation));
            }
        }
    }