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

Mark Multiple Hotspot on an event #158

Open
sohilmathur79 opened this issue May 2, 2022 · 2 comments
Open

Mark Multiple Hotspot on an event #158

sohilmathur79 opened this issue May 2, 2022 · 2 comments

Comments

@sohilmathur79
Copy link

On Longpress event mark hotspots on that touched coordinate ,currently it is not accurate when I am doing

@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

Not 100% accurate in zoom out panorama image-

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
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

2 participants