Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / Difference between Bresenham line vs DDA line algorithms.md
Last active December 24, 2022 20:36
Difference between Bresenham line vs DDA line algorithms?

// chatGPT

Difference between Bresenham line vs DDA line algorithms?

Bresenham's line algorithm and Digital Differential Analyzer (DDA) line algorithm are two popular algorithms for drawing a line on a computer screen. Both algorithms are used to determine which pixels should be turned on to form a straight line on a display device.

Bresenham's algorithm is an incremental method, which means that it determines the next pixel to be plotted based on the previously plotted pixel. It works by taking advantage of the fact that the slope of a line is constant and iteratively incrementing or decrementing the x or y coordinate of the line to get to the next pixel. This algorithm is efficient because it only uses integer arithmetic and makes use of the error term to determine the next pixel to be plotted.

DDA line algorithm is a digital method for drawing a line. It works by calculating the slope of the line and the difference between the x and y coordinates of the line. It then iteratively increments the x or

@unitycoder
unitycoder / Reciprocal.md
Created December 24, 2022 20:58
What is Reciprocal?

// chatGPT

What is Reciprocal?

The reciprocal of a number is 1 divided by that number. For example, the reciprocal of 4 is 1/4, and the reciprocal of 3 is 1/3.

In mathematical notation, the reciprocal of a number x is written as 1/x.

Reciprocals are often used in mathematics and computer science to simplify or transform expressions. For example, if you want to divide two numbers a and b, you can multiply a by the reciprocal of b instead, which is the same as dividing a by b. This can be useful when you want to avoid using the division operator, which can be slow or prone to errors in some contexts.

Here's an example of using the reciprocal to divide two numbers:

@unitycoder
unitycoder / Little Endian vs. Big Endian.md
Last active December 25, 2022 07:49
Little Endian vs. Big Endian

// chatGPT

Endianness refers to the order in which bytes are stored in a computer's memory. There are two main types of endianness: little-endian and big-endian.

In little-endian systems, the least significant byte (LSB) is stored at the lowest memory address and the most significant byte (MSB) is stored at the highest memory address. For example, the 32-bit integer 0x12345678 would be stored as follows in little-endian order:

78 56 34 12

In big-endian systems, the MSB is stored at the lowest memory address and the LSB is stored at the highest memory address. Using the same example, the integer 0x12345678 would be stored as follows in big-endian order:

@unitycoder
unitycoder / gyrp-drifting.md
Created January 2, 2023 17:29
Gyro Camera has too much drifting:

// chatGPT If the camera orientation is drifting (i.e., slowly changing over time without input from the user), it could be due to several factors. Here are some possible causes of drifting and some things you can try to reduce or eliminate it:

  • Bias in the gyroscope readings: Gyroscopes can have a small constant offset (bias) in their readings, which can cause the orientation to drift over time. To reduce the effect of bias, you can try using a complementary filter or Kalman filter to fuse the gyroscope data with data from other sensors, such as an accelerometer.
  • Noise in the gyroscope readings: Gyroscopes can also be affected by noise, which can cause the orientation to fluctuate. To reduce the effect of noise, you can try applying a low-pass filter to the gyroscope data.
  • Gyroscope drift: Gyroscopes can drift over time, which can cause the orientation to drift. This can be caused by various factors, such as temperature changes, mechanical wear, and so on. There is no straightforward way to fix drift, b
@unitycoder
unitycoder / ScriptFileWatcher.cs
Created January 8, 2023 11:09 — forked from Asuta/ScriptFileWatcher.cs
Modify the version to be directly available, monitor all folders containing C# scripts under assets, and directly copy them to any directory under assets
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace Naninovel
# Simulator for depth comparison error (i.e. z-fighting)
# Nathan Reed, June 2015
# Written for Python 3.4; requires numpy
import math
import numpy as np
import optparse
# Parse command-line options
parser = optparse.OptionParser()
@unitycoder
unitycoder / ExampleInterface.cs
Created January 9, 2023 13:01 — forked from James-Frowen/ExampleInterface.cs
Unity3d, How to show an interface field in Inspector
namespace JamesFrowen
{
public interface ISomeInterface
{
void SomeMethod();
}
[System.Serializable]
public class SomeInterfaceWrapper : InterfaceWrapper<ISomeInterface>
{
@unitycoder
unitycoder / PixelDot.shader
Created January 10, 2023 09:47 — forked from EntranceJew/PixelDot.shader
Renders a screen-aligned, distance-independent, resolution-independent, pixel-perfect quad in Unity. Use it with the built-in quad mesh. You don't have to rotate or scale the mesh renderer, the shader will take care of it.
Shader "FX/PixelDot"
{
Properties
{
[NoScaleOffset] _MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
_Size ("Pixel Size", Range(1, 64)) = 1
}
SubShader
{
@unitycoder
unitycoder / CustomInterfaceDrawer.cs
Created January 10, 2023 09:51
unity how to make inspector property drawer for custom interface?
// chatGPT
// in Unity, you can create a custom property drawer for a class or interface by creating a script that inherits from UnityEditor.PropertyDrawer and overriding the OnGUI() method. In the OnGUI() method, you can write the custom code to handle drawing the interface fields in the Unity inspector.
// Here's an example of a property drawer for a custom interface called ICustomInterface:
// Make sure this script is in a folder named "Editor" so Unity recognize it as an Editor script.
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ICustomInterface))]
public class CustomInterfaceDrawer : PropertyDrawer
@unitycoder
unitycoder / FOV Depth.shader
Created January 11, 2023 10:28
Raycast FOV cone
// https://forum.unity.com/threads/using-a-camera-to-do-a-fan-of-raycasts.512817/#post-8721729
Shader "FOV Depth"
{
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100
 
        Pass
        {