GearVRf在球体中的位置

时间:2016-07-01 10:52:48

标签: android position coordinates samsung-mobile gear-vr

我正在使用GearVR框架开发广告应用程序,其中我必须在相机周围的此球体上显示球体和一系列交互点(边框上有一些点的360照片)。我可以创建一个360度照片的球体并将相机放入,但我无法弄清楚如何将这些点放到球体上,因为它们是给我的照片相关的(照片就像,4608 x 2304我的观点是图像280 x 1115)。如何将x,y坐标转换为球体? 我尝试了很多公式,但似乎都没有。这是我的代码,提前谢谢:

private int wSphere = 4608;
private int hSphere = 2304;

@Override
public void onInit(GVRContext gvrContext) {
    GVRScene scene = gvrContext.getNextMainScene();

    GVRSphereSceneObject sphereObject = null;
    Future<GVRTexture> texture = gvrContext.loadFutureTexture(new GVRAndroidResource(gvrContext, R.raw.office));
    sphereObject = new GVRSphereSceneObject(gvrContext, false, texture);
    sphereObject.getTransform().setScale(50f, 50f, 50f);
    Future<GVRTexture> futureTexture = gvrContext.loadFutureTexture(new GVRAndroidResource(gvrContext, R.raw.texture));
    GVRMaterial material = new GVRMaterial(gvrContext);
    material.setMainTexture(futureTexture);

    float normX = (280f);
    float normY = (1115f);

    HashMap<String, Float> positions = xyToXYZ(normX, normY, 50);

    GVRCubeSceneObject cubeObject = new GVRCubeSceneObject(gvrContext, true, material);

    cubeObject.getTransform().setScale(5.5f, 5.5f, 5.5f);

    cubeObject.getTransform().setPosition(positions.get("x"), positions.get("z"), positions.get("y"));
    cubeObject.getRenderData().setMaterial(material);

    scene.addSceneObject(sphereObject);
    scene.addSceneObject(cubeObject);
}

public HashMap<String, Float> xyToXYZ(float x, float y, float r) {
        HashMap<String, Float> map = new HashMap<String, Float>();

        float theta = (float) (-2* Math.atan((Math.sqrt(Math.pow(x,2) + Math.pow(y,2)))/(2*r)) + 90);
        float phi = (float) Math.atan((x/(-y)));

        float sinTheta = (float) Math.sin(theta);
        float cosTheta = (float) Math.cos(theta);
        float sinPhi = (float) Math.sin(phi);
        float cosPhi = (float) Math.cos(phi);

        float nX = (float) (cosTheta * sinPhi);
        float nY = (float) cosPhi * cosTheta;
        float nZ = (float) sinTheta;

        map.put("x", nX);
        map.put("y", nY);
        map.put("z", nZ);

        return map;
    }

0 个答案:

没有答案