Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotspot on Click #155

Open
mohdDanishCode opened this issue Apr 26, 2022 · 3 comments
Open

Hotspot on Click #155

mohdDanishCode opened this issue Apr 26, 2022 · 3 comments

Comments

@mohdDanishCode
Copy link

mohdDanishCode commented Apr 26, 2022

Not Able to get the actual touch coordinate of the panorama image
create a hotspot with GestureDetector - on long press on the Screen

@stale
Copy link

stale bot commented Jun 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

@stale stale bot added the stale label Jun 4, 2023
@gouravide
Copy link

override fun onLongPress(e: MotionEvent) {

    val x = e.x
    val y = e.y
    val screenWidth = resources.displayMetrics.widthPixels
    val screenHeight = resources.displayMetrics.heightPixels
    val normalizedX = x / screenWidth
    val normalizedY = y / screenHeight

    addHotspotAt(normalizedX, normalizedY, screenWidth, screenHeight)
    Toast.makeText(this, "${normalizedX}, ${screenHeight}", Toast.LENGTH_SHORT).show()
}

private fun addHotspotAt(
    normalizedX: Float, normalizedY: Float, screenWidth: Int, screenHeight: Int
) {
    // These values would ideally come from your panorama viewer or camera settings
    val currentYaw = plManager.panorama.camera.yaw
    val currentPitch = plManager.panorama.camera.pitch
    val fov = plManager.panorama.camera.fov  // Current FOV considering zoom
    val aspectRatio = screenWidth.toFloat() / screenHeight

    // Convert normalized screen coordinates to changes in yaw and pitch
    val yawChange = (normalizedX - 0.5f) * fov
    val pitchChange = (0.5f - normalizedY) * (fov / aspectRatio)

    // Calculate new yaw and pitch for the hotspot
    val hotspotYaw = (currentYaw + yawChange) % 360
    val hotspotPitch = currentPitch + pitchChange
    // Ensure pitch stays within bounds [-90, 90]
    val clampedPitch = hotspotPitch.coerceIn(-90f, 90f)

    // Now, create your hotspot at this new yaw and pitch
    createHotspot(hotspotPitch = clampedPitch, hotspotYaw = hotspotYaw)
}

private fun createHotspot(hotspotPitch: Float, hotspotYaw: Float) {
    val hotspot = ActionPLHotspot(
        this,
        System.currentTimeMillis(),
        PLImage(BitmapFactory.decodeResource(resources, R.raw.hotspot)),
        hotspotPitch,
        hotspotYaw,
        PLConstants.kDefaultHotspotSize,
        PLConstants.kDefaultHotspotSize
    )
    plManager.panorama.addHotspot(hotspot)
}

@stale stale bot removed the stale label Mar 12, 2024
@LSE-AP
Copy link

LSE-AP commented Jan 30, 2025

@gouravide are you sure the code is correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants