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

Fix Star Flickering by Positioning on Unit Sphere #283

Merged
merged 7 commits into from
Dec 19, 2024
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.github.lookupgroup27.lookup.model.map

import PlanetsRepository
import android.content.Context
import android.opengl.GLES20
import android.opengl.GLSurfaceView
import android.util.Log
import com.github.lookupgroup27.lookup.R
import com.github.lookupgroup27.lookup.model.loader.StarsLoader
import com.github.lookupgroup27.lookup.model.map.planets.PlanetsRepository
import com.github.lookupgroup27.lookup.model.map.renderables.Planet
import com.github.lookupgroup27.lookup.model.map.renderables.Star
import com.github.lookupgroup27.lookup.model.map.renderables.utils.RayUtils.calculateRay
import com.github.lookupgroup27.lookup.model.map.skybox.SkyBox
import com.github.lookupgroup27.lookup.model.map.stars.StarDataRepository
import com.github.lookupgroup27.lookup.model.map.stars.StarsLoader
import com.github.lookupgroup27.lookup.util.opengl.TextureManager
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.github.lookupgroup27.lookup.model.map.planets

import android.content.Context
import com.github.lookupgroup27.lookup.R
import com.github.lookupgroup27.lookup.model.location.LocationProvider
import com.github.lookupgroup27.lookup.model.map.planets.PlanetData
import com.github.lookupgroup27.lookup.model.map.renderables.Moon
import com.github.lookupgroup27.lookup.model.map.renderables.Planet
import com.github.lookupgroup27.lookup.utils.CelestialObjectsUtils
import com.github.lookupgroup27.lookup.util.CelestialObjectsUtils
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Calendar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.lookupgroup27.lookup.model.map.renderables

import android.content.Context
import androidx.annotation.VisibleForTesting
import com.github.lookupgroup27.lookup.R
import com.github.lookupgroup27.lookup.utils.CelestialObjectsUtils
import com.github.lookupgroup27.lookup.util.CelestialObjectsUtils
import java.util.Calendar
import java.util.TimeZone

Expand Down Expand Up @@ -30,7 +31,8 @@ class Moon(
position = position,
textureId = getCurrentMoonPhaseTextureId(),
numBands = numBands,
stepsPerBand = stepsPerBand) {
stepsPerBand = stepsPerBand,
scale = 0.05f) {
/** Companion object containing moon phase calculation and texture mapping logic. */
companion object {
/**
Expand All @@ -49,7 +51,8 @@ class Moon(
* @param calendar The calendar instance to calculate the moon phase from.
* @return Resource ID for the moon phase texture.
*/
private fun getMoonPhaseTextureId(calendar: Calendar): Int {
@VisibleForTesting
fun getMoonPhaseTextureId(calendar: Calendar): Int {
// Approximate lunar cycle calculation
val year = calendar.get(Calendar.YEAR)
val month = calendar.get(Calendar.MONTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open class Planet(
protected var textureId: Int,
numBands: Int = SphereRenderer.DEFAULT_NUM_BANDS,
stepsPerBand: Int = SphereRenderer.DEFAULT_STEPS_PER_BAND,
private val scale: Float = 0.3f
private val scale: Float = 0.02f
) : Object() {

private val sphereRenderer = SphereRenderer(context, numBands, stepsPerBand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.lookupgroup27.lookup.model.map.stars

import android.content.Context
import com.github.lookupgroup27.lookup.model.location.LocationProvider
import com.github.lookupgroup27.lookup.utils.CelestialObjectsUtils
import com.github.lookupgroup27.lookup.util.CelestialObjectsUtils

/**
* Repository class to manage star data, including:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.github.lookupgroup27.lookup.model.loader
package com.github.lookupgroup27.lookup.model.map.stars

import android.content.Context
import com.github.lookupgroup27.lookup.model.map.renderables.Star
import com.github.lookupgroup27.lookup.model.map.stars.StarDataRepository

/**
* Converts star data into renderable objects for OpenGL rendering.
Expand All @@ -26,7 +25,7 @@ class StarsLoader(private val context: Context, private val repository: StarData
Star(
context = context,
position = floatArrayOf(starData.x.toFloat(), starData.y.toFloat(), starData.z.toFloat()),
size = 0.2f)
size = 0.002f)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.lookupgroup27.lookup.ui.map

import PlanetsRepository
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.ActivityInfo
Expand All @@ -15,13 +14,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.github.lookupgroup27.lookup.model.location.LocationProviderSingleton
import com.github.lookupgroup27.lookup.model.map.MapRenderer
import com.github.lookupgroup27.lookup.model.map.planets.PlanetsRepository
import com.github.lookupgroup27.lookup.model.map.stars.StarDataRepository

// FOV constants
const val DEFAULT_FOV = 45f
const val MAX_FOV = DEFAULT_FOV + 40f
const val MIN_FOV = DEFAULT_FOV - 40f

/** The ViewModel for the map screen. */
class MapViewModel(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.lookupgroup27.lookup.utils
package com.github.lookupgroup27.lookup.util

import java.time.ZoneOffset
import java.time.ZonedDateTime
Expand All @@ -7,8 +7,6 @@ import kotlin.math.floor

object CelestialObjectsUtils {

private val SCALING_FACTOR = 100

/**
* Converts Right Ascension (RA) from hours to degrees.
*
Expand Down Expand Up @@ -191,9 +189,9 @@ object CelestialObjectsUtils {
val azRad = Math.toRadians(azimuth)
val altRad = Math.toRadians(altitude)

val x = (SCALING_FACTOR * cos(altRad) * sin(azRad)).toFloat()
val y = (SCALING_FACTOR * cos(altRad) * cos(azRad)).toFloat()
val z = (SCALING_FACTOR * sin(altRad)).toFloat()
val x = (cos(altRad) * sin(azRad)).toFloat()
val y = (cos(altRad) * cos(azRad)).toFloat()
val z = (sin(altRad)).toFloat()

return Triple(x, y, z)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import com.github.lookupgroup27.lookup.R
import com.github.lookupgroup27.lookup.model.map.renderables.Moon
import java.util.Calendar
import java.util.TimeZone
import org.junit.Assert.assertEquals
import org.junit.Test

class MoonTest {

@Test
fun testGetMoonPhaseTextureId() {
val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"))

calendar.set(2024, Calendar.JULY, 6)
var textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.new_moon, textureId)

calendar.set(2024, Calendar.AUGUST, 9)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.waxing_crescent, textureId)

calendar.set(2024, Calendar.MAY, 15)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.first_quarter, textureId)

calendar.set(2021, Calendar.AUGUST, 19)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.waxing_gibbous, textureId)

calendar.set(2025, Calendar.JANUARY, 13)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.full_moon, textureId)

calendar.set(2023, Calendar.OCTOBER, 2)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.waning_gibbous, textureId)

calendar.set(2024, Calendar.JANUARY, 3)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.last_quarter, textureId)

calendar.set(2021, Calendar.MAY, 8)
textureId = Moon.getMoonPhaseTextureId(calendar)
assertEquals(R.drawable.waning_crescent, textureId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.res.AssetManager
import android.location.Location
import androidx.test.core.app.ApplicationProvider
import com.github.lookupgroup27.lookup.model.location.LocationProvider
import com.github.lookupgroup27.lookup.utils.CelestialObjectsUtils
import com.github.lookupgroup27.lookup.util.CelestialObjectsUtils
import com.google.firebase.FirebaseApp
import java.io.ByteArrayInputStream
import java.io.InputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import android.location.Location
import androidx.test.core.app.ApplicationProvider
import com.github.lookupgroup27.lookup.model.location.LocationProvider
import com.github.lookupgroup27.lookup.model.map.planets.PlanetData
import com.github.lookupgroup27.lookup.model.map.planets.PlanetsRepository
import com.google.firebase.FirebaseApp
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.lookupgroup27.lookup.ui.map

import PlanetsRepository
import android.content.Context
import android.content.pm.ActivityInfo
import android.hardware.Sensor
import android.hardware.SensorManager
import android.view.ScaleGestureDetector
import androidx.activity.ComponentActivity
import com.github.lookupgroup27.lookup.model.map.planets.PlanetsRepository
import com.github.lookupgroup27.lookup.model.map.stars.StarDataRepository
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertTrue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.lookupgroup27.lookup.utils
package com.github.lookupgroup27.lookup.util

import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
Expand Down Expand Up @@ -55,8 +55,7 @@ class CelestialObjectsUtilsTest {
* Temporary test as computeSiderealTime changes values with time emporary test as
* computeSiderealTime changes values with time
*/

/*@Test
/*@Test TODO : Remove this code ???
fun `test convertToHorizonCoordinates with Stellarium data for Vega`() {
// Given values derived from Stellarium
val ra = 279.4380 // Right Ascension in degrees (converted from 18h 37m 45.2s)
Expand Down Expand Up @@ -93,10 +92,10 @@ class CelestialObjectsUtilsTest {

// Calculated expected values manually for testing
val expectedY =
(100 * Math.cos(Math.toRadians(altitude)) * Math.cos(Math.toRadians(azimuth))).toFloat()
(Math.cos(Math.toRadians(altitude)) * Math.cos(Math.toRadians(azimuth))).toFloat()
val expectedX =
(100 * Math.cos(Math.toRadians(altitude)) * Math.sin(Math.toRadians(azimuth))).toFloat()
val expectedZ = (100 * Math.sin(Math.toRadians(altitude))).toFloat()
(Math.cos(Math.toRadians(altitude)) * Math.sin(Math.toRadians(azimuth))).toFloat()
val expectedZ = (Math.sin(Math.toRadians(altitude))).toFloat()

assertEquals(expectedX, x, 0.01f)
assertEquals(expectedY, y, 0.01f)
Expand Down
Loading