Skip to content

Commit

Permalink
Merge pull request #317 from LookUpGroup27/feature/display-planet-fact
Browse files Browse the repository at this point in the history
feat: display planet fact
  • Loading branch information
Kenzoud authored Dec 19, 2024
2 parents 6917a3f + 017f786 commit 5abd708
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class MapRenderer(
* @param screenY The y-coordinate of the touch event on the screen.
* @return The name of the intersected planet, or null if no intersection occurred.
*/
fun getIntersectedPlanetName(screenX: Float, screenY: Float): String? {
fun getIntersectedPlanetFact(screenX: Float, screenY: Float): String? {
if (viewport[2] == 0 || viewport[3] == 0) {
Log.d("Viewport dimensions", "Viewport dimensions are invalid: ${viewport.joinToString()}")
return null
Expand All @@ -151,7 +151,7 @@ class MapRenderer(
val ray = calculateRay(screenX, screenY, camera, viewport)
for (planet in renderablePlanets) {
if (planet.checkHit(ray.origin, ray.direction)) {
return planet.name
return planet.funFact
}
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class MapSurfaceView(context: Context, private val viewModel: MapViewModel) :
renderMode = RENDERMODE_CONTINUOUSLY
}

private fun showPlanetInfo(planetName: String) {
Toast.makeText(context, "You clicked on $planetName!", Toast.LENGTH_SHORT).show()
private fun showPlanetInfo(planetFact: String) {
Toast.makeText(context, "Fun fact: $planetFact", Toast.LENGTH_SHORT).show()
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
scaleGestureDetector.onTouchEvent(event)
if (event.action == MotionEvent.ACTION_DOWN) {
val planetName = viewModel.mapRenderer.getIntersectedPlanetName(event.x, event.y)
if (planetName != null) {
showPlanetInfo(planetName)
val planetFact = viewModel.mapRenderer.getIntersectedPlanetFact(event.x, event.y)
if (planetFact != null) {
showPlanetInfo(planetFact)
} else {
Log.d("On touch event", "No planet was clicked.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ data class PlanetData(
var dec: Double = 0.0, // Declination in degrees
var cartesian: Triple<Float, Float, Float> = Triple(0.0f, 0.0f, 0.0f), // Cartesian coordinates
val textureId: Int,
val iconRes: Int = 0 // New field for the button icon
val iconRes: Int = 0, // New field for the button icon
val funFact: String = "" // New field for the planet fun fact
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,44 @@ class PlanetsRepository(
"Mercury",
"199",
textureId = R.drawable.mercury_texture,
iconRes = R.drawable.mercury_icon),
iconRes = R.drawable.mercury_icon,
funFact = "Mercury’s surface has ice on it !"),
PlanetData(
"Venus",
"299",
textureId = R.drawable.venus_texture,
iconRes = R.drawable.venus_icon),
iconRes = R.drawable.venus_icon,
funFact = "A day is longer than a year on Venus !"),
PlanetData(
"Mars", "499", textureId = R.drawable.mars_texture, iconRes = R.drawable.mars_icon),
"Mars",
"499",
textureId = R.drawable.mars_texture,
iconRes = R.drawable.mars_icon,
funFact = "Mars has the largest volcano in the solar system !"),
PlanetData(
"Jupiter",
"599",
textureId = R.drawable.jupiter_texture,
iconRes = R.drawable.jupiter_icon),
iconRes = R.drawable.jupiter_icon,
funFact = "Jupiter is a great comet catcher !"),
PlanetData(
"Saturn",
"699",
textureId = R.drawable.saturn_texture,
iconRes = R.drawable.saturn_icon),
iconRes = R.drawable.saturn_icon,
funFact = "Saturn's rings are 90% water !"),
PlanetData(
"Uranus",
"799",
textureId = R.drawable.uranus_texture,
iconRes = R.drawable.uranus_icon),
iconRes = R.drawable.uranus_icon,
funFact = "You can't stand on Uranus !"),
PlanetData(
"Neptune",
"899",
textureId = R.drawable.neptune_texture,
iconRes = R.drawable.neptune_icon)))
iconRes = R.drawable.neptune_icon,
funFact = "Neptune has supersonic winds !")))
}

/**
Expand Down Expand Up @@ -142,8 +152,8 @@ class PlanetsRepository(
context = context,
name = planetData.name,
position = floatArrayOf(position.first, position.second, position.third),
textureId = planetData.textureId // Resource ID for the planet’s texture
)
textureId = planetData.textureId, // Resource ID for the planet’s texture
funFact = planetData.funFact)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Moon(
textureId = getCurrentMoonPhaseTextureId(),
numBands = numBands,
stepsPerBand = stepsPerBand,
scale = 0.05f) {
scale = 0.05f,
funFact = "The Moon is moving away from Earth !") {
/** Companion object containing moon phase calculation and texture mapping logic. */
companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ open class Planet(
var textureId: Int,
numBands: Int = SphereRenderer.DEFAULT_NUM_BANDS,
stepsPerBand: Int = SphereRenderer.DEFAULT_STEPS_PER_BAND,
private val scale: Float = 0.02f
private val scale: Float = 0.02f,
val funFact: String = ""
) : Object() {

private val sphereRenderer = SphereRenderer(context, numBands, stepsPerBand)
Expand Down
Binary file added app/src/main/res/drawable/astro_logo3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/white_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@drawable/white_background" />
<foreground android:drawable="@drawable/astro_logo3" />
<monochrome android:drawable="@drawable/astro_logo3" />
</adaptive-icon>

0 comments on commit 5abd708

Please sign in to comment.