2

I'm developing ad app withthe GearVR framework in which I must show a sphere and a series of interactive points on this sphere around the camera (a 360 photo with some points on the border). I could create the sphere witha a 360 photo and put the camera in but I can't figure out how to put the points onto the sphere because they are given to me related to the photo (photo is, like, 4608 x 2304 and my point is on the image 280 x 1115). How can I transalate the x,y coordinates to the sphere? I tried many formulas but none seem to work. Here's my code, thanks in advance:

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;
    }
e_ori
  • 845
  • 1
  • 11
  • 29

0 Answers0