Skip to content

Instantly share code, notes, and snippets.

@Lucodivo
Lucodivo / ObliqueProjectionMatrix.cpp
Created July 31, 2021 23:23
Oblique Projection Matrix for Portals
/*
* // NOTE: Oblique View Frustum Depth Projection and Clipping by Eric Lengyel (Terathon Software)
* Arguments:
* mat4 perspectiveMat: Perspective matrix that is being used for the rest of the scene
* vec3 planeNormal_viewSpace: Plane normal in view space. MUST be normalized. This is a normal that points INTO the frustum, NOT one that is generally pointing towards the camera.
* vec3 planePos_viewSpace: Any position on the plane in view space.
*/
mat4 obliquePerspective(const mat4& perspectiveMat, vec3 planeNormal_viewSpace, vec3 planePos_viewSpace, f32 far) {
mat4 persp = perspectiveMat;
@Lucodivo
Lucodivo / gist:175ca905505347f4e9095619b7ad846a
Last active June 16, 2024 08:18
Performance Test: Spacer vs. Padding
package com.packagename.spacervspadding
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@Lucodivo
Lucodivo / multi_if_let.kt
Last active September 12, 2024 19:56
Kotlin: multiple if let
// taken from Jayson Minard's answer to the
// StackOverflow question "Multiple variable let in Kotlin" by Daniel Gomez Rico
// source: https://stackoverflow.com/a/35522422/3926619
// 2
inline fun <T1: Any, T2: Any, R: Any> multiIfLet(p1: T1?, p2: T2?, block: (T1, T2)->R?): R? {
return if (p1 != null && p2 != null) block(p1, p2) else null
}
// 3
inline fun <T1: Any, T2: Any, T3: Any, R: Any> multiIfLet(p1: T1?, p2: T2?, p3: T3?, block: (T1, T2, T3)->R?): R? {
@Lucodivo
Lucodivo / viewmodel_to_ui_communication_1.kt
Last active September 17, 2024 16:46
ViewModel to UI Communication: Part 1
// enough time to prevent flows from timing out on basic configuration changes
const val STATEIN_TIMEOUT_MILLIS = 5_000L
// ViewModel
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val purgeRepository: PurgeRepository,
private val userPreferencesRepository: UserPreferencesRepository,
): ViewModel() {
@Lucodivo
Lucodivo / viewmodel_to_ui_communication_2_data_class_and_interface.kt
Last active September 17, 2024 16:47
ViewModel to UI Communication: Part 2
// UI state enums
enum class SettingsDropdownMenuState {
None,
DarkMode,
ColorPalette,
HighContrast,
Typography,
ImageQuality,
}
@Lucodivo
Lucodivo / viewmodel_to_ui_communication_3_ui_events_and_udf.kt
Last active September 17, 2024 16:47
ViewModel to UI communication: Part 3 - UI Events & UI Effects
// UI state enums
enum class SettingsDropdownMenuState {
None,
DarkMode,
ColorPalette,
HighContrast,
Typography,
ImageQuality,
}
@Lucodivo
Lucodivo / viewmodel_to_ui_communication_4_state_management_with_compose.kt
Last active September 17, 2024 16:48
ViewModel to UI Communication: Part 4 - Compose state management
// UI state enums
enum class SettingsDropdownMenuState {
None,
DarkMode,
ColorPalette,
HighContrast,
Typography,
ImageQuality,
}
@Lucodivo
Lucodivo / viewmodel_to_ui_communication_4_1_stateIn_fix.kt
Last active September 17, 2024 16:49
ViewModel to UI Communication: Part 4.1 - stateIn() fix
// UI state enums
enum class SettingsDropdownMenuState {
None,
DarkMode,
ColorPalette,
HighContrast,
Typography,
ImageQuality,
}
@Lucodivo
Lucodivo / viewmodel_to_ui_communication_5_compose_ui_state_manager.kt
Created September 17, 2024 16:51
ViewModel to UI Communication: Part 5 - Compose UI State Manager
// UI state enums
enum class SettingsDropdownMenuState {
None,
DarkMode,
ColorPalette,
HighContrast,
Typography,
ImageQuality,
}